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 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 namespace wasm { | 13 namespace wasm { |
14 | 14 |
15 // Binary encoding of local types. | 15 // Binary encoding of local types. |
16 enum LocalTypeCode { | 16 enum LocalTypeCode { |
17 kLocalVoid = 0, | 17 kLocalVoid = 0, |
18 kLocalI32 = 1, | 18 kLocalI32 = 1, |
19 kLocalI64 = 2, | 19 kLocalI64 = 2, |
20 kLocalF32 = 3, | 20 kLocalF32 = 3, |
21 kLocalF64 = 4, | 21 kLocalF64 = 4, |
22 kLocalS128 = 5 | 22 kLocalS128 = 5 |
23 }; | 23 }; |
24 | 24 |
25 // Type code for multi-value block types. | |
26 static const uint8_t kMultivalBlock = 0x41; | |
27 | |
28 // We reuse the internal machine type to represent WebAssembly AST types. | 25 // We reuse the internal machine type to represent WebAssembly AST types. |
29 // A typedef improves readability without adding a whole new type system. | 26 // A typedef improves readability without adding a whole new type system. |
30 typedef MachineRepresentation LocalType; | 27 typedef MachineRepresentation LocalType; |
31 const LocalType kAstStmt = MachineRepresentation::kNone; | 28 const LocalType kAstStmt = MachineRepresentation::kNone; |
32 const LocalType kAstI32 = MachineRepresentation::kWord32; | 29 const LocalType kAstI32 = MachineRepresentation::kWord32; |
33 const LocalType kAstI64 = MachineRepresentation::kWord64; | 30 const LocalType kAstI64 = MachineRepresentation::kWord64; |
34 const LocalType kAstF32 = MachineRepresentation::kFloat32; | 31 const LocalType kAstF32 = MachineRepresentation::kFloat32; |
35 const LocalType kAstF64 = MachineRepresentation::kFloat64; | 32 const LocalType kAstF64 = MachineRepresentation::kFloat64; |
36 const LocalType kAstS128 = MachineRepresentation::kSimd128; | 33 const LocalType kAstS128 = MachineRepresentation::kSimd128; |
37 // We use kTagged here because kNone is already used by kAstStmt. | 34 // We use kTagged here because kNone is already used by kAstStmt. |
38 const LocalType kAstEnd = MachineRepresentation::kTagged; | 35 const LocalType kAstEnd = MachineRepresentation::kTagged; |
39 | 36 |
40 typedef Signature<LocalType> FunctionSig; | 37 typedef Signature<LocalType> FunctionSig; |
41 std::ostream& operator<<(std::ostream& os, const FunctionSig& function); | 38 std::ostream& operator<<(std::ostream& os, const FunctionSig& function); |
42 | 39 |
43 typedef Vector<const char> WasmName; | 40 typedef Vector<const char> WasmName; |
44 | 41 |
45 typedef int WasmCodePosition; | 42 typedef int WasmCodePosition; |
46 const WasmCodePosition kNoCodePosition = -1; | 43 const WasmCodePosition kNoCodePosition = -1; |
47 | 44 |
48 // Control expressions and blocks. | 45 // Control expressions and blocks. |
49 #define FOREACH_CONTROL_OPCODE(V) \ | 46 #define FOREACH_CONTROL_OPCODE(V) \ |
50 V(Unreachable, 0x00, _) \ | 47 V(Nop, 0x00, _) \ |
51 V(Block, 0x01, _) \ | 48 V(Block, 0x01, _) \ |
52 V(Loop, 0x02, _) \ | 49 V(Loop, 0x02, _) \ |
53 V(If, 0x03, _) \ | 50 V(If, 0x03, _) \ |
54 V(Else, 0x04, _) \ | 51 V(Else, 0x04, _) \ |
55 V(Select, 0x05, _) \ | 52 V(Select, 0x05, _) \ |
56 V(Br, 0x06, _) \ | 53 V(Br, 0x06, _) \ |
57 V(BrIf, 0x07, _) \ | 54 V(BrIf, 0x07, _) \ |
58 V(BrTable, 0x08, _) \ | 55 V(BrTable, 0x08, _) \ |
59 V(Return, 0x09, _) \ | 56 V(Return, 0x09, _) \ |
60 V(Nop, 0x0a, _) \ | 57 V(Unreachable, 0x0a, _) \ |
61 V(Throw, 0xfa, _) \ | 58 V(Throw, 0xfa, _) \ |
62 V(Try, 0xfb, _) \ | 59 V(Try, 0xfb, _) \ |
63 V(Catch, 0xfe, _) \ | 60 V(Catch, 0xfe, _) \ |
64 V(End, 0x0F, _) | 61 V(End, 0x0F, _) |
65 | 62 |
66 // Constants, locals, globals, and calls. | 63 // Constants, locals, globals, and calls. |
67 #define FOREACH_MISC_OPCODE(V) \ | 64 #define FOREACH_MISC_OPCODE(V) \ |
68 V(I32Const, 0x10, _) \ | 65 V(I32Const, 0x10, _) \ |
69 V(I64Const, 0x11, _) \ | 66 V(I64Const, 0x11, _) \ |
70 V(F64Const, 0x12, _) \ | 67 V(F64Const, 0x12, _) \ |
71 V(F32Const, 0x13, _) \ | 68 V(F32Const, 0x13, _) \ |
72 V(GetLocal, 0x14, _) \ | 69 V(GetLocal, 0x14, _) \ |
73 V(SetLocal, 0x15, _) \ | 70 V(SetLocal, 0x15, _) \ |
74 V(TeeLocal, 0x19, _) \ | |
75 V(Drop, 0x0b, _) \ | |
76 V(CallFunction, 0x16, _) \ | 71 V(CallFunction, 0x16, _) \ |
77 V(CallIndirect, 0x17, _) \ | 72 V(CallIndirect, 0x17, _) \ |
| 73 V(CallImport, 0x18, _) \ |
78 V(I8Const, 0xcb, _) \ | 74 V(I8Const, 0xcb, _) \ |
79 V(GetGlobal, 0xbb, _) \ | 75 V(GetGlobal, 0xbb, _) \ |
80 V(SetGlobal, 0xbc, _) | 76 V(SetGlobal, 0xbc, _) |
81 | 77 |
82 // Load memory expressions. | 78 // Load memory expressions. |
83 #define FOREACH_LOAD_MEM_OPCODE(V) \ | 79 #define FOREACH_LOAD_MEM_OPCODE(V) \ |
84 V(I32LoadMem8S, 0x20, i_i) \ | 80 V(I32LoadMem8S, 0x20, i_i) \ |
85 V(I32LoadMem8U, 0x21, i_i) \ | 81 V(I32LoadMem8U, 0x21, i_i) \ |
86 V(I32LoadMem16S, 0x22, i_i) \ | 82 V(I32LoadMem16S, 0x22, i_i) \ |
87 V(I32LoadMem16U, 0x23, i_i) \ | 83 V(I32LoadMem16U, 0x23, i_i) \ |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 static FunctionSig* AsmjsSignature(WasmOpcode opcode); | 490 static FunctionSig* AsmjsSignature(WasmOpcode opcode); |
495 static bool IsPrefixOpcode(WasmOpcode opcode); | 491 static bool IsPrefixOpcode(WasmOpcode opcode); |
496 | 492 |
497 static int TrapReasonToMessageId(TrapReason reason); | 493 static int TrapReasonToMessageId(TrapReason reason); |
498 static const char* TrapReasonMessage(TrapReason reason); | 494 static const char* TrapReasonMessage(TrapReason reason); |
499 | 495 |
500 static byte MemSize(MachineType type) { | 496 static byte MemSize(MachineType type) { |
501 return 1 << ElementSizeLog2Of(type.representation()); | 497 return 1 << ElementSizeLog2Of(type.representation()); |
502 } | 498 } |
503 | 499 |
504 static byte MemSize(LocalType type) { return 1 << ElementSizeLog2Of(type); } | |
505 | |
506 static LocalTypeCode LocalTypeCodeFor(LocalType type) { | 500 static LocalTypeCode LocalTypeCodeFor(LocalType type) { |
507 switch (type) { | 501 switch (type) { |
508 case kAstI32: | 502 case kAstI32: |
509 return kLocalI32; | 503 return kLocalI32; |
510 case kAstI64: | 504 case kAstI64: |
511 return kLocalI64; | 505 return kLocalI64; |
512 case kAstF32: | 506 case kAstF32: |
513 return kLocalF32; | 507 return kLocalF32; |
514 case kAstF64: | 508 case kAstF64: |
515 return kLocalF64; | 509 return kLocalF64; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 default: | 634 default: |
641 return "<unknown>"; | 635 return "<unknown>"; |
642 } | 636 } |
643 } | 637 } |
644 }; | 638 }; |
645 } // namespace wasm | 639 } // namespace wasm |
646 } // namespace internal | 640 } // namespace internal |
647 } // namespace v8 | 641 } // namespace v8 |
648 | 642 |
649 #endif // V8_WASM_OPCODES_H_ | 643 #endif // V8_WASM_OPCODES_H_ |
OLD | NEW |