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

Side by Side 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: Rebase to fix patch failure with git cl try. 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 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 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 " this.func = function(a, b, c, d, e, f, g, h, i, j) {" 797 " this.func = function(a, b, c, d, e, f, g, h, i, j) {"
798 " return this.prefix + a + b + c + d + e + f + g + h + i + j;" 798 " return this.prefix + a + b + c + d + e + f + g + h + i + j;"
799 " }" 799 " }"
800 "})()"); 800 "})()");
801 Handle<Object> return_val = callable(object).ToHandleChecked(); 801 Handle<Object> return_val = callable(object).ToHandleChecked();
802 Handle<i::String> expected = 802 Handle<i::String> expected =
803 factory->NewStringFromAsciiChecked("prefix_abcdefghij"); 803 factory->NewStringFromAsciiChecked("prefix_abcdefghij");
804 CHECK(i::String::cast(*return_val)->Equals(*expected)); 804 CHECK(i::String::cast(*return_val)->Equals(*expected));
805 } 805 }
806 } 806 }
807
808
809 static BytecodeArrayBuilder& SetRegister(BytecodeArrayBuilder& builder,
810 Register reg, int value,
811 Register scratch) {
812 return builder.StoreAccumulatorInRegister(scratch)
813 .LoadLiteral(Smi::FromInt(value))
814 .StoreAccumulatorInRegister(reg)
815 .LoadAccumulatorWithRegister(scratch);
816 }
817
818
819 static BytecodeArrayBuilder& IncrementRegister(BytecodeArrayBuilder& builder,
820 Register reg, int value,
821 Register scratch) {
822 return builder.StoreAccumulatorInRegister(scratch)
823 .LoadLiteral(Smi::FromInt(value))
824 .BinaryOperation(Token::Value::ADD, reg)
825 .StoreAccumulatorInRegister(reg)
826 .LoadAccumulatorWithRegister(scratch);
827 }
828
829
830 TEST(InterpreterJumps) {
831 HandleAndZoneScope handles;
832 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
833 builder.set_locals_count(2);
834 builder.set_parameter_count(0);
835 Register reg(0), scratch(1);
836 BytecodeLabel label[3];
837
838 builder.LoadLiteral(Smi::FromInt(0))
839 .StoreAccumulatorInRegister(reg)
840 .Jump(&label[1]);
841 SetRegister(builder, reg, 1024, scratch).Bind(&label[0]);
842 IncrementRegister(builder, reg, 1, scratch).Jump(&label[2]);
843 SetRegister(builder, reg, 2048, scratch).Bind(&label[1]);
844 IncrementRegister(builder, reg, 2, scratch).Jump(&label[0]);
845 SetRegister(builder, reg, 4096, scratch).Bind(&label[2]);
846 IncrementRegister(builder, reg, 4, scratch)
847 .LoadAccumulatorWithRegister(reg)
848 .Return();
849
850 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
851 InterpreterTester tester(handles.main_isolate(), bytecode_array);
852 auto callable = tester.GetCallable<>();
853 Handle<Object> return_value = callable().ToHandleChecked();
854 CHECK_EQ(Smi::cast(*return_value)->value(), 7);
855 }
856
857
858 TEST(InterpreterConditionalJumps) {
859 HandleAndZoneScope handles;
860 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
861 builder.set_locals_count(2);
862 builder.set_parameter_count(0);
863 Register reg(0), scratch(1);
864 BytecodeLabel label[2];
865 BytecodeLabel done, done1;
866
867 builder.LoadLiteral(Smi::FromInt(0))
868 .StoreAccumulatorInRegister(reg)
869 .LoadFalse()
870 .JumpIfFalse(&label[0]);
871 IncrementRegister(builder, reg, 1024, scratch)
872 .Bind(&label[0])
873 .LoadTrue()
874 .JumpIfFalse(&done);
875 IncrementRegister(builder, reg, 1, scratch).LoadTrue().JumpIfTrue(&label[1]);
876 IncrementRegister(builder, reg, 2048, scratch).Bind(&label[1]);
877 IncrementRegister(builder, reg, 2, scratch).LoadFalse().JumpIfTrue(&done1);
878 IncrementRegister(builder, reg, 4, scratch)
879 .LoadAccumulatorWithRegister(reg)
880 .Bind(&done)
881 .Bind(&done1)
882 .Return();
883
884 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
885 InterpreterTester tester(handles.main_isolate(), bytecode_array);
886 auto callable = tester.GetCallable<>();
887 Handle<Object> return_value = callable().ToHandleChecked();
888 CHECK_EQ(Smi::cast(*return_value)->value(), 7);
889 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698