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-containers.h" | 9 #include "src/zone-containers.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace base { | 12 namespace base { |
13 class AccountingAllocator; | 13 class AccountingAllocator; |
14 } | 14 } |
15 | 15 |
16 namespace internal { | 16 namespace internal { |
17 namespace wasm { | 17 namespace wasm { |
18 | 18 |
19 // forward declarations. | 19 // forward declarations. |
20 struct WasmFunction; | 20 struct WasmFunction; |
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; |
| 30 |
29 // Visible for testing. A {ControlTransfer} helps the interpreter figure out | 31 // Visible for testing. A {ControlTransfer} helps the interpreter figure out |
30 // the target program counter and stack manipulations for a branch. | 32 // the target program counter and stack manipulations for a branch. |
31 struct ControlTransfer { | 33 struct ControlTransfer { |
32 enum StackAction { kNoAction, kPopAndRepush, kPushVoid }; | 34 enum StackAction { kNoAction, kPopAndRepush, kPushVoid }; |
33 pcdiff_t pcdiff; // adjustment to the program counter (positive or negative). | 35 pcdiff_t pcdiff; // adjustment to the program counter (positive or negative). |
34 spdiff_t spdiff; // number of elements to pop off the stack. | 36 spdiff_t spdiff; // number of elements to pop off the stack. |
35 StackAction action; // action to perform on the stack. | 37 StackAction action; // action to perform on the stack. |
36 }; | 38 }; |
37 typedef ZoneMap<pc_t, ControlTransfer> ControlTransferMap; | 39 typedef ZoneMap<pc_t, ControlTransfer> ControlTransferMap; |
38 | 40 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // Execution control. | 121 // Execution control. |
120 virtual State state() = 0; | 122 virtual State state() = 0; |
121 virtual void PushFrame(const WasmFunction* function, WasmVal* args) = 0; | 123 virtual void PushFrame(const WasmFunction* function, WasmVal* args) = 0; |
122 virtual State Run() = 0; | 124 virtual State Run() = 0; |
123 virtual State Step() = 0; | 125 virtual State Step() = 0; |
124 virtual void Pause() = 0; | 126 virtual void Pause() = 0; |
125 virtual void Reset() = 0; | 127 virtual void Reset() = 0; |
126 virtual ~Thread() {} | 128 virtual ~Thread() {} |
127 | 129 |
128 // Stack inspection and modification. | 130 // Stack inspection and modification. |
| 131 virtual pc_t GetBreakpointPc() = 0; |
129 virtual int GetFrameCount() = 0; | 132 virtual int GetFrameCount() = 0; |
130 virtual const WasmFrame* GetFrame(int index) = 0; | 133 virtual const WasmFrame* GetFrame(int index) = 0; |
131 virtual WasmFrame* GetMutableFrame(int index) = 0; | 134 virtual WasmFrame* GetMutableFrame(int index) = 0; |
132 virtual WasmVal GetReturnValue() = 0; | 135 virtual WasmVal GetReturnValue() = 0; |
133 | 136 |
134 // Thread-specific breakpoints. | 137 // Thread-specific breakpoints. |
135 bool SetBreakpoint(const WasmFunction* function, int pc, bool enabled); | 138 bool SetBreakpoint(const WasmFunction* function, int pc, bool enabled); |
136 bool GetBreakpoint(const WasmFunction* function, int pc); | 139 bool GetBreakpoint(const WasmFunction* function, int pc); |
137 }; | 140 }; |
138 | 141 |
139 WasmInterpreter(WasmModuleInstance* instance, | 142 WasmInterpreter(WasmModuleInstance* instance, |
140 base::AccountingAllocator* allocator); | 143 base::AccountingAllocator* allocator); |
141 ~WasmInterpreter(); | 144 ~WasmInterpreter(); |
142 | 145 |
143 //========================================================================== | 146 //========================================================================== |
144 // Execution controls. | 147 // Execution controls. |
145 //========================================================================== | 148 //========================================================================== |
146 void Run(); | 149 void Run(); |
147 void Pause(); | 150 void Pause(); |
148 | 151 |
149 // Set a breakpoint at {pc} in {function} to be {enabled}. Returns the | 152 // Set a breakpoint at {pc} in {function} to be {enabled}. Returns the |
150 // previous state of the breakpoint at {pc}. | 153 // previous state of the breakpoint at {pc}. |
151 bool SetBreakpoint(const WasmFunction* function, int pc, bool enabled); | 154 bool SetBreakpoint(const WasmFunction* function, pc_t pc, bool enabled); |
152 | 155 |
153 // Gets the current state of the breakpoint at {function}. | 156 // Gets the current state of the breakpoint at {function}. |
154 bool GetBreakpoint(const WasmFunction* function, int pc); | 157 bool GetBreakpoint(const WasmFunction* function, pc_t pc); |
155 | 158 |
156 // Enable or disable tracing for {function}. Return the previous state. | 159 // Enable or disable tracing for {function}. Return the previous state. |
157 bool SetTracing(const WasmFunction* function, bool enabled); | 160 bool SetTracing(const WasmFunction* function, bool enabled); |
158 | 161 |
159 //========================================================================== | 162 //========================================================================== |
160 // Thread iteration and inspection. | 163 // Thread iteration and inspection. |
161 //========================================================================== | 164 //========================================================================== |
162 int GetThreadCount(); | 165 int GetThreadCount(); |
163 Thread& GetThread(int id); | 166 Thread& GetThread(int id); |
164 | 167 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 private: | 200 private: |
198 Zone zone_; | 201 Zone zone_; |
199 WasmInterpreterInternals* internals_; | 202 WasmInterpreterInternals* internals_; |
200 }; | 203 }; |
201 | 204 |
202 } // namespace wasm | 205 } // namespace wasm |
203 } // namespace internal | 206 } // namespace internal |
204 } // namespace v8 | 207 } // namespace v8 |
205 | 208 |
206 #endif // V8_WASM_INTERPRETER_H_ | 209 #endif // V8_WASM_INTERPRETER_H_ |
OLD | NEW |