OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ | 5 #ifndef V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ |
6 #define V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ | 6 #define V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 #include "test/cctest/cctest.h" | 9 #include "test/cctest/cctest.h" |
10 | 10 |
11 #include "src/compiler.h" | 11 #include "src/compiler.h" |
12 #include "src/compiler/pipeline.h" | 12 #include "src/compiler/pipeline.h" |
13 #include "src/execution.h" | 13 #include "src/execution.h" |
14 #include "src/full-codegen.h" | 14 #include "src/full-codegen.h" |
15 #include "src/handles.h" | 15 #include "src/handles.h" |
16 #include "src/objects-inl.h" | 16 #include "src/objects-inl.h" |
17 #include "src/parser.h" | 17 #include "src/parser.h" |
18 #include "src/rewriter.h" | 18 #include "src/rewriter.h" |
19 #include "src/scopes.h" | 19 #include "src/scopes.h" |
20 | 20 |
21 #define USE_CRANKSHAFT 0 | 21 #define USE_CRANKSHAFT 0 |
22 | 22 |
23 namespace v8 { | 23 namespace v8 { |
24 namespace internal { | 24 namespace internal { |
25 namespace compiler { | 25 namespace compiler { |
26 | 26 |
27 class FunctionTester : public InitializedHandleScope { | 27 class FunctionTester : public InitializedHandleScope { |
28 public: | 28 public: |
29 explicit FunctionTester(const char* source) | 29 explicit FunctionTester(const char* source, bool context_specialization = |
| 30 FLAG_context_specialization) |
30 : isolate(main_isolate()), | 31 : isolate(main_isolate()), |
31 function((FLAG_allow_natives_syntax = true, NewFunction(source))) { | 32 function((FLAG_allow_natives_syntax = true, NewFunction(source))), |
| 33 context_specialization_(context_specialization) { |
32 Compile(function); | 34 Compile(function); |
33 } | 35 } |
34 | 36 |
35 Isolate* isolate; | 37 Isolate* isolate; |
36 Handle<JSFunction> function; | 38 Handle<JSFunction> function; |
37 | 39 |
38 Handle<JSFunction> Compile(Handle<JSFunction> function) { | 40 Handle<JSFunction> Compile(Handle<JSFunction> function) { |
39 #if V8_TURBOFAN_TARGET | 41 #if V8_TURBOFAN_TARGET |
40 CompilationInfoWithZone info(function); | 42 CompilationInfoWithZone info(function); |
41 | 43 |
42 CHECK(Parser::Parse(&info)); | 44 CHECK(Parser::Parse(&info)); |
43 StrictMode strict_mode = info.function()->strict_mode(); | 45 StrictMode strict_mode = info.function()->strict_mode(); |
44 info.SetStrictMode(strict_mode); | 46 info.SetStrictMode(strict_mode); |
45 info.SetOptimizing(BailoutId::None(), Handle<Code>(function->code())); | 47 info.SetOptimizing(BailoutId::None(), Handle<Code>(function->code())); |
46 CHECK(Rewriter::Rewrite(&info)); | 48 CHECK(Rewriter::Rewrite(&info)); |
47 CHECK(Scope::Analyze(&info)); | 49 CHECK(Scope::Analyze(&info)); |
48 CHECK_NE(NULL, info.scope()); | 50 CHECK_NE(NULL, info.scope()); |
49 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(), info.zone()); | 51 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(), info.zone()); |
50 info.shared_info()->set_scope_info(*scope_info); | 52 info.shared_info()->set_scope_info(*scope_info); |
51 | 53 |
52 EnsureDeoptimizationSupport(&info); | 54 EnsureDeoptimizationSupport(&info); |
53 | 55 |
54 Pipeline pipeline(&info); | 56 Pipeline pipeline(&info, context_specialization_); |
55 Handle<Code> code = pipeline.GenerateCode(); | 57 Handle<Code> code = pipeline.GenerateCode(); |
56 | 58 |
57 CHECK(!code.is_null()); | 59 CHECK(!code.is_null()); |
58 function->ReplaceCode(*code); | 60 function->ReplaceCode(*code); |
59 #elif USE_CRANKSHAFT | 61 #elif USE_CRANKSHAFT |
60 Handle<Code> unoptimized = Handle<Code>(function->code()); | 62 Handle<Code> unoptimized = Handle<Code>(function->code()); |
61 Handle<Code> code = Compiler::GetOptimizedCode(function, unoptimized, | 63 Handle<Code> code = Compiler::GetOptimizedCode(function, unoptimized, |
62 Compiler::NOT_CONCURRENT); | 64 Compiler::NOT_CONCURRENT); |
63 CHECK(!code.is_null()); | 65 CHECK(!code.is_null()); |
64 #if ENABLE_DISASSEMBLER | 66 #if ENABLE_DISASSEMBLER |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 183 |
182 Handle<Object> nan() { return isolate->factory()->nan_value(); } | 184 Handle<Object> nan() { return isolate->factory()->nan_value(); } |
183 | 185 |
184 Handle<Object> undefined() { return isolate->factory()->undefined_value(); } | 186 Handle<Object> undefined() { return isolate->factory()->undefined_value(); } |
185 | 187 |
186 Handle<Object> null() { return isolate->factory()->null_value(); } | 188 Handle<Object> null() { return isolate->factory()->null_value(); } |
187 | 189 |
188 Handle<Object> true_value() { return isolate->factory()->true_value(); } | 190 Handle<Object> true_value() { return isolate->factory()->true_value(); } |
189 | 191 |
190 Handle<Object> false_value() { return isolate->factory()->false_value(); } | 192 Handle<Object> false_value() { return isolate->factory()->false_value(); } |
| 193 |
| 194 private: |
| 195 bool context_specialization_; |
191 }; | 196 }; |
192 } | 197 } |
193 } | 198 } |
194 } // namespace v8::internal::compiler | 199 } // namespace v8::internal::compiler |
195 | 200 |
196 #endif // V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ | 201 #endif // V8_CCTEST_COMPILER_FUNCTION_TESTER_H_ |
OLD | NEW |