process //export with initLink
This commit is contained in:
23
cl/import.go
23
cl/import.go
@@ -310,7 +310,10 @@ func (p *context) initLinkname(line string, f func(inPkgName string) (fullName s
|
||||
p.initLink(line, len(llgolink), f)
|
||||
return hasLinkname
|
||||
} else if strings.HasPrefix(line, export) {
|
||||
p.initCgoExport(line, len(export), f)
|
||||
// rewrite //export FuncName to //export FuncName FuncName
|
||||
funcName := strings.TrimSpace(line[len(export):])
|
||||
line = line + " " + funcName
|
||||
p.initLink(line, len(export), f)
|
||||
return hasLinkname
|
||||
} else if strings.HasPrefix(line, directive) {
|
||||
// skip unknown annotation but continue to parse the next annotation
|
||||
@@ -319,24 +322,13 @@ func (p *context) initLinkname(line string, f func(inPkgName string) (fullName s
|
||||
return noDirective
|
||||
}
|
||||
|
||||
func (p *context) initCgoExport(line string, prefix int, f func(inPkgName string) (fullName string, isVar, ok bool)) {
|
||||
name := strings.TrimSpace(line[prefix:])
|
||||
if fullName, _, ok := f(name); ok {
|
||||
p.cgoExports[fullName] = name // TODO(xsw): why not use prog.SetLinkname?
|
||||
}
|
||||
}
|
||||
|
||||
func (p *context) initLink(line string, prefix int, f func(inPkgName string) (fullName string, isVar, ok bool)) {
|
||||
text := strings.TrimSpace(line[prefix:])
|
||||
if idx := strings.IndexByte(text, ' '); idx > 0 {
|
||||
inPkgName := text[:idx]
|
||||
if fullName, isVar, ok := f(inPkgName); ok {
|
||||
if fullName, _, ok := f(inPkgName); ok {
|
||||
link := strings.TrimLeft(text[idx+1:], " ")
|
||||
if isVar || strings.Contains(link, ".") { // eg. C.printf, C.strlen, llgo.cstr
|
||||
p.prog.SetLinkname(fullName, link)
|
||||
} else {
|
||||
p.prog.SetLinkname(fullName, "C."+link)
|
||||
}
|
||||
p.prog.SetLinkname(fullName, link)
|
||||
} else {
|
||||
fmt.Fprintln(os.Stderr, "==>", line)
|
||||
fmt.Fprintf(os.Stderr, "llgo: linkname %s not found and ignored\n", inPkgName)
|
||||
@@ -523,6 +515,9 @@ func (p *context) funcName(fn *ssa.Function) (*types.Package, string, int) {
|
||||
if checkCgo(fname) && !cgoIgnored(fname) {
|
||||
return nil, fname, llgoInstr
|
||||
}
|
||||
if strings.HasPrefix(fname, "_cgoexp_") {
|
||||
return nil, fname, ignoredFunc
|
||||
}
|
||||
if isCgoExternSymbol(fn) {
|
||||
if _, ok := llgoInstrs[fname]; ok {
|
||||
return nil, fname, llgoInstr
|
||||
|
||||
Reference in New Issue
Block a user