github.com/AR1011/wazero@v1.0.5/internal/engine/wazevo/backend/machine_test.go (about) 1 package backend 2 3 import ( 4 "context" 5 6 "github.com/AR1011/wazero/internal/engine/wazevo/backend/regalloc" 7 "github.com/AR1011/wazero/internal/engine/wazevo/ssa" 8 "github.com/AR1011/wazero/internal/engine/wazevo/wazevoapi" 9 ) 10 11 // mockMachine implements Machine for testing. 12 type mockMachine struct { 13 abi mockABI 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 rinfo *regalloc.RegisterInfo 27 } 28 29 func (m mockMachine) CompileEntryPreamble(signature *ssa.Signature) []byte { 30 panic("TODO") 31 } 32 33 func (m mockMachine) CompileStackGrowCallSequence() []byte { 34 panic("TODO") 35 } 36 37 // CompileGoFunctionTrampoline implements Machine.CompileGoFunctionTrampoline. 38 func (m mockMachine) CompileGoFunctionTrampoline(wazevoapi.ExitCode, *ssa.Signature, bool) []byte { 39 panic("TODO") 40 } 41 42 // Encode implements Machine.Encode. 43 func (m mockMachine) Encode() {} 44 45 // ResolveRelocations implements Machine.ResolveRelocations. 46 func (m mockMachine) ResolveRelocations(map[ssa.FuncRef]int, []byte, []RelocationInfo) {} 47 48 // SetupPrologue implements Machine.SetupPrologue. 49 func (m mockMachine) SetupPrologue() {} 50 51 // SetupEpilogue implements Machine.SetupEpilogue. 52 func (m mockMachine) SetupEpilogue() {} 53 54 // ResolveRelativeAddresses implements Machine.ResolveRelativeAddresses. 55 func (m mockMachine) ResolveRelativeAddresses(ctx context.Context) {} 56 57 // Function implements Machine.Function. 58 func (m mockMachine) Function() (f regalloc.Function) { return } 59 60 // RegisterInfo implements Machine.RegisterInfo. 61 func (m mockMachine) RegisterInfo() *regalloc.RegisterInfo { 62 if m.rinfo != nil { 63 return m.rinfo 64 } 65 return ®alloc.RegisterInfo{} 66 } 67 68 // InsertReturn implements Machine.InsertReturn. 69 func (m mockMachine) InsertReturn() { panic("TODO") } 70 71 // LinkAdjacentBlocks implements Machine.LinkAdjacentBlocks. 72 func (m mockMachine) LinkAdjacentBlocks(prev, next ssa.BasicBlock) { m.linkAdjacentBlocks(prev, next) } 73 74 // InitializeABI implements Machine.InitializeABI. 75 func (m mockMachine) InitializeABI(*ssa.Signature) {} 76 77 // ABI implements Machine.ABI. 78 func (m mockMachine) ABI() FunctionABI { return m.abi } 79 80 // SetCompiler implements Machine.SetCompiler. 81 func (m mockMachine) SetCompiler(Compiler) {} 82 83 // StartLoweringFunction implements Machine.StartLoweringFunction. 84 func (m mockMachine) StartLoweringFunction(id ssa.BasicBlockID) { 85 m.startLoweringFunction(id) 86 } 87 88 // StartBlock implements Machine.StartBlock. 89 func (m mockMachine) StartBlock(block ssa.BasicBlock) { 90 m.startBlock(block) 91 } 92 93 // LowerSingleBranch implements Machine.LowerSingleBranch. 94 func (m mockMachine) LowerSingleBranch(b *ssa.Instruction) { 95 m.lowerSingleBranch(b) 96 } 97 98 // LowerConditionalBranch implements Machine.LowerConditionalBranch. 99 func (m mockMachine) LowerConditionalBranch(b *ssa.Instruction) { 100 m.lowerConditionalBranch(b) 101 } 102 103 // LowerInstr implements Machine.LowerInstr. 104 func (m mockMachine) LowerInstr(instruction *ssa.Instruction) { 105 m.lowerInstr(instruction) 106 } 107 108 // EndBlock implements Machine.EndBlock. 109 func (m mockMachine) EndBlock() { 110 m.endBlock() 111 } 112 113 // EndLoweringFunction implements Machine.EndLoweringFunction. 114 func (m mockMachine) EndLoweringFunction() { 115 m.endLoweringFunction() 116 } 117 118 // Reset implements Machine.Reset. 119 func (m mockMachine) Reset() { 120 m.reset() 121 } 122 123 // FlushPendingInstructions implements Machine.FlushPendingInstructions. 124 func (m mockMachine) FlushPendingInstructions() {} 125 126 // InsertMove implements Machine.InsertMove. 127 func (m mockMachine) InsertMove(dst, src regalloc.VReg, typ ssa.Type) { 128 m.insertMove(dst, src) 129 } 130 131 // InsertLoadConstant implements Machine.InsertLoadConstant. 132 func (m mockMachine) InsertLoadConstant(instr *ssa.Instruction, vr regalloc.VReg) { 133 m.insertLoadConstant(instr, vr) 134 } 135 136 // Format implements Machine.Format. 137 func (m mockMachine) Format() string { 138 return m.format() 139 } 140 141 // DisableStackCheck implements Machine.DisableStackCheck. 142 func (m mockMachine) DisableStackCheck() {} 143 144 var _ Machine = (*mockMachine)(nil) 145 146 // mockABI implements ABI for testing. 147 type mockABI struct{} 148 149 func (m mockABI) EmitGoEntryPreamble() {} 150 151 func (m mockABI) CalleeGenFunctionArgsToVRegs(regs []ssa.Value) { 152 panic("TODO") 153 } 154 155 func (m mockABI) CalleeGenVRegsToFunctionReturns(regs []ssa.Value) { 156 panic("TODO") 157 } 158 159 var _ FunctionABI = (*mockABI)(nil)