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

Side by Side Diff: src/fast-codegen.h

Issue 549108: Rename the toplevel code generator from "Fast" to "Full". It was... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 11 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/compiler.cc ('k') | src/fast-codegen.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 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 17 matching lines...) Expand all
28 #ifndef V8_FAST_CODEGEN_H_ 28 #ifndef V8_FAST_CODEGEN_H_
29 #define V8_FAST_CODEGEN_H_ 29 #define V8_FAST_CODEGEN_H_
30 30
31 #include "v8.h" 31 #include "v8.h"
32 32
33 #include "ast.h" 33 #include "ast.h"
34 34
35 namespace v8 { 35 namespace v8 {
36 namespace internal { 36 namespace internal {
37 37
38 class FullCodeGenSyntaxChecker: public AstVisitor {
39 public:
40 FullCodeGenSyntaxChecker() : has_supported_syntax_(true) {}
41
42 void Check(FunctionLiteral* fun);
43
44 bool has_supported_syntax() { return has_supported_syntax_; }
45
46 private:
47 void VisitDeclarations(ZoneList<Declaration*>* decls);
48 void VisitStatements(ZoneList<Statement*>* stmts);
49
50 // AST node visit functions.
51 #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
52 AST_NODE_LIST(DECLARE_VISIT)
53 #undef DECLARE_VISIT
54
55 bool has_supported_syntax_;
56
57 DISALLOW_COPY_AND_ASSIGN(FullCodeGenSyntaxChecker);
58 };
59
60
38 // ----------------------------------------------------------------------------- 61 // -----------------------------------------------------------------------------
39 // Fast code generator. 62 // Full code generator.
40 63
41 class FastCodeGenerator: public AstVisitor { 64 class FullCodeGenerator: public AstVisitor {
42 public: 65 public:
43 FastCodeGenerator(MacroAssembler* masm, Handle<Script> script, bool is_eval) 66 FullCodeGenerator(MacroAssembler* masm, Handle<Script> script, bool is_eval)
44 : masm_(masm), 67 : masm_(masm),
45 function_(NULL), 68 function_(NULL),
46 script_(script), 69 script_(script),
47 is_eval_(is_eval), 70 is_eval_(is_eval),
48 nesting_stack_(NULL), 71 nesting_stack_(NULL),
49 loop_depth_(0), 72 loop_depth_(0),
50 location_(kStack), 73 location_(kStack),
51 true_label_(NULL), 74 true_label_(NULL),
52 false_label_(NULL) { 75 false_label_(NULL) {
53 } 76 }
54 77
55 static Handle<Code> MakeCode(FunctionLiteral* fun, 78 static Handle<Code> MakeCode(FunctionLiteral* fun,
56 Handle<Script> script, 79 Handle<Script> script,
57 bool is_eval); 80 bool is_eval);
58 81
59 void Generate(FunctionLiteral* fun); 82 void Generate(FunctionLiteral* fun);
60 83
61 private: 84 private:
62 class Breakable; 85 class Breakable;
63 class Iteration; 86 class Iteration;
64 class TryCatch; 87 class TryCatch;
65 class TryFinally; 88 class TryFinally;
66 class Finally; 89 class Finally;
67 class ForIn; 90 class ForIn;
68 91
69 class NestedStatement BASE_EMBEDDED { 92 class NestedStatement BASE_EMBEDDED {
70 public: 93 public:
71 explicit NestedStatement(FastCodeGenerator* codegen) : codegen_(codegen) { 94 explicit NestedStatement(FullCodeGenerator* codegen) : codegen_(codegen) {
72 // Link into codegen's nesting stack. 95 // Link into codegen's nesting stack.
73 previous_ = codegen->nesting_stack_; 96 previous_ = codegen->nesting_stack_;
74 codegen->nesting_stack_ = this; 97 codegen->nesting_stack_ = this;
75 } 98 }
76 virtual ~NestedStatement() { 99 virtual ~NestedStatement() {
77 // Unlink from codegen's nesting stack. 100 // Unlink from codegen's nesting stack.
78 ASSERT_EQ(this, codegen_->nesting_stack_); 101 ASSERT_EQ(this, codegen_->nesting_stack_);
79 codegen_->nesting_stack_ = previous_; 102 codegen_->nesting_stack_ = previous_;
80 } 103 }
81 104
(...skipping 17 matching lines...) Expand all
99 // contains the value in case of a return). 122 // contains the value in case of a return).
100 virtual int Exit(int stack_depth) { 123 virtual int Exit(int stack_depth) {
101 // Default implementation for the case where there is 124 // Default implementation for the case where there is
102 // nothing to clean up. 125 // nothing to clean up.
103 return stack_depth; 126 return stack_depth;
104 } 127 }
105 NestedStatement* outer() { return previous_; } 128 NestedStatement* outer() { return previous_; }
106 protected: 129 protected:
107 MacroAssembler* masm() { return codegen_->masm(); } 130 MacroAssembler* masm() { return codegen_->masm(); }
108 private: 131 private:
109 FastCodeGenerator* codegen_; 132 FullCodeGenerator* codegen_;
110 NestedStatement* previous_; 133 NestedStatement* previous_;
111 DISALLOW_COPY_AND_ASSIGN(NestedStatement); 134 DISALLOW_COPY_AND_ASSIGN(NestedStatement);
112 }; 135 };
113 136
114 class Breakable : public NestedStatement { 137 class Breakable : public NestedStatement {
115 public: 138 public:
116 Breakable(FastCodeGenerator* codegen, 139 Breakable(FullCodeGenerator* codegen,
117 BreakableStatement* break_target) 140 BreakableStatement* break_target)
118 : NestedStatement(codegen), 141 : NestedStatement(codegen),
119 target_(break_target) {} 142 target_(break_target) {}
120 virtual ~Breakable() {} 143 virtual ~Breakable() {}
121 virtual Breakable* AsBreakable() { return this; } 144 virtual Breakable* AsBreakable() { return this; }
122 virtual bool IsBreakTarget(Statement* statement) { 145 virtual bool IsBreakTarget(Statement* statement) {
123 return target_ == statement; 146 return target_ == statement;
124 } 147 }
125 BreakableStatement* statement() { return target_; } 148 BreakableStatement* statement() { return target_; }
126 Label* break_target() { return &break_target_label_; } 149 Label* break_target() { return &break_target_label_; }
127 private: 150 private:
128 BreakableStatement* target_; 151 BreakableStatement* target_;
129 Label break_target_label_; 152 Label break_target_label_;
130 DISALLOW_COPY_AND_ASSIGN(Breakable); 153 DISALLOW_COPY_AND_ASSIGN(Breakable);
131 }; 154 };
132 155
133 class Iteration : public Breakable { 156 class Iteration : public Breakable {
134 public: 157 public:
135 Iteration(FastCodeGenerator* codegen, 158 Iteration(FullCodeGenerator* codegen,
136 IterationStatement* iteration_statement) 159 IterationStatement* iteration_statement)
137 : Breakable(codegen, iteration_statement) {} 160 : Breakable(codegen, iteration_statement) {}
138 virtual ~Iteration() {} 161 virtual ~Iteration() {}
139 virtual Iteration* AsIteration() { return this; } 162 virtual Iteration* AsIteration() { return this; }
140 virtual bool IsContinueTarget(Statement* statement) { 163 virtual bool IsContinueTarget(Statement* statement) {
141 return this->statement() == statement; 164 return this->statement() == statement;
142 } 165 }
143 Label* continue_target() { return &continue_target_label_; } 166 Label* continue_target() { return &continue_target_label_; }
144 private: 167 private:
145 Label continue_target_label_; 168 Label continue_target_label_;
146 DISALLOW_COPY_AND_ASSIGN(Iteration); 169 DISALLOW_COPY_AND_ASSIGN(Iteration);
147 }; 170 };
148 171
149 // The environment inside the try block of a try/catch statement. 172 // The environment inside the try block of a try/catch statement.
150 class TryCatch : public NestedStatement { 173 class TryCatch : public NestedStatement {
151 public: 174 public:
152 explicit TryCatch(FastCodeGenerator* codegen, Label* catch_entry) 175 explicit TryCatch(FullCodeGenerator* codegen, Label* catch_entry)
153 : NestedStatement(codegen), catch_entry_(catch_entry) { } 176 : NestedStatement(codegen), catch_entry_(catch_entry) { }
154 virtual ~TryCatch() {} 177 virtual ~TryCatch() {}
155 virtual TryCatch* AsTryCatch() { return this; } 178 virtual TryCatch* AsTryCatch() { return this; }
156 Label* catch_entry() { return catch_entry_; } 179 Label* catch_entry() { return catch_entry_; }
157 virtual int Exit(int stack_depth); 180 virtual int Exit(int stack_depth);
158 private: 181 private:
159 Label* catch_entry_; 182 Label* catch_entry_;
160 DISALLOW_COPY_AND_ASSIGN(TryCatch); 183 DISALLOW_COPY_AND_ASSIGN(TryCatch);
161 }; 184 };
162 185
163 // The environment inside the try block of a try/finally statement. 186 // The environment inside the try block of a try/finally statement.
164 class TryFinally : public NestedStatement { 187 class TryFinally : public NestedStatement {
165 public: 188 public:
166 explicit TryFinally(FastCodeGenerator* codegen, Label* finally_entry) 189 explicit TryFinally(FullCodeGenerator* codegen, Label* finally_entry)
167 : NestedStatement(codegen), finally_entry_(finally_entry) { } 190 : NestedStatement(codegen), finally_entry_(finally_entry) { }
168 virtual ~TryFinally() {} 191 virtual ~TryFinally() {}
169 virtual TryFinally* AsTryFinally() { return this; } 192 virtual TryFinally* AsTryFinally() { return this; }
170 Label* finally_entry() { return finally_entry_; } 193 Label* finally_entry() { return finally_entry_; }
171 virtual int Exit(int stack_depth); 194 virtual int Exit(int stack_depth);
172 private: 195 private:
173 Label* finally_entry_; 196 Label* finally_entry_;
174 DISALLOW_COPY_AND_ASSIGN(TryFinally); 197 DISALLOW_COPY_AND_ASSIGN(TryFinally);
175 }; 198 };
176 199
177 // A FinallyEnvironment represents being inside a finally block. 200 // A FinallyEnvironment represents being inside a finally block.
178 // Abnormal termination of the finally block needs to clean up 201 // Abnormal termination of the finally block needs to clean up
179 // the block's parameters from the stack. 202 // the block's parameters from the stack.
180 class Finally : public NestedStatement { 203 class Finally : public NestedStatement {
181 public: 204 public:
182 explicit Finally(FastCodeGenerator* codegen) : NestedStatement(codegen) { } 205 explicit Finally(FullCodeGenerator* codegen) : NestedStatement(codegen) { }
183 virtual ~Finally() {} 206 virtual ~Finally() {}
184 virtual Finally* AsFinally() { return this; } 207 virtual Finally* AsFinally() { return this; }
185 virtual int Exit(int stack_depth) { 208 virtual int Exit(int stack_depth) {
186 return stack_depth + kFinallyStackElementCount; 209 return stack_depth + kFinallyStackElementCount;
187 } 210 }
188 private: 211 private:
189 // Number of extra stack slots occupied during a finally block. 212 // Number of extra stack slots occupied during a finally block.
190 static const int kFinallyStackElementCount = 2; 213 static const int kFinallyStackElementCount = 2;
191 DISALLOW_COPY_AND_ASSIGN(Finally); 214 DISALLOW_COPY_AND_ASSIGN(Finally);
192 }; 215 };
193 216
194 // A ForInEnvironment represents being inside a for-in loop. 217 // A ForInEnvironment represents being inside a for-in loop.
195 // Abnormal termination of the for-in block needs to clean up 218 // Abnormal termination of the for-in block needs to clean up
196 // the block's temporary storage from the stack. 219 // the block's temporary storage from the stack.
197 class ForIn : public Iteration { 220 class ForIn : public Iteration {
198 public: 221 public:
199 ForIn(FastCodeGenerator* codegen, 222 ForIn(FullCodeGenerator* codegen,
200 ForInStatement* statement) 223 ForInStatement* statement)
201 : Iteration(codegen, statement) { } 224 : Iteration(codegen, statement) { }
202 virtual ~ForIn() {} 225 virtual ~ForIn() {}
203 virtual ForIn* AsForIn() { return this; } 226 virtual ForIn* AsForIn() { return this; }
204 virtual int Exit(int stack_depth) { 227 virtual int Exit(int stack_depth) {
205 return stack_depth + kForInStackElementCount; 228 return stack_depth + kForInStackElementCount;
206 } 229 }
207 private: 230 private:
208 // TODO(lrn): Check that this value is correct when implementing 231 // TODO(lrn): Check that this value is correct when implementing
209 // for-in. 232 // for-in.
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 NestedStatement* nesting_stack_; 426 NestedStatement* nesting_stack_;
404 int loop_depth_; 427 int loop_depth_;
405 428
406 Expression::Context context_; 429 Expression::Context context_;
407 Location location_; 430 Location location_;
408 Label* true_label_; 431 Label* true_label_;
409 Label* false_label_; 432 Label* false_label_;
410 433
411 friend class NestedStatement; 434 friend class NestedStatement;
412 435
413 DISALLOW_COPY_AND_ASSIGN(FastCodeGenerator); 436 DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator);
414 }; 437 };
415 438
416 439
417 } } // namespace v8::internal 440 } } // namespace v8::internal
418 441
419 #endif // V8_FAST_CODEGEN_H_ 442 #endif // V8_FAST_CODEGEN_H_
OLDNEW
« no previous file with comments | « src/compiler.cc ('k') | src/fast-codegen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698