Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Side by Side Diff: src/compiler.h

Issue 660095: Merge revision 3813 to 3930 from bleeding_edge to partial snapshots branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: '' Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/codegen.cc ('k') | src/compiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_COMPILER_H_ 28 #ifndef V8_COMPILER_H_
29 #define V8_COMPILER_H_ 29 #define V8_COMPILER_H_
30 30
31 #include "ast.h"
31 #include "frame-element.h" 32 #include "frame-element.h"
32 #include "parser.h" 33 #include "parser.h"
34 #include "register-allocator.h"
33 #include "zone.h" 35 #include "zone.h"
34 36
35 namespace v8 { 37 namespace v8 {
36 namespace internal { 38 namespace internal {
37 39
38 // CompilationInfo encapsulates some information known at compile time. It 40 // CompilationInfo encapsulates some information known at compile time. It
39 // is constructed based on the resources available at compile-time. 41 // is constructed based on the resources available at compile-time.
40 class CompilationInfo BASE_EMBEDDED { 42 class CompilationInfo BASE_EMBEDDED {
41 public: 43 public:
44 // Compilation mode. Either the compiler is used as the primary
45 // compiler and needs to setup everything or the compiler is used as
46 // the secondary compiler for split compilation and has to handle
47 // bailouts.
48 enum Mode {
49 PRIMARY,
50 SECONDARY
51 };
52
53 // A description of the compilation state at a bailout to the secondary
54 // code generator.
55 //
56 // The state is currently simple: there are no parameters or local
57 // variables to worry about ('this' can be found in the stack frame).
58 // There are at most two live values.
59 //
60 // There is a label that should be bound to the beginning of the bailout
61 // stub code.
62 class Bailout : public ZoneObject {
63 public:
64 Bailout(Register left, Register right) : left_(left), right_(right) {}
65
66 Label* label() { return &label_; }
67
68 private:
69 Register left_;
70 Register right_;
71 Label label_;
72 };
73
74
42 // Lazy compilation of a JSFunction. 75 // Lazy compilation of a JSFunction.
43 CompilationInfo(Handle<JSFunction> closure, 76 CompilationInfo(Handle<JSFunction> closure,
44 int loop_nesting, 77 int loop_nesting,
45 Handle<Object> receiver) 78 Handle<Object> receiver)
46 : closure_(closure), 79 : closure_(closure),
47 function_(NULL), 80 function_(NULL),
48 is_eval_(false), 81 is_eval_(false),
49 loop_nesting_(loop_nesting), 82 loop_nesting_(loop_nesting),
50 receiver_(receiver) { 83 receiver_(receiver) {
51 Initialize(); 84 Initialize();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 void set_function(FunctionLiteral* literal) { 141 void set_function(FunctionLiteral* literal) {
109 ASSERT(function_ == NULL); 142 ASSERT(function_ == NULL);
110 function_ = literal; 143 function_ = literal;
111 } 144 }
112 145
113 // Simple accessors. 146 // Simple accessors.
114 bool is_eval() { return is_eval_; } 147 bool is_eval() { return is_eval_; }
115 int loop_nesting() { return loop_nesting_; } 148 int loop_nesting() { return loop_nesting_; }
116 bool has_receiver() { return !receiver_.is_null(); } 149 bool has_receiver() { return !receiver_.is_null(); }
117 Handle<Object> receiver() { return receiver_; } 150 Handle<Object> receiver() { return receiver_; }
151 List<Bailout*>* bailouts() { return &bailouts_; }
118 152
119 // Accessors for mutable fields, possibly set by analysis passes with 153 // Accessors for mutable fields (possibly set by analysis passes) with
120 // default values given by Initialize. 154 // default values given by Initialize.
155 Mode mode() { return mode_; }
156 void set_mode(Mode mode) { mode_ = mode; }
157
121 bool has_this_properties() { return has_this_properties_; } 158 bool has_this_properties() { return has_this_properties_; }
122 void set_has_this_properties(bool flag) { has_this_properties_ = flag; } 159 void set_has_this_properties(bool flag) { has_this_properties_ = flag; }
123 160
124 bool has_global_object() { 161 bool has_global_object() {
125 return !closure().is_null() && (closure()->context()->global() != NULL); 162 return !closure().is_null() && (closure()->context()->global() != NULL);
126 } 163 }
127 164
128 GlobalObject* global_object() { 165 GlobalObject* global_object() {
129 return has_global_object() ? closure()->context()->global() : NULL; 166 return has_global_object() ? closure()->context()->global() : NULL;
130 } 167 }
131 168
132 bool has_globals() { return has_globals_; } 169 bool has_globals() { return has_globals_; }
133 void set_has_globals(bool flag) { has_globals_ = flag; } 170 void set_has_globals(bool flag) { has_globals_ = flag; }
134 171
135 // Derived accessors. 172 // Derived accessors.
136 Scope* scope() { return function()->scope(); } 173 Scope* scope() { return function()->scope(); }
137 174
175 // Add a bailout with two live values.
176 Label* AddBailout(Register left, Register right) {
177 Bailout* bailout = new Bailout(left, right);
178 bailouts_.Add(bailout);
179 return bailout->label();
180 }
181
182 // Add a bailout with no live values.
183 Label* AddBailout() { return AddBailout(no_reg, no_reg); }
184
138 private: 185 private:
139 void Initialize() { 186 void Initialize() {
187 mode_ = PRIMARY;
140 has_this_properties_ = false; 188 has_this_properties_ = false;
141 has_globals_ = false; 189 has_globals_ = false;
142 } 190 }
143 191
144 Handle<JSFunction> closure_; 192 Handle<JSFunction> closure_;
145 Handle<SharedFunctionInfo> shared_info_; 193 Handle<SharedFunctionInfo> shared_info_;
146 Handle<Script> script_; 194 Handle<Script> script_;
147 195
148 FunctionLiteral* function_; 196 FunctionLiteral* function_;
197 Mode mode_;
149 198
150 bool is_eval_; 199 bool is_eval_;
151 int loop_nesting_; 200 int loop_nesting_;
152 201
153 Handle<Object> receiver_; 202 Handle<Object> receiver_;
154 203
155 bool has_this_properties_; 204 bool has_this_properties_;
156 bool has_globals_; 205 bool has_globals_;
157 206
207 // An ordered list of bailout points encountered during fast-path
208 // compilation.
209 List<Bailout*> bailouts_;
210
158 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); 211 DISALLOW_COPY_AND_ASSIGN(CompilationInfo);
159 }; 212 };
160 213
161 214
162 // The V8 compiler 215 // The V8 compiler
163 // 216 //
164 // General strategy: Source code is translated into an anonymous function w/o 217 // General strategy: Source code is translated into an anonymous function w/o
165 // parameters which then can be executed. If the source code contains other 218 // parameters which then can be executed. If the source code contains other
166 // functions, they will be compiled and allocated as part of the compilation 219 // functions, they will be compiled and allocated as part of the compilation
167 // of the source code. 220 // of the source code.
168 221
169 // Please note this interface returns function boilerplates. 222 // Please note this interface returns function boilerplates.
170 // This means you need to call Factory::NewFunctionFromBoilerplate 223 // This means you need to call Factory::NewFunctionFromBoilerplate
171 // before you have a real function with context. 224 // before you have a real function with context.
172 225
173 class Compiler : public AllStatic { 226 class Compiler : public AllStatic {
174 public: 227 public:
175 enum ValidationState { VALIDATE_JSON, DONT_VALIDATE_JSON }; 228 enum ValidationState { VALIDATE_JSON, DONT_VALIDATE_JSON };
176 229
177 // All routines return a JSFunction. 230 // All routines return a JSFunction.
178 // If an error occurs an exception is raised and 231 // If an error occurs an exception is raised and
179 // the return handle contains NULL. 232 // the return handle contains NULL.
180 233
181 // Compile a String source within a context. 234 // Compile a String source within a context.
182 static Handle<JSFunction> Compile(Handle<String> source, 235 static Handle<JSFunction> Compile(Handle<String> source,
183 Handle<Object> script_name, 236 Handle<Object> script_name,
184 int line_offset, int column_offset, 237 int line_offset, int column_offset,
185 v8::Extension* extension, 238 v8::Extension* extension,
186 ScriptDataImpl* script_Data, 239 ScriptDataImpl* pre_data,
240 Handle<Object> script_data,
187 NativesFlag is_natives_code); 241 NativesFlag is_natives_code);
188 242
189 // Compile a String source within a context for Eval. 243 // Compile a String source within a context for Eval.
190 static Handle<JSFunction> CompileEval(Handle<String> source, 244 static Handle<JSFunction> CompileEval(Handle<String> source,
191 Handle<Context> context, 245 Handle<Context> context,
192 bool is_global, 246 bool is_global,
193 ValidationState validation); 247 ValidationState validation);
194 248
195 // Compile from function info (used for lazy compilation). Returns 249 // Compile from function info (used for lazy compilation). Returns
196 // true on success and false if the compilation resulted in a stack 250 // true on success and false if the compilation resulted in a stack
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 FrameElement::ClearConstantList(); 288 FrameElement::ClearConstantList();
235 Result::ClearConstantList(); 289 Result::ClearConstantList();
236 } 290 }
237 } 291 }
238 }; 292 };
239 293
240 294
241 } } // namespace v8::internal 295 } } // namespace v8::internal
242 296
243 #endif // V8_COMPILER_H_ 297 #endif // V8_COMPILER_H_
OLDNEW
« no previous file with comments | « src/codegen.cc ('k') | src/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698