Skip to content

Commit 2ba6a30

Browse files
committed
ssa: TestAbiTables
1 parent d0878d2 commit 2ba6a30

File tree

5 files changed

+75
-18
lines changed

5 files changed

+75
-18
lines changed

ssa/abi/abi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func ChanDir(dir types.ChanDir) (abi.ChanDir, string) {
7575
case types.RecvOnly:
7676
return abi.RecvDir, "<-chan"
7777
}
78-
panic("invlid chan dir")
78+
panic("invalid chan dir")
7979
}
8080

8181
// -----------------------------------------------------------------------------

ssa/abi/type.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import (
77
"github.com/goplus/llgo/runtime/abi"
88
)
99

10+
const (
11+
TFlagUncommon = abi.TFlagUncommon
12+
KindDirectIface = abi.KindDirectIface
13+
)
14+
1015
func (b *Builder) MapBucket(t *types.Map) types.Type {
1116
return MapBucketType(t, b.Sizes)
1217
}

ssa/abitype.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ func (b Builder) abiCommonFields(t types.Type, name string, hasUncommon bool) (f
7575
hash := binary.LittleEndian.Uint32(h[:4])
7676
fields = append(fields, prog.IntVal(uint64(hash), prog.Uint32()).impl)
7777
// TFlag uint8
78-
tflag := uint64(ab.TFlag(t))
78+
tflag := ab.TFlag(t)
7979
if hasUncommon {
80-
tflag |= (1 << 0) // TFlagUncommon
80+
tflag |= abi.TFlagUncommon
8181
}
82-
fields = append(fields, prog.IntVal(tflag, prog.Byte()).impl)
82+
fields = append(fields, prog.IntVal(uint64(tflag), prog.Byte()).impl)
8383
// Align uint8
8484
align := prog.IntVal(uint64(ab.Align(t)), prog.Byte()).impl
8585
fields = append(fields, align)
@@ -88,7 +88,7 @@ func (b Builder) abiCommonFields(t types.Type, name string, hasUncommon bool) (f
8888
// Kind uint8
8989
kind := uint8(ab.Kind(t))
9090
if k, _, _ := abi.DataKindOf(t, 0, prog.is32Bits); k != abi.Indirect {
91-
kind |= (1 << 5) //KindDirectIface
91+
kind |= uint8(abi.KindDirectIface)
9292
}
9393
fields = append(fields, prog.IntVal(uint64(kind), prog.Byte()).impl)
9494
// Equal func(unsafe.Pointer, unsafe.Pointer) bool

ssa/package.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,10 @@ type aProgram struct {
168168
pyObjPtr Type
169169
pyObjPPtr Type
170170

171-
abiTy Type
172-
abiTyPtr Type
173-
abiTyPPtr Type
174-
deferTy Type
175-
deferPtr Type
171+
abiTy Type
172+
abiTyPtr Type
173+
deferTy Type
174+
deferPtr Type
176175

177176
pyImpTy *types.Signature
178177
pyNewList *types.Signature
@@ -476,14 +475,6 @@ func (p Program) AbiTypePtr() Type {
476475
return p.abiTyPtr
477476
}
478477

479-
// AbiTypePtrPtr returns **abi.Type type.
480-
func (p Program) AbiTypePtrPtr() Type {
481-
if p.abiTyPPtr == nil {
482-
p.abiTyPPtr = p.Pointer(p.AbiTypePtr())
483-
}
484-
return p.abiTyPPtr
485-
}
486-
487478
// Void returns void type.
488479
func (p Program) Void() Type {
489480
if p.voidTy == nil {

ssa/ssa_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,3 +1187,64 @@ declare i32 @setjmp(ptr) #0
11871187
attributes #0 = { returns_twice }
11881188
`)
11891189
}
1190+
1191+
func TestAbiTables(t *testing.T) {
1192+
prog := NewProgram(nil)
1193+
prog.sizes = types.SizesFor("gc", runtime.GOARCH)
1194+
prog.SetRuntime(func() *types.Package {
1195+
pkg, err := importer.For("source", nil).Import(PkgRuntime)
1196+
if err != nil {
1197+
t.Fatal(err)
1198+
}
1199+
return pkg
1200+
})
1201+
pkg := prog.NewPackage("bar", "foo/bar")
1202+
1203+
emptyIface := types.NewInterfaceType(nil, nil)
1204+
emptyIface.Complete()
1205+
emptyType := prog.Type(emptyIface, InGo)
1206+
1207+
makeFn := func(name string, x Expr) {
1208+
sig := types.NewSignatureType(nil, nil, nil, nil, types.NewTuple(types.NewVar(0, nil, "", emptyIface)), false)
1209+
fn := pkg.NewFunc(name, sig, InGo)
1210+
b := fn.MakeBody(1)
1211+
iface := b.MakeInterface(emptyType, x)
1212+
b.Return(iface)
1213+
}
1214+
1215+
makeFn("intIface", prog.Val(1))
1216+
makeFn("ptrIface", prog.Nil(prog.VoidPtr()))
1217+
makeFn("floatIface", prog.FloatVal(3.5, prog.Float32()))
1218+
1219+
st := types.NewStruct([]*types.Var{
1220+
types.NewVar(0, nil, "a", types.Typ[types.Int]),
1221+
types.NewVar(0, nil, "b", types.Typ[types.Int]),
1222+
}, nil)
1223+
makeFn("structIface", prog.Zero(prog.Type(st, InGo)))
1224+
1225+
single := types.NewStruct([]*types.Var{
1226+
types.NewVar(0, nil, "v", types.Typ[types.Int]),
1227+
}, nil)
1228+
makeFn("singleFieldIface", prog.Zero(prog.Type(single, InGo)))
1229+
1230+
pkgTypes := types.NewPackage("foo/bar", "bar")
1231+
rawSig := types.NewSignatureType(nil, nil, nil, nil, nil, false)
1232+
rawMeth := types.NewFunc(0, pkgTypes, "M", rawSig)
1233+
nonEmpty := types.NewInterfaceType([]*types.Func{rawMeth}, nil)
1234+
nonEmpty.Complete()
1235+
nonEmptyType := prog.Type(nonEmpty, InGo)
1236+
sigNE := types.NewSignatureType(nil, nil, nil, nil, types.NewTuple(types.NewVar(0, nil, "", nonEmpty)), false)
1237+
fnNE := pkg.NewFunc("nonEmptyIface", sigNE, InGo)
1238+
bNE := fnNE.MakeBody(1)
1239+
bNE.Return(bNE.MakeInterface(nonEmptyType, prog.Val(7)))
1240+
1241+
fn := pkg.InitAbiTypes(pkg.Path() + ".init$abitables")
1242+
s := fn.impl.String()
1243+
if !strings.Contains(s, `define void @"foo/bar.init$abitables"() {
1244+
_llgo_0:
1245+
call void @"github.com/goplus/llgo/runtime/internal/runtime.initTypes"(ptr @"foo/bar.init$abitables$slice")
1246+
ret void
1247+
}`) {
1248+
t.Fatal("error abi tables", s)
1249+
}
1250+
}

0 commit comments

Comments
 (0)