ssa: fix abiType & abiNamedOf

This commit is contained in:
visualfc
2024-06-25 12:11:51 +08:00
parent f41511047e
commit ef3619350d
10 changed files with 7115 additions and 885 deletions

View File

@@ -185,15 +185,24 @@ func (b Builder) abiInterfaceOf(pkgPath string, name string, t *types.Interface)
// func NewNamed(kind abi.Kind, methods, ptrMethods int)
func (b Builder) abiNamedOf(t *types.Named) func() Expr {
return func() Expr {
pkg := b.Pkg
tunder := t.Underlying()
kind := int(abi.UnderlyingKind(tunder))
numMethods, numPtrMethods := b.abiMethods(t)
newNamed := pkg.rtFunc("NewNamed")
return b.Call(newNamed, b.Prog.Val(kind), b.Prog.Val(numMethods), b.Prog.Val(numPtrMethods))
return b.abiNamed(t)
}
}
func (b Builder) abiNamed(t *types.Named) Expr {
if expr, ok := b.Pkg.named[t]; ok {
return expr
}
pkg := b.Pkg
tunder := t.Underlying()
kind := int(abi.UnderlyingKind(tunder))
numMethods, numPtrMethods := b.abiMethods(t)
newNamed := pkg.rtFunc("NewNamed")
expr := b.Call(newNamed, b.Prog.Val(kind), b.Prog.Val(numMethods), b.Prog.Val(numPtrMethods))
b.Pkg.named[t] = expr
return expr
}
// func InitNamed(ret *Type, pkgPath, name string, underlying *Type, methods, ptrMethods []Method)
func (b Builder) abiInitNamed(ret Expr, t *types.Named) func() Expr {
under := b.abiType(t.Underlying())
@@ -359,6 +368,15 @@ func (p Package) abiTypeInit(g Global, t types.Type, pub bool) {
// abiType returns the abi type of the specified type.
func (b Builder) abiType(t types.Type) Expr {
switch t := t.(type) {
case *types.Pointer:
b.loadType(t.Elem())
}
g := b.loadType(t)
return b.Load(g.Expr)
}
func (b Builder) loadType(t types.Type) Global {
pkg := b.Pkg
name, pub := pkg.abi.TypeName(t)
g := pkg.VarOf(name)
@@ -371,7 +389,7 @@ func (b Builder) abiType(t types.Type) Expr {
}
pkg.abiTypeInit(g, t, pub)
}
return b.Load(g.Expr)
return g
}
// -----------------------------------------------------------------------------

View File

@@ -316,12 +316,13 @@ func (p Program) NewPackage(name, pkgPath string) Package {
pyobjs := make(map[string]PyObjRef)
pymods := make(map[string]Global)
strs := make(map[string]llvm.Value)
named := make(map[types.Type]Expr)
p.NeedRuntime = false
// Don't need reset p.needPyInit here
// p.needPyInit = false
ret := &aPackage{
mod: mod, vars: gbls, fns: fns, stubs: stubs,
pyobjs: pyobjs, pymods: pymods, strs: strs, Prog: p}
pyobjs: pyobjs, pymods: pymods, strs: strs, named: named, Prog: p}
ret.abi.Init(pkgPath)
return ret
}
@@ -565,6 +566,7 @@ type aPackage struct {
pyobjs map[string]PyObjRef
pymods map[string]Global
strs map[string]llvm.Value
named map[types.Type]Expr
afterb unsafe.Pointer
iRoutine int