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