aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/export_test.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2017-03-18 22:00:28 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2017-03-19 05:37:39 +0000
commita68e5d94fad421e64d471dae1c5ee0b95b933242 (patch)
treed1718f76809e68d4021b5dfb9f6e0922521ffe78 /src/cmd/compile/internal/ssa/export_test.go
parent62947bedd28a884b46f5df71070a9e86dad17081 (diff)
downloadgo-a68e5d94fad421e64d471dae1c5ee0b95b933242.tar.gz
go-a68e5d94fad421e64d471dae1c5ee0b95b933242.zip
cmd/compile: clean up SSA test API
I noted in CL 38327 that the SSA test API felt a bit clunky after the ssa.Func/ssa.Cache/ssa.Config refactoring, and promised to clean it up once the dust settled. The dust has settled. Along the way, this CL fixes a potential latent bug, in which the amd64 test context was used for all dummy Syslook calls. The lone SSA test using the s390x context did not depend on the Syslook context being correct, so the bug did not arise in practice. Change-Id: If964251d1807976073ad7f47da0b1f1f77c58413 Reviewed-on: https://go-review.googlesource.com/38346 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/export_test.go')
-rw-r--r--src/cmd/compile/internal/ssa/export_test.go44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/ssa/export_test.go b/src/cmd/compile/internal/ssa/export_test.go
index 33e0ffb416..fd8d3617f2 100644
--- a/src/cmd/compile/internal/ssa/export_test.go
+++ b/src/cmd/compile/internal/ssa/export_test.go
@@ -16,20 +16,48 @@ var CheckFunc = checkFunc
var Opt = opt
var Deadcode = deadcode
var Copyelim = copyelim
-var TestCtxt = obj.Linknew(&x86.Linkamd64)
-func testConfig(t testing.TB) *Config {
- return NewConfig("amd64", dummyTypes, TestCtxt, true)
+var testCtxts = map[string]*obj.Link{
+ "amd64": obj.Linknew(&x86.Linkamd64),
+ "s390x": obj.Linknew(&s390x.Links390x),
}
-func testConfigS390X(t testing.TB) *Config {
- return NewConfig("s390x", dummyTypes, obj.Linknew(&s390x.Links390x), true)
+func testConfig(tb testing.TB) *Conf { return testConfigArch(tb, "amd64") }
+func testConfigS390X(tb testing.TB) *Conf { return testConfigArch(tb, "s390x") }
+
+func testConfigArch(tb testing.TB, arch string) *Conf {
+ ctxt, ok := testCtxts[arch]
+ if !ok {
+ tb.Fatalf("unknown arch %s", arch)
+ }
+ if ctxt.Arch.IntSize != 8 {
+ tb.Fatal("dummyTypes is 64-bit only")
+ }
+ c := &Conf{
+ config: NewConfig(arch, dummyTypes, ctxt, true),
+ tb: tb,
+ }
+ return c
+}
+
+type Conf struct {
+ config *Config
+ tb testing.TB
+ fe Frontend
+}
+
+func (c *Conf) Frontend() Frontend {
+ if c.fe == nil {
+ c.fe = DummyFrontend{t: c.tb, ctxt: c.config.ctxt}
+ }
+ return c.fe
}
// DummyFrontend is a test-only frontend.
// It assumes 64 bit integers and pointers.
type DummyFrontend struct {
- t testing.TB
+ t testing.TB
+ ctxt *obj.Link
}
type DummyAuto struct {
@@ -85,8 +113,8 @@ func (DummyFrontend) Line(_ src.XPos) string {
}
func (DummyFrontend) AllocFrame(f *Func) {
}
-func (DummyFrontend) Syslook(s string) *obj.LSym {
- return obj.Linklookup(TestCtxt, s, 0)
+func (d DummyFrontend) Syslook(s string) *obj.LSym {
+ return obj.Linklookup(d.ctxt, s, 0)
}
func (DummyFrontend) UseWriteBarrier() bool {
return true // only writebarrier_test cares