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>
This commit is contained in:
Josh Bleecher Snyder 2017-03-18 22:00:28 -07:00
parent 62947bedd2
commit a68e5d94fa
17 changed files with 117 additions and 89 deletions

View file

@ -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