OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_COMPILER_H_ | 5 #ifndef V8_COMPILER_H_ |
6 #define V8_COMPILER_H_ | 6 #define V8_COMPILER_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/ast.h" | 9 #include "src/ast.h" |
10 #include "src/zone.h" | 10 #include "src/zone.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 class AstValueFactory; | 15 class AstValueFactory; |
16 class HydrogenCodeStub; | 16 class HydrogenCodeStub; |
17 | 17 |
18 // ParseRestriction is used to restrict the set of valid statements in a | 18 // ParseRestriction is used to restrict the set of valid statements in a |
19 // unit of compilation. Restriction violations cause a syntax error. | 19 // unit of compilation. Restriction violations cause a syntax error. |
20 enum ParseRestriction { | 20 enum ParseRestriction { |
21 NO_PARSE_RESTRICTION, // All expressions are allowed. | 21 NO_PARSE_RESTRICTION, // All expressions are allowed. |
22 ONLY_SINGLE_FUNCTION_LITERAL // Only a single FunctionLiteral expression. | 22 ONLY_SINGLE_FUNCTION_LITERAL // Only a single FunctionLiteral expression. |
23 }; | 23 }; |
24 | 24 |
25 enum CachedDataMode { | |
26 NO_CACHED_DATA, | |
27 CONSUME_CACHED_DATA, | |
28 PRODUCE_CACHED_DATA | |
29 }; | |
30 | |
31 struct OffsetRange { | 25 struct OffsetRange { |
32 OffsetRange(int from, int to) : from(from), to(to) {} | 26 OffsetRange(int from, int to) : from(from), to(to) {} |
33 int from; | 27 int from; |
34 int to; | 28 int to; |
35 }; | 29 }; |
36 | 30 |
37 | 31 |
38 class ScriptData { | 32 class ScriptData { |
39 public: | 33 public: |
40 ScriptData(const byte* data, int length); | 34 ScriptData(const byte* data, int length); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 FunctionLiteral* function() const { return function_; } | 77 FunctionLiteral* function() const { return function_; } |
84 Scope* scope() const { return scope_; } | 78 Scope* scope() const { return scope_; } |
85 Scope* global_scope() const { return global_scope_; } | 79 Scope* global_scope() const { return global_scope_; } |
86 Handle<Code> code() const { return code_; } | 80 Handle<Code> code() const { return code_; } |
87 Handle<JSFunction> closure() const { return closure_; } | 81 Handle<JSFunction> closure() const { return closure_; } |
88 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } | 82 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } |
89 Handle<Script> script() const { return script_; } | 83 Handle<Script> script() const { return script_; } |
90 HydrogenCodeStub* code_stub() const {return code_stub_; } | 84 HydrogenCodeStub* code_stub() const {return code_stub_; } |
91 v8::Extension* extension() const { return extension_; } | 85 v8::Extension* extension() const { return extension_; } |
92 ScriptData** cached_data() const { return cached_data_; } | 86 ScriptData** cached_data() const { return cached_data_; } |
93 CachedDataMode cached_data_mode() const { | 87 ScriptCompiler::CompileOptions compile_options() const { |
94 return cached_data_mode_; | 88 return compile_options_; |
95 } | 89 } |
96 Handle<Context> context() const { return context_; } | 90 Handle<Context> context() const { return context_; } |
97 BailoutId osr_ast_id() const { return osr_ast_id_; } | 91 BailoutId osr_ast_id() const { return osr_ast_id_; } |
98 Handle<Code> unoptimized_code() const { return unoptimized_code_; } | 92 Handle<Code> unoptimized_code() const { return unoptimized_code_; } |
99 int opt_count() const { return opt_count_; } | 93 int opt_count() const { return opt_count_; } |
100 int num_parameters() const; | 94 int num_parameters() const; |
101 int num_heap_slots() const; | 95 int num_heap_slots() const; |
102 Code::Flags flags() const; | 96 Code::Flags flags() const; |
103 | 97 |
104 void MarkAsEval() { | 98 void MarkAsEval() { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 214 } |
221 Handle<FixedArray> feedback_vector() const { | 215 Handle<FixedArray> feedback_vector() const { |
222 return feedback_vector_; | 216 return feedback_vector_; |
223 } | 217 } |
224 void SetCode(Handle<Code> code) { code_ = code; } | 218 void SetCode(Handle<Code> code) { code_ = code; } |
225 void SetExtension(v8::Extension* extension) { | 219 void SetExtension(v8::Extension* extension) { |
226 ASSERT(!is_lazy()); | 220 ASSERT(!is_lazy()); |
227 extension_ = extension; | 221 extension_ = extension; |
228 } | 222 } |
229 void SetCachedData(ScriptData** cached_data, | 223 void SetCachedData(ScriptData** cached_data, |
230 CachedDataMode cached_data_mode) { | 224 ScriptCompiler::CompileOptions compile_options) { |
231 cached_data_mode_ = cached_data_mode; | 225 compile_options_ = compile_options; |
232 if (cached_data_mode == NO_CACHED_DATA) { | 226 if (compile_options == ScriptCompiler::kNoCompileOptions) { |
233 cached_data_ = NULL; | 227 cached_data_ = NULL; |
234 } else { | 228 } else { |
235 ASSERT(!is_lazy()); | 229 ASSERT(!is_lazy()); |
236 cached_data_ = cached_data; | 230 cached_data_ = cached_data; |
237 } | 231 } |
238 } | 232 } |
239 void SetContext(Handle<Context> context) { | 233 void SetContext(Handle<Context> context) { |
240 context_ = context; | 234 context_ = context; |
241 } | 235 } |
242 | 236 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 Handle<Code> code_; | 448 Handle<Code> code_; |
455 | 449 |
456 // Possible initial inputs to the compilation process. | 450 // Possible initial inputs to the compilation process. |
457 Handle<JSFunction> closure_; | 451 Handle<JSFunction> closure_; |
458 Handle<SharedFunctionInfo> shared_info_; | 452 Handle<SharedFunctionInfo> shared_info_; |
459 Handle<Script> script_; | 453 Handle<Script> script_; |
460 | 454 |
461 // Fields possibly needed for eager compilation, NULL by default. | 455 // Fields possibly needed for eager compilation, NULL by default. |
462 v8::Extension* extension_; | 456 v8::Extension* extension_; |
463 ScriptData** cached_data_; | 457 ScriptData** cached_data_; |
464 CachedDataMode cached_data_mode_; | 458 ScriptCompiler::CompileOptions compile_options_; |
465 | 459 |
466 // The context of the caller for eval code, and the global context for a | 460 // The context of the caller for eval code, and the global context for a |
467 // global script. Will be a null handle otherwise. | 461 // global script. Will be a null handle otherwise. |
468 Handle<Context> context_; | 462 Handle<Context> context_; |
469 | 463 |
470 // Used by codegen, ultimately kept rooted by the SharedFunctionInfo. | 464 // Used by codegen, ultimately kept rooted by the SharedFunctionInfo. |
471 Handle<FixedArray> feedback_vector_; | 465 Handle<FixedArray> feedback_vector_; |
472 | 466 |
473 // Compilation mode flag and whether deoptimization is allowed. | 467 // Compilation mode flag and whether deoptimization is allowed. |
474 Mode mode_; | 468 Mode mode_; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 // Compile a String source within a context for eval. | 679 // Compile a String source within a context for eval. |
686 MUST_USE_RESULT static MaybeHandle<JSFunction> GetFunctionFromEval( | 680 MUST_USE_RESULT static MaybeHandle<JSFunction> GetFunctionFromEval( |
687 Handle<String> source, | 681 Handle<String> source, |
688 Handle<Context> context, | 682 Handle<Context> context, |
689 StrictMode strict_mode, | 683 StrictMode strict_mode, |
690 ParseRestriction restriction, | 684 ParseRestriction restriction, |
691 int scope_position); | 685 int scope_position); |
692 | 686 |
693 // Compile a String source within a context. | 687 // Compile a String source within a context. |
694 static Handle<SharedFunctionInfo> CompileScript( | 688 static Handle<SharedFunctionInfo> CompileScript( |
695 Handle<String> source, | 689 Handle<String> source, Handle<Object> script_name, int line_offset, |
696 Handle<Object> script_name, | 690 int column_offset, bool is_shared_cross_origin, Handle<Context> context, |
697 int line_offset, | 691 v8::Extension* extension, ScriptData** cached_data, |
698 int column_offset, | 692 ScriptCompiler::CompileOptions compile_options, |
699 bool is_shared_cross_origin, | |
700 Handle<Context> context, | |
701 v8::Extension* extension, | |
702 ScriptData** cached_data, | |
703 CachedDataMode cached_data_mode, | |
704 NativesFlag is_natives_code); | 693 NativesFlag is_natives_code); |
705 | 694 |
706 // Create a shared function info object (the code may be lazily compiled). | 695 // Create a shared function info object (the code may be lazily compiled). |
707 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, | 696 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, |
708 Handle<Script> script); | 697 Handle<Script> script); |
709 | 698 |
710 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; | 699 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; |
711 | 700 |
712 // Generate and return optimized code or start a concurrent optimization job. | 701 // Generate and return optimized code or start a concurrent optimization job. |
713 // In the latter case, return the InOptimizationQueue builtin. On failure, | 702 // In the latter case, return the InOptimizationQueue builtin. On failure, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 Zone zone_; | 736 Zone zone_; |
748 unsigned info_zone_start_allocation_size_; | 737 unsigned info_zone_start_allocation_size_; |
749 base::ElapsedTimer timer_; | 738 base::ElapsedTimer timer_; |
750 | 739 |
751 DISALLOW_COPY_AND_ASSIGN(CompilationPhase); | 740 DISALLOW_COPY_AND_ASSIGN(CompilationPhase); |
752 }; | 741 }; |
753 | 742 |
754 } } // namespace v8::internal | 743 } } // namespace v8::internal |
755 | 744 |
756 #endif // V8_COMPILER_H_ | 745 #endif // V8_COMPILER_H_ |
OLD | NEW |