github.com/gocuntian/go@v0.0.0-20160610041250-fee02d270bf8/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) SplitStruct(s LocalSlot, i int) LocalSlot { 53 return LocalSlot{s.N, s.Type.FieldType(i), s.Off + s.Type.FieldOff(i)} 54 } 55 func (DummyFrontend) Line(line int32) string { 56 return "unknown.go:0" 57 } 58 59 func (d DummyFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, args...) } 60 func (d DummyFrontend) Log() bool { return true } 61 62 func (d DummyFrontend) Fatalf(line int32, msg string, args ...interface{}) { d.t.Fatalf(msg, args...) } 63 func (d DummyFrontend) Unimplementedf(line int32, msg string, args ...interface{}) { 64 d.t.Fatalf(msg, args...) 65 } 66 func (d DummyFrontend) Warnl(line int32, msg string, args ...interface{}) { d.t.Logf(msg, args...) } 67 func (d DummyFrontend) Debug_checknil() bool { return false } 68 69 func (d DummyFrontend) TypeBool() Type { return TypeBool } 70 func (d DummyFrontend) TypeInt8() Type { return TypeInt8 } 71 func (d DummyFrontend) TypeInt16() Type { return TypeInt16 } 72 func (d DummyFrontend) TypeInt32() Type { return TypeInt32 } 73 func (d DummyFrontend) TypeInt64() Type { return TypeInt64 } 74 func (d DummyFrontend) TypeUInt8() Type { return TypeUInt8 } 75 func (d DummyFrontend) TypeUInt16() Type { return TypeUInt16 } 76 func (d DummyFrontend) TypeUInt32() Type { return TypeUInt32 } 77 func (d DummyFrontend) TypeUInt64() Type { return TypeUInt64 } 78 func (d DummyFrontend) TypeFloat32() Type { return TypeFloat32 } 79 func (d DummyFrontend) TypeFloat64() Type { return TypeFloat64 } 80 func (d DummyFrontend) TypeInt() Type { return TypeInt64 } 81 func (d DummyFrontend) TypeUintptr() Type { return TypeUInt64 } 82 func (d DummyFrontend) TypeString() Type { panic("unimplemented") } 83 func (d DummyFrontend) TypeBytePtr() Type { return TypeBytePtr } 84 85 func (d DummyFrontend) CanSSA(t Type) bool { 86 // There are no un-SSAable types in dummy land. 87 return true 88 }