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