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

Unified Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1343363002: [Interpreter] Basic flow control. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Switch test-bytecode-generator/IfConditions to use new style bytecode array check. Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: test/cctest/interpreter/test-interpreter.cc
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
index c92ca13b32a8cdbb3c51d388b49697a33e482633..701a369280b27870dae1443174beadbdb159dc59 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -891,3 +891,86 @@ TEST(InterpreterCall) {
CHECK(i::String::cast(*return_val)->Equals(*expected));
}
}
+
+
+static BytecodeArrayBuilder& SetRegister(BytecodeArrayBuilder& builder,
+ Register reg, int value,
+ Register scratch) {
+ return builder.StoreAccumulatorInRegister(scratch)
+ .LoadLiteral(Smi::FromInt(value))
+ .StoreAccumulatorInRegister(reg)
+ .LoadAccumulatorWithRegister(scratch);
+}
+
+
+static BytecodeArrayBuilder& IncrementRegister(BytecodeArrayBuilder& builder,
+ Register reg, int value,
+ Register scratch) {
+ return builder.StoreAccumulatorInRegister(scratch)
+ .LoadLiteral(Smi::FromInt(value))
+ .BinaryOperation(Token::Value::ADD, reg)
+ .StoreAccumulatorInRegister(reg)
+ .LoadAccumulatorWithRegister(scratch);
+}
+
+
+TEST(InterpreterJumps) {
+ HandleAndZoneScope handles;
+ BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
+ builder.set_locals_count(2);
+ builder.set_parameter_count(0);
+ Register reg(0), scratch(1);
+ BytecodeLabel label[3];
+
+ builder.LoadLiteral(Smi::FromInt(0))
+ .StoreAccumulatorInRegister(reg)
+ .Jump(&label[1]);
+ SetRegister(builder, reg, 1024, scratch).Bind(&label[0]);
+ IncrementRegister(builder, reg, 1, scratch).Jump(&label[2]);
+ SetRegister(builder, reg, 2048, scratch).Bind(&label[1]);
+ IncrementRegister(builder, reg, 2, scratch).Jump(&label[0]);
+ SetRegister(builder, reg, 4096, scratch).Bind(&label[2]);
+ IncrementRegister(builder, reg, 4, scratch)
+ .LoadAccumulatorWithRegister(reg)
+ .Return();
+
+ Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ auto callable = tester.GetCallable<>();
+ Handle<Object> return_value = callable().ToHandleChecked();
+ CHECK_EQ(Smi::cast(*return_value)->value(), 7);
+}
+
+
+TEST(InterpreterConditionalJumps) {
+ HandleAndZoneScope handles;
+ BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
+ builder.set_locals_count(2);
+ builder.set_parameter_count(0);
+ Register reg(0), scratch(1);
+ BytecodeLabel label[2];
+ BytecodeLabel done, done1;
+
+ builder.LoadLiteral(Smi::FromInt(0))
+ .StoreAccumulatorInRegister(reg)
+ .LoadFalse()
+ .JumpIfFalse(&label[0]);
+ IncrementRegister(builder, reg, 1024, scratch)
+ .Bind(&label[0])
+ .LoadTrue()
+ .JumpIfFalse(&done);
+ IncrementRegister(builder, reg, 1, scratch).LoadTrue().JumpIfTrue(&label[1]);
+ IncrementRegister(builder, reg, 2048, scratch).Bind(&label[1]);
+ IncrementRegister(builder, reg, 2, scratch).LoadFalse().JumpIfTrue(&done1);
+ IncrementRegister(builder, reg, 4, scratch)
+ .LoadAccumulatorWithRegister(reg)
+ .Bind(&done)
+ .Bind(&done1)
+ .Return();
+
+ Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ auto callable = tester.GetCallable<>();
+ Handle<Object> return_value = callable().ToHandleChecked();
+ CHECK_EQ(Smi::cast(*return_value)->value(), 7);
+}
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/compiler/interpreter-assembler-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698