github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/engine/wazevo/backend/abi.go (about) 1 package backend 2 3 import ( 4 "fmt" 5 6 "github.com/bananabytelabs/wazero/internal/engine/wazevo/backend/regalloc" 7 "github.com/bananabytelabs/wazero/internal/engine/wazevo/ssa" 8 ) 9 10 // FunctionABI represents an ABI for the specific target combined with the function signature. 11 type FunctionABI interface { 12 // CalleeGenFunctionArgsToVRegs generates instructions to move arguments to virtual registers. 13 CalleeGenFunctionArgsToVRegs(regs []ssa.Value) 14 // CalleeGenVRegsToFunctionReturns generates instructions to move virtual registers to a return value locations. 15 CalleeGenVRegsToFunctionReturns(regs []ssa.Value) 16 } 17 18 type ( 19 // ABIArg represents either argument or return value's location. 20 ABIArg struct { 21 // Index is the index of the argument. 22 Index int 23 // Kind is the kind of the argument. 24 Kind ABIArgKind 25 // Reg is valid if Kind == ABIArgKindReg. 26 // This VReg must be based on RealReg. 27 Reg regalloc.VReg 28 // Offset is valid if Kind == ABIArgKindStack. 29 // This is the offset from the beginning of either arg or ret stack slot. 30 Offset int64 31 // Type is the type of the argument. 32 Type ssa.Type 33 } 34 35 // ABIArgKind is the kind of ABI argument. 36 ABIArgKind byte 37 ) 38 39 const ( 40 // ABIArgKindReg represents an argument passed in a register. 41 ABIArgKindReg = iota 42 // ABIArgKindStack represents an argument passed in the stack. 43 ABIArgKindStack 44 ) 45 46 // String implements fmt.Stringer. 47 func (a *ABIArg) String() string { 48 return fmt.Sprintf("args[%d]: %s", a.Index, a.Kind) 49 } 50 51 // String implements fmt.Stringer. 52 func (a ABIArgKind) String() string { 53 switch a { 54 case ABIArgKindReg: 55 return "reg" 56 case ABIArgKindStack: 57 return "stack" 58 default: 59 panic("BUG") 60 } 61 }