| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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_INTERPRETER_H_ | 5 #ifndef V8_WASM_INTERPRETER_H_ |
| 6 #define V8_WASM_INTERPRETER_H_ | 6 #define V8_WASM_INTERPRETER_H_ |
| 7 | 7 |
| 8 #include "src/wasm/wasm-opcodes.h" | 8 #include "src/wasm/wasm-opcodes.h" |
| 9 #include "src/zone/zone-containers.h" | 9 #include "src/zone/zone-containers.h" |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 typedef size_t sp_t; | 25 typedef size_t sp_t; |
| 26 typedef int32_t pcdiff_t; | 26 typedef int32_t pcdiff_t; |
| 27 typedef uint32_t spdiff_t; | 27 typedef uint32_t spdiff_t; |
| 28 | 28 |
| 29 const pc_t kInvalidPc = 0x80000000; | 29 const pc_t kInvalidPc = 0x80000000; |
| 30 | 30 |
| 31 typedef ZoneMap<pc_t, pcdiff_t> ControlTransferMap; | 31 typedef ZoneMap<pc_t, pcdiff_t> ControlTransferMap; |
| 32 | 32 |
| 33 // Macro for defining union members. | 33 // Macro for defining union members. |
| 34 #define FOREACH_UNION_MEMBER(V) \ | 34 #define FOREACH_UNION_MEMBER(V) \ |
| 35 V(i32, kAstI32, int32_t) \ | 35 V(i32, kWasmI32, int32_t) \ |
| 36 V(u32, kAstI32, uint32_t) \ | 36 V(u32, kWasmI32, uint32_t) \ |
| 37 V(i64, kAstI64, int64_t) \ | 37 V(i64, kWasmI64, int64_t) \ |
| 38 V(u64, kAstI64, uint64_t) \ | 38 V(u64, kWasmI64, uint64_t) \ |
| 39 V(f32, kAstF32, float) \ | 39 V(f32, kWasmF32, float) \ |
| 40 V(f64, kAstF64, double) | 40 V(f64, kWasmF64, double) |
| 41 | 41 |
| 42 // Representation of values within the interpreter. | 42 // Representation of values within the interpreter. |
| 43 struct WasmVal { | 43 struct WasmVal { |
| 44 LocalType type; | 44 ValueType type; |
| 45 union { | 45 union { |
| 46 #define DECLARE_FIELD(field, localtype, ctype) ctype field; | 46 #define DECLARE_FIELD(field, localtype, ctype) ctype field; |
| 47 FOREACH_UNION_MEMBER(DECLARE_FIELD) | 47 FOREACH_UNION_MEMBER(DECLARE_FIELD) |
| 48 #undef DECLARE_FIELD | 48 #undef DECLARE_FIELD |
| 49 } val; | 49 } val; |
| 50 | 50 |
| 51 WasmVal() : type(kAstStmt) {} | 51 WasmVal() : type(kWasmStmt) {} |
| 52 | 52 |
| 53 #define DECLARE_CONSTRUCTOR(field, localtype, ctype) \ | 53 #define DECLARE_CONSTRUCTOR(field, localtype, ctype) \ |
| 54 explicit WasmVal(ctype v) : type(localtype) { val.field = v; } | 54 explicit WasmVal(ctype v) : type(localtype) { val.field = v; } |
| 55 FOREACH_UNION_MEMBER(DECLARE_CONSTRUCTOR) | 55 FOREACH_UNION_MEMBER(DECLARE_CONSTRUCTOR) |
| 56 #undef DECLARE_CONSTRUCTOR | 56 #undef DECLARE_CONSTRUCTOR |
| 57 | 57 |
| 58 template <typename T> | 58 template <typename T> |
| 59 T to() { | 59 T to() { |
| 60 UNREACHABLE(); | 60 UNREACHABLE(); |
| 61 } | 61 } |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 #define DECLARE_CAST(field, localtype, ctype) \ | 64 #define DECLARE_CAST(field, localtype, ctype) \ |
| 65 template <> \ | 65 template <> \ |
| 66 inline ctype WasmVal::to() { \ | 66 inline ctype WasmVal::to() { \ |
| 67 CHECK_EQ(localtype, type); \ | 67 CHECK_EQ(localtype, type); \ |
| 68 return val.field; \ | 68 return val.field; \ |
| 69 } | 69 } |
| 70 FOREACH_UNION_MEMBER(DECLARE_CAST) | 70 FOREACH_UNION_MEMBER(DECLARE_CAST) |
| 71 #undef DECLARE_CAST | 71 #undef DECLARE_CAST |
| 72 | 72 |
| 73 template <> | 73 template <> |
| 74 inline void WasmVal::to() { | 74 inline void WasmVal::to() { |
| 75 CHECK_EQ(kAstStmt, type); | 75 CHECK_EQ(kWasmStmt, type); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Representation of frames within the interpreter. | 78 // Representation of frames within the interpreter. |
| 79 class WasmFrame { | 79 class WasmFrame { |
| 80 public: | 80 public: |
| 81 const WasmFunction* function() const { return function_; } | 81 const WasmFunction* function() const { return function_; } |
| 82 int pc() const { return pc_; } | 82 int pc() const { return pc_; } |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 friend class WasmInterpreter; | 85 friend class WasmInterpreter; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 private: | 194 private: |
| 195 Zone zone_; | 195 Zone zone_; |
| 196 WasmInterpreterInternals* internals_; | 196 WasmInterpreterInternals* internals_; |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 } // namespace wasm | 199 } // namespace wasm |
| 200 } // namespace internal | 200 } // namespace internal |
| 201 } // namespace v8 | 201 } // namespace v8 |
| 202 | 202 |
| 203 #endif // V8_WASM_INTERPRETER_H_ | 203 #endif // V8_WASM_INTERPRETER_H_ |
| OLD | NEW |