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 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/ast.h" | 7 #include "src/ast.h" |
8 #include "src/ast-numbering.h" | 8 #include "src/ast-numbering.h" |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 267 |
268 bool FullCodeGenerator::ShouldInlineSmiCase(Token::Value op) { | 268 bool FullCodeGenerator::ShouldInlineSmiCase(Token::Value op) { |
269 // Inline smi case inside loops, but not division and modulo which | 269 // Inline smi case inside loops, but not division and modulo which |
270 // are too complicated and take up too much space. | 270 // are too complicated and take up too much space. |
271 if (op == Token::DIV ||op == Token::MOD) return false; | 271 if (op == Token::DIV ||op == Token::MOD) return false; |
272 if (FLAG_always_inline_smi_code) return true; | 272 if (FLAG_always_inline_smi_code) return true; |
273 return loop_depth_ > 0; | 273 return loop_depth_ > 0; |
274 } | 274 } |
275 | 275 |
276 | 276 |
277 void FullCodeGenerator::EffectContext::Plug(Variable* var) const { | |
278 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | |
279 } | |
280 | |
281 | |
282 void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const { | |
283 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | |
284 codegen()->GetVar(result_register(), var); | |
285 } | |
286 | |
287 | |
288 void FullCodeGenerator::TestContext::Plug(Variable* var) const { | |
289 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | |
290 // For simplicity we always test the accumulator register. | |
291 codegen()->GetVar(result_register(), var); | |
292 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); | |
293 codegen()->DoTest(this); | |
294 } | |
295 | |
296 | |
297 void FullCodeGenerator::EffectContext::Plug(Register reg) const { | 277 void FullCodeGenerator::EffectContext::Plug(Register reg) const { |
298 } | 278 } |
299 | 279 |
300 | 280 |
301 void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const { | 281 void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const { |
302 __ Move(result_register(), reg); | 282 __ Move(result_register(), reg); |
303 } | 283 } |
304 | 284 |
305 | 285 |
306 void FullCodeGenerator::StackValueContext::Plug(Register reg) const { | 286 void FullCodeGenerator::StackValueContext::Plug(Register reg) const { |
307 __ Push(reg); | 287 __ Push(reg); |
308 } | 288 } |
309 | 289 |
310 | 290 |
311 void FullCodeGenerator::TestContext::Plug(Register reg) const { | 291 void FullCodeGenerator::TestContext::Plug(Register reg) const { |
312 // For simplicity we always test the accumulator register. | 292 // For simplicity we always test the accumulator register. |
313 __ Move(result_register(), reg); | 293 __ Move(result_register(), reg); |
314 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); | 294 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
315 codegen()->DoTest(this); | 295 codegen()->DoTest(this); |
316 } | 296 } |
317 | 297 |
318 | 298 |
319 void FullCodeGenerator::EffectContext::Plug(bool flag) const {} | |
320 | |
321 | |
322 void FullCodeGenerator::EffectContext::PlugTOS() const { | 299 void FullCodeGenerator::EffectContext::PlugTOS() const { |
323 __ Drop(1); | 300 __ Drop(1); |
324 } | 301 } |
325 | 302 |
326 | 303 |
327 void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const { | 304 void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const { |
328 __ Pop(result_register()); | 305 __ Pop(result_register()); |
329 } | 306 } |
330 | 307 |
331 | 308 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 isolate()->factory()->NewFixedArray(globals_->length(), TENURED); | 387 isolate()->factory()->NewFixedArray(globals_->length(), TENURED); |
411 for (int i = 0; i < globals_->length(); ++i) | 388 for (int i = 0; i < globals_->length(); ++i) |
412 array->set(i, *globals_->at(i)); | 389 array->set(i, *globals_->at(i)); |
413 DeclareGlobals(array); | 390 DeclareGlobals(array); |
414 } | 391 } |
415 | 392 |
416 globals_ = saved_globals; | 393 globals_ = saved_globals; |
417 } | 394 } |
418 | 395 |
419 | 396 |
420 void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { | |
421 VariableProxy* proxy = declaration->proxy(); | |
422 Variable* variable = proxy->var(); | |
423 switch (variable->location()) { | |
424 case VariableLocation::GLOBAL: | |
425 case VariableLocation::UNALLOCATED: | |
426 // TODO(rossberg) | |
427 break; | |
428 | |
429 case VariableLocation::CONTEXT: { | |
430 Comment cmnt(masm_, "[ ImportDeclaration"); | |
431 EmitDebugCheckDeclarationContext(variable); | |
432 // TODO(rossberg) | |
433 break; | |
434 } | |
435 | |
436 case VariableLocation::PARAMETER: | |
437 case VariableLocation::LOCAL: | |
438 case VariableLocation::LOOKUP: | |
439 UNREACHABLE(); | |
440 } | |
441 } | |
442 | |
443 | |
444 void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) { | |
445 // TODO(rossberg) | |
446 } | |
447 | |
448 | |
449 void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { | |
450 Comment cmnt(masm_, "[ VariableProxy"); | |
451 EmitVariableLoad(expr); | |
452 } | |
453 | |
454 | |
455 int FullCodeGenerator::DeclareGlobalsFlags() { | 397 int FullCodeGenerator::DeclareGlobalsFlags() { |
456 DCHECK(DeclareGlobalsLanguageMode::is_valid(language_mode())); | 398 DCHECK(DeclareGlobalsLanguageMode::is_valid(language_mode())); |
457 return DeclareGlobalsEvalFlag::encode(is_eval()) | | 399 return DeclareGlobalsEvalFlag::encode(is_eval()) | |
458 DeclareGlobalsNativeFlag::encode(is_native()) | | 400 DeclareGlobalsNativeFlag::encode(is_native()) | |
459 DeclareGlobalsLanguageMode::encode(language_mode()); | 401 DeclareGlobalsLanguageMode::encode(language_mode()); |
460 } | 402 } |
461 | 403 |
462 | 404 |
463 void FullCodeGenerator::EmitSubString(CallRuntime* expr) { | |
464 // Load the arguments on the stack and call the stub. | |
465 SubStringStub stub(isolate()); | |
466 ZoneList<Expression*>* args = expr->arguments(); | |
467 DCHECK(args->length() == 3); | |
468 VisitForStackValue(args->at(0)); | |
469 VisitForStackValue(args->at(1)); | |
470 VisitForStackValue(args->at(2)); | |
471 __ CallStub(&stub); | |
472 context()->Plug(result_register()); | |
473 } | |
474 | |
475 | |
476 void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) { | |
477 // Load the arguments on the stack and call the stub. | |
478 RegExpExecStub stub(isolate()); | |
479 ZoneList<Expression*>* args = expr->arguments(); | |
480 DCHECK(args->length() == 4); | |
481 VisitForStackValue(args->at(0)); | |
482 VisitForStackValue(args->at(1)); | |
483 VisitForStackValue(args->at(2)); | |
484 VisitForStackValue(args->at(3)); | |
485 __ CallStub(&stub); | |
486 context()->Plug(result_register()); | |
487 } | |
488 | |
489 | |
490 void FullCodeGenerator::EmitMathPow(CallRuntime* expr) { | |
491 // Load the arguments on the stack and call the runtime function. | |
492 ZoneList<Expression*>* args = expr->arguments(); | |
493 DCHECK(args->length() == 2); | |
494 VisitForStackValue(args->at(0)); | |
495 VisitForStackValue(args->at(1)); | |
496 | |
497 MathPowStub stub(isolate(), MathPowStub::ON_STACK); | |
498 __ CallStub(&stub); | |
499 context()->Plug(result_register()); | |
500 } | |
501 | |
502 | |
503 void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) { | |
504 ZoneList<Expression*>* args = expr->arguments(); | |
505 DCHECK_EQ(args->length(), 1); | |
506 | |
507 // Load the argument into eax and call the stub. | |
508 VisitForAccumulatorValue(args->at(0)); | |
509 | |
510 NumberToStringStub stub(isolate()); | |
511 __ CallStub(&stub); | |
512 context()->Plug(result_register()); | |
513 } | |
514 | |
515 | |
516 void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) { | |
517 ZoneList<Expression*>* args = expr->arguments(); | |
518 DCHECK_EQ(2, args->length()); | |
519 | |
520 VisitForStackValue(args->at(0)); | |
521 VisitForStackValue(args->at(1)); | |
522 | |
523 StringCompareStub stub(isolate()); | |
524 __ CallStub(&stub); | |
525 context()->Plug(result_register()); | |
526 } | |
527 | |
528 | |
529 bool RecordStatementPosition(MacroAssembler* masm, int pos) { | 405 bool RecordStatementPosition(MacroAssembler* masm, int pos) { |
530 if (pos == RelocInfo::kNoPosition) return false; | 406 if (pos == RelocInfo::kNoPosition) return false; |
531 masm->positions_recorder()->RecordStatementPosition(pos); | 407 masm->positions_recorder()->RecordStatementPosition(pos); |
532 masm->positions_recorder()->RecordPosition(pos); | 408 masm->positions_recorder()->RecordPosition(pos); |
533 return masm->positions_recorder()->WriteRecordedPositions(); | 409 return masm->positions_recorder()->WriteRecordedPositions(); |
534 } | 410 } |
535 | 411 |
536 | 412 |
537 bool RecordPosition(MacroAssembler* masm, int pos) { | 413 bool RecordPosition(MacroAssembler* masm, int pos) { |
538 if (pos == RelocInfo::kNoPosition) return false; | 414 if (pos == RelocInfo::kNoPosition) return false; |
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 codegen_->PrepareForBailoutForId(exit_id_, NO_REGISTERS); | 1475 codegen_->PrepareForBailoutForId(exit_id_, NO_REGISTERS); |
1600 codegen_->scope_ = saved_scope_; | 1476 codegen_->scope_ = saved_scope_; |
1601 } | 1477 } |
1602 | 1478 |
1603 | 1479 |
1604 #undef __ | 1480 #undef __ |
1605 | 1481 |
1606 | 1482 |
1607 } // namespace internal | 1483 } // namespace internal |
1608 } // namespace v8 | 1484 } // namespace v8 |
OLD | NEW |