| 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/compiler/pipeline.h" | 7 #include "src/compiler/pipeline.h" |
| 8 #include "src/handles.h" | 8 #include "src/handles.h" |
| 9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
| 10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
| 11 #include "src/isolate.h" | 11 #include "src/isolate.h" |
| 12 #include "src/parsing/parser.h" | 12 #include "src/parsing/parser.h" |
| 13 #include "test/cctest/cctest.h" | 13 #include "test/cctest/cctest.h" |
| 14 #include "test/cctest/interpreter/source-position-matcher.h" | 14 #include "test/cctest/interpreter/source-position-matcher.h" |
| 15 | 15 |
| 16 namespace v8 { | 16 namespace v8 { |
| 17 namespace internal { | 17 namespace internal { |
| 18 namespace interpreter { | 18 namespace interpreter { |
| 19 | 19 |
| 20 // Flags enabling optimizations that change generated bytecode array. | 20 // Flags enabling optimizations that change generated bytecode array. |
| 21 // Format is <command-line flag> <flag name> <bit index> | 21 // Format is <command-line flag> <flag name> <bit index> |
| 22 #define OPTIMIZATION_FLAGS(V) \ | 22 #define OPTIMIZATION_FLAGS(V) \ |
| 23 V(FLAG_ignition_reo, kUseReo, 0) \ | 23 V(FLAG_ignition_reo, kUseReo, 0) \ |
| 24 V(FLAG_ignition_peephole, kUsePeephole, 1) | 24 V(FLAG_ignition_peephole, kUsePeephole, 1) \ |
| 25 V(FLAG_ignition_filter_positions, kUsePositionFiltering, 2) |
| 25 | 26 |
| 26 #define DECLARE_BIT(_, Name, BitIndex) static const int Name = 1 << BitIndex; | 27 #define DECLARE_BIT(_, Name, BitIndex) static const int Name = 1 << BitIndex; |
| 27 OPTIMIZATION_FLAGS(DECLARE_BIT) | 28 OPTIMIZATION_FLAGS(DECLARE_BIT) |
| 28 #undef DECLARE_BIT | 29 #undef DECLARE_BIT |
| 29 | 30 |
| 30 // Test cases source positions are checked for. Please ensure all | 31 // Test cases source positions are checked for. Please ensure all |
| 31 // combinations of flags are present here. This is done manually | 32 // combinations of flags are present here. This is done manually |
| 32 // because it provides easier to comprehend failure case for humans. | 33 // because it provides easier to comprehend failure case for humans. |
| 33 #define TEST_CASES(V) \ | 34 #define TEST_CASES(V) \ |
| 34 V(UsingReo, kUseReo) \ | 35 V(UsingReo, kUseReo) \ |
| 35 V(UsingReoAndPeephole, kUseReo | kUsePeephole) \ | 36 V(UsingPeephole, kUsePeephole) \ |
| 36 V(UsingPeephole, kUsePeephole) | 37 V(UsingReoAndPeephole, kUseReo | kUsePeephole) \ |
| 38 V(UsingPositionFiltering, kUsePositionFiltering) \ |
| 39 V(UsingReoAndPositionFiltering, kUseReo | kUsePositionFiltering) \ |
| 40 V(UsingPeepholeAndPositionFiltering, kUsePeephole | kUsePositionFiltering) \ |
| 41 V(UsingAllOptimizations, kUseReo | kUsePeephole | kUsePositionFiltering) |
| 37 | 42 |
| 38 static const char* kTestScripts[] = { | 43 static const char* kTestScripts[] = { |
| 39 "var x = (y = 3) + (x = y); return x + y;", | 44 "var x = (y = 3) + (x = y); return x + y;", |
| 40 | 45 |
| 41 "var x = 55;\n" | 46 "var x = 55;\n" |
| 42 "var y = x + (x = 1) + (x = 2) + (x = 3);\n" | 47 "var y = x + (x = 1) + (x = 2) + (x = 3);\n" |
| 43 "return y;", | 48 "return y;", |
| 44 | 49 |
| 45 "var x = 10; return x >>> 3;", | 50 "var x = 10; return x >>> 3;", |
| 46 | 51 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 221 |
| 217 void TestSourcePositionsEquivalent(int optimization_bitmap) { | 222 void TestSourcePositionsEquivalent(int optimization_bitmap) { |
| 218 HandleAndZoneScope handles; | 223 HandleAndZoneScope handles; |
| 219 // Ensure handler table is generated. | 224 // Ensure handler table is generated. |
| 220 handles.main_isolate()->interpreter()->Initialize(); | 225 handles.main_isolate()->interpreter()->Initialize(); |
| 221 | 226 |
| 222 OptimizedBytecodeSourcePositionTester tester(handles.main_isolate()); | 227 OptimizedBytecodeSourcePositionTester tester(handles.main_isolate()); |
| 223 for (auto test_script : kTestScripts) { | 228 for (auto test_script : kTestScripts) { |
| 224 CHECK(tester.SourcePositionsMatch(optimization_bitmap, test_script)); | 229 CHECK(tester.SourcePositionsMatch(optimization_bitmap, test_script)); |
| 225 } | 230 } |
| 231 |
| 232 CHECK(tester.SourcePositionsMatch( |
| 233 optimization_bitmap, "return some_global[name];", "name", "'a'")); |
| 226 } | 234 } |
| 227 | 235 |
| 228 #define MAKE_TEST(Name, Bitmap) \ | 236 #define MAKE_TEST(Name, Bitmap) \ |
| 229 TEST(TestSourcePositionsEquivalent##Name) { \ | 237 TEST(TestSourcePositionsEquivalent##Name) { \ |
| 230 TestSourcePositionsEquivalent(Bitmap); \ | 238 TestSourcePositionsEquivalent(Bitmap); \ |
| 231 } | 239 } |
| 232 TEST_CASES(MAKE_TEST) | 240 TEST_CASES(MAKE_TEST) |
| 233 #undef MAKE_TEST | 241 #undef MAKE_TEST |
| 234 | 242 |
| 235 } // namespace interpreter | 243 } // namespace interpreter |
| 236 } // namespace internal | 244 } // namespace internal |
| 237 } // namespace v8 | 245 } // namespace v8 |
| OLD | NEW |