wa-lang.org/wazero@v1.0.2/internal/engine/compiler/compiler.go (about) 1 package compiler 2 3 import ( 4 "wa-lang.org/wazero/internal/asm" 5 "wa-lang.org/wazero/internal/wazeroir" 6 ) 7 8 // compiler is the interface of architecture-specific native code compiler, 9 // and this is responsible for compiling native code for all wazeroir operations. 10 type compiler interface { 11 // String is for debugging purpose. 12 String() string 13 // compilePreamble is called before compiling any wazeroir operation. 14 // This is used, for example, to initialize the reserved registers, etc. 15 compilePreamble() error 16 // compile generates the byte slice of native code. 17 // stackPointerCeil is the max stack pointer that the target function would reach. 18 compile() (code []byte, stackPointerCeil uint64, err error) 19 // compileGoHostFunction adds the trampoline code from which native code can jump into the Go-defined host function. 20 // TODO: maybe we wouldn't need to have trampoline for host functions. 21 compileGoDefinedHostFunction() error 22 // compileLabel notify compilers of the beginning of a label. 23 // Return true if the compiler decided to skip the entire label. 24 // See wazeroir.OperationLabel 25 compileLabel(o *wazeroir.OperationLabel) (skipThisLabel bool) 26 // compileUnreachable adds instruction to perform wazeroir.OperationUnreachable. 27 compileUnreachable() error 28 // compileSet adds instruction to perform wazeroir.OperationSet. 29 compileSet(o *wazeroir.OperationSet) error 30 // compileGlobalGet adds instructions to perform wazeroir.OperationGlobalGet. 31 compileGlobalGet(o *wazeroir.OperationGlobalGet) error 32 // compileGlobalSet adds instructions to perform wazeroir.OperationGlobalSet. 33 compileGlobalSet(o *wazeroir.OperationGlobalSet) error 34 // compileBr adds instructions to perform wazeroir.OperationBr. 35 compileBr(o *wazeroir.OperationBr) error 36 // compileBrIf adds instructions to perform wazeroir.OperationBrIf. 37 compileBrIf(o *wazeroir.OperationBrIf) error 38 // compileBrTable adds instructions to perform wazeroir.OperationBrTable. 39 compileBrTable(o *wazeroir.OperationBrTable) error 40 // compileCall adds instructions to perform wazeroir.OperationCall. 41 compileCall(o *wazeroir.OperationCall) error 42 // compileCallIndirect adds instructions to perform wazeroir.OperationCallIndirect. 43 compileCallIndirect(o *wazeroir.OperationCallIndirect) error 44 // compileDrop adds instructions to perform wazeroir.OperationDrop. 45 compileDrop(o *wazeroir.OperationDrop) error 46 // compileSelect adds instructions to perform wazeroir.OperationSelect. 47 compileSelect(o *wazeroir.OperationSelect) error 48 // compilePick adds instructions to perform wazeroir.OperationPick. 49 compilePick(o *wazeroir.OperationPick) error 50 // compileAdd adds instructions to perform wazeroir.OperationAdd. 51 compileAdd(o *wazeroir.OperationAdd) error 52 // compileSub adds instructions to perform wazeroir.OperationSub. 53 compileSub(o *wazeroir.OperationSub) error 54 // compileMul adds instructions to perform wazeroir.OperationMul. 55 compileMul(o *wazeroir.OperationMul) error 56 // compileClz adds instructions to perform wazeroir.OperationClz. 57 compileClz(o *wazeroir.OperationClz) error 58 // compileCtz adds instructions to perform wazeroir.OperationCtz. 59 compileCtz(o *wazeroir.OperationCtz) error 60 // compilePopcnt adds instructions to perform wazeroir.OperationPopcnt. 61 compilePopcnt(o *wazeroir.OperationPopcnt) error 62 // compileDiv adds instructions to perform wazeroir.OperationDiv. 63 compileDiv(o *wazeroir.OperationDiv) error 64 // compileRem adds instructions to perform wazeroir.OperationRem. 65 compileRem(o *wazeroir.OperationRem) error 66 // compileAnd adds instructions to perform wazeroir.OperationAnd. 67 compileAnd(o *wazeroir.OperationAnd) error 68 // compileOr adds instructions to perform wazeroir.OperationOr. 69 compileOr(o *wazeroir.OperationOr) error 70 // compileXor adds instructions to perform wazeroir.OperationXor. 71 compileXor(o *wazeroir.OperationXor) error 72 // compileShl adds instructions to perform wazeroir.OperationShl. 73 compileShl(o *wazeroir.OperationShl) error 74 // compileShr adds instructions to perform wazeroir.OperationShr. 75 compileShr(o *wazeroir.OperationShr) error 76 // compileRotl adds instructions to perform wazeroir.OperationRotl. 77 compileRotl(o *wazeroir.OperationRotl) error 78 // compileRotr adds instructions to perform wazeroir.OperationRotr. 79 compileRotr(o *wazeroir.OperationRotr) error 80 // compileNeg adds instructions to perform wazeroir.OperationAbs. 81 compileAbs(o *wazeroir.OperationAbs) error 82 // compileNeg adds instructions to perform wazeroir.OperationNeg. 83 compileNeg(o *wazeroir.OperationNeg) error 84 // compileCeil adds instructions to perform wazeroir.OperationCeil. 85 compileCeil(o *wazeroir.OperationCeil) error 86 // compileFloor adds instructions to perform wazeroir.OperationFloor. 87 compileFloor(o *wazeroir.OperationFloor) error 88 // compileTrunc adds instructions to perform wazeroir.OperationTrunc. 89 compileTrunc(o *wazeroir.OperationTrunc) error 90 // compileNearest adds instructions to perform wazeroir.OperationNearest. 91 compileNearest(o *wazeroir.OperationNearest) error 92 // compileSqrt adds instructions perform wazeroir.OperationSqrt. 93 compileSqrt(o *wazeroir.OperationSqrt) error 94 // compileMin adds instructions perform wazeroir.OperationMin. 95 compileMin(o *wazeroir.OperationMin) error 96 // compileMax adds instructions perform wazeroir.OperationMax. 97 compileMax(o *wazeroir.OperationMax) error 98 // compileCopysign adds instructions to perform wazeroir.OperationCopysign. 99 compileCopysign(o *wazeroir.OperationCopysign) error 100 // compileI32WrapFromI64 adds instructions to perform wazeroir.OperationI32WrapFromI64. 101 compileI32WrapFromI64() error 102 // compileITruncFromF adds instructions to perform wazeroir.OperationITruncFromF. 103 compileITruncFromF(o *wazeroir.OperationITruncFromF) error 104 // compileFConvertFromI adds instructions to perform wazeroir.OperationFConvertFromI. 105 compileFConvertFromI(o *wazeroir.OperationFConvertFromI) error 106 // compileF32DemoteFromF64 adds instructions to perform wazeroir.OperationF32DemoteFromF64. 107 compileF32DemoteFromF64() error 108 // compileF64PromoteFromF32 adds instructions to perform wazeroir.OperationF64PromoteFromF32. 109 compileF64PromoteFromF32() error 110 // compileI32ReinterpretFromF32 adds instructions to perform wazeroir.OperationI32ReinterpretFromF32. 111 compileI32ReinterpretFromF32() error 112 // compileI64ReinterpretFromF64 adds instructions to perform wazeroir.OperationI64ReinterpretFromF64. 113 compileI64ReinterpretFromF64() error 114 // compileF32ReinterpretFromI32 adds instructions to perform wazeroir.OperationF32ReinterpretFromI32. 115 compileF32ReinterpretFromI32() error 116 // compileF64ReinterpretFromI64 adds instructions to perform wazeroir.OperationF64ReinterpretFromI64. 117 compileF64ReinterpretFromI64() error 118 // compileExtend adds instructions to perform wazeroir.OperationExtend. 119 compileExtend(o *wazeroir.OperationExtend) error 120 // compileEq adds instructions to perform wazeroir.OperationEq. 121 compileEq(o *wazeroir.OperationEq) error 122 // compileEq adds instructions to perform wazeroir.OperationNe. 123 compileNe(o *wazeroir.OperationNe) error 124 // compileEq adds instructions to perform wazeroir.OperationEqz. 125 compileEqz(o *wazeroir.OperationEqz) error 126 // compileLt adds instructions to perform wazeroir.OperationLt. 127 compileLt(o *wazeroir.OperationLt) error 128 // compileGt adds instructions to perform wazeroir.OperationGt. 129 compileGt(o *wazeroir.OperationGt) error 130 // compileLe adds instructions to perform wazeroir.OperationLe. 131 compileLe(o *wazeroir.OperationLe) error 132 // compileLe adds instructions to perform wazeroir.OperationGe. 133 compileGe(o *wazeroir.OperationGe) error 134 // compileLoad adds instructions to perform wazeroir.OperationLoad. 135 compileLoad(o *wazeroir.OperationLoad) error 136 // compileLoad8 adds instructions to perform wazeroir.OperationLoad8. 137 compileLoad8(o *wazeroir.OperationLoad8) error 138 // compileLoad16 adds instructions to perform wazeroir.OperationLoad16. 139 compileLoad16(o *wazeroir.OperationLoad16) error 140 // compileLoad32 adds instructions to perform wazeroir.OperationLoad32. 141 compileLoad32(o *wazeroir.OperationLoad32) error 142 // compileStore adds instructions to perform wazeroir.OperationStore. 143 compileStore(o *wazeroir.OperationStore) error 144 // compileStore8 adds instructions to perform wazeroir.OperationStore8. 145 compileStore8(o *wazeroir.OperationStore8) error 146 // compileStore16 adds instructions to perform wazeroir.OperationStore16. 147 compileStore16(o *wazeroir.OperationStore16) error 148 // compileStore32 adds instructions to perform wazeroir.OperationStore32. 149 compileStore32(o *wazeroir.OperationStore32) error 150 // compileMemorySize adds instruction to perform wazeroir.OperationMemoryGrow. 151 compileMemoryGrow() error 152 // compileMemorySize adds instruction to perform wazeroir.OperationMemorySize. 153 compileMemorySize() error 154 // compileConstI32 adds instruction to perform wazeroir.OperationConstI32. 155 compileConstI32(o *wazeroir.OperationConstI32) error 156 // compileConstI64 adds instruction to perform wazeroir.OperationConstI64. 157 compileConstI64(o *wazeroir.OperationConstI64) error 158 // compileConstF32 adds instruction to perform wazeroir.OperationConstF32. 159 compileConstF32(o *wazeroir.OperationConstF32) error 160 // compileConstF64 adds instruction to perform wazeroir.OperationConstF64. 161 compileConstF64(o *wazeroir.OperationConstF64) error 162 // compileSignExtend32From8 adds instructions to perform wazeroir.OperationSignExtend32From8. 163 compileSignExtend32From8() error 164 // compileSignExtend32From16 adds instructions to perform wazeroir.OperationSignExtend32From16. 165 compileSignExtend32From16() error 166 // compileSignExtend64From8 adds instructions to perform wazeroir.OperationSignExtend64From8. 167 compileSignExtend64From8() error 168 // compileSignExtend64From16 adds instructions to perform wazeroir.OperationSignExtend64From16. 169 compileSignExtend64From16() error 170 // compileSignExtend64From32 adds instructions to perform wazeroir.OperationSignExtend64From32. 171 compileSignExtend64From32() error 172 // compileMemoryInit adds instructions to perform wazeroir.OperationMemoryInit. 173 compileMemoryInit(*wazeroir.OperationMemoryInit) error 174 // compileDataDrop adds instructions to perform wazeroir.OperationDataDrop. 175 compileDataDrop(*wazeroir.OperationDataDrop) error 176 // compileMemoryCopy adds instructions to perform wazeroir.OperationMemoryCopy. 177 compileMemoryCopy() error 178 // compileMemoryFill adds instructions to perform wazeroir.OperationMemoryFill. 179 compileMemoryFill() error 180 // compileTableInit adds instructions to perform wazeroir.OperationTableInit. 181 compileTableInit(*wazeroir.OperationTableInit) error 182 // compileTableCopy adds instructions to perform wazeroir.OperationTableCopy. 183 compileTableCopy(*wazeroir.OperationTableCopy) error 184 // compileElemDrop adds instructions to perform wazeroir.OperationElemDrop. 185 compileElemDrop(*wazeroir.OperationElemDrop) error 186 // compileRefFunc adds instructions to perform wazeroir.OperationRefFunc. 187 compileRefFunc(*wazeroir.OperationRefFunc) error 188 // compileTableGet adds instructions to perform wazeroir.OperationTableGet. 189 compileTableGet(*wazeroir.OperationTableGet) error 190 // compileTableSet adds instructions to perform wazeroir.OperationTableSet. 191 compileTableSet(*wazeroir.OperationTableSet) error 192 // compileTableGrow adds instructions to perform wazeroir.OperationTableGrow. 193 compileTableGrow(*wazeroir.OperationTableGrow) error 194 // compileTableSize adds instructions to perform wazeroir.OperationTableSize. 195 compileTableSize(*wazeroir.OperationTableSize) error 196 // compileTableFill adds instructions to perform wazeroir.OperationTableFill. 197 compileTableFill(*wazeroir.OperationTableFill) error 198 // compileV128Const adds instructions to perform wazeroir.OperationV128Const. 199 compileV128Const(*wazeroir.OperationV128Const) error 200 // compileV128Add adds instructions to perform wazeroir.OperationV128Add. 201 compileV128Add(o *wazeroir.OperationV128Add) error 202 // compileV128Sub adds instructions to perform wazeroir.OperationV128Sub. 203 compileV128Sub(o *wazeroir.OperationV128Sub) error 204 // compileV128Load adds instructions to perform wazeroir.OperationV128Load. 205 compileV128Load(o *wazeroir.OperationV128Load) error 206 // compileV128LoadLane adds instructions to perform wazeroir.OperationV128LoadLane. 207 compileV128LoadLane(o *wazeroir.OperationV128LoadLane) error 208 // compileV128Store adds instructions to perform wazeroir.OperationV128Store. 209 compileV128Store(o *wazeroir.OperationV128Store) error 210 // compileV128StoreLane adds instructions to perform wazeroir.OperationV128StoreLane. 211 compileV128StoreLane(o *wazeroir.OperationV128StoreLane) error 212 // compileV128ExtractLane adds instructions to perform wazeroir.OperationV128ExtractLane. 213 compileV128ExtractLane(o *wazeroir.OperationV128ExtractLane) error 214 // compileV128ReplaceLane adds instructions to perform wazeroir.OperationV128ReplaceLane. 215 compileV128ReplaceLane(o *wazeroir.OperationV128ReplaceLane) error 216 // compileV128Splat adds instructions to perform wazeroir.OperationV128Splat. 217 compileV128Splat(o *wazeroir.OperationV128Splat) error 218 // compileV128Shuffle adds instructions to perform wazeroir.OperationV128Shuffle. 219 compileV128Shuffle(o *wazeroir.OperationV128Shuffle) error 220 // compileV128Swizzle adds instructions to perform wazeroir.OperationV128Swizzle. 221 compileV128Swizzle(o *wazeroir.OperationV128Swizzle) error 222 // compileV128AnyTrue adds instructions to perform wazeroir.OperationV128AnyTrue. 223 compileV128AnyTrue(o *wazeroir.OperationV128AnyTrue) error 224 // compileV128AllTrue adds instructions to perform wazeroir.OperationV128AllTrue. 225 compileV128AllTrue(o *wazeroir.OperationV128AllTrue) error 226 // compileV128BitMask adds instructions to perform wazeroir.OperationV128BitMask. 227 compileV128BitMask(*wazeroir.OperationV128BitMask) error 228 // compileV128And adds instructions to perform wazeroir.OperationV128And. 229 compileV128And(*wazeroir.OperationV128And) error 230 // compileV128Not adds instructions to perform wazeroir.OperationV128Not. 231 compileV128Not(*wazeroir.OperationV128Not) error 232 // compileV128Or adds instructions to perform wazeroir.OperationV128Or. 233 compileV128Or(*wazeroir.OperationV128Or) error 234 // compileV128Xor adds instructions to perform wazeroir.OperationV128Xor. 235 compileV128Xor(*wazeroir.OperationV128Xor) error 236 // compileV128Bitselect adds instructions to perform wazeroir.OperationV128Bitselect. 237 compileV128Bitselect(*wazeroir.OperationV128Bitselect) error 238 // compileV128AndNot adds instructions to perform wazeroir.OperationV128AndNot. 239 compileV128AndNot(*wazeroir.OperationV128AndNot) error 240 // compileV128Shr adds instructions to perform wazeroir.OperationV128Shr. 241 compileV128Shr(*wazeroir.OperationV128Shr) error 242 // compileV128Shl adds instructions to perform wazeroir.OperationV128Shl. 243 compileV128Shl(*wazeroir.OperationV128Shl) error 244 // compileV128Cmp adds instructions to perform wazeroir.OperationV128Cmp. 245 compileV128Cmp(*wazeroir.OperationV128Cmp) error 246 // compileV128AddSat adds instructions to perform wazeroir.OperationV128AddSat. 247 compileV128AddSat(*wazeroir.OperationV128AddSat) error 248 // compileV128SubSat adds instructions to perform wazeroir.OperationV128SubSat. 249 compileV128SubSat(*wazeroir.OperationV128SubSat) error 250 // compileV128Mul adds instructions to perform wazeroir.OperationV128Mul. 251 compileV128Mul(*wazeroir.OperationV128Mul) error 252 // compileV128Div adds instructions to perform wazeroir.OperationV128Div. 253 compileV128Div(*wazeroir.OperationV128Div) error 254 // compileV128Neg adds instructions to perform wazeroir.OperationV128Neg. 255 compileV128Neg(*wazeroir.OperationV128Neg) error 256 // compileV128Sqrt adds instructions to perform wazeroir.OperationV128Sqrt. 257 compileV128Sqrt(*wazeroir.OperationV128Sqrt) error 258 // compileV128Abs adds instructions to perform wazeroir.OperationV128Abs. 259 compileV128Abs(*wazeroir.OperationV128Abs) error 260 // compileV128Popcnt adds instructions to perform wazeroir.OperationV128Popcnt. 261 compileV128Popcnt(*wazeroir.OperationV128Popcnt) error 262 // compileV128Min adds instructions to perform wazeroir.OperationV128Min. 263 compileV128Min(*wazeroir.OperationV128Min) error 264 // compileV128Max adds instructions to perform wazeroir.OperationV128Max. 265 compileV128Max(*wazeroir.OperationV128Max) error 266 // compileV128AvgrU adds instructions to perform wazeroir.OperationV128AvgrU. 267 compileV128AvgrU(*wazeroir.OperationV128AvgrU) error 268 // compileV128Pmin adds instructions to perform wazeroir.OperationV128Pmin. 269 compileV128Pmin(*wazeroir.OperationV128Pmin) error 270 // compileV128Pmax adds instructions to perform wazeroir.OperationV128Pmax. 271 compileV128Pmax(*wazeroir.OperationV128Pmax) error 272 // compileV128Ceil adds instructions to perform wazeroir.OperationV128Ceil. 273 compileV128Ceil(*wazeroir.OperationV128Ceil) error 274 // compileV128Floor adds instructions to perform wazeroir.OperationV128Floor. 275 compileV128Floor(*wazeroir.OperationV128Floor) error 276 // compileV128Trunc adds instructions to perform wazeroir.OperationV128Trunc. 277 compileV128Trunc(*wazeroir.OperationV128Trunc) error 278 // compileV128Nearest adds instructions to perform wazeroir.OperationV128Nearest. 279 compileV128Nearest(*wazeroir.OperationV128Nearest) error 280 // compileV128Extend adds instructions to perform wazeroir.OperationV128Extend. 281 compileV128Extend(*wazeroir.OperationV128Extend) error 282 // compileV128ExtMul adds instructions to perform wazeroir.OperationV128ExtMul. 283 compileV128ExtMul(*wazeroir.OperationV128ExtMul) error 284 // compileV128Q15mulrSatS adds instructions to perform wazeroir.OperationV128Q15mulrSatS. 285 compileV128Q15mulrSatS(*wazeroir.OperationV128Q15mulrSatS) error 286 // compileV128ExtAddPairwise adds instructions to perform wazeroir.OperationV128ExtAddPairwise. 287 compileV128ExtAddPairwise(o *wazeroir.OperationV128ExtAddPairwise) error 288 // compileV128FloatPromote adds instructions to perform wazeroir.OperationV128FloatPromote. 289 compileV128FloatPromote(o *wazeroir.OperationV128FloatPromote) error 290 // compileV128FloatDemote adds instructions to perform wazeroir.OperationV128FloatDemote. 291 compileV128FloatDemote(o *wazeroir.OperationV128FloatDemote) error 292 // compileV128FConvertFromI adds instructions to perform wazeroir.OperationV128FConvertFromI. 293 compileV128FConvertFromI(o *wazeroir.OperationV128FConvertFromI) error 294 // compileV128Dot adds instructions to perform wazeroir.OperationV128Dot. 295 compileV128Dot(o *wazeroir.OperationV128Dot) error 296 // compileV128Narrow adds instructions to perform wazeroir.OperationV128Narrow. 297 compileV128Narrow(o *wazeroir.OperationV128Narrow) error 298 // compileV128ITruncSatFromF adds instructions to perform wazeroir.OperationV128ITruncSatFromF. 299 compileV128ITruncSatFromF(o *wazeroir.OperationV128ITruncSatFromF) error 300 301 // compileReleaseRegisterToStack adds instructions to write the value on a register back to memory stack region. 302 compileReleaseRegisterToStack(loc *runtimeValueLocation) 303 // compileLoadValueOnStackToRegister adds instructions to load the value located on the stack to the assigned register. 304 compileLoadValueOnStackToRegister(loc *runtimeValueLocation) 305 306 // maybeCompileMoveTopConditionalToGeneralPurposeRegister moves the top value on the stack 307 // if the value is located on a conditional register. 308 // 309 // This is usually called at the beginning of methods on compiler interface where we possibly 310 // compile instructions without saving the conditional register value. 311 // The compileXXX functions without calling this function is saving the conditional 312 // value to the stack or register by invoking compileEnsureOnRegister for the top. 313 maybeCompileMoveTopConditionalToGeneralPurposeRegister() error 314 // allocateRegister returns an unused register of the given type. The register will be taken 315 // either from the free register pool or by stealing a used register. 316 // 317 // Note: resulting registers will not be marked as used so the call site should 318 // mark it used if necessary. 319 allocateRegister(t registerType) (reg asm.Register, err error) 320 // runtimeValueLocationStack returns the current runtimeValueLocationStack of the compiler implementation. 321 runtimeValueLocationStack() *runtimeValueLocationStack 322 // pushRuntimeValueLocationOnRegister pushes a new runtimeValueLocation on a register `reg` and of the type `vt`. 323 pushRuntimeValueLocationOnRegister(reg asm.Register, vt runtimeValueType) (ret *runtimeValueLocation) 324 // pushRuntimeValueLocationOnRegister pushes a new vector value's runtimeValueLocation on a register `reg`. 325 pushVectorRuntimeValueLocationOnRegister(reg asm.Register) (lowerBitsLocation *runtimeValueLocation) 326 }