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 #include "src/interpreter/interpreter.h" | 5 #include "src/interpreter/interpreter.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/compiler/interpreter-assembler.h" | 8 #include "src/compiler/interpreter-assembler.h" |
9 #include "src/factory.h" | 9 #include "src/factory.h" |
10 #include "src/interpreter/bytecode-generator.h" | 10 #include "src/interpreter/bytecode-generator.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 Unique<HeapObject>::CreateImmovable(isolate_->factory()->false_value())); | 158 Unique<HeapObject>::CreateImmovable(isolate_->factory()->false_value())); |
159 __ SetAccumulator(false_value); | 159 __ SetAccumulator(false_value); |
160 __ Dispatch(); | 160 __ Dispatch(); |
161 } | 161 } |
162 | 162 |
163 | 163 |
164 // Ldar <src> | 164 // Ldar <src> |
165 // | 165 // |
166 // Load accumulator with value from register <src>. | 166 // Load accumulator with value from register <src>. |
167 void Interpreter::DoLdar(compiler::InterpreterAssembler* assembler) { | 167 void Interpreter::DoLdar(compiler::InterpreterAssembler* assembler) { |
168 Node* value = __ LoadRegister(__ BytecodeOperandReg(0)); | 168 Node* reg_index = __ BytecodeOperandReg(0); |
| 169 Node* value = __ LoadRegister(reg_index); |
169 __ SetAccumulator(value); | 170 __ SetAccumulator(value); |
170 __ Dispatch(); | 171 __ Dispatch(); |
171 } | 172 } |
172 | 173 |
173 | 174 |
174 // Star <dst> | 175 // Star <dst> |
175 // | 176 // |
176 // Store accumulator to register <dst>. | 177 // Store accumulator to register <dst>. |
177 void Interpreter::DoStar(compiler::InterpreterAssembler* assembler) { | 178 void Interpreter::DoStar(compiler::InterpreterAssembler* assembler) { |
178 Node* reg_index = __ BytecodeOperandReg(0); | 179 Node* reg_index = __ BytecodeOperandReg(0); |
179 Node* accumulator = __ GetAccumulator(); | 180 Node* accumulator = __ GetAccumulator(); |
180 __ StoreRegister(accumulator, reg_index); | 181 __ StoreRegister(accumulator, reg_index); |
181 __ Dispatch(); | 182 __ Dispatch(); |
182 } | 183 } |
183 | 184 |
184 | 185 |
| 186 void Interpreter::DoBinaryOp(Builtins::JavaScript binop_builtin, |
| 187 compiler::InterpreterAssembler* assembler) { |
| 188 // TODO(rmcilroy): Call ICs which back-patch bytecode with type specialized |
| 189 // operations, instead of calling builtins directly. |
| 190 Node* reg_index = __ BytecodeOperandReg(0); |
| 191 Node* lhs = __ LoadRegister(reg_index); |
| 192 Node* rhs = __ GetAccumulator(); |
| 193 Node* result = __ CallJSBuiltin(binop_builtin, lhs, rhs); |
| 194 __ SetAccumulator(result); |
| 195 __ Dispatch(); |
| 196 } |
| 197 |
| 198 |
185 // Add <src> | 199 // Add <src> |
186 // | 200 // |
187 // Add register <src> to accumulator. | 201 // Add register <src> to accumulator. |
188 void Interpreter::DoAdd(compiler::InterpreterAssembler* assembler) { | 202 void Interpreter::DoAdd(compiler::InterpreterAssembler* assembler) { |
189 // TODO(rmcilroy) Implement. | 203 DoBinaryOp(Builtins::ADD, assembler); |
190 __ Dispatch(); | |
191 } | 204 } |
192 | 205 |
193 | 206 |
194 // Sub <src> | 207 // Sub <src> |
195 // | 208 // |
196 // Subtract register <src> from accumulator. | 209 // Subtract register <src> from accumulator. |
197 void Interpreter::DoSub(compiler::InterpreterAssembler* assembler) { | 210 void Interpreter::DoSub(compiler::InterpreterAssembler* assembler) { |
198 // TODO(rmcilroy) Implement. | 211 DoBinaryOp(Builtins::SUB, assembler); |
199 __ Dispatch(); | |
200 } | 212 } |
201 | 213 |
202 | 214 |
203 // Mul <src> | 215 // Mul <src> |
204 // | 216 // |
205 // Multiply accumulator by register <src>. | 217 // Multiply accumulator by register <src>. |
206 void Interpreter::DoMul(compiler::InterpreterAssembler* assembler) { | 218 void Interpreter::DoMul(compiler::InterpreterAssembler* assembler) { |
207 // TODO(rmcilroy) Implement add register to accumulator. | 219 DoBinaryOp(Builtins::MUL, assembler); |
208 __ Dispatch(); | |
209 } | 220 } |
210 | 221 |
211 | 222 |
212 // Div <src> | 223 // Div <src> |
213 // | 224 // |
214 // Divide register <src> by accumulator. | 225 // Divide register <src> by accumulator. |
215 void Interpreter::DoDiv(compiler::InterpreterAssembler* assembler) { | 226 void Interpreter::DoDiv(compiler::InterpreterAssembler* assembler) { |
216 // TODO(rmcilroy) Implement. | 227 DoBinaryOp(Builtins::DIV, assembler); |
217 __ Dispatch(); | |
218 } | 228 } |
219 | 229 |
220 | 230 |
| 231 // Mod <src> |
| 232 // |
| 233 // Modulo register <src> by accumulator. |
| 234 void Interpreter::DoMod(compiler::InterpreterAssembler* assembler) { |
| 235 DoBinaryOp(Builtins::MOD, assembler); |
| 236 } |
| 237 |
| 238 |
221 // Return | 239 // Return |
222 // | 240 // |
223 // Return the value in register 0. | 241 // Return the value in register 0. |
224 void Interpreter::DoReturn(compiler::InterpreterAssembler* assembler) { | 242 void Interpreter::DoReturn(compiler::InterpreterAssembler* assembler) { |
225 __ Return(); | 243 __ Return(); |
226 } | 244 } |
227 | 245 |
228 | 246 |
229 } // namespace interpreter | 247 } // namespace interpreter |
230 } // namespace internal | 248 } // namespace internal |
231 } // namespace v8 | 249 } // namespace v8 |
OLD | NEW |