Serenity Operating System
at master 252 lines 11 kB view raw
1/* 2 * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <AK/DistinctNumeric.h> 10 11namespace Wasm { 12 13AK_TYPEDEF_DISTINCT_ORDERED_ID(u32, OpCode); 14 15namespace Instructions { 16 17#define ENUMERATE_SINGLE_BYTE_WASM_OPCODES(M) \ 18 M(unreachable, 0x00) \ 19 M(nop, 0x01) \ 20 M(block, 0x02) \ 21 M(loop, 0x03) \ 22 M(if_, 0x04) \ 23 M(br, 0x0c) \ 24 M(br_if, 0x0d) \ 25 M(br_table, 0x0e) \ 26 M(return_, 0x0f) \ 27 M(call, 0x10) \ 28 M(call_indirect, 0x11) \ 29 M(drop, 0x1a) \ 30 M(select, 0x1b) \ 31 M(select_typed, 0x1c) \ 32 M(local_get, 0x20) \ 33 M(local_set, 0x21) \ 34 M(local_tee, 0x22) \ 35 M(global_get, 0x23) \ 36 M(global_set, 0x24) \ 37 M(table_get, 0x25) \ 38 M(table_set, 0x26) \ 39 M(i32_load, 0x28) \ 40 M(i64_load, 0x29) \ 41 M(f32_load, 0x2a) \ 42 M(f64_load, 0x2b) \ 43 M(i32_load8_s, 0x2c) \ 44 M(i32_load8_u, 0x2d) \ 45 M(i32_load16_s, 0x2e) \ 46 M(i32_load16_u, 0x2f) \ 47 M(i64_load8_s, 0x30) \ 48 M(i64_load8_u, 0x31) \ 49 M(i64_load16_s, 0x32) \ 50 M(i64_load16_u, 0x33) \ 51 M(i64_load32_s, 0x34) \ 52 M(i64_load32_u, 0x35) \ 53 M(i32_store, 0x36) \ 54 M(i64_store, 0x37) \ 55 M(f32_store, 0x38) \ 56 M(f64_store, 0x39) \ 57 M(i32_store8, 0x3a) \ 58 M(i32_store16, 0x3b) \ 59 M(i64_store8, 0x3c) \ 60 M(i64_store16, 0x3d) \ 61 M(i64_store32, 0x3e) \ 62 M(memory_size, 0x3f) \ 63 M(memory_grow, 0x40) \ 64 M(i32_const, 0x41) \ 65 M(i64_const, 0x42) \ 66 M(f32_const, 0x43) \ 67 M(f64_const, 0x44) \ 68 M(i32_eqz, 0x45) \ 69 M(i32_eq, 0x46) \ 70 M(i32_ne, 0x47) \ 71 M(i32_lts, 0x48) \ 72 M(i32_ltu, 0x49) \ 73 M(i32_gts, 0x4a) \ 74 M(i32_gtu, 0x4b) \ 75 M(i32_les, 0x4c) \ 76 M(i32_leu, 0x4d) \ 77 M(i32_ges, 0x4e) \ 78 M(i32_geu, 0x4f) \ 79 M(i64_eqz, 0x50) \ 80 M(i64_eq, 0x51) \ 81 M(i64_ne, 0x52) \ 82 M(i64_lts, 0x53) \ 83 M(i64_ltu, 0x54) \ 84 M(i64_gts, 0x55) \ 85 M(i64_gtu, 0x56) \ 86 M(i64_les, 0x57) \ 87 M(i64_leu, 0x58) \ 88 M(i64_ges, 0x59) \ 89 M(i64_geu, 0x5a) \ 90 M(f32_eq, 0x5b) \ 91 M(f32_ne, 0x5c) \ 92 M(f32_lt, 0x5d) \ 93 M(f32_gt, 0x5e) \ 94 M(f32_le, 0x5f) \ 95 M(f32_ge, 0x60) \ 96 M(f64_eq, 0x61) \ 97 M(f64_ne, 0x62) \ 98 M(f64_lt, 0x63) \ 99 M(f64_gt, 0x64) \ 100 M(f64_le, 0x65) \ 101 M(f64_ge, 0x66) \ 102 M(i32_clz, 0x67) \ 103 M(i32_ctz, 0x68) \ 104 M(i32_popcnt, 0x69) \ 105 M(i32_add, 0x6a) \ 106 M(i32_sub, 0x6b) \ 107 M(i32_mul, 0x6c) \ 108 M(i32_divs, 0x6d) \ 109 M(i32_divu, 0x6e) \ 110 M(i32_rems, 0x6f) \ 111 M(i32_remu, 0x70) \ 112 M(i32_and, 0x71) \ 113 M(i32_or, 0x72) \ 114 M(i32_xor, 0x73) \ 115 M(i32_shl, 0x74) \ 116 M(i32_shrs, 0x75) \ 117 M(i32_shru, 0x76) \ 118 M(i32_rotl, 0x77) \ 119 M(i32_rotr, 0x78) \ 120 M(i64_clz, 0x79) \ 121 M(i64_ctz, 0x7a) \ 122 M(i64_popcnt, 0x7b) \ 123 M(i64_add, 0x7c) \ 124 M(i64_sub, 0x7d) \ 125 M(i64_mul, 0x7e) \ 126 M(i64_divs, 0x7f) \ 127 M(i64_divu, 0x80) \ 128 M(i64_rems, 0x81) \ 129 M(i64_remu, 0x82) \ 130 M(i64_and, 0x83) \ 131 M(i64_or, 0x84) \ 132 M(i64_xor, 0x85) \ 133 M(i64_shl, 0x86) \ 134 M(i64_shrs, 0x87) \ 135 M(i64_shru, 0x88) \ 136 M(i64_rotl, 0x89) \ 137 M(i64_rotr, 0x8a) \ 138 M(f32_abs, 0x8b) \ 139 M(f32_neg, 0x8c) \ 140 M(f32_ceil, 0x8d) \ 141 M(f32_floor, 0x8e) \ 142 M(f32_trunc, 0x8f) \ 143 M(f32_nearest, 0x90) \ 144 M(f32_sqrt, 0x91) \ 145 M(f32_add, 0x92) \ 146 M(f32_sub, 0x93) \ 147 M(f32_mul, 0x94) \ 148 M(f32_div, 0x95) \ 149 M(f32_min, 0x96) \ 150 M(f32_max, 0x97) \ 151 M(f32_copysign, 0x98) \ 152 M(f64_abs, 0x99) \ 153 M(f64_neg, 0x9a) \ 154 M(f64_ceil, 0x9b) \ 155 M(f64_floor, 0x9c) \ 156 M(f64_trunc, 0x9d) \ 157 M(f64_nearest, 0x9e) \ 158 M(f64_sqrt, 0x9f) \ 159 M(f64_add, 0xa0) \ 160 M(f64_sub, 0xa1) \ 161 M(f64_mul, 0xa2) \ 162 M(f64_div, 0xa3) \ 163 M(f64_min, 0xa4) \ 164 M(f64_max, 0xa5) \ 165 M(f64_copysign, 0xa6) \ 166 M(i32_wrap_i64, 0xa7) \ 167 M(i32_trunc_sf32, 0xa8) \ 168 M(i32_trunc_uf32, 0xa9) \ 169 M(i32_trunc_sf64, 0xaa) \ 170 M(i32_trunc_uf64, 0xab) \ 171 M(i64_extend_si32, 0xac) \ 172 M(i64_extend_ui32, 0xad) \ 173 M(i64_trunc_sf32, 0xae) \ 174 M(i64_trunc_uf32, 0xaf) \ 175 M(i64_trunc_sf64, 0xb0) \ 176 M(i64_trunc_uf64, 0xb1) \ 177 M(f32_convert_si32, 0xb2) \ 178 M(f32_convert_ui32, 0xb3) \ 179 M(f32_convert_si64, 0xb4) \ 180 M(f32_convert_ui64, 0xb5) \ 181 M(f32_demote_f64, 0xb6) \ 182 M(f64_convert_si32, 0xb7) \ 183 M(f64_convert_ui32, 0xb8) \ 184 M(f64_convert_si64, 0xb9) \ 185 M(f64_convert_ui64, 0xba) \ 186 M(f64_promote_f32, 0xbb) \ 187 M(i32_reinterpret_f32, 0xbc) \ 188 M(i64_reinterpret_f64, 0xbd) \ 189 M(f32_reinterpret_i32, 0xbe) \ 190 M(f64_reinterpret_i64, 0xbf) \ 191 M(i32_extend8_s, 0xc0) \ 192 M(i32_extend16_s, 0xc1) \ 193 M(i64_extend8_s, 0xc2) \ 194 M(i64_extend16_s, 0xc3) \ 195 M(i64_extend32_s, 0xc4) \ 196 M(ref_null, 0xd0) \ 197 M(ref_is_null, 0xd1) \ 198 M(ref_func, 0xd2) 199 200// These are synthetic opcodes, they are _not_ seen in wasm with these values. 201#define ENUMERATE_MULTI_BYTE_WASM_OPCODES(M) \ 202 M(i32_trunc_sat_f32_s, 0xfc00) \ 203 M(i32_trunc_sat_f32_u, 0xfc01) \ 204 M(i32_trunc_sat_f64_s, 0xfc02) \ 205 M(i32_trunc_sat_f64_u, 0xfc03) \ 206 M(i64_trunc_sat_f32_s, 0xfc04) \ 207 M(i64_trunc_sat_f32_u, 0xfc05) \ 208 M(i64_trunc_sat_f64_s, 0xfc06) \ 209 M(i64_trunc_sat_f64_u, 0xfc07) \ 210 M(memory_init, 0xfc08) \ 211 M(data_drop, 0xfc09) \ 212 M(memory_copy, 0xfc0a) \ 213 M(memory_fill, 0x0fc0b) \ 214 M(table_init, 0xfc0c) \ 215 M(elem_drop, 0xfc0d) \ 216 M(table_copy, 0xfc0e) \ 217 M(table_grow, 0xfc0f) \ 218 M(table_size, 0xfc10) \ 219 M(table_fill, 0xfc11) \ 220 M(structured_else, 0xff00) \ 221 M(structured_end, 0xff01) 222 223#define ENUMERATE_WASM_OPCODES(M) \ 224 ENUMERATE_SINGLE_BYTE_WASM_OPCODES(M) \ 225 ENUMERATE_MULTI_BYTE_WASM_OPCODES(M) 226 227#define M(name, value) static constexpr OpCode name = value; 228ENUMERATE_WASM_OPCODES(M) 229#undef M 230 231static constexpr u32 i32_trunc_sat_f32_s_second = 0, 232 i32_trunc_sat_f32_u_second = 1, 233 i32_trunc_sat_f64_s_second = 2, 234 i32_trunc_sat_f64_u_second = 3, 235 i64_trunc_sat_f32_s_second = 4, 236 i64_trunc_sat_f32_u_second = 5, 237 i64_trunc_sat_f64_s_second = 6, 238 i64_trunc_sat_f64_u_second = 7, 239 memory_init_second = 8, 240 data_drop_second = 9, 241 memory_copy_second = 10, 242 memory_fill_second = 11, 243 table_init_second = 12, 244 elem_drop_second = 13, 245 table_copy_second = 14, 246 table_grow_second = 15, 247 table_size_second = 16, 248 table_fill_second = 17; 249 250} 251 252}