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