diff options
Diffstat (limited to 'src/cmd/compile/internal/ssa/export_test.go')
-rw-r--r-- | src/cmd/compile/internal/ssa/export_test.go | 108 |
1 files changed, 43 insertions, 65 deletions
diff --git a/src/cmd/compile/internal/ssa/export_test.go b/src/cmd/compile/internal/ssa/export_test.go index b4c3e5cfdf..df83383308 100644 --- a/src/cmd/compile/internal/ssa/export_test.go +++ b/src/cmd/compile/internal/ssa/export_test.go @@ -5,6 +5,7 @@ package ssa import ( + "cmd/compile/internal/ir" "cmd/compile/internal/types" "cmd/internal/obj" "cmd/internal/obj/arm64" @@ -36,10 +37,10 @@ func testConfigArch(tb testing.TB, arch string) *Conf { tb.Fatalf("unknown arch %s", arch) } if ctxt.Arch.PtrSize != 8 { - tb.Fatal("dummyTypes is 64-bit only") + tb.Fatal("testTypes is 64-bit only") } c := &Conf{ - config: NewConfig(arch, dummyTypes, ctxt, true), + config: NewConfig(arch, testTypes, ctxt, true), tb: tb, } return c @@ -53,108 +54,85 @@ type Conf struct { func (c *Conf) Frontend() Frontend { if c.fe == nil { - c.fe = DummyFrontend{t: c.tb, ctxt: c.config.ctxt} + c.fe = TestFrontend{t: c.tb, ctxt: c.config.ctxt} } return c.fe } -// DummyFrontend is a test-only frontend. +// TestFrontend is a test-only frontend. // It assumes 64 bit integers and pointers. -type DummyFrontend struct { +type TestFrontend struct { t testing.TB ctxt *obj.Link } -type DummyAuto struct { - t *types.Type - s string -} - -func (d *DummyAuto) Typ() *types.Type { - return d.t -} - -func (d *DummyAuto) String() string { - return d.s -} - -func (d *DummyAuto) StorageClass() StorageClass { - return ClassAuto -} - -func (d *DummyAuto) IsSynthetic() bool { - return false -} - -func (d *DummyAuto) IsAutoTmp() bool { - return true -} - -func (DummyFrontend) StringData(s string) *obj.LSym { +func (TestFrontend) StringData(s string) *obj.LSym { return nil } -func (DummyFrontend) Auto(pos src.XPos, t *types.Type) GCNode { - return &DummyAuto{t: t, s: "aDummyAuto"} +func (TestFrontend) Auto(pos src.XPos, t *types.Type) ir.Node { + n := ir.NewNameAt(pos, &types.Sym{Name: "aFakeAuto"}) + n.SetClass(ir.PAUTO) + return n } -func (d DummyFrontend) SplitString(s LocalSlot) (LocalSlot, LocalSlot) { - return LocalSlot{N: s.N, Type: dummyTypes.BytePtr, Off: s.Off}, LocalSlot{N: s.N, Type: dummyTypes.Int, Off: s.Off + 8} +func (d TestFrontend) SplitString(s LocalSlot) (LocalSlot, LocalSlot) { + return LocalSlot{N: s.N, Type: testTypes.BytePtr, Off: s.Off}, LocalSlot{N: s.N, Type: testTypes.Int, Off: s.Off + 8} } -func (d DummyFrontend) SplitInterface(s LocalSlot) (LocalSlot, LocalSlot) { - return LocalSlot{N: s.N, Type: dummyTypes.BytePtr, Off: s.Off}, LocalSlot{N: s.N, Type: dummyTypes.BytePtr, Off: s.Off + 8} +func (d TestFrontend) SplitInterface(s LocalSlot) (LocalSlot, LocalSlot) { + return LocalSlot{N: s.N, Type: testTypes.BytePtr, Off: s.Off}, LocalSlot{N: s.N, Type: testTypes.BytePtr, Off: s.Off + 8} } -func (d DummyFrontend) SplitSlice(s LocalSlot) (LocalSlot, LocalSlot, LocalSlot) { +func (d TestFrontend) SplitSlice(s LocalSlot) (LocalSlot, LocalSlot, LocalSlot) { return LocalSlot{N: s.N, Type: s.Type.Elem().PtrTo(), Off: s.Off}, - LocalSlot{N: s.N, Type: dummyTypes.Int, Off: s.Off + 8}, - LocalSlot{N: s.N, Type: dummyTypes.Int, Off: s.Off + 16} + LocalSlot{N: s.N, Type: testTypes.Int, Off: s.Off + 8}, + LocalSlot{N: s.N, Type: testTypes.Int, Off: s.Off + 16} } -func (d DummyFrontend) SplitComplex(s LocalSlot) (LocalSlot, LocalSlot) { +func (d TestFrontend) SplitComplex(s LocalSlot) (LocalSlot, LocalSlot) { if s.Type.Size() == 16 { - return LocalSlot{N: s.N, Type: dummyTypes.Float64, Off: s.Off}, LocalSlot{N: s.N, Type: dummyTypes.Float64, Off: s.Off + 8} + return LocalSlot{N: s.N, Type: testTypes.Float64, Off: s.Off}, LocalSlot{N: s.N, Type: testTypes.Float64, Off: s.Off + 8} } - return LocalSlot{N: s.N, Type: dummyTypes.Float32, Off: s.Off}, LocalSlot{N: s.N, Type: dummyTypes.Float32, Off: s.Off + 4} + return LocalSlot{N: s.N, Type: testTypes.Float32, Off: s.Off}, LocalSlot{N: s.N, Type: testTypes.Float32, Off: s.Off + 4} } -func (d DummyFrontend) SplitInt64(s LocalSlot) (LocalSlot, LocalSlot) { +func (d TestFrontend) SplitInt64(s LocalSlot) (LocalSlot, LocalSlot) { if s.Type.IsSigned() { - return LocalSlot{N: s.N, Type: dummyTypes.Int32, Off: s.Off + 4}, LocalSlot{N: s.N, Type: dummyTypes.UInt32, Off: s.Off} + return LocalSlot{N: s.N, Type: testTypes.Int32, Off: s.Off + 4}, LocalSlot{N: s.N, Type: testTypes.UInt32, Off: s.Off} } - return LocalSlot{N: s.N, Type: dummyTypes.UInt32, Off: s.Off + 4}, LocalSlot{N: s.N, Type: dummyTypes.UInt32, Off: s.Off} + return LocalSlot{N: s.N, Type: testTypes.UInt32, Off: s.Off + 4}, LocalSlot{N: s.N, Type: testTypes.UInt32, Off: s.Off} } -func (d DummyFrontend) SplitStruct(s LocalSlot, i int) LocalSlot { +func (d TestFrontend) SplitStruct(s LocalSlot, i int) LocalSlot { return LocalSlot{N: s.N, Type: s.Type.FieldType(i), Off: s.Off + s.Type.FieldOff(i)} } -func (d DummyFrontend) SplitArray(s LocalSlot) LocalSlot { +func (d TestFrontend) SplitArray(s LocalSlot) LocalSlot { return LocalSlot{N: s.N, Type: s.Type.Elem(), Off: s.Off} } -func (d DummyFrontend) SplitSlot(parent *LocalSlot, suffix string, offset int64, t *types.Type) LocalSlot { +func (d TestFrontend) SplitSlot(parent *LocalSlot, suffix string, offset int64, t *types.Type) LocalSlot { return LocalSlot{N: parent.N, Type: t, Off: offset} } -func (DummyFrontend) Line(_ src.XPos) string { +func (TestFrontend) Line(_ src.XPos) string { return "unknown.go:0" } -func (DummyFrontend) AllocFrame(f *Func) { +func (TestFrontend) AllocFrame(f *Func) { } -func (d DummyFrontend) Syslook(s string) *obj.LSym { +func (d TestFrontend) Syslook(s string) *obj.LSym { return d.ctxt.Lookup(s) } -func (DummyFrontend) UseWriteBarrier() bool { +func (TestFrontend) UseWriteBarrier() bool { return true // only writebarrier_test cares } -func (DummyFrontend) SetWBPos(pos src.XPos) { +func (TestFrontend) SetWBPos(pos src.XPos) { } -func (d DummyFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, args...) } -func (d DummyFrontend) Log() bool { return true } +func (d TestFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, args...) } +func (d TestFrontend) Log() bool { return true } -func (d DummyFrontend) Fatalf(_ src.XPos, msg string, args ...interface{}) { d.t.Fatalf(msg, args...) } -func (d DummyFrontend) Warnl(_ src.XPos, msg string, args ...interface{}) { d.t.Logf(msg, args...) } -func (d DummyFrontend) Debug_checknil() bool { return false } +func (d TestFrontend) Fatalf(_ src.XPos, msg string, args ...interface{}) { d.t.Fatalf(msg, args...) } +func (d TestFrontend) Warnl(_ src.XPos, msg string, args ...interface{}) { d.t.Logf(msg, args...) } +func (d TestFrontend) Debug_checknil() bool { return false } -func (d DummyFrontend) MyImportPath() string { +func (d TestFrontend) MyImportPath() string { return "my/import/path" } -var dummyTypes Types +var testTypes Types func init() { // Initialize just enough of the universe and the types package to make our tests function. @@ -198,12 +176,12 @@ func init() { t.Align = uint8(typ.width) types.Types[typ.et] = t } - dummyTypes.SetTypPtrs() + testTypes.SetTypPtrs() } -func (d DummyFrontend) DerefItab(sym *obj.LSym, off int64) *obj.LSym { return nil } +func (d TestFrontend) DerefItab(sym *obj.LSym, off int64) *obj.LSym { return nil } -func (d DummyFrontend) CanSSA(t *types.Type) bool { - // There are no un-SSAable types in dummy land. +func (d TestFrontend) CanSSA(t *types.Type) bool { + // There are no un-SSAable types in test land. return true } |