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 10 matching lines...) Expand all Loading... |
21 struct WasmModuleInstance; | 21 struct WasmModuleInstance; |
22 class WasmInterpreterInternals; | 22 class WasmInterpreterInternals; |
23 | 23 |
24 typedef size_t pc_t; | 24 typedef size_t pc_t; |
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 // Visible for testing. A {ControlTransfer} helps the interpreter figure out |
| 32 // the target program counter and stack manipulations for a branch. |
| 33 struct ControlTransfer { |
| 34 enum StackAction { kNoAction, kPopAndRepush, kPushVoid }; |
| 35 pcdiff_t pcdiff; // adjustment to the program counter (positive or negative). |
| 36 spdiff_t spdiff; // number of elements to pop off the stack. |
| 37 StackAction action; // action to perform on the stack. |
| 38 }; |
| 39 typedef ZoneMap<pc_t, ControlTransfer> ControlTransferMap; |
32 | 40 |
33 // Macro for defining union members. | 41 // Macro for defining union members. |
34 #define FOREACH_UNION_MEMBER(V) \ | 42 #define FOREACH_UNION_MEMBER(V) \ |
35 V(i32, kAstI32, int32_t) \ | 43 V(i32, kAstI32, int32_t) \ |
36 V(u32, kAstI32, uint32_t) \ | 44 V(u32, kAstI32, uint32_t) \ |
37 V(i64, kAstI64, int64_t) \ | 45 V(i64, kAstI64, int64_t) \ |
38 V(u64, kAstI64, uint64_t) \ | 46 V(u64, kAstI64, uint64_t) \ |
39 V(f32, kAstF32, float) \ | 47 V(f32, kAstF32, float) \ |
40 V(f64, kAstF64, double) | 48 V(f64, kAstF64, double) |
41 | 49 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 virtual State Step() = 0; | 125 virtual State Step() = 0; |
118 virtual void Pause() = 0; | 126 virtual void Pause() = 0; |
119 virtual void Reset() = 0; | 127 virtual void Reset() = 0; |
120 virtual ~Thread() {} | 128 virtual ~Thread() {} |
121 | 129 |
122 // Stack inspection and modification. | 130 // Stack inspection and modification. |
123 virtual pc_t GetBreakpointPc() = 0; | 131 virtual pc_t GetBreakpointPc() = 0; |
124 virtual int GetFrameCount() = 0; | 132 virtual int GetFrameCount() = 0; |
125 virtual const WasmFrame* GetFrame(int index) = 0; | 133 virtual const WasmFrame* GetFrame(int index) = 0; |
126 virtual WasmFrame* GetMutableFrame(int index) = 0; | 134 virtual WasmFrame* GetMutableFrame(int index) = 0; |
127 virtual WasmVal GetReturnValue(int index = 0) = 0; | 135 virtual WasmVal GetReturnValue() = 0; |
128 | 136 |
129 // Thread-specific breakpoints. | 137 // Thread-specific breakpoints. |
130 bool SetBreakpoint(const WasmFunction* function, int pc, bool enabled); | 138 bool SetBreakpoint(const WasmFunction* function, int pc, bool enabled); |
131 bool GetBreakpoint(const WasmFunction* function, int pc); | 139 bool GetBreakpoint(const WasmFunction* function, int pc); |
132 }; | 140 }; |
133 | 141 |
134 WasmInterpreter(WasmModuleInstance* instance, AccountingAllocator* allocator); | 142 WasmInterpreter(WasmModuleInstance* instance, AccountingAllocator* allocator); |
135 ~WasmInterpreter(); | 143 ~WasmInterpreter(); |
136 | 144 |
137 //========================================================================== | 145 //========================================================================== |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 //========================================================================== | 182 //========================================================================== |
175 // Testing functionality. | 183 // Testing functionality. |
176 //========================================================================== | 184 //========================================================================== |
177 // Manually adds a function to this interpreter, returning the index of the | 185 // Manually adds a function to this interpreter, returning the index of the |
178 // function. | 186 // function. |
179 int AddFunctionForTesting(const WasmFunction* function); | 187 int AddFunctionForTesting(const WasmFunction* function); |
180 // Manually adds code to the interpreter for the given function. | 188 // Manually adds code to the interpreter for the given function. |
181 bool SetFunctionCodeForTesting(const WasmFunction* function, | 189 bool SetFunctionCodeForTesting(const WasmFunction* function, |
182 const byte* start, const byte* end); | 190 const byte* start, const byte* end); |
183 | 191 |
184 // Computes the control transfers for the given bytecode. Used internally in | 192 // Computes the control targets for the given bytecode as {pc offset, sp |
185 // the interpreter, but exposed for testing. | 193 // offset} |
| 194 // pairs. Used internally in the interpreter, but exposed for testing. |
186 static ControlTransferMap ComputeControlTransfersForTesting(Zone* zone, | 195 static ControlTransferMap ComputeControlTransfersForTesting(Zone* zone, |
187 const byte* start, | 196 const byte* start, |
188 const byte* end); | 197 const byte* end); |
189 | 198 |
190 private: | 199 private: |
191 Zone zone_; | 200 Zone zone_; |
192 WasmInterpreterInternals* internals_; | 201 WasmInterpreterInternals* internals_; |
193 }; | 202 }; |
194 | 203 |
195 } // namespace wasm | 204 } // namespace wasm |
196 } // namespace internal | 205 } // namespace internal |
197 } // namespace v8 | 206 } // namespace v8 |
198 | 207 |
199 #endif // V8_WASM_INTERPRETER_H_ | 208 #endif // V8_WASM_INTERPRETER_H_ |
OLD | NEW |