cl: call llgo/ssa.CType/CFuncDecl
This commit is contained in:
@@ -177,15 +177,18 @@ func (p *context) compileMethods(pkg llssa.Package, typ types.Type) {
|
||||
// Global variable.
|
||||
func (p *context) compileGlobal(pkg llssa.Package, gbl *ssa.Global) {
|
||||
typ := gbl.Type()
|
||||
name, isDef := p.varName(gbl.Pkg.Pkg, gbl)
|
||||
name, vtype := p.varName(gbl.Pkg.Pkg, gbl)
|
||||
if ignoreName(name) || checkCgo(gbl.Name()) {
|
||||
return
|
||||
}
|
||||
if debugInstr {
|
||||
log.Println("==> NewVar", name, typ)
|
||||
}
|
||||
if vtype == cVar {
|
||||
typ = llssa.CType(typ)
|
||||
}
|
||||
g := pkg.NewVar(name, typ)
|
||||
if isDef {
|
||||
if vtype == goVar {
|
||||
g.Init(p.prog.Null(g.Type))
|
||||
}
|
||||
}
|
||||
@@ -200,6 +203,9 @@ func (p *context) compileFunc(pkg llssa.Package, pkgTypes *types.Package, f *ssa
|
||||
if debugInstr {
|
||||
log.Println("==> NewFunc", name, "type:", sig.Recv(), sig)
|
||||
}
|
||||
if ftype == cFunc {
|
||||
sig = llssa.CFuncDecl(sig)
|
||||
}
|
||||
fn := pkg.NewFunc(name, sig)
|
||||
p.inits = append(p.inits, func() {
|
||||
p.fn = fn
|
||||
|
||||
12
cl/import.go
12
cl/import.go
@@ -220,12 +220,18 @@ func (p *context) funcName(pkg *types.Package, fn *ssa.Function, ignore bool) (s
|
||||
return name, goFunc
|
||||
}
|
||||
|
||||
func (p *context) varName(pkg *types.Package, v *ssa.Global) (vName string, isDef bool) {
|
||||
const (
|
||||
ignoredVar = iota
|
||||
goVar
|
||||
cVar
|
||||
)
|
||||
|
||||
func (p *context) varName(pkg *types.Package, v *ssa.Global) (vName string, vtype int) {
|
||||
name := llssa.FullName(pkg, v.Name())
|
||||
if v, ok := p.link[name]; ok {
|
||||
return v, false
|
||||
return v, cVar
|
||||
}
|
||||
return name, true
|
||||
return name, goVar
|
||||
}
|
||||
|
||||
// funcOf returns a function by name and set ftype = goFunc, cFunc, etc.
|
||||
|
||||
Reference in New Issue
Block a user