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 // Binary encoding of memory types. | |
26 enum MemTypeCode { | |
27 kMemI8 = 0, | |
28 kMemU8 = 1, | |
29 kMemI16 = 2, | |
30 kMemU16 = 3, | |
31 kMemI32 = 4, | |
32 kMemU32 = 5, | |
33 kMemI64 = 6, | |
34 kMemU64 = 7, | |
35 kMemF32 = 8, | |
36 kMemF64 = 9, | |
37 kMemS128 = 10 | |
38 }; | |
39 | |
40 // We reuse the internal machine type to represent WebAssembly AST types. | 25 // We reuse the internal machine type to represent WebAssembly AST types. |
41 // A typedef improves readability without adding a whole new type system. | 26 // A typedef improves readability without adding a whole new type system. |
42 typedef MachineRepresentation LocalType; | 27 typedef MachineRepresentation LocalType; |
43 const LocalType kAstStmt = MachineRepresentation::kNone; | 28 const LocalType kAstStmt = MachineRepresentation::kNone; |
44 const LocalType kAstI32 = MachineRepresentation::kWord32; | 29 const LocalType kAstI32 = MachineRepresentation::kWord32; |
45 const LocalType kAstI64 = MachineRepresentation::kWord64; | 30 const LocalType kAstI64 = MachineRepresentation::kWord64; |
46 const LocalType kAstF32 = MachineRepresentation::kFloat32; | 31 const LocalType kAstF32 = MachineRepresentation::kFloat32; |
47 const LocalType kAstF64 = MachineRepresentation::kFloat64; | 32 const LocalType kAstF64 = MachineRepresentation::kFloat64; |
48 const LocalType kAstS128 = MachineRepresentation::kSimd128; | 33 const LocalType kAstS128 = MachineRepresentation::kSimd128; |
49 // We use kTagged here because kNone is already used by kAstStmt. | 34 // We use kTagged here because kNone is already used by kAstStmt. |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 case kAstStmt: | 509 case kAstStmt: |
525 return kLocalVoid; | 510 return kLocalVoid; |
526 case kAstS128: | 511 case kAstS128: |
527 return kLocalS128; | 512 return kLocalS128; |
528 default: | 513 default: |
529 UNREACHABLE(); | 514 UNREACHABLE(); |
530 return kLocalVoid; | 515 return kLocalVoid; |
531 } | 516 } |
532 } | 517 } |
533 | 518 |
534 static MemTypeCode MemTypeCodeFor(MachineType type) { | |
535 if (type == MachineType::Int8()) { | |
536 return kMemI8; | |
537 } else if (type == MachineType::Uint8()) { | |
538 return kMemU8; | |
539 } else if (type == MachineType::Int16()) { | |
540 return kMemI16; | |
541 } else if (type == MachineType::Uint16()) { | |
542 return kMemU16; | |
543 } else if (type == MachineType::Int32()) { | |
544 return kMemI32; | |
545 } else if (type == MachineType::Uint32()) { | |
546 return kMemU32; | |
547 } else if (type == MachineType::Int64()) { | |
548 return kMemI64; | |
549 } else if (type == MachineType::Uint64()) { | |
550 return kMemU64; | |
551 } else if (type == MachineType::Float32()) { | |
552 return kMemF32; | |
553 } else if (type == MachineType::Float64()) { | |
554 return kMemF64; | |
555 } else if (type == MachineType::Simd128()) { | |
556 return kMemS128; | |
557 } else { | |
558 UNREACHABLE(); | |
559 return kMemI32; | |
560 } | |
561 } | |
562 | |
563 static MachineType MachineTypeFor(LocalType type) { | 519 static MachineType MachineTypeFor(LocalType type) { |
564 switch (type) { | 520 switch (type) { |
565 case kAstI32: | 521 case kAstI32: |
566 return MachineType::Int32(); | 522 return MachineType::Int32(); |
567 case kAstI64: | 523 case kAstI64: |
568 return MachineType::Int64(); | 524 return MachineType::Int64(); |
569 case kAstF32: | 525 case kAstF32: |
570 return MachineType::Float32(); | 526 return MachineType::Float32(); |
571 case kAstF64: | 527 case kAstF64: |
572 return MachineType::Float64(); | 528 return MachineType::Float64(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 default: | 633 default: |
678 return "<unknown>"; | 634 return "<unknown>"; |
679 } | 635 } |
680 } | 636 } |
681 }; | 637 }; |
682 } // namespace wasm | 638 } // namespace wasm |
683 } // namespace internal | 639 } // namespace internal |
684 } // namespace v8 | 640 } // namespace v8 |
685 | 641 |
686 #endif // V8_WASM_OPCODES_H_ | 642 #endif // V8_WASM_OPCODES_H_ |
OLD | NEW |