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