yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_COMPILER_H_ |
| 29 | #define V8_COMPILER_H_ |
| 30 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 31 | #include "allocation.h" |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 32 | #include "ast.h" |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 33 | #include "zone.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 35 | namespace v8 { |
| 36 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 38 | class ScriptDataImpl; |
| 39 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 40 | // CompilationInfo encapsulates some information known at compile time. It |
| 41 | // is constructed based on the resources available at compile-time. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 42 | class CompilationInfo BASE_EMBEDDED { |
| 43 | public: |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 44 | CompilationInfo(Handle<Script> script, Zone* zone); |
| 45 | CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone); |
| 46 | CompilationInfo(Handle<JSFunction> closure, Zone* zone); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 47 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 48 | Isolate* isolate() { |
| 49 | ASSERT(Isolate::Current() == isolate_); |
| 50 | return isolate_; |
| 51 | } |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 52 | Zone* zone() { |
| 53 | return zone_; |
| 54 | } |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 55 | bool is_lazy() const { return IsLazy::decode(flags_); } |
| 56 | bool is_eval() const { return IsEval::decode(flags_); } |
| 57 | bool is_global() const { return IsGlobal::decode(flags_); } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 58 | bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; } |
| 59 | bool is_extended_mode() const { return language_mode() == EXTENDED_MODE; } |
| 60 | LanguageMode language_mode() const { |
| 61 | return LanguageModeField::decode(flags_); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 62 | } |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 63 | bool is_in_loop() const { return IsInLoop::decode(flags_); } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 64 | FunctionLiteral* function() const { return function_; } |
| 65 | Scope* scope() const { return scope_; } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 66 | Scope* global_scope() const { return global_scope_; } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 67 | Handle<Code> code() const { return code_; } |
| 68 | Handle<JSFunction> closure() const { return closure_; } |
| 69 | Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } |
| 70 | Handle<Script> script() const { return script_; } |
| 71 | v8::Extension* extension() const { return extension_; } |
| 72 | ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } |
| 73 | Handle<Context> calling_context() const { return calling_context_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 74 | int osr_ast_id() const { return osr_ast_id_; } |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 75 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 76 | void MarkAsEval() { |
| 77 | ASSERT(!is_lazy()); |
| 78 | flags_ |= IsEval::encode(true); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 79 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 80 | void MarkAsGlobal() { |
| 81 | ASSERT(!is_lazy()); |
| 82 | flags_ |= IsGlobal::encode(true); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 83 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 84 | void SetLanguageMode(LanguageMode language_mode) { |
| 85 | ASSERT(this->language_mode() == CLASSIC_MODE || |
| 86 | this->language_mode() == language_mode || |
| 87 | language_mode == EXTENDED_MODE); |
| 88 | flags_ = LanguageModeField::update(flags_, language_mode); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 89 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 90 | void MarkAsInLoop() { |
| 91 | ASSERT(is_lazy()); |
| 92 | flags_ |= IsInLoop::encode(true); |
| 93 | } |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 94 | void MarkAsNative() { |
| 95 | flags_ |= IsNative::encode(true); |
| 96 | } |
| 97 | bool is_native() const { |
| 98 | return IsNative::decode(flags_); |
| 99 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 100 | void SetFunction(FunctionLiteral* literal) { |
| 101 | ASSERT(function_ == NULL); |
| 102 | function_ = literal; |
| 103 | } |
| 104 | void SetScope(Scope* scope) { |
| 105 | ASSERT(scope_ == NULL); |
| 106 | scope_ = scope; |
| 107 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 108 | void SetGlobalScope(Scope* global_scope) { |
| 109 | ASSERT(global_scope_ == NULL); |
| 110 | global_scope_ = global_scope; |
| 111 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 112 | void SetCode(Handle<Code> code) { code_ = code; } |
| 113 | void SetExtension(v8::Extension* extension) { |
| 114 | ASSERT(!is_lazy()); |
| 115 | extension_ = extension; |
| 116 | } |
| 117 | void SetPreParseData(ScriptDataImpl* pre_parse_data) { |
| 118 | ASSERT(!is_lazy()); |
| 119 | pre_parse_data_ = pre_parse_data; |
| 120 | } |
| 121 | void SetCallingContext(Handle<Context> context) { |
| 122 | ASSERT(is_eval()); |
| 123 | calling_context_ = context; |
| 124 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 125 | void SetOsrAstId(int osr_ast_id) { |
| 126 | ASSERT(IsOptimizing()); |
| 127 | osr_ast_id_ = osr_ast_id; |
| 128 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 129 | void MarkCompilingForDebugging(Handle<Code> current_code) { |
| 130 | ASSERT(mode_ != OPTIMIZE); |
| 131 | ASSERT(current_code->kind() == Code::FUNCTION); |
| 132 | flags_ |= IsCompilingForDebugging::encode(true); |
| 133 | if (current_code->is_compiled_optimizable()) { |
| 134 | EnableDeoptimizationSupport(); |
| 135 | } else { |
| 136 | mode_ = CompilationInfo::NONOPT; |
| 137 | } |
| 138 | } |
| 139 | bool IsCompilingForDebugging() { |
| 140 | return IsCompilingForDebugging::decode(flags_); |
| 141 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 142 | |
| 143 | bool has_global_object() const { |
| 144 | return !closure().is_null() && (closure()->context()->global() != NULL); |
| 145 | } |
| 146 | |
| 147 | GlobalObject* global_object() const { |
| 148 | return has_global_object() ? closure()->context()->global() : NULL; |
| 149 | } |
| 150 | |
| 151 | // Accessors for the different compilation modes. |
| 152 | bool IsOptimizing() const { return mode_ == OPTIMIZE; } |
| 153 | bool IsOptimizable() const { return mode_ == BASE; } |
| 154 | void SetOptimizing(int osr_ast_id) { |
| 155 | SetMode(OPTIMIZE); |
| 156 | osr_ast_id_ = osr_ast_id; |
| 157 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 158 | void DisableOptimization(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 159 | |
| 160 | // Deoptimization support. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 161 | bool HasDeoptimizationSupport() const { |
| 162 | return SupportsDeoptimization::decode(flags_); |
| 163 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 164 | void EnableDeoptimizationSupport() { |
| 165 | ASSERT(IsOptimizable()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 166 | flags_ |= SupportsDeoptimization::encode(true); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 167 | } |
| 168 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 169 | // Determines whether or not to insert a self-optimization header. |
| 170 | bool ShouldSelfOptimize(); |
| 171 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 172 | // Disable all optimization attempts of this info for the rest of the |
| 173 | // current compilation pipeline. |
| 174 | void AbortOptimization(); |
| 175 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 176 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 177 | Isolate* isolate_; |
| 178 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 179 | // Compilation mode. |
| 180 | // BASE is generated by the full codegen, optionally prepared for bailouts. |
| 181 | // OPTIMIZE is optimized code generated by the Hydrogen-based backend. |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 182 | // NONOPT is generated by the full codegen and is not prepared for |
| 183 | // recompilation/bailouts. These functions are never recompiled. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 184 | enum Mode { |
| 185 | BASE, |
| 186 | OPTIMIZE, |
| 187 | NONOPT |
| 188 | }; |
| 189 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 190 | void Initialize(Mode mode) { |
| 191 | mode_ = V8::UseCrankshaft() ? mode : NONOPT; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 192 | ASSERT(!script_.is_null()); |
| 193 | if (script_->type()->value() == Script::TYPE_NATIVE) { |
| 194 | MarkAsNative(); |
| 195 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 196 | if (!shared_info_.is_null()) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 197 | ASSERT(language_mode() == CLASSIC_MODE); |
| 198 | SetLanguageMode(shared_info_->language_mode()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 199 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void SetMode(Mode mode) { |
| 203 | ASSERT(V8::UseCrankshaft()); |
| 204 | mode_ = mode; |
| 205 | } |
| 206 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 207 | // Flags using template class BitField<type, start, length>. All are |
| 208 | // false by default. |
| 209 | // |
| 210 | // Compilation is either eager or lazy. |
| 211 | class IsLazy: public BitField<bool, 0, 1> {}; |
| 212 | // Flags that can be set for eager compilation. |
| 213 | class IsEval: public BitField<bool, 1, 1> {}; |
| 214 | class IsGlobal: public BitField<bool, 2, 1> {}; |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 215 | // Flags that can be set for lazy compilation. |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 216 | class IsInLoop: public BitField<bool, 3, 1> {}; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 217 | // Strict mode - used in eager compilation. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 218 | class LanguageModeField: public BitField<LanguageMode, 4, 2> {}; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 219 | // Is this a function from our natives. |
| 220 | class IsNative: public BitField<bool, 6, 1> {}; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 221 | // Is this code being compiled with support for deoptimization.. |
| 222 | class SupportsDeoptimization: public BitField<bool, 7, 1> {}; |
| 223 | // If compiling for debugging produce just full code matching the |
| 224 | // initial mode setting. |
| 225 | class IsCompilingForDebugging: public BitField<bool, 8, 1> {}; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 226 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 227 | |
| 228 | unsigned flags_; |
| 229 | |
| 230 | // Fields filled in by the compilation pipeline. |
| 231 | // AST filled in by the parser. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 232 | FunctionLiteral* function_; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 233 | // The scope of the function literal as a convenience. Set to indicate |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 234 | // that scopes have been analyzed. |
| 235 | Scope* scope_; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 236 | // The global scope provided as a convenience. |
| 237 | Scope* global_scope_; |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 238 | // The compiled code. |
| 239 | Handle<Code> code_; |
| 240 | |
| 241 | // Possible initial inputs to the compilation process. |
| 242 | Handle<JSFunction> closure_; |
| 243 | Handle<SharedFunctionInfo> shared_info_; |
| 244 | Handle<Script> script_; |
| 245 | |
| 246 | // Fields possibly needed for eager compilation, NULL by default. |
| 247 | v8::Extension* extension_; |
| 248 | ScriptDataImpl* pre_parse_data_; |
| 249 | |
| 250 | // The context of the caller is needed for eval code, and will be a null |
| 251 | // handle otherwise. |
| 252 | Handle<Context> calling_context_; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 253 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 254 | // Compilation mode flag and whether deoptimization is allowed. |
| 255 | Mode mode_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 256 | int osr_ast_id_; |
| 257 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 258 | // The zone from which the compilation pipeline working on this |
| 259 | // CompilationInfo allocates. |
| 260 | Zone* zone_; |
| 261 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 262 | DISALLOW_COPY_AND_ASSIGN(CompilationInfo); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 263 | }; |
| 264 | |
| 265 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 266 | // Exactly like a CompilationInfo, except also creates and enters a |
| 267 | // Zone on construction and deallocates it on exit. |
| 268 | class CompilationInfoWithZone: public CompilationInfo { |
| 269 | public: |
| 270 | explicit CompilationInfoWithZone(Handle<Script> script) |
| 271 | : CompilationInfo(script, &zone_), |
| 272 | zone_(script->GetIsolate()), |
| 273 | zone_scope_(&zone_, DELETE_ON_EXIT) {} |
| 274 | explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info) |
| 275 | : CompilationInfo(shared_info, &zone_), |
| 276 | zone_(shared_info->GetIsolate()), |
| 277 | zone_scope_(&zone_, DELETE_ON_EXIT) {} |
| 278 | explicit CompilationInfoWithZone(Handle<JSFunction> closure) |
| 279 | : CompilationInfo(closure, &zone_), |
| 280 | zone_(closure->GetIsolate()), |
| 281 | zone_scope_(&zone_, DELETE_ON_EXIT) {} |
| 282 | |
| 283 | private: |
| 284 | Zone zone_; |
| 285 | ZoneScope zone_scope_; |
| 286 | }; |
| 287 | |
| 288 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 289 | // The V8 compiler |
| 290 | // |
| 291 | // General strategy: Source code is translated into an anonymous function w/o |
| 292 | // parameters which then can be executed. If the source code contains other |
| 293 | // functions, they will be compiled and allocated as part of the compilation |
| 294 | // of the source code. |
| 295 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 296 | // Please note this interface returns shared function infos. This means you |
| 297 | // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a |
| 298 | // real function with a context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 299 | |
| 300 | class Compiler : public AllStatic { |
| 301 | public: |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 302 | // Default maximum number of function optimization attempts before we |
| 303 | // give up. |
| 304 | static const int kDefaultMaxOptCount = 10; |
| 305 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 306 | static const int kMaxInliningLevels = 3; |
| 307 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 308 | // Call count before primitive functions trigger their own optimization. |
| 309 | static const int kCallsUntilPrimitiveOpt = 200; |
| 310 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 311 | // All routines return a SharedFunctionInfo. |
| 312 | // If an error occurs an exception is raised and the return handle |
| 313 | // contains NULL. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 314 | |
| 315 | // Compile a String source within a context. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 316 | static Handle<SharedFunctionInfo> Compile(Handle<String> source, |
| 317 | Handle<Object> script_name, |
| 318 | int line_offset, |
| 319 | int column_offset, |
| 320 | v8::Extension* extension, |
| 321 | ScriptDataImpl* pre_data, |
| 322 | Handle<Object> script_data, |
| 323 | NativesFlag is_natives_code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 324 | |
| 325 | // Compile a String source within a context for Eval. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 326 | static Handle<SharedFunctionInfo> CompileEval(Handle<String> source, |
| 327 | Handle<Context> context, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 328 | bool is_global, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 329 | LanguageMode language_mode, |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 330 | int scope_position); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 331 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 332 | // Compile from function info (used for lazy compilation). Returns true on |
| 333 | // success and false if the compilation resulted in a stack overflow. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 334 | static bool CompileLazy(CompilationInfo* info); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 335 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 336 | // Compile a shared function info object (the function is possibly lazily |
| 337 | // compiled). |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 338 | static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 339 | Handle<Script> script); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 340 | |
| 341 | // Set the function info for a newly compiled function. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 342 | static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 343 | FunctionLiteral* lit, |
| 344 | bool is_toplevel, |
| 345 | Handle<Script> script); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 346 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 347 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 348 | static bool MakeCodeForLiveEdit(CompilationInfo* info); |
| 349 | #endif |
| 350 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 351 | static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 352 | CompilationInfo* info, |
| 353 | Handle<SharedFunctionInfo> shared); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 354 | }; |
| 355 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 356 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 357 | } } // namespace v8::internal |
| 358 | |
| 359 | #endif // V8_COMPILER_H_ |