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

Side by Side Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1300813005: [Interpreter] Add implementations of arithmetic binary op bytecodes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@mstar_v8h
Patch Set: Fix unittest too... Created 5 years, 4 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
OLDNEW
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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/execution.h" 7 #include "src/execution.h"
8 #include "src/handles.h" 8 #include "src/handles.h"
9 #include "src/interpreter/bytecode-array-builder.h" 9 #include "src/interpreter/bytecode-array-builder.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 }; 62 };
63 63
64 } // namespace interpreter 64 } // namespace interpreter
65 } // namespace internal 65 } // namespace internal
66 } // namespace v8 66 } // namespace v8
67 67
68 using v8::internal::BytecodeArray; 68 using v8::internal::BytecodeArray;
69 using v8::internal::Handle; 69 using v8::internal::Handle;
70 using v8::internal::Object; 70 using v8::internal::Object;
71 using v8::internal::Smi; 71 using v8::internal::Smi;
72 using v8::internal::Token;
72 using namespace v8::internal::interpreter; 73 using namespace v8::internal::interpreter;
73 74
74 TEST(TestInterpreterReturn) { 75 TEST(TestInterpreterReturn) {
75 InitializedHandleScope handles; 76 InitializedHandleScope handles;
76 Handle<Object> undefined_value = 77 Handle<Object> undefined_value =
77 handles.main_isolate()->factory()->undefined_value(); 78 handles.main_isolate()->factory()->undefined_value();
78 79
79 BytecodeArrayBuilder builder(handles.main_isolate()); 80 BytecodeArrayBuilder builder(handles.main_isolate());
80 builder.set_locals_count(0); 81 builder.set_locals_count(0);
81 builder.Return(); 82 builder.Return();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 .LoadAccumulatorWithRegister(reg) 200 .LoadAccumulatorWithRegister(reg)
200 .Return(); 201 .Return();
201 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 202 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
202 203
203 InterpreterTester tester(handles.main_isolate(), bytecode_array); 204 InterpreterTester tester(handles.main_isolate(), bytecode_array);
204 InterpreterCallable callable(tester.GetCallable()); 205 InterpreterCallable callable(tester.GetCallable());
205 Handle<Object> return_val = callable().ToHandleChecked(); 206 Handle<Object> return_val = callable().ToHandleChecked();
206 CHECK(return_val.is_identical_to(true_value)); 207 CHECK(return_val.is_identical_to(true_value));
207 } 208 }
208 } 209 }
210
211
212 TEST(TestInterpreterAdd) {
213 InitializedHandleScope handles;
214 // TODO(rmcilroy): Do add tests for heap numbers and strings once we support
215 // them.
216 BytecodeArrayBuilder builder(handles.main_isolate());
217 builder.set_locals_count(1);
218 Register reg(0);
219 builder.LoadLiteral(Smi::FromInt(1))
220 .StoreAccumulatorInRegister(reg)
221 .LoadLiteral(Smi::FromInt(2))
222 .BinaryOperation(Token::Value::ADD, reg)
223 .Return();
224 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
225
226 InterpreterTester tester(handles.main_isolate(), bytecode_array);
227 InterpreterCallable callable(tester.GetCallable());
228 Handle<Object> return_val = callable().ToHandleChecked();
229 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3));
230 }
231
232
233 TEST(TestInterpreterSub) {
234 InitializedHandleScope handles;
235 // TODO(rmcilroy): Do add tests for heap numbers once we support them.
236 BytecodeArrayBuilder builder(handles.main_isolate());
237 builder.set_locals_count(1);
238 Register reg(0);
239 builder.LoadLiteral(Smi::FromInt(5))
240 .StoreAccumulatorInRegister(reg)
241 .LoadLiteral(Smi::FromInt(31))
242 .BinaryOperation(Token::Value::SUB, reg)
243 .Return();
244 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
245
246 InterpreterTester tester(handles.main_isolate(), bytecode_array);
247 InterpreterCallable callable(tester.GetCallable());
248 Handle<Object> return_val = callable().ToHandleChecked();
249 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(-26));
250 }
251
252
253 TEST(TestInterpreterMul) {
254 InitializedHandleScope handles;
255 // TODO(rmcilroy): Do add tests for heap numbers once we support them.
256 BytecodeArrayBuilder builder(handles.main_isolate());
257 builder.set_locals_count(1);
258 Register reg(0);
259 builder.LoadLiteral(Smi::FromInt(111))
260 .StoreAccumulatorInRegister(reg)
261 .LoadLiteral(Smi::FromInt(6))
262 .BinaryOperation(Token::Value::MUL, reg)
263 .Return();
264 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
265
266 InterpreterTester tester(handles.main_isolate(), bytecode_array);
267 InterpreterCallable callable(tester.GetCallable());
268 Handle<Object> return_val = callable().ToHandleChecked();
269 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(666));
270 }
271
272
273 TEST(TestInterpreterDiv) {
274 InitializedHandleScope handles;
275 // TODO(rmcilroy): Do add tests for heap numbers once we support them.
276 BytecodeArrayBuilder builder(handles.main_isolate());
277 builder.set_locals_count(1);
278 Register reg(0);
279 builder.LoadLiteral(Smi::FromInt(-20))
280 .StoreAccumulatorInRegister(reg)
281 .LoadLiteral(Smi::FromInt(5))
282 .BinaryOperation(Token::Value::DIV, reg)
283 .Return();
284 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
285
286 InterpreterTester tester(handles.main_isolate(), bytecode_array);
287 InterpreterCallable callable(tester.GetCallable());
288 Handle<Object> return_val = callable().ToHandleChecked();
289 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(-4));
290 }
291
292
293 TEST(TestInterpreterMod) {
294 InitializedHandleScope handles;
295 // TODO(rmcilroy): Do add tests for heap numbers once we support them.
296 BytecodeArrayBuilder builder(handles.main_isolate());
297 builder.set_locals_count(1);
298 Register reg(0);
299 builder.LoadLiteral(Smi::FromInt(121))
300 .StoreAccumulatorInRegister(reg)
301 .LoadLiteral(Smi::FromInt(100))
302 .BinaryOperation(Token::Value::MOD, reg)
303 .Return();
304 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
305
306 InterpreterTester tester(handles.main_isolate(), bytecode_array);
307 InterpreterCallable callable(tester.GetCallable());
308 Handle<Object> return_val = callable().ToHandleChecked();
309 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(21));
310 }
OLDNEW
« no previous file with comments | « src/interpreter/interpreter.cc ('k') | test/unittests/compiler/instruction-selector-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698