1
2
3
4
5 package ssa
6
7 import (
8 "testing"
9
10 "cmd/compile/internal/ir"
11 "cmd/compile/internal/typecheck"
12 "cmd/compile/internal/types"
13 "cmd/internal/obj"
14 "cmd/internal/obj/arm64"
15 "cmd/internal/obj/s390x"
16 "cmd/internal/obj/x86"
17 "cmd/internal/src"
18 )
19
20 var CheckFunc = checkFunc
21 var Opt = opt
22 var Deadcode = deadcode
23 var Copyelim = copyelim
24
25 var testCtxts = map[string]*obj.Link{
26 "amd64": obj.Linknew(&x86.Linkamd64),
27 "s390x": obj.Linknew(&s390x.Links390x),
28 "arm64": obj.Linknew(&arm64.Linkarm64),
29 }
30
31 func testConfig(tb testing.TB) *Conf { return testConfigArch(tb, "amd64") }
32 func testConfigS390X(tb testing.TB) *Conf { return testConfigArch(tb, "s390x") }
33 func testConfigARM64(tb testing.TB) *Conf { return testConfigArch(tb, "arm64") }
34
35 func testConfigArch(tb testing.TB, arch string) *Conf {
36 ctxt, ok := testCtxts[arch]
37 if !ok {
38 tb.Fatalf("unknown arch %s", arch)
39 }
40 if ctxt.Arch.PtrSize != 8 {
41 tb.Fatal("testTypes is 64-bit only")
42 }
43 c := &Conf{
44 config: NewConfig(arch, testTypes, ctxt, true, false),
45 tb: tb,
46 }
47 return c
48 }
49
50 type Conf struct {
51 config *Config
52 tb testing.TB
53 fe Frontend
54 }
55
56 func (c *Conf) Frontend() Frontend {
57 if c.fe == nil {
58 c.fe = TestFrontend{t: c.tb, ctxt: c.config.ctxt}
59 }
60 return c.fe
61 }
62
63
64
65 type TestFrontend struct {
66 t testing.TB
67 ctxt *obj.Link
68 }
69
70 func (TestFrontend) StringData(s string) *obj.LSym {
71 return nil
72 }
73 func (TestFrontend) Auto(pos src.XPos, t *types.Type) *ir.Name {
74 n := ir.NewNameAt(pos, &types.Sym{Name: "aFakeAuto"})
75 n.Class = ir.PAUTO
76 return n
77 }
78 func (d TestFrontend) SplitSlot(parent *LocalSlot, suffix string, offset int64, t *types.Type) LocalSlot {
79 return LocalSlot{N: parent.N, Type: t, Off: offset}
80 }
81 func (TestFrontend) Line(_ src.XPos) string {
82 return "unknown.go:0"
83 }
84 func (TestFrontend) AllocFrame(f *Func) {
85 }
86 func (d TestFrontend) Syslook(s string) *obj.LSym {
87 return d.ctxt.Lookup(s)
88 }
89 func (TestFrontend) UseWriteBarrier() bool {
90 return true
91 }
92 func (TestFrontend) SetWBPos(pos src.XPos) {
93 }
94
95 func (d TestFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, args...) }
96 func (d TestFrontend) Log() bool { return true }
97
98 func (d TestFrontend) Fatalf(_ src.XPos, msg string, args ...interface{}) { d.t.Fatalf(msg, args...) }
99 func (d TestFrontend) Warnl(_ src.XPos, msg string, args ...interface{}) { d.t.Logf(msg, args...) }
100 func (d TestFrontend) Debug_checknil() bool { return false }
101
102 func (d TestFrontend) MyImportPath() string {
103 return "my/import/path"
104 }
105
106 var testTypes Types
107
108 func init() {
109
110 types.PtrSize = 8
111 types.RegSize = 8
112 types.MaxWidth = 1 << 50
113
114 typecheck.InitUniverse()
115 testTypes.SetTypPtrs()
116 }
117
118 func (d TestFrontend) DerefItab(sym *obj.LSym, off int64) *obj.LSym { return nil }
119
120 func (d TestFrontend) CanSSA(t *types.Type) bool {
121
122 return true
123 }
124
View as plain text