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/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // the object heap should be kept inside this class. | 30 // the object heap should be kept inside this class. |
31 // | 31 // |
32 // General strategy: Scripts are translated into anonymous functions w/o | 32 // General strategy: Scripts are translated into anonymous functions w/o |
33 // parameters which then can be executed. If the source code contains other | 33 // parameters which then can be executed. If the source code contains other |
34 // functions, they might be compiled and allocated as part of the compilation | 34 // functions, they might be compiled and allocated as part of the compilation |
35 // of the source code or deferred for lazy compilation at a later point. | 35 // of the source code or deferred for lazy compilation at a later point. |
36 class Compiler : public AllStatic { | 36 class Compiler : public AllStatic { |
37 public: | 37 public: |
38 enum ClearExceptionFlag { KEEP_EXCEPTION, CLEAR_EXCEPTION }; | 38 enum ClearExceptionFlag { KEEP_EXCEPTION, CLEAR_EXCEPTION }; |
39 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; | 39 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; |
40 enum CompilationTier { INTERPRETED, BASELINE, OPTIMIZED }; | |
41 | 40 |
42 // =========================================================================== | 41 // =========================================================================== |
43 // The following family of methods ensures a given function is compiled. The | 42 // The following family of methods ensures a given function is compiled. The |
44 // general contract is that failures will be reported by returning {false}, | 43 // general contract is that failures will be reported by returning {false}, |
45 // whereas successful compilation ensures the {is_compiled} predicate on the | 44 // whereas successful compilation ensures the {is_compiled} predicate on the |
46 // given function holds (except for live-edit, which compiles the world). | 45 // given function holds (except for live-edit, which compiles the world). |
47 | 46 |
48 static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); | 47 static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); |
49 static bool CompileBaseline(Handle<JSFunction> function); | 48 static bool CompileBaseline(Handle<JSFunction> function); |
50 static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode); | 49 static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode); |
51 static bool CompileDebugCode(Handle<JSFunction> function); | 50 static bool CompileDebugCode(Handle<JSFunction> function); |
52 static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); | 51 static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); |
53 static MaybeHandle<JSArray> CompileForLiveEdit(Handle<Script> script); | 52 static MaybeHandle<JSArray> CompileForLiveEdit(Handle<Script> script); |
54 | 53 |
55 // Generate and install code from previously queued compilation job. | 54 // Generate and install code from previously queued compilation job. |
56 static void FinalizeCompilationJob(CompilationJob* job); | 55 static void FinalizeCompilationJob(CompilationJob* job); |
57 | 56 |
58 // Give the compiler a chance to perform low-latency initialization tasks of | 57 // Give the compiler a chance to perform low-latency initialization tasks of |
59 // the given {function} on its instantiation. Note that only the runtime will | 58 // the given {function} on its instantiation. Note that only the runtime will |
60 // offer this chance, optimized closure instantiation will not call this. | 59 // offer this chance, optimized closure instantiation will not call this. |
61 static void PostInstantiation(Handle<JSFunction> function, PretenureFlag); | 60 static void PostInstantiation(Handle<JSFunction> function, PretenureFlag); |
62 | 61 |
63 // Parser::Parse, then Compiler::Analyze. | 62 // Parser::Parse, then Compiler::Analyze. |
64 static bool ParseAndAnalyze(ParseInfo* info); | 63 static bool ParseAndAnalyze(ParseInfo* info); |
65 // Rewrite, analyze scopes, and renumber. | 64 // Rewrite, analyze scopes, and renumber. |
66 static bool Analyze(ParseInfo* info); | 65 static bool Analyze(ParseInfo* info); |
67 // Adds deoptimization support, requires ParseAndAnalyze. | 66 // Adds deoptimization support, requires ParseAndAnalyze. |
68 static bool EnsureDeoptimizationSupport(CompilationInfo* info); | 67 static bool EnsureDeoptimizationSupport(CompilationInfo* info); |
69 // Ensures that bytecode is generated, calls ParseAndAnalyze internally. | |
70 static bool EnsureBytecode(CompilationInfo* info); | |
71 | |
72 // The next compilation tier which the function should be compiled to for | |
73 // optimization. This is used as a hint by the runtime profiler. | |
74 static CompilationTier NextCompilationTier(JSFunction* function); | |
75 | 68 |
76 // =========================================================================== | 69 // =========================================================================== |
77 // The following family of methods instantiates new functions for scripts or | 70 // The following family of methods instantiates new functions for scripts or |
78 // function literals. The decision whether those functions will be compiled, | 71 // function literals. The decision whether those functions will be compiled, |
79 // is left to the discretion of the compiler. | 72 // is left to the discretion of the compiler. |
80 // | 73 // |
81 // Please note this interface returns shared function infos. This means you | 74 // Please note this interface returns shared function infos. This means you |
82 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a | 75 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a |
83 // real function with a context. | 76 // real function with a context. |
84 | 77 |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 MUST_USE_RESULT Status SetLastStatus(Status status) { | 577 MUST_USE_RESULT Status SetLastStatus(Status status) { |
585 last_status_ = status; | 578 last_status_ = status; |
586 return last_status_; | 579 return last_status_; |
587 } | 580 } |
588 }; | 581 }; |
589 | 582 |
590 } // namespace internal | 583 } // namespace internal |
591 } // namespace v8 | 584 } // namespace v8 |
592 | 585 |
593 #endif // V8_COMPILER_H_ | 586 #endif // V8_COMPILER_H_ |
OLD | NEW |