| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_WASM_OPCODES_H_ | 5 #ifndef V8_WASM_OPCODES_H_ |
| 6 #define V8_WASM_OPCODES_H_ | 6 #define V8_WASM_OPCODES_H_ |
| 7 | 7 |
| 8 #include "src/machine-type.h" | 8 #include "src/machine-type.h" |
| 9 #include "src/signature.h" | 9 #include "src/signature.h" |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 const LocalType kAstEnd = MachineRepresentation::kTagged; | 47 const LocalType kAstEnd = MachineRepresentation::kTagged; |
| 48 | 48 |
| 49 typedef Signature<LocalType> FunctionSig; | 49 typedef Signature<LocalType> FunctionSig; |
| 50 std::ostream& operator<<(std::ostream& os, const FunctionSig& function); | 50 std::ostream& operator<<(std::ostream& os, const FunctionSig& function); |
| 51 | 51 |
| 52 struct WasmName { | 52 struct WasmName { |
| 53 const char* name; | 53 const char* name; |
| 54 uint32_t length; | 54 uint32_t length; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // TODO(titzer): Renumber all the opcodes to fill in holes. | |
| 58 | |
| 59 // Control expressions and blocks. | 57 // Control expressions and blocks. |
| 60 #define FOREACH_CONTROL_OPCODE(V) \ | 58 #define FOREACH_CONTROL_OPCODE(V) \ |
| 61 V(Nop, 0x00, _) \ | 59 V(Nop, 0x00, _) \ |
| 62 V(Block, 0x01, _) \ | 60 V(Block, 0x01, _) \ |
| 63 V(Loop, 0x02, _) \ | 61 V(Loop, 0x02, _) \ |
| 64 V(If, 0x03, _) \ | 62 V(If, 0x03, _) \ |
| 65 V(IfElse, 0x04, _) \ | 63 V(Else, 0x04, _) \ |
| 66 V(Select, 0x05, _) \ | 64 V(Select, 0x05, _) \ |
| 67 V(Br, 0x06, _) \ | 65 V(Br, 0x06, _) \ |
| 68 V(BrIf, 0x07, _) \ | 66 V(BrIf, 0x07, _) \ |
| 69 V(BrTable, 0x08, _) \ | 67 V(BrTable, 0x08, _) \ |
| 70 V(Return, 0x14, _) \ | 68 V(Return, 0x09, _) \ |
| 71 V(Unreachable, 0x15, _) | 69 V(Unreachable, 0x0a, _) \ |
| 70 V(End, 0x0F, _) |
| 72 | 71 |
| 73 // Constants, locals, globals, and calls. | 72 // Constants, locals, globals, and calls. |
| 74 #define FOREACH_MISC_OPCODE(V) \ | 73 #define FOREACH_MISC_OPCODE(V) \ |
| 75 V(I8Const, 0x09, _) \ | 74 V(I32Const, 0x10, _) \ |
| 76 V(I32Const, 0x0a, _) \ | 75 V(I64Const, 0x11, _) \ |
| 77 V(I64Const, 0x0b, _) \ | 76 V(F64Const, 0x12, _) \ |
| 78 V(F64Const, 0x0c, _) \ | 77 V(F32Const, 0x13, _) \ |
| 79 V(F32Const, 0x0d, _) \ | 78 V(GetLocal, 0x14, _) \ |
| 80 V(GetLocal, 0x0e, _) \ | 79 V(SetLocal, 0x15, _) \ |
| 81 V(SetLocal, 0x0f, _) \ | 80 V(CallFunction, 0x16, _) \ |
| 82 V(LoadGlobal, 0x10, _) \ | 81 V(CallIndirect, 0x17, _) \ |
| 83 V(StoreGlobal, 0x11, _) \ | 82 V(CallImport, 0x18, _) \ |
| 84 V(CallFunction, 0x12, _) \ | 83 V(I8Const, 0xcb, _) \ |
| 85 V(CallIndirect, 0x13, _) \ | 84 V(LoadGlobal, 0xcc, _) \ |
| 86 V(CallImport, 0x1F, _) \ | 85 V(StoreGlobal, 0xcd, _) |
| 87 V(DeclLocals, 0x1E, _) | |
| 88 | 86 |
| 89 // Load memory expressions. | 87 // Load memory expressions. |
| 90 #define FOREACH_LOAD_MEM_OPCODE(V) \ | 88 #define FOREACH_LOAD_MEM_OPCODE(V) \ |
| 91 V(I32LoadMem8S, 0x20, i_i) \ | 89 V(I32LoadMem8S, 0x20, i_i) \ |
| 92 V(I32LoadMem8U, 0x21, i_i) \ | 90 V(I32LoadMem8U, 0x21, i_i) \ |
| 93 V(I32LoadMem16S, 0x22, i_i) \ | 91 V(I32LoadMem16S, 0x22, i_i) \ |
| 94 V(I32LoadMem16U, 0x23, i_i) \ | 92 V(I32LoadMem16U, 0x23, i_i) \ |
| 95 V(I64LoadMem8S, 0x24, l_i) \ | 93 V(I64LoadMem8S, 0x24, l_i) \ |
| 96 V(I64LoadMem8U, 0x25, l_i) \ | 94 V(I64LoadMem8U, 0x25, l_i) \ |
| 97 V(I64LoadMem16S, 0x26, l_i) \ | 95 V(I64LoadMem16S, 0x26, l_i) \ |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 #define DECLARE_NAMED_ENUM(name, opcode, sig) kExpr##name = opcode, | 303 #define DECLARE_NAMED_ENUM(name, opcode, sig) kExpr##name = opcode, |
| 306 FOREACH_OPCODE(DECLARE_NAMED_ENUM) | 304 FOREACH_OPCODE(DECLARE_NAMED_ENUM) |
| 307 #undef DECLARE_NAMED_ENUM | 305 #undef DECLARE_NAMED_ENUM |
| 308 }; | 306 }; |
| 309 | 307 |
| 310 // A collection of opcode-related static methods. | 308 // A collection of opcode-related static methods. |
| 311 class WasmOpcodes { | 309 class WasmOpcodes { |
| 312 public: | 310 public: |
| 313 static bool IsSupported(WasmOpcode opcode); | 311 static bool IsSupported(WasmOpcode opcode); |
| 314 static const char* OpcodeName(WasmOpcode opcode); | 312 static const char* OpcodeName(WasmOpcode opcode); |
| 313 static const char* ShortOpcodeName(WasmOpcode opcode); |
| 315 static FunctionSig* Signature(WasmOpcode opcode); | 314 static FunctionSig* Signature(WasmOpcode opcode); |
| 316 | 315 |
| 317 static byte MemSize(MachineType type) { | 316 static byte MemSize(MachineType type) { |
| 318 return 1 << ElementSizeLog2Of(type.representation()); | 317 return 1 << ElementSizeLog2Of(type.representation()); |
| 319 } | 318 } |
| 320 | 319 |
| 321 static LocalTypeCode LocalTypeCodeFor(LocalType type) { | 320 static LocalTypeCode LocalTypeCodeFor(LocalType type) { |
| 322 switch (type) { | 321 switch (type) { |
| 323 case kAstI32: | 322 case kAstI32: |
| 324 return kLocalI32; | 323 return kLocalI32; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 default: | 471 default: |
| 473 return "<unknown>"; | 472 return "<unknown>"; |
| 474 } | 473 } |
| 475 } | 474 } |
| 476 }; | 475 }; |
| 477 } // namespace wasm | 476 } // namespace wasm |
| 478 } // namespace internal | 477 } // namespace internal |
| 479 } // namespace v8 | 478 } // namespace v8 |
| 480 | 479 |
| 481 #endif // V8_WASM_OPCODES_H_ | 480 #endif // V8_WASM_OPCODES_H_ |
| OLD | NEW |