Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: src/wasm/wasm-interpreter.h

Issue 2639013002: [wasm] Use pimpl idiom for interpreter thread implementation (Closed)
Patch Set: Fix android and windows compile errors Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/wasm/wasm-interpreter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 template <> 73 template <>
74 inline void WasmVal::to() { 74 inline void WasmVal::to() {
75 CHECK_EQ(kWasmStmt, 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 {
83 // TODO(wasm): Remove USE once we actually use them.
84 USE(fp_);
85 USE(sp_);
86 return pc_;
87 }
83 88
84 private: 89 private:
85 friend class WasmInterpreter; 90 friend class WasmInterpreter;
86 91
87 WasmFrame(const WasmFunction* function, int pc, int fp, int sp) 92 WasmFrame(const WasmFunction* function, int pc, int fp, int sp)
88 : function_(function), pc_(pc), fp_(fp), sp_(sp) {} 93 : function_(function), pc_(pc), fp_(fp), sp_(sp) {}
89 94
90 const WasmFunction* function_; 95 const WasmFunction* function_;
91 int pc_; 96 int pc_;
92 int fp_; 97 int fp_;
93 int sp_; 98 int sp_;
94 }; 99 };
95 100
96 // An interpreter capable of executing WASM. 101 // An interpreter capable of executing WASM.
97 class V8_EXPORT_PRIVATE WasmInterpreter { 102 class V8_EXPORT_PRIVATE WasmInterpreter {
98 public: 103 public:
99 // State machine for a Thread: 104 // State machine for a Thread:
100 // +---------------Run()-----------+ 105 // +---------------Run()-----------+
101 // V | 106 // V |
102 // STOPPED ---Run()--> RUNNING ------Pause()-----+-> PAUSED <------+ 107 // STOPPED ---Run()--> RUNNING ------Pause()-----+-> PAUSED <------+
103 // | | | / | | 108 // | | | / | |
104 // | | +---- Breakpoint ---+ +-- Step() --+ 109 // | | +---- Breakpoint ---+ +-- Step() --+
105 // | | 110 // | |
106 // | +------------ Trap --------------> TRAPPED 111 // | +------------ Trap --------------> TRAPPED
107 // +------------- Finish -------------> FINISHED 112 // +------------- Finish -------------> FINISHED
108 enum State { STOPPED, RUNNING, PAUSED, FINISHED, TRAPPED }; 113 enum State { STOPPED, RUNNING, PAUSED, FINISHED, TRAPPED };
109 114
110 // Representation of a thread in the interpreter. 115 // Representation of a thread in the interpreter.
111 class Thread { 116 class ThreadImpl;
117 class V8_EXPORT_PRIVATE Thread {
118 ThreadImpl* impl_;
119
112 public: 120 public:
121 explicit Thread(ThreadImpl*);
122
113 // Execution control. 123 // Execution control.
114 virtual State state() = 0; 124 State state();
115 virtual void PushFrame(const WasmFunction* function, WasmVal* args) = 0; 125 void PushFrame(const WasmFunction* function, WasmVal* args);
116 virtual State Run() = 0; 126 State Run();
117 virtual State Step() = 0; 127 State Step();
118 virtual void Pause() = 0; 128 void Pause();
119 virtual void Reset() = 0; 129 void Reset();
120 virtual ~Thread() {}
121 130
122 // Stack inspection and modification. 131 // Stack inspection and modification.
123 virtual pc_t GetBreakpointPc() = 0; 132 pc_t GetBreakpointPc();
124 virtual int GetFrameCount() = 0; 133 int GetFrameCount();
125 virtual const WasmFrame* GetFrame(int index) = 0; 134 const WasmFrame* GetFrame(int index);
126 virtual WasmFrame* GetMutableFrame(int index) = 0; 135 WasmFrame* GetMutableFrame(int index);
127 virtual WasmVal GetReturnValue(int index = 0) = 0; 136 WasmVal GetReturnValue(int index = 0);
128 // Returns true if the thread executed an instruction which may produce 137 // Returns true if the thread executed an instruction which may produce
129 // nondeterministic results, e.g. float div, float sqrt, and float mul, 138 // nondeterministic results, e.g. float div, float sqrt, and float mul,
130 // where the sign bit of a NaN is nondeterministic. 139 // where the sign bit of a NaN is nondeterministic.
131 virtual bool PossibleNondeterminism() = 0; 140 bool PossibleNondeterminism();
132 141
133 // Thread-specific breakpoints. 142 // Thread-specific breakpoints.
134 bool SetBreakpoint(const WasmFunction* function, int pc, bool enabled); 143 // TODO(wasm): Implement this once we support multiple threads.
135 bool GetBreakpoint(const WasmFunction* function, int pc); 144 // bool SetBreakpoint(const WasmFunction* function, int pc, bool enabled);
145 // bool GetBreakpoint(const WasmFunction* function, int pc);
136 }; 146 };
137 147
138 WasmInterpreter(const ModuleBytesEnv& env, AccountingAllocator* allocator); 148 WasmInterpreter(const ModuleBytesEnv& env, AccountingAllocator* allocator);
139 ~WasmInterpreter(); 149 ~WasmInterpreter();
140 150
141 //========================================================================== 151 //==========================================================================
142 // Execution controls. 152 // Execution controls.
143 //========================================================================== 153 //==========================================================================
144 void Run(); 154 void Run();
145 void Pause(); 155 void Pause();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 private: 204 private:
195 Zone zone_; 205 Zone zone_;
196 WasmInterpreterInternals* internals_; 206 WasmInterpreterInternals* internals_;
197 }; 207 };
198 208
199 } // namespace wasm 209 } // namespace wasm
200 } // namespace internal 210 } // namespace internal
201 } // namespace v8 211 } // namespace v8
202 212
203 #endif // V8_WASM_INTERPRETER_H_ 213 #endif // V8_WASM_INTERPRETER_H_
OLDNEW
« no previous file with comments | « no previous file | src/wasm/wasm-interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698