github.com/freddyisaac/sicortex-golang@v0.0.0-20231019035217-e03519e66f60/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/s390x"
    10  	"cmd/internal/obj/x86"
    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  func testConfigS390X(t testing.TB) *Config {
    26  	return NewConfig("s390x", DummyFrontend{t}, obj.Linknew(&s390x.Links390x), true)
    27  }
    28  
    29  // DummyFrontend is a test-only frontend.
    30  // It assumes 64 bit integers and pointers.
    31  type DummyFrontend struct {
    32  	t testing.TB
    33  }
    34  
    35  func (DummyFrontend) StringData(s string) interface{} {
    36  	return nil
    37  }
    38  
    39  type dummyGCNode struct {
    40  	typ  Type
    41  	name string
    42  }
    43  
    44  func (d *dummyGCNode) Typ() Type {
    45  	return d.typ
    46  }
    47  func (d *dummyGCNode) String() string {
    48  	return d.name
    49  }
    50  func (d DummyFrontend) Auto(t Type) GCNode {
    51  	return &dummyGCNode{typ: t, name: "dummy"}
    52  }
    53  func (d DummyFrontend) SplitString(s LocalSlot) (LocalSlot, LocalSlot) {
    54  	return LocalSlot{s.N, d.TypeBytePtr(), s.Off}, LocalSlot{s.N, d.TypeInt(), s.Off + 8}
    55  }
    56  func (d DummyFrontend) SplitInterface(s LocalSlot) (LocalSlot, LocalSlot) {
    57  	return LocalSlot{s.N, d.TypeBytePtr(), s.Off}, LocalSlot{s.N, d.TypeBytePtr(), s.Off + 8}
    58  }
    59  func (d DummyFrontend) SplitSlice(s LocalSlot) (LocalSlot, LocalSlot, LocalSlot) {
    60  	return LocalSlot{s.N, s.Type.ElemType().PtrTo(), s.Off},
    61  		LocalSlot{s.N, d.TypeInt(), s.Off + 8},
    62  		LocalSlot{s.N, d.TypeInt(), s.Off + 16}
    63  }
    64  func (d DummyFrontend) SplitComplex(s LocalSlot) (LocalSlot, LocalSlot) {
    65  	if s.Type.Size() == 16 {
    66  		return LocalSlot{s.N, d.TypeFloat64(), s.Off}, LocalSlot{s.N, d.TypeFloat64(), s.Off + 8}
    67  	}
    68  	return LocalSlot{s.N, d.TypeFloat32(), s.Off}, LocalSlot{s.N, d.TypeFloat32(), s.Off + 4}
    69  }
    70  func (d DummyFrontend) SplitInt64(s LocalSlot) (LocalSlot, LocalSlot) {
    71  	if s.Type.IsSigned() {
    72  		return LocalSlot{s.N, d.TypeInt32(), s.Off + 4}, LocalSlot{s.N, d.TypeUInt32(), s.Off}
    73  	}
    74  	return LocalSlot{s.N, d.TypeUInt32(), s.Off + 4}, LocalSlot{s.N, d.TypeUInt32(), s.Off}
    75  }
    76  func (d DummyFrontend) SplitStruct(s LocalSlot, i int) LocalSlot {
    77  	return LocalSlot{s.N, s.Type.FieldType(i), s.Off + s.Type.FieldOff(i)}
    78  }
    79  func (d DummyFrontend) SplitArray(s LocalSlot) LocalSlot {
    80  	return LocalSlot{s.N, s.Type.ElemType(), s.Off}
    81  }
    82  func (DummyFrontend) Line(line int32) string {
    83  	return "unknown.go:0"
    84  }
    85  func (DummyFrontend) AllocFrame(f *Func) {
    86  }
    87  func (DummyFrontend) Syslook(s string) interface{} {
    88  	return DummySym(s)
    89  }
    90  
    91  func (d DummyFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, args...) }
    92  func (d DummyFrontend) Log() bool                            { return true }
    93  
    94  func (d DummyFrontend) Fatalf(line int32, msg string, args ...interface{}) { d.t.Fatalf(msg, args...) }
    95  func (d DummyFrontend) Warnl(line int32, msg string, args ...interface{})  { d.t.Logf(msg, args...) }
    96  func (d DummyFrontend) Debug_checknil() bool                               { return false }
    97  func (d DummyFrontend) Debug_wb() bool                                     { return false }
    98  
    99  func (d DummyFrontend) TypeBool() Type    { return TypeBool }
   100  func (d DummyFrontend) TypeInt8() Type    { return TypeInt8 }
   101  func (d DummyFrontend) TypeInt16() Type   { return TypeInt16 }
   102  func (d DummyFrontend) TypeInt32() Type   { return TypeInt32 }
   103  func (d DummyFrontend) TypeInt64() Type   { return TypeInt64 }
   104  func (d DummyFrontend) TypeUInt8() Type   { return TypeUInt8 }
   105  func (d DummyFrontend) TypeUInt16() Type  { return TypeUInt16 }
   106  func (d DummyFrontend) TypeUInt32() Type  { return TypeUInt32 }
   107  func (d DummyFrontend) TypeUInt64() Type  { return TypeUInt64 }
   108  func (d DummyFrontend) TypeFloat32() Type { return TypeFloat32 }
   109  func (d DummyFrontend) TypeFloat64() Type { return TypeFloat64 }
   110  func (d DummyFrontend) TypeInt() Type     { return TypeInt64 }
   111  func (d DummyFrontend) TypeUintptr() Type { return TypeUInt64 }
   112  func (d DummyFrontend) TypeString() Type  { panic("unimplemented") }
   113  func (d DummyFrontend) TypeBytePtr() Type { return TypeBytePtr }
   114  
   115  func (d DummyFrontend) CanSSA(t Type) bool {
   116  	// There are no un-SSAable types in dummy land.
   117  	return true
   118  }
   119  
   120  type DummySym string
   121  
   122  func (s DummySym) String() string { return string(s) }