llgo/ssa: NewPyFunc add param doInit

This commit is contained in:
xushiwei
2024-05-12 12:14:26 +08:00
parent 8a0189b079
commit 2e3cc49782
6 changed files with 14 additions and 12 deletions

View File

@@ -294,15 +294,17 @@ type aPyFunction struct {
type PyFunction = *aPyFunction
// NewPyFunc creates a new python function.
func (p Package) NewPyFunc(name string, sig *types.Signature) PyFunction {
func (p Package) NewPyFunc(name string, sig *types.Signature, doInit bool) PyFunction {
if v, ok := p.pyfns[name]; ok {
return v
}
prog := p.Prog
prog.needPyInit = true
obj := p.NewVar(name, prog.PyObjectPtrPtr().RawType(), InC)
obj.Init(prog.Null(obj.Type))
obj.impl.SetLinkage(llvm.LinkOnceAnyLinkage)
if doInit {
obj.Init(prog.Null(obj.Type))
obj.impl.SetLinkage(llvm.LinkOnceAnyLinkage)
}
ty := &aType{obj.ll, rawType{sig}, vkPyFunc}
expr := Expr{obj.impl, ty}
ret := &aPyFunction{expr, obj}

View File

@@ -143,8 +143,8 @@ func TestPyFunc(t *testing.T) {
prog.SetPython(py)
pkg := prog.NewPackage("bar", "foo/bar")
sig := types.NewSignatureType(nil, nil, nil, nil, nil, false)
a := pkg.NewPyFunc("a", sig)
if pkg.NewPyFunc("a", sig) != a {
a := pkg.NewPyFunc("a", sig, false)
if pkg.NewPyFunc("a", sig, false) != a {
t.Fatal("NewPyFunc(a) failed")
}
foo := pkg.NewPyModVar("foo")