ssa: abi check interface method

This commit is contained in:
visualfc
2024-10-10 16:07:52 +08:00
parent 9ea88fe247
commit d62c2d913e
19 changed files with 13557 additions and 11948 deletions

View File

@@ -408,18 +408,45 @@ func (p Package) abiTypeInit(g Global, t types.Type, pub bool) {
func (b Builder) abiType(t types.Type) Expr {
switch t := t.(type) {
case *types.Pointer:
b.loadType(t.Elem())
b.checkAbi(t.Elem())
case *types.Array:
b.abiType(t.Elem())
b.checkAbi(t.Elem())
case *types.Map:
b.abiType(t.Key())
b.abiType(t.Elem())
b.checkAbi(t.Key())
b.checkAbi(t.Elem())
case *types.Slice:
b.checkAbi(t.Elem())
case *types.Chan:
b.checkAbi(t.Elem())
case *types.Struct:
for i := 0; i < t.NumFields(); i++ {
b.checkAbi(t.Field(i).Type())
}
case *types.Interface:
for i := 0; i < t.NumMethods(); i++ {
b.checkAbi(t.Method(i).Type())
}
case *types.Signature:
for i := 0; i < t.Params().Len(); i++ {
b.checkAbi(t.Params().At(i).Type())
}
for i := 0; i < t.Results().Len(); i++ {
b.checkAbi(t.Results().At(i).Type())
}
}
g := b.loadType(t)
return b.Load(g.Expr)
}
func (b Builder) checkAbi(t types.Type) {
if b.Pkg.chkabi[t] {
return
}
b.abiType(t)
}
func (b Builder) loadType(t types.Type) Global {
b.Pkg.chkabi[t] = true
pkg := b.Pkg
name, pub := pkg.abi.TypeName(t)
g := pkg.VarOf(name)

View File

@@ -346,13 +346,14 @@ func (p Program) NewPackage(name, pkgPath string) Package {
pyobjs := make(map[string]PyObjRef)
pymods := make(map[string]Global)
strs := make(map[string]llvm.Value)
chkabi := make(map[types.Type]bool)
glbDbgVars := make(map[Expr]bool)
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, chkabi: chkabi, Prog: p,
di: nil, cu: nil, glbDbgVars: glbDbgVars,
}
ret.abi.Init(pkgPath)
@@ -602,6 +603,7 @@ type aPackage struct {
pyobjs map[string]PyObjRef
pymods map[string]Global
strs map[string]llvm.Value
chkabi map[types.Type]bool
afterb unsafe.Pointer
patch func(types.Type) types.Type
fnlink func(string) string