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. |
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) { |
| 275 // TODO(oth): Avoid storing the accumulator in the register if the |
| 276 // previous bytecode loaded the accumulator with the same register. |
273 Output(Bytecode::kStar, reg.ToOperand()); | 277 Output(Bytecode::kStar, reg.ToOperand()); |
274 return *this; | 278 return *this; |
275 } | 279 } |
276 | 280 |
277 | 281 |
278 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadGlobal( | 282 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadGlobal( |
279 size_t name_index, int feedback_slot, LanguageMode language_mode) { | 283 size_t name_index, int feedback_slot, LanguageMode language_mode) { |
280 Bytecode bytecode = BytecodeForLoadGlobal(language_mode); | 284 Bytecode bytecode = BytecodeForLoadGlobal(language_mode); |
281 if (FitsInIdx8Operand(name_index) && FitsInIdx8Operand(feedback_slot)) { | 285 if (FitsInIdx8Operand(name_index) && FitsInIdx8Operand(feedback_slot)) { |
282 Output(bytecode, static_cast<uint8_t>(name_index), | 286 Output(bytecode, static_cast<uint8_t>(name_index), |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 default: | 478 default: |
475 // Fall through to output kToBoolean. | 479 // Fall through to output kToBoolean. |
476 break; | 480 break; |
477 } | 481 } |
478 } | 482 } |
479 Output(Bytecode::kToBoolean); | 483 Output(Bytecode::kToBoolean); |
480 return *this; | 484 return *this; |
481 } | 485 } |
482 | 486 |
483 | 487 |
| 488 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToJSObject() { |
| 489 Output(Bytecode::kToObject); |
| 490 return *this; |
| 491 } |
| 492 |
| 493 |
484 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToName() { | 494 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToName() { |
485 Output(Bytecode::kToName); | 495 Output(Bytecode::kToName); |
486 return *this; | 496 return *this; |
487 } | 497 } |
488 | 498 |
489 | 499 |
490 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToNumber() { | 500 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToNumber() { |
491 // TODO(rmcilroy): consider omitting if the preceeding bytecode always returns | 501 // TODO(rmcilroy): consider omitting if the preceeding bytecode always returns |
492 // a number. | 502 // a number. |
493 Output(Bytecode::kToNumber); | 503 Output(Bytecode::kToNumber); |
(...skipping 30 matching lines...) Expand all Loading... |
524 case Bytecode::kJump: | 534 case Bytecode::kJump: |
525 return Bytecode::kJumpConstant; | 535 return Bytecode::kJumpConstant; |
526 case Bytecode::kJumpIfTrue: | 536 case Bytecode::kJumpIfTrue: |
527 return Bytecode::kJumpIfTrueConstant; | 537 return Bytecode::kJumpIfTrueConstant; |
528 case Bytecode::kJumpIfFalse: | 538 case Bytecode::kJumpIfFalse: |
529 return Bytecode::kJumpIfFalseConstant; | 539 return Bytecode::kJumpIfFalseConstant; |
530 case Bytecode::kJumpIfToBooleanTrue: | 540 case Bytecode::kJumpIfToBooleanTrue: |
531 return Bytecode::kJumpIfToBooleanTrueConstant; | 541 return Bytecode::kJumpIfToBooleanTrueConstant; |
532 case Bytecode::kJumpIfToBooleanFalse: | 542 case Bytecode::kJumpIfToBooleanFalse: |
533 return Bytecode::kJumpIfToBooleanFalseConstant; | 543 return Bytecode::kJumpIfToBooleanFalseConstant; |
| 544 case Bytecode::kJumpIfNull: |
| 545 return Bytecode::kJumpIfNullConstant; |
| 546 case Bytecode::kJumpIfUndefined: |
| 547 return Bytecode::kJumpIfUndefinedConstant; |
534 default: | 548 default: |
535 UNREACHABLE(); | 549 UNREACHABLE(); |
536 return Bytecode::kJumpConstant; | 550 return Bytecode::kJumpConstant; |
537 } | 551 } |
538 } | 552 } |
539 | 553 |
540 | 554 |
541 void BytecodeArrayBuilder::PatchJump( | 555 void BytecodeArrayBuilder::PatchJump( |
542 const ZoneVector<uint8_t>::iterator& jump_target, | 556 const ZoneVector<uint8_t>::iterator& jump_target, |
543 ZoneVector<uint8_t>::iterator jump_location) { | 557 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); | 638 return OutputJump(Bytecode::kJumpIfToBooleanTrue, label); |
625 } | 639 } |
626 | 640 |
627 | 641 |
628 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfToBooleanFalse( | 642 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfToBooleanFalse( |
629 BytecodeLabel* label) { | 643 BytecodeLabel* label) { |
630 return OutputJump(Bytecode::kJumpIfToBooleanFalse, label); | 644 return OutputJump(Bytecode::kJumpIfToBooleanFalse, label); |
631 } | 645 } |
632 | 646 |
633 | 647 |
| 648 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNull(BytecodeLabel* label) { |
| 649 return OutputJump(Bytecode::kJumpIfNull, label); |
| 650 } |
| 651 |
| 652 |
| 653 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfUndefined( |
| 654 BytecodeLabel* label) { |
| 655 return OutputJump(Bytecode::kJumpIfUndefined, label); |
| 656 } |
| 657 |
| 658 |
634 BytecodeArrayBuilder& BytecodeArrayBuilder::Throw() { | 659 BytecodeArrayBuilder& BytecodeArrayBuilder::Throw() { |
635 Output(Bytecode::kThrow); | 660 Output(Bytecode::kThrow); |
636 exit_seen_in_block_ = true; | 661 exit_seen_in_block_ = true; |
637 return *this; | 662 return *this; |
638 } | 663 } |
639 | 664 |
640 | 665 |
641 BytecodeArrayBuilder& BytecodeArrayBuilder::Return() { | 666 BytecodeArrayBuilder& BytecodeArrayBuilder::Return() { |
642 Output(Bytecode::kReturn); | 667 Output(Bytecode::kReturn); |
643 exit_seen_in_block_ = true; | 668 exit_seen_in_block_ = true; |
644 return *this; | 669 return *this; |
645 } | 670 } |
646 | 671 |
647 | 672 |
| 673 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInPrepare(Register receiver) { |
| 674 Output(Bytecode::kForInPrepare, receiver.ToOperand()); |
| 675 return *this; |
| 676 } |
| 677 |
| 678 |
| 679 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInNext(Register for_in_state, |
| 680 Register index) { |
| 681 Output(Bytecode::kForInNext, for_in_state.ToOperand(), index.ToOperand()); |
| 682 return *this; |
| 683 } |
| 684 |
| 685 |
| 686 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInDone(Register for_in_state) { |
| 687 Output(Bytecode::kForInDone, for_in_state.ToOperand()); |
| 688 return *this; |
| 689 } |
| 690 |
| 691 |
648 BytecodeArrayBuilder& BytecodeArrayBuilder::EnterBlock() { return *this; } | 692 BytecodeArrayBuilder& BytecodeArrayBuilder::EnterBlock() { return *this; } |
649 | 693 |
650 | 694 |
651 BytecodeArrayBuilder& BytecodeArrayBuilder::LeaveBlock() { | 695 BytecodeArrayBuilder& BytecodeArrayBuilder::LeaveBlock() { |
652 last_block_end_ = bytecodes()->size(); | 696 last_block_end_ = bytecodes()->size(); |
653 exit_seen_in_block_ = false; | 697 exit_seen_in_block_ = false; |
654 return *this; | 698 return *this; |
655 } | 699 } |
656 | 700 |
657 | 701 |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 DCHECK_GT(next_consecutive_count_, 0); | 1151 DCHECK_GT(next_consecutive_count_, 0); |
1108 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); | 1152 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); |
1109 allocated_.push_back(next_consecutive_register_); | 1153 allocated_.push_back(next_consecutive_register_); |
1110 next_consecutive_count_--; | 1154 next_consecutive_count_--; |
1111 return Register(next_consecutive_register_++); | 1155 return Register(next_consecutive_register_++); |
1112 } | 1156 } |
1113 | 1157 |
1114 } // namespace interpreter | 1158 } // namespace interpreter |
1115 } // namespace internal | 1159 } // namespace internal |
1116 } // namespace v8 | 1160 } // namespace v8 |
OLD | NEW |