OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/interpreter/bytecode-array-builder.h" | 5 #include "src/interpreter/bytecode-array-builder.h" |
6 | 6 |
7 namespace v8 { | 7 namespace v8 { |
8 namespace internal { | 8 namespace internal { |
9 namespace interpreter { | 9 namespace interpreter { |
10 | 10 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 | 256 |
257 | 257 |
258 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadFalse() { | 258 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadFalse() { |
259 Output(Bytecode::kLdaFalse); | 259 Output(Bytecode::kLdaFalse); |
260 return *this; | 260 return *this; |
261 } | 261 } |
262 | 262 |
263 | 263 |
264 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadAccumulatorWithRegister( | 264 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadAccumulatorWithRegister( |
265 Register reg) { | 265 Register reg) { |
266 // TODO(oth): Avoid loading the accumulator with the register if the | |
267 // previous bytecode stored the accumulator with the same register. | |
rmcilroy
2015/10/28 13:46:22
Same could apply for StoreAccumulatorInRegister co
oth
2015/10/28 22:50:40
Comment added.
| |
266 Output(Bytecode::kLdar, reg.ToOperand()); | 268 Output(Bytecode::kLdar, reg.ToOperand()); |
267 return *this; | 269 return *this; |
268 } | 270 } |
269 | 271 |
270 | 272 |
271 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreAccumulatorInRegister( | 273 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreAccumulatorInRegister( |
272 Register reg) { | 274 Register reg) { |
273 Output(Bytecode::kStar, reg.ToOperand()); | 275 Output(Bytecode::kStar, reg.ToOperand()); |
274 return *this; | 276 return *this; |
275 } | 277 } |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 default: | 476 default: |
475 // Fall through to output kToBoolean. | 477 // Fall through to output kToBoolean. |
476 break; | 478 break; |
477 } | 479 } |
478 } | 480 } |
479 Output(Bytecode::kToBoolean); | 481 Output(Bytecode::kToBoolean); |
480 return *this; | 482 return *this; |
481 } | 483 } |
482 | 484 |
483 | 485 |
486 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToJSObject() { | |
487 Output(Bytecode::kToObject); | |
488 return *this; | |
489 } | |
490 | |
491 | |
484 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToName() { | 492 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToName() { |
485 Output(Bytecode::kToName); | 493 Output(Bytecode::kToName); |
486 return *this; | 494 return *this; |
487 } | 495 } |
488 | 496 |
489 | 497 |
490 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToNumber() { | 498 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToNumber() { |
491 // TODO(rmcilroy): consider omitting if the preceeding bytecode always returns | 499 // TODO(rmcilroy): consider omitting if the preceeding bytecode always returns |
492 // a number. | 500 // a number. |
493 Output(Bytecode::kToNumber); | 501 Output(Bytecode::kToNumber); |
(...skipping 30 matching lines...) Expand all Loading... | |
524 case Bytecode::kJump: | 532 case Bytecode::kJump: |
525 return Bytecode::kJumpConstant; | 533 return Bytecode::kJumpConstant; |
526 case Bytecode::kJumpIfTrue: | 534 case Bytecode::kJumpIfTrue: |
527 return Bytecode::kJumpIfTrueConstant; | 535 return Bytecode::kJumpIfTrueConstant; |
528 case Bytecode::kJumpIfFalse: | 536 case Bytecode::kJumpIfFalse: |
529 return Bytecode::kJumpIfFalseConstant; | 537 return Bytecode::kJumpIfFalseConstant; |
530 case Bytecode::kJumpIfToBooleanTrue: | 538 case Bytecode::kJumpIfToBooleanTrue: |
531 return Bytecode::kJumpIfToBooleanTrueConstant; | 539 return Bytecode::kJumpIfToBooleanTrueConstant; |
532 case Bytecode::kJumpIfToBooleanFalse: | 540 case Bytecode::kJumpIfToBooleanFalse: |
533 return Bytecode::kJumpIfToBooleanFalseConstant; | 541 return Bytecode::kJumpIfToBooleanFalseConstant; |
542 case Bytecode::kJumpIfNull: | |
543 return Bytecode::kJumpIfNullConstant; | |
544 case Bytecode::kJumpIfUndefined: | |
545 return Bytecode::kJumpIfUndefinedConstant; | |
534 default: | 546 default: |
535 UNREACHABLE(); | 547 UNREACHABLE(); |
536 return Bytecode::kJumpConstant; | 548 return Bytecode::kJumpConstant; |
537 } | 549 } |
538 } | 550 } |
539 | 551 |
540 | 552 |
541 void BytecodeArrayBuilder::PatchJump( | 553 void BytecodeArrayBuilder::PatchJump( |
542 const ZoneVector<uint8_t>::iterator& jump_target, | 554 const ZoneVector<uint8_t>::iterator& jump_target, |
543 ZoneVector<uint8_t>::iterator jump_location) { | 555 ZoneVector<uint8_t>::iterator jump_location) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 return OutputJump(Bytecode::kJumpIfToBooleanTrue, label); | 636 return OutputJump(Bytecode::kJumpIfToBooleanTrue, label); |
625 } | 637 } |
626 | 638 |
627 | 639 |
628 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfToBooleanFalse( | 640 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfToBooleanFalse( |
629 BytecodeLabel* label) { | 641 BytecodeLabel* label) { |
630 return OutputJump(Bytecode::kJumpIfToBooleanFalse, label); | 642 return OutputJump(Bytecode::kJumpIfToBooleanFalse, label); |
631 } | 643 } |
632 | 644 |
633 | 645 |
646 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNull(BytecodeLabel* label) { | |
647 return OutputJump(Bytecode::kJumpIfNull, label); | |
648 } | |
649 | |
650 | |
651 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfUndefined( | |
652 BytecodeLabel* label) { | |
653 return OutputJump(Bytecode::kJumpIfUndefined, label); | |
654 } | |
655 | |
656 | |
634 BytecodeArrayBuilder& BytecodeArrayBuilder::Throw() { | 657 BytecodeArrayBuilder& BytecodeArrayBuilder::Throw() { |
635 Output(Bytecode::kThrow); | 658 Output(Bytecode::kThrow); |
636 exit_seen_in_block_ = true; | 659 exit_seen_in_block_ = true; |
637 return *this; | 660 return *this; |
638 } | 661 } |
639 | 662 |
640 | 663 |
641 BytecodeArrayBuilder& BytecodeArrayBuilder::Return() { | 664 BytecodeArrayBuilder& BytecodeArrayBuilder::Return() { |
642 Output(Bytecode::kReturn); | 665 Output(Bytecode::kReturn); |
643 exit_seen_in_block_ = true; | 666 exit_seen_in_block_ = true; |
644 return *this; | 667 return *this; |
645 } | 668 } |
646 | 669 |
647 | 670 |
671 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInPrepare(Register receiver) { | |
672 Output(Bytecode::kForInPrepare, receiver.ToOperand()); | |
673 return *this; | |
674 } | |
675 | |
676 | |
677 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInNext(Register for_in_state) { | |
678 Output(Bytecode::kForInNext, for_in_state.ToOperand()); | |
679 return *this; | |
680 } | |
681 | |
682 | |
683 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInDone(Register for_in_state) { | |
684 Output(Bytecode::kForInDone, for_in_state.ToOperand()); | |
685 return *this; | |
686 } | |
687 | |
688 | |
648 BytecodeArrayBuilder& BytecodeArrayBuilder::EnterBlock() { return *this; } | 689 BytecodeArrayBuilder& BytecodeArrayBuilder::EnterBlock() { return *this; } |
649 | 690 |
650 | 691 |
651 BytecodeArrayBuilder& BytecodeArrayBuilder::LeaveBlock() { | 692 BytecodeArrayBuilder& BytecodeArrayBuilder::LeaveBlock() { |
652 last_block_end_ = bytecodes()->size(); | 693 last_block_end_ = bytecodes()->size(); |
653 exit_seen_in_block_ = false; | 694 exit_seen_in_block_ = false; |
654 return *this; | 695 return *this; |
655 } | 696 } |
656 | 697 |
657 | 698 |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 DCHECK_GT(next_consecutive_count_, 0); | 1148 DCHECK_GT(next_consecutive_count_, 0); |
1108 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); | 1149 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); |
1109 allocated_.push_back(next_consecutive_register_); | 1150 allocated_.push_back(next_consecutive_register_); |
1110 next_consecutive_count_--; | 1151 next_consecutive_count_--; |
1111 return Register(next_consecutive_register_++); | 1152 return Register(next_consecutive_register_++); |
1112 } | 1153 } |
1113 | 1154 |
1114 } // namespace interpreter | 1155 } // namespace interpreter |
1115 } // namespace internal | 1156 } // namespace internal |
1116 } // namespace v8 | 1157 } // namespace v8 |
OLD | NEW |