github.com/euank/go@v0.0.0-20160829210321-495514729181/src/cmd/compile/internal/ssa/export_test.go (about) 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 "testing" 10 ) 11 12 var CheckFunc = checkFunc 13 var PrintFunc = printFunc 14 var Opt = opt 15 var Deadcode = deadcode 16 var Copyelim = copyelim 17 18 func testConfig(t testing.TB) *Config { 19 testCtxt := &obj.Link{} 20 return NewConfig("amd64", DummyFrontend{t}, testCtxt, true) 21 } 22 23 // DummyFrontend is a test-only frontend. 24 // It assumes 64 bit integers and pointers. 25 type DummyFrontend struct { 26 t testing.TB 27 } 28 29 func (DummyFrontend) StringData(s string) interface{} { 30 return nil 31 } 32 func (DummyFrontend) Auto(t Type) GCNode { 33 return nil 34 } 35 func (d DummyFrontend) SplitString(s LocalSlot) (LocalSlot, LocalSlot) { 36 return LocalSlot{s.N, d.TypeBytePtr(), s.Off}, LocalSlot{s.N, d.TypeInt(), s.Off + 8} 37 } 38 func (d DummyFrontend) SplitInterface(s LocalSlot) (LocalSlot, LocalSlot) { 39 return LocalSlot{s.N, d.TypeBytePtr(), s.Off}, LocalSlot{s.N, d.TypeBytePtr(), s.Off + 8} 40 } 41 func (d DummyFrontend) SplitSlice(s LocalSlot) (LocalSlot, LocalSlot, LocalSlot) { 42 return LocalSlot{s.N, s.Type.ElemType().PtrTo(), s.Off}, 43 LocalSlot{s.N, d.TypeInt(), s.Off + 8}, 44 LocalSlot{s.N, d.TypeInt(), s.Off + 16} 45 } 46 func (d DummyFrontend) SplitComplex(s LocalSlot) (LocalSlot, LocalSlot) { 47 if s.Type.Size() == 16 { 48 return LocalSlot{s.N, d.TypeFloat64(), s.Off}, LocalSlot{s.N, d.TypeFloat64(), s.Off + 8} 49 } 50 return LocalSlot{s.N, d.TypeFloat32(), s.Off}, LocalSlot{s.N, d.TypeFloat32(), s.Off + 4} 51 } 52 func (d DummyFrontend) SplitInt64(s LocalSlot) (LocalSlot, LocalSlot) { 53 if s.Type.IsSigned() { 54 return LocalSlot{s.N, d.TypeInt32(), s.Off + 4}, LocalSlot{s.N, d.TypeUInt32(), s.Off} 55 } 56 return LocalSlot{s.N, d.TypeUInt32(), s.Off + 4}, LocalSlot{s.N, d.TypeUInt32(), s.Off} 57 } 58 func (d DummyFrontend) SplitStruct(s LocalSlot, i int) LocalSlot { 59 return LocalSlot{s.N, s.Type.FieldType(i), s.Off + s.Type.FieldOff(i)} 60 } 61 func (DummyFrontend) Line(line int32) string { 62 return "unknown.go:0" 63 } 64 65 func (d DummyFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, args...) } 66 func (d DummyFrontend) Log() bool { return true } 67 68 func (d DummyFrontend) Fatalf(line int32, msg string, args ...interface{}) { d.t.Fatalf(msg, args...) } 69 func (d DummyFrontend) Unimplementedf(line int32, msg string, args ...interface{}) { 70 d.t.Fatalf(msg, args...) 71 } 72 func (d DummyFrontend) Warnl(line int32, msg string, args ...interface{}) { d.t.Logf(msg, args...) } 73 func (d DummyFrontend) Debug_checknil() bool { return false } 74 75 func (d DummyFrontend) TypeBool() Type { return TypeBool } 76 func (d DummyFrontend) TypeInt8() Type { return TypeInt8 } 77 func (d DummyFrontend) TypeInt16() Type { return TypeInt16 } 78 func (d DummyFrontend) TypeInt32() Type { return TypeInt32 } 79 func (d DummyFrontend) TypeInt64() Type { return TypeInt64 } 80 func (d DummyFrontend) TypeUInt8() Type { return TypeUInt8 } 81 func (d DummyFrontend) TypeUInt16() Type { return TypeUInt16 } 82 func (d DummyFrontend) TypeUInt32() Type { return TypeUInt32 } 83 func (d DummyFrontend) TypeUInt64() Type { return TypeUInt64 } 84 func (d DummyFrontend) TypeFloat32() Type { return TypeFloat32 } 85 func (d DummyFrontend) TypeFloat64() Type { return TypeFloat64 } 86 func (d DummyFrontend) TypeInt() Type { return TypeInt64 } 87 func (d DummyFrontend) TypeUintptr() Type { return TypeUInt64 } 88 func (d DummyFrontend) TypeString() Type { panic("unimplemented") } 89 func (d DummyFrontend) TypeBytePtr() Type { return TypeBytePtr } 90 91 func (d DummyFrontend) CanSSA(t Type) bool { 92 // There are no un-SSAable types in dummy land. 93 return true 94 }