cl: call llgo/ssa.CType/CFuncDecl

This commit is contained in:
xushiwei
2024-05-03 16:00:31 +08:00
parent afd3d40348
commit 4a5c8d3fbb
3 changed files with 43 additions and 26 deletions

View File

@@ -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