// Copyright 2015 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #if !V8_ENABLE_WEBASSEMBLY #error This header should only be included if WebAssembly is enabled. #endif // !V8_ENABLE_WEBASSEMBLY #ifndef V8_WASM_WASM_OPCODES_H_ #define V8_WASM_WASM_OPCODES_H_ #include <memory> #include "src/common/globals.h" #include "src/common/message-template.h" #include "src/wasm/value-type.h" #include "src/wasm/wasm-constants.h" namespace v8 { namespace internal { namespace wasm { struct WasmModule; V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, const FunctionSig& function); V8_EXPORT_PRIVATE bool IsJSCompatibleSignature(const FunctionSig* sig); // Format of all opcode macros: kExprName, binary, signature, wat name // Control expressions and blocks. #define FOREACH_CONTROL_OPCODE(V) … // Constants, locals, globals, calls, etc. #define FOREACH_MISC_OPCODE(V) … // Load memory expressions. #define FOREACH_LOAD_MEM_OPCODE(V) … // Store memory expressions. #define FOREACH_STORE_MEM_OPCODE(V) … // Miscellaneous memory expressions #define FOREACH_MISC_MEM_OPCODE(V) … // Expressions with signatures. // Opcodes that can also be used in constant expressions (via the 'extended // constant expressions' proposal). #define FOREACH_SIMPLE_EXTENDED_CONST_OPCODE(V) … #define FOREACH_SIMPLE_NON_CONST_OPCODE(V) … #define FOREACH_SIMPLE_OPCODE(V) … #define FOREACH_SIMPLE_PROTOTYPE_OPCODE(V) … // For compatibility with Asm.js. // These opcodes are not spec'ed (or visible) externally; the idea is // to use unused ranges for internal purposes. #define FOREACH_ASMJS_COMPAT_OPCODE(V) … #define FOREACH_SIMD_MEM_OPCODE(V) … #define FOREACH_SIMD_MEM_1_OPERAND_OPCODE(V) … #define FOREACH_SIMD_CONST_OPCODE(V) … #define FOREACH_SIMD_MASK_OPERAND_OPCODE(V) … #define FOREACH_SIMD_MVP_0_OPERAND_OPCODE(V) … #define FOREACH_RELAXED_SIMD_OPCODE(V) … #define FOREACH_SIMD_1_OPERAND_1_PARAM_OPCODE(V) … #define FOREACH_SIMD_1_OPERAND_2_PARAM_OPCODE(V) … #define FOREACH_SIMD_0_OPERAND_OPCODE(V) … #define FOREACH_SIMD_1_OPERAND_OPCODE(V) … #define FOREACH_SIMD_OPCODE(V) … #define FOREACH_NUMERIC_OPCODE_WITH_SIG(V) … #define FOREACH_NUMERIC_OPCODE_VARIADIC(V) … #define FOREACH_NUMERIC_OPCODE(V) … // kExprName, binary, signature for memory32, wat name, signature for memory64. #define FOREACH_ATOMIC_OPCODE(V) … #define FOREACH_ATOMIC_0_OPERAND_OPCODE(V) … #define FOREACH_GC_OPCODE(V) … // All opcodes. #define FOREACH_OPCODE(V) … // All signatures. #define FOREACH_SIGNATURE(V) … #define FOREACH_SIMD_SIGNATURE(V) … #define FOREACH_PREFIX(V) … // Prefixed opcodes are encoded as 1 prefix byte, followed by LEB encoded // opcode bytes. We internally encode them as {WasmOpcode} as follows: // 1) non-prefixed opcodes use the opcode itself as {WasmOpcode} enum value; // 2) prefixed opcodes in [0, 0xff] use {(prefix << 8) | opcode}; // 3) prefixed opcodes in [0x100, 0xfff] use {(prefix << 12) | opcode} (this is // only used for relaxed simd so far). // // This encoding is bijective (i.e. a one-to-one mapping in both directions). // The used opcode ranges are: // 1) [0, 0xff] -> no prefix, 8 bits opcode // 2) [0xfb00, 0xfe00] -> prefix shifted by 8 bits, and 8 bits opcode // 3) [0xfd100, 0xfdfff] -> prefix shifted by 12 bits, and 12 bits opcode // (only [0xfd100, 0xfd1ff] used so far) // // This allows to compute back the prefix and the non-prefixed opcode from each // WasmOpcode, see {WasmOpcodes::ExtractPrefix} and // {ExtractPrefixedOpcodeBytes} (for testing). enum WasmOpcode { … }; enum TrapReason { … }; // A collection of opcode-related static methods. class V8_EXPORT_PRIVATE WasmOpcodes { … }; } // namespace wasm } // namespace internal } // namespace v8 #endif // V8_WASM_WASM_OPCODES_H_