1// Copyright 2018 The OPA Authors. All rights reserved. 2// Use of this source code is governed by an Apache2 3// license that can be found in the LICENSE file. 4 5// Package opcode contains constants and utilities for working with WASM opcodes. 6package opcode 7 8// Opcode represents a WASM instruction opcode. 9type Opcode byte 10 11// Control instructions. 12const ( 13 Unreachable Opcode = iota 14 Nop 15 Block 16 Loop 17 If 18 Else 19) 20 21const ( 22 // End defines the special end WASM opcode. 23 End Opcode = 0x0B 24) 25 26// Extended control instructions. 27const ( 28 Br Opcode = iota + 0x0C 29 BrIf 30 BrTable 31 Return 32 Call 33 CallIndirect 34) 35 36// Parameter instructions. 37const ( 38 Drop Opcode = iota + 0x1A 39 Select 40) 41 42// Variable instructions. 43const ( 44 GetLocal Opcode = iota + 0x20 45 SetLocal 46 TeeLocal 47 GetGlobal 48 SetGlobal 49) 50 51// Memory instructions. 52const ( 53 I32Load Opcode = iota + 0x28 54 I64Load 55 F32Load 56 F64Load 57 I32Load8S 58 I32Load8U 59 I32Load16S 60 I32Load16U 61 I64Load8S 62 I64Load8U 63 I64Load16S 64 I64Load16U 65 I64Load32S 66 I64Load32U 67 I32Store 68 I64Store 69 F32Store 70 F64Store 71 I32Store8 72 I32Store16 73 I64Store8 74 I64Store16 75 I64Store32 76 MemorySize 77 MemoryGrow 78) 79 80// Numeric instructions. 81const ( 82 I32Const Opcode = iota + 0x41 83 I64Const 84 F32Const 85 F64Const 86 87 I32Eqz 88 I32Eq 89 I32Ne 90 I32LtS 91 I32LtU 92 I32GtS 93 I32GtU 94 I32LeS 95 I32LeU 96 I32GeS 97 I32GeU 98 99 I64Eqz 100 I64Eq 101 I64Ne 102 I64LtS 103 I64LtU 104 I64GtS 105 I64GtU 106 I64LeS 107 I64LeU 108 I64GeS 109 I64GeU 110 111 F32Eq 112 F32Ne 113 F32Lt 114 F32Gt 115 F32Le 116 F32Ge 117 118 F64Eq 119 F64Ne 120 F64Lt 121 F64Gt 122 F64Le 123 F64Ge 124 125 I32Clz 126 I32Ctz 127 I32Popcnt 128 I32Add 129 I32Sub 130 I32Mul 131 I32DivS 132 I32DivU 133 I32RemS 134 I32RemU 135 I32And 136 I32Or 137 I32Xor 138 I32Shl 139 I32ShrS 140 I32ShrU 141 I32Rotl 142 I32Rotr 143 144 I64Clz 145 I64Ctz 146 I64Popcnt 147 I64Add 148 I64Sub 149 I64Mul 150 I64DivS 151 I64DivU 152 I64RemS 153 I64RemU 154 I64And 155 I64Or 156 I64Xor 157 I64Shl 158 I64ShrS 159 I64ShrU 160 I64Rotl 161 I64Rotr 162 163 F32Abs 164 F32Neg 165 F32Ceil 166 F32Floor 167 F32Trunc 168 F32Nearest 169 F32Sqrt 170 F32Add 171 F32Sub 172 F32Mul 173 F32Div 174 F32Min 175 F32Max 176 F32Copysign 177 178 F64Abs 179 F64Neg 180 F64Ceil 181 F64Floor 182 F64Trunc 183 F64Nearest 184 F64Sqrt 185 F64Add 186 F64Sub 187 F64Mul 188 F64Div 189 F64Min 190 F64Max 191 F64Copysign 192 193 I32WrapI64 194 I32TruncSF32 195 I32TruncUF32 196 I32TruncSF64 197 I32TruncUF64 198 I64ExtendSI32 199 I64ExtendUI32 200 I64TruncSF32 201 I64TruncUF32 202 I64TruncSF64 203 I64TruncUF64 204 F32ConvertSI32 205 F32ConvertUI32 206 F32ConvertSI64 207 F32ConvertUI64 208 F32DemoteF64 209 F64ConvertSI32 210 F64ConvertUI32 211 F64ConvertSI64 212 F64ConvertUI64 213 F64PromoteF32 214 I32ReinterpretF32 215 I64ReinterpretF64 216 F32ReinterpretI32 217 F64ReinterpretI64 218) 219