1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package ssa 6 7 import ( 8 "cmd/internal/obj" 9 "cmd/internal/obj/x86" 10 "testing" 11 ) 12 13 var CheckFunc = checkFunc 14 var PrintFunc = printFunc 15 var Opt = opt 16 var Deadcode = deadcode 17 var Copyelim = copyelim 18 19 func testConfig(t testing.TB) *Config { 20 testCtxt := &obj.Link{Arch: &x86.Linkamd64} 21 return NewConfig("amd64", DummyFrontend{t}, testCtxt, true) 22 } 23 24 // DummyFrontend is a test-only frontend. 25 // It assumes 64 bit integers and pointers. 26 type DummyFrontend struct { 27 t testing.TB 28 } 29 30 func (DummyFrontend) StringData(s string) interface{} { 31 return nil 32 } 33 func (DummyFrontend) Auto(t Type) GCNode { 34 return nil 35 } 36 func (d DummyFrontend) SplitString(s LocalSlot) (LocalSlot, LocalSlot) { 37 return LocalSlot{s.N, d.TypeBytePtr(), s.Off}, LocalSlot{s.N, d.TypeInt(), s.Off + 8} 38 } 39 func (d DummyFrontend) SplitInterface(s LocalSlot) (LocalSlot, LocalSlot) { 40 return LocalSlot{s.N, d.TypeBytePtr(), s.Off}, LocalSlot{s.N, d.TypeBytePtr(), s.Off + 8} 41 } 42 func (d DummyFrontend) SplitSlice(s LocalSlot) (LocalSlot, LocalSlot, LocalSlot) { 43 return LocalSlot{s.N, s.Type.ElemType().PtrTo(), s.Off}, 44 LocalSlot{s.N, d.TypeInt(), s.Off + 8}, 45 LocalSlot{s.N, d.TypeInt(), s.Off + 16} 46 } 47 func (d DummyFrontend) SplitComplex(s LocalSlot) (LocalSlot, LocalSlot) { 48 if s.Type.Size() == 16 { 49 return LocalSlot{s.N, d.TypeFloat64(), s.Off}, LocalSlot{s.N, d.TypeFloat64(), s.Off + 8} 50 } 51 return LocalSlot{s.N, d.TypeFloat32(), s.Off}, LocalSlot{s.N, d.TypeFloat32(), s.Off + 4} 52 } 53 func (d DummyFrontend) SplitInt64(s LocalSlot) (LocalSlot, LocalSlot) { 54 if s.Type.IsSigned() { 55 return LocalSlot{s.N, d.TypeInt32(), s.Off + 4}, LocalSlot{s.N, d.TypeUInt32(), s.Off} 56 } 57 return LocalSlot{s.N, d.TypeUInt32(), s.Off + 4}, LocalSlot{s.N, d.TypeUInt32(), s.Off} 58 } 59 func (d DummyFrontend) SplitStruct(s LocalSlot, i int) LocalSlot { 60 return LocalSlot{s.N, s.Type.FieldType(i), s.Off + s.Type.FieldOff(i)} 61 } 62 func (d DummyFrontend) SplitArray(s LocalSlot) LocalSlot { 63 return LocalSlot{s.N, s.Type.ElemType(), s.Off} 64 } 65 func (DummyFrontend) Line(line int32) string { 66 return "unknown.go:0" 67 } 68 func (DummyFrontend) AllocFrame(f *Func) { 69 } 70 func (DummyFrontend) Syslook(s string) interface{} { 71 return DummySym(s) 72 } 73 74 func (d DummyFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, args...) } 75 func (d DummyFrontend) Log() bool { return true } 76 77 func (d DummyFrontend) Fatalf(line int32, msg string, args ...interface{}) { d.t.Fatalf(msg, args...) } 78 func (d DummyFrontend) Warnl(line int32, msg string, args ...interface{}) { d.t.Logf(msg, args...) } 79 func (d DummyFrontend) Debug_checknil() bool { return false } 80 func (d DummyFrontend) Debug_wb() bool { return false } 81 82 func (d DummyFrontend) TypeBool() Type { return TypeBool } 83 func (d DummyFrontend) TypeInt8() Type { return TypeInt8 } 84 func (d DummyFrontend) TypeInt16() Type { return TypeInt16 } 85 func (d DummyFrontend) TypeInt32() Type { return TypeInt32 } 86 func (d DummyFrontend) TypeInt64() Type { return TypeInt64 } 87 func (d DummyFrontend) TypeUInt8() Type { return TypeUInt8 } 88 func (d DummyFrontend) TypeUInt16() Type { return TypeUInt16 } 89 func (d DummyFrontend) TypeUInt32() Type { return TypeUInt32 } 90 func (d DummyFrontend) TypeUInt64() Type { return TypeUInt64 } 91 func (d DummyFrontend) TypeFloat32() Type { return TypeFloat32 } 92 func (d DummyFrontend) TypeFloat64() Type { return TypeFloat64 } 93 func (d DummyFrontend) TypeInt() Type { return TypeInt64 } 94 func (d DummyFrontend) TypeUintptr() Type { return TypeUInt64 } 95 func (d DummyFrontend) TypeString() Type { panic("unimplemented") } 96 func (d DummyFrontend) TypeBytePtr() Type { return TypeBytePtr } 97 98 func (d DummyFrontend) CanSSA(t Type) bool { 99 // There are no un-SSAable types in dummy land. 100 return true 101 } 102 103 type DummySym string 104 105 func (s DummySym) String() string { return string(s) } 106