github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/engine/wazevo/backend/machine_test.go (about)

     1  package backend
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc"
     7  	"github.com/tetratelabs/wazero/internal/engine/wazevo/ssa"
     8  	"github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi"
     9  )
    10  
    11  // mockMachine implements Machine for testing.
    12  type mockMachine struct {
    13  	argResultInts, argResultFloats []regalloc.RealReg
    14  	startLoweringFunction          func(id ssa.BasicBlockID)
    15  	startBlock                     func(block ssa.BasicBlock)
    16  	lowerSingleBranch              func(b *ssa.Instruction)
    17  	lowerConditionalBranch         func(b *ssa.Instruction)
    18  	lowerInstr                     func(instruction *ssa.Instruction)
    19  	endBlock                       func()
    20  	endLoweringFunction            func()
    21  	reset                          func()
    22  	insertMove                     func(dst, src regalloc.VReg)
    23  	insertLoadConstant             func(instr *ssa.Instruction, vr regalloc.VReg)
    24  	format                         func() string
    25  	linkAdjacentBlocks             func(prev, next ssa.BasicBlock)
    26  }
    27  
    28  func (m mockMachine) CallTrampolineIslandInfo(_ int) (_, _ int, _ error) { panic("implement me") }
    29  
    30  func (m mockMachine) ArgsResultsRegs() (argResultInts, argResultFloats []regalloc.RealReg) {
    31  	return m.argResultInts, m.argResultFloats
    32  }
    33  
    34  func (m mockMachine) RegAlloc() { panic("implement me") }
    35  
    36  func (m mockMachine) LowerParams(params []ssa.Value) { panic("implement me") }
    37  
    38  func (m mockMachine) LowerReturns(returns []ssa.Value) { panic("implement me") }
    39  
    40  func (m mockMachine) ExecutableContext() ExecutableContext { panic("implement me") }
    41  
    42  func (m mockMachine) CompileEntryPreamble(signature *ssa.Signature) []byte {
    43  	panic("TODO")
    44  }
    45  
    46  func (m mockMachine) CompileStackGrowCallSequence() []byte {
    47  	panic("TODO")
    48  }
    49  
    50  // CompileGoFunctionTrampoline implements Machine.CompileGoFunctionTrampoline.
    51  func (m mockMachine) CompileGoFunctionTrampoline(wazevoapi.ExitCode, *ssa.Signature, bool) []byte {
    52  	panic("TODO")
    53  }
    54  
    55  // Encode implements Machine.Encode.
    56  func (m mockMachine) Encode(context.Context) (err error) { return }
    57  
    58  // ResolveRelocations implements Machine.ResolveRelocations.
    59  func (m mockMachine) ResolveRelocations([]int, []byte, []RelocationInfo, []int) {}
    60  
    61  // PostRegAlloc implements Machine.SetupPrologue.
    62  func (m mockMachine) PostRegAlloc() {}
    63  
    64  // InsertReturn implements Machine.InsertReturn.
    65  func (m mockMachine) InsertReturn() { panic("TODO") }
    66  
    67  // LinkAdjacentBlocks implements Machine.LinkAdjacentBlocks.
    68  func (m mockMachine) LinkAdjacentBlocks(prev, next ssa.BasicBlock) { m.linkAdjacentBlocks(prev, next) }
    69  
    70  // SetCurrentABI implements Machine.SetCurrentABI.
    71  func (m mockMachine) SetCurrentABI(*FunctionABI) {}
    72  
    73  // SetCompiler implements Machine.SetCompiler.
    74  func (m mockMachine) SetCompiler(Compiler) {}
    75  
    76  // StartLoweringFunction implements Machine.StartLoweringFunction.
    77  func (m mockMachine) StartLoweringFunction(id ssa.BasicBlockID) {
    78  	m.startLoweringFunction(id)
    79  }
    80  
    81  // StartBlock implements Machine.StartBlock.
    82  func (m mockMachine) StartBlock(block ssa.BasicBlock) {
    83  	m.startBlock(block)
    84  }
    85  
    86  // LowerSingleBranch implements Machine.LowerSingleBranch.
    87  func (m mockMachine) LowerSingleBranch(b *ssa.Instruction) {
    88  	m.lowerSingleBranch(b)
    89  }
    90  
    91  // LowerConditionalBranch implements Machine.LowerConditionalBranch.
    92  func (m mockMachine) LowerConditionalBranch(b *ssa.Instruction) {
    93  	m.lowerConditionalBranch(b)
    94  }
    95  
    96  // LowerInstr implements Machine.LowerInstr.
    97  func (m mockMachine) LowerInstr(instruction *ssa.Instruction) {
    98  	m.lowerInstr(instruction)
    99  }
   100  
   101  // EndBlock implements Machine.EndBlock.
   102  func (m mockMachine) EndBlock() {
   103  	m.endBlock()
   104  }
   105  
   106  // EndLoweringFunction implements Machine.EndLoweringFunction.
   107  func (m mockMachine) EndLoweringFunction() {
   108  	m.endLoweringFunction()
   109  }
   110  
   111  // Reset implements Machine.Reset.
   112  func (m mockMachine) Reset() {
   113  	m.reset()
   114  }
   115  
   116  // FlushPendingInstructions implements Machine.FlushPendingInstructions.
   117  func (m mockMachine) FlushPendingInstructions() {}
   118  
   119  // InsertMove implements Machine.InsertMove.
   120  func (m mockMachine) InsertMove(dst, src regalloc.VReg, typ ssa.Type) {
   121  	m.insertMove(dst, src)
   122  }
   123  
   124  // InsertLoadConstantBlockArg implements Machine.InsertLoadConstantBlockArg.
   125  func (m mockMachine) InsertLoadConstantBlockArg(instr *ssa.Instruction, vr regalloc.VReg) {
   126  	m.insertLoadConstant(instr, vr)
   127  }
   128  
   129  // Format implements Machine.Format.
   130  func (m mockMachine) Format() string {
   131  	return m.format()
   132  }
   133  
   134  // DisableStackCheck implements Machine.DisableStackCheck.
   135  func (m mockMachine) DisableStackCheck() {}
   136  
   137  var _ Machine = (*mockMachine)(nil)