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

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

Issue 339082: Initial implementation of top-level compilation of expressions in test... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 1 month 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
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 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "codegen-inl.h" 30 #include "codegen-inl.h"
31 #include "fast-codegen.h" 31 #include "fast-codegen.h"
32 #include "stub-cache.h" 32 #include "stub-cache.h"
33 #include "debug.h" 33 #include "debug.h"
34 34
35 namespace v8 { 35 namespace v8 {
36 namespace internal { 36 namespace internal {
37 37
38 #define __ ACCESS_MASM(masm_)
39
38 Handle<Code> FastCodeGenerator::MakeCode(FunctionLiteral* fun, 40 Handle<Code> FastCodeGenerator::MakeCode(FunctionLiteral* fun,
39 Handle<Script> script, 41 Handle<Script> script,
40 bool is_eval) { 42 bool is_eval) {
41 CodeGenerator::MakeCodePrologue(fun); 43 CodeGenerator::MakeCodePrologue(fun);
42 const int kInitialBufferSize = 4 * KB; 44 const int kInitialBufferSize = 4 * KB;
43 MacroAssembler masm(NULL, kInitialBufferSize); 45 MacroAssembler masm(NULL, kInitialBufferSize);
44 FastCodeGenerator cgen(&masm, script, is_eval); 46 FastCodeGenerator cgen(&masm, script, is_eval);
45 cgen.Generate(fun); 47 cgen.Generate(fun);
46 if (cgen.HasStackOverflow()) { 48 if (cgen.HasStackOverflow()) {
47 ASSERT(!Top::has_pending_exception()); 49 ASSERT(!Top::has_pending_exception());
(...skipping 16 matching lines...) Expand all
64 case Slot::LOCAL: 66 case Slot::LOCAL:
65 offset += JavaScriptFrameConstants::kLocal0Offset; 67 offset += JavaScriptFrameConstants::kLocal0Offset;
66 break; 68 break;
67 default: 69 default:
68 UNREACHABLE(); 70 UNREACHABLE();
69 } 71 }
70 return offset; 72 return offset;
71 } 73 }
72 74
73 75
74 // All platform macro assemblers in {ia32,x64,arm} have a push(Register)
75 // function.
76 void FastCodeGenerator::Move(Expression::Context context, Register source) {
77 switch (context) {
78 case Expression::kUninitialized:
79 UNREACHABLE();
80 case Expression::kEffect:
81 break;
82 case Expression::kValue:
83 masm_->push(source);
84 break;
85 }
86 }
87
88
89 void FastCodeGenerator::VisitDeclarations( 76 void FastCodeGenerator::VisitDeclarations(
90 ZoneList<Declaration*>* declarations) { 77 ZoneList<Declaration*>* declarations) {
91 int length = declarations->length(); 78 int length = declarations->length();
92 int globals = 0; 79 int globals = 0;
93 for (int i = 0; i < length; i++) { 80 for (int i = 0; i < length; i++) {
94 Declaration* node = declarations->at(i); 81 Declaration* node = declarations->at(i);
95 Variable* var = node->proxy()->var(); 82 Variable* var = node->proxy()->var();
96 Slot* slot = var->slot(); 83 Slot* slot = var->slot();
97 84
98 // If it was not possible to allocate the variable at compile 85 // If it was not possible to allocate the variable at compile
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 182 }
196 183
197 184
198 void FastCodeGenerator::SetSourcePosition(int pos) { 185 void FastCodeGenerator::SetSourcePosition(int pos) {
199 if (FLAG_debug_info && pos != RelocInfo::kNoPosition) { 186 if (FLAG_debug_info && pos != RelocInfo::kNoPosition) {
200 masm_->RecordPosition(pos); 187 masm_->RecordPosition(pos);
201 } 188 }
202 } 189 }
203 190
204 191
192 void FastCodeGenerator::EmitLogicalOperation(BinaryOperation* expr) {
193 #ifdef DEBUG
194 Expression::Context expected = Expression::kUninitialized;
195 switch (expr->context()) {
196 case Expression::kUninitialized:
197 UNREACHABLE();
198 case Expression::kEffect: // Fall through.
199 case Expression::kTest:
200 // The value of the left subexpression is not needed.
201 expected = Expression::kTest;
202 break;
203 case Expression::kValue:
204 // The value of the left subexpression is needed and its specific
205 // context depends on the operator.
206 expected = (expr->op() == Token::OR)
207 ? Expression::kValueTest
208 : Expression::kTestValue;
209 break;
210 case Expression::kValueTest:
211 // The value of the left subexpression is needed for OR.
212 expected = (expr->op() == Token::OR)
213 ? Expression::kValueTest
214 : Expression::kTest;
215 break;
216 case Expression::kTestValue:
217 // The value of the left subexpression is needed for AND.
218 expected = (expr->op() == Token::OR)
219 ? Expression::kTest
220 : Expression::kTestValue;
221 break;
222 }
223 ASSERT_EQ(expected, expr->left()->context());
224 ASSERT_EQ(expr->context(), expr->right()->context());
225 #endif
226
227 Label eval_right, done;
228 Label* saved_true = true_label_;
229 Label* saved_false = false_label_;
230
231 // Set up the appropriate context for the left subexpression based on the
232 // operation and our own context.
233 if (expr->op() == Token::OR) {
234 // If there is no usable true label in the OR expression's context, use
235 // the end of this expression, otherwise inherit the same true label.
236 if (expr->context() == Expression::kEffect ||
237 expr->context() == Expression::kValue) {
238 true_label_ = &done;
239 }
240 // The false label is the label of the second subexpression.
241 false_label_ = &eval_right;
242 } else {
243 ASSERT_EQ(Token::AND, expr->op());
244 // The true label is the label of the second subexpression.
245 true_label_ = &eval_right;
246 // If there is no usable false label in the AND expression's context,
247 // use the end of the expression, otherwise inherit the same true label.
William Hesse 2009/10/30 12:09:39 Typo: inherit the same false label
Kevin Millikin (Chromium) 2009/10/30 13:45:53 Thanks.
248 if (expr->context() == Expression::kEffect ||
249 expr->context() == Expression::kValue) {
250 false_label_ = &done;
251 }
252 }
253
254 Visit(expr->left());
255 true_label_ = saved_true;
256 false_label_ = saved_false;
257
258 __ bind(&eval_right);
259 Visit(expr->right());
260
261 __ bind(&done);
262 }
263
264
205 void FastCodeGenerator::VisitDeclaration(Declaration* decl) { 265 void FastCodeGenerator::VisitDeclaration(Declaration* decl) {
206 UNREACHABLE(); 266 UNREACHABLE();
207 } 267 }
208 268
209 269
210 void FastCodeGenerator::VisitBlock(Block* stmt) { 270 void FastCodeGenerator::VisitBlock(Block* stmt) {
211 Comment cmnt(masm_, "[ Block"); 271 Comment cmnt(masm_, "[ Block");
212 SetStatementPosition(stmt); 272 SetStatementPosition(stmt);
213 VisitStatements(stmt->statements()); 273 VisitStatements(stmt->statements());
214 } 274 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 void FastCodeGenerator::VisitCompareOperation(CompareOperation* expr) { 397 void FastCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
338 UNREACHABLE(); 398 UNREACHABLE();
339 } 399 }
340 400
341 401
342 void FastCodeGenerator::VisitThisFunction(ThisFunction* expr) { 402 void FastCodeGenerator::VisitThisFunction(ThisFunction* expr) {
343 UNREACHABLE(); 403 UNREACHABLE();
344 } 404 }
345 405
346 406
407 #undef __
408
409
347 } } // namespace v8::internal 410 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698