diff --git a/cl/_testgo/strucintf/out.ll b/cl/_testgo/strucintf/out.ll index 2bfabedd..b8dd18f3 100644 --- a/cl/_testgo/strucintf/out.ll +++ b/cl/_testgo/strucintf/out.ll @@ -110,6 +110,7 @@ _llgo_2: ; preds = %_llgo_3, %_llgo_1 %47 = extractvalue { { i64 }, i1 } %45, 1 br i1 %47, label %_llgo_4, label %_llgo_6 + _llgo_3: ; preds = %_llgo_0 %48 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %49 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %48, i32 0, i32 0 diff --git a/ssa/decl.go b/ssa/decl.go index f859563f..2243e975 100644 --- a/ssa/decl.go +++ b/ssa/decl.go @@ -238,6 +238,13 @@ func newParams(fn Type, prog Program) (params []Type, hasVArg bool) { return } +/* +// Name returns the function's name. +func (p Function) Name() string { + return p.impl.Name() +} +*/ + // Params returns the function's ith parameter. func (p Function) Param(i int) Expr { i += p.base // skip if hasFreeVars diff --git a/ssa/interface.go b/ssa/interface.go index 374ce102..14ffe0fa 100644 --- a/ssa/interface.go +++ b/ssa/interface.go @@ -20,6 +20,7 @@ import ( "go/token" "go/types" "log" + "unsafe" "github.com/goplus/llgo/ssa/abi" "github.com/goplus/llvm" @@ -44,7 +45,8 @@ func (b Builder) abiStruct(t *types.Struct) Expr { g = pkg.doNewVar(name, prog.AbiTypePtrPtr()) g.Init(prog.Null(g.Type)) g.impl.SetLinkage(llvm.LinkOnceAnyLinkage) - pkg.ainits = append(pkg.ainits, func() { + pkg.ainits = append(pkg.ainits, func(param unsafe.Pointer) { + b := Builder(param) tabi := b.structOf(t) b.Store(g.Expr, tabi) }) diff --git a/ssa/package.go b/ssa/package.go index 905fa966..03d0ff26 100644 --- a/ssa/package.go +++ b/ssa/package.go @@ -19,6 +19,7 @@ package ssa import ( "go/token" "go/types" + "unsafe" "github.com/goplus/llgo/ssa/abi" "github.com/goplus/llvm" @@ -490,7 +491,7 @@ func (p Program) Uint64() Type { type aPackage struct { mod llvm.Module abi abi.Builder - ainits []func() + ainits []func(b unsafe.Pointer) // b Builder vars map[string]Global fns map[string]Function stubs map[string]Function @@ -558,8 +559,8 @@ func (p Package) AfterInit(b Builder, ret BasicBlock) { doAfterInit := len(p.ainits) > 0 || p.pyHasModSyms() if doAfterInit { b.SetBlockEx(ret, afterInit) - for _, afterInit := range p.ainits { - afterInit() + for _, fnAfterInit := range p.ainits { + fnAfterInit(unsafe.Pointer(b)) } p.pyLoadModSyms(b) }