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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 return *this; | 443 return *this; |
444 } | 444 } |
445 | 445 |
446 | 446 |
447 BytecodeArrayBuilder& BytecodeArrayBuilder::PopContext(Register context) { | 447 BytecodeArrayBuilder& BytecodeArrayBuilder::PopContext(Register context) { |
448 Output(Bytecode::kPopContext, context.ToOperand()); | 448 Output(Bytecode::kPopContext, context.ToOperand()); |
449 return *this; | 449 return *this; |
450 } | 450 } |
451 | 451 |
452 | 452 |
453 bool BytecodeArrayBuilder::IsAccumulatorBoolean() { | |
454 if (!LastBytecodeInSameBlock()) { | |
455 // If the previous bytecode was from a different block return false. | |
456 return false; | |
457 } | |
458 | |
459 // If the previous bytecode puts a boolean in | |
460 // the accumulator return true. | |
rmcilroy
2015/10/30 10:36:00
nit - put comment on one line (or as much of it as
mythria
2015/10/30 11:44:47
Done.
| |
461 switch (Bytecodes::FromByte(bytecodes()->at(last_bytecode_start_))) { | |
462 case Bytecode::kToBoolean: | |
463 UNREACHABLE(); | |
464 case Bytecode::kLdaTrue: | |
465 case Bytecode::kLdaFalse: | |
466 case Bytecode::kLogicalNot: | |
467 case Bytecode::kTestEqual: | |
468 case Bytecode::kTestNotEqual: | |
469 case Bytecode::kTestEqualStrict: | |
470 case Bytecode::kTestNotEqualStrict: | |
471 case Bytecode::kTestLessThan: | |
472 case Bytecode::kTestLessThanOrEqual: | |
473 case Bytecode::kTestGreaterThan: | |
474 case Bytecode::kTestGreaterThanOrEqual: | |
475 case Bytecode::kTestInstanceOf: | |
476 case Bytecode::kTestIn: | |
477 return true; | |
478 default: | |
479 return false; | |
480 } | |
481 } | |
482 | |
483 | |
453 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToBoolean() { | 484 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToBoolean() { |
454 if (LastBytecodeInSameBlock()) { | 485 // If the previous bytecode puts a boolean in the accumulator |
455 // If the previous bytecode puts a boolean in the accumulator | 486 // there is no need to emit an instruction. |
456 // there is no need to emit an instruction. | 487 if (!IsAccumulatorBoolean()) { |
457 switch (Bytecodes::FromByte(bytecodes()->at(last_bytecode_start_))) { | 488 Output(Bytecode::kToBoolean); |
458 case Bytecode::kToBoolean: | |
459 UNREACHABLE(); | |
460 case Bytecode::kLdaTrue: | |
461 case Bytecode::kLdaFalse: | |
462 case Bytecode::kLogicalNot: | |
463 case Bytecode::kTestEqual: | |
464 case Bytecode::kTestNotEqual: | |
465 case Bytecode::kTestEqualStrict: | |
466 case Bytecode::kTestNotEqualStrict: | |
467 case Bytecode::kTestLessThan: | |
468 case Bytecode::kTestLessThanOrEqual: | |
469 case Bytecode::kTestGreaterThan: | |
470 case Bytecode::kTestGreaterThanOrEqual: | |
471 case Bytecode::kTestInstanceOf: | |
472 case Bytecode::kTestIn: | |
473 return *this; | |
474 default: | |
475 // Fall through to output kToBoolean. | |
476 break; | |
477 } | |
478 } | 489 } |
479 Output(Bytecode::kToBoolean); | |
480 return *this; | 490 return *this; |
481 } | 491 } |
482 | 492 |
483 | 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 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 // to match the size of the code it's replacing. In future, | 576 // to match the size of the code it's replacing. In future, |
567 // there will probably be a jump with 32-bit operand for cases | 577 // there will probably be a jump with 32-bit operand for cases |
568 // when constant pool is full, but that needs to be emitted in | 578 // when constant pool is full, but that needs to be emitted in |
569 // OutputJump too. | 579 // OutputJump too. |
570 UNIMPLEMENTED(); | 580 UNIMPLEMENTED(); |
571 } | 581 } |
572 } | 582 } |
573 } | 583 } |
574 | 584 |
575 | 585 |
586 // static | |
587 Bytecode BytecodeArrayBuilder::GetJumpWithToBoolean(Bytecode jump_bytecode) { | |
588 switch (jump_bytecode) { | |
589 case Bytecode::kJump: | |
590 return Bytecode::kJump; | |
591 case Bytecode::kJumpIfTrue: | |
592 return Bytecode::kJumpIfToBooleanTrue; | |
593 case Bytecode::kJumpIfFalse: | |
594 return Bytecode::kJumpIfToBooleanFalse; | |
595 default: | |
596 UNREACHABLE(); | |
597 } | |
rmcilroy
2015/10/30 10:36:00
You probably need to return return static_cast<Byt
mythria
2015/10/30 11:44:47
Done.
| |
598 } | |
599 | |
600 | |
576 BytecodeArrayBuilder& BytecodeArrayBuilder::OutputJump(Bytecode jump_bytecode, | 601 BytecodeArrayBuilder& BytecodeArrayBuilder::OutputJump(Bytecode jump_bytecode, |
577 BytecodeLabel* label) { | 602 BytecodeLabel* label) { |
603 // Check if the value in accumulator is boolean, if not choose an | |
604 // appropriate JumpIfToBoolean bytecode. | |
605 if (!IsAccumulatorBoolean()) { | |
606 jump_bytecode = GetJumpWithToBoolean(jump_bytecode); | |
607 } | |
608 | |
578 int delta; | 609 int delta; |
579 if (label->is_bound()) { | 610 if (label->is_bound()) { |
580 // Label has been bound already so this is a backwards jump. | 611 // Label has been bound already so this is a backwards jump. |
581 CHECK_GE(bytecodes()->size(), label->offset()); | 612 CHECK_GE(bytecodes()->size(), label->offset()); |
582 CHECK_LE(bytecodes()->size(), static_cast<size_t>(kMaxInt)); | 613 CHECK_LE(bytecodes()->size(), static_cast<size_t>(kMaxInt)); |
583 size_t abs_delta = bytecodes()->size() - label->offset(); | 614 size_t abs_delta = bytecodes()->size() - label->offset(); |
584 delta = -static_cast<int>(abs_delta); | 615 delta = -static_cast<int>(abs_delta); |
585 } else { | 616 } else { |
586 // Label has not yet been bound so this is a forward reference | 617 // Label has not yet been bound so this is a forward reference |
587 // that will be patched when the label is bound. | 618 // that will be patched when the label is bound. |
(...skipping 24 matching lines...) Expand all Loading... | |
612 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfTrue(BytecodeLabel* label) { | 643 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfTrue(BytecodeLabel* label) { |
613 return OutputJump(Bytecode::kJumpIfTrue, label); | 644 return OutputJump(Bytecode::kJumpIfTrue, label); |
614 } | 645 } |
615 | 646 |
616 | 647 |
617 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfFalse(BytecodeLabel* label) { | 648 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfFalse(BytecodeLabel* label) { |
618 return OutputJump(Bytecode::kJumpIfFalse, label); | 649 return OutputJump(Bytecode::kJumpIfFalse, label); |
619 } | 650 } |
620 | 651 |
621 | 652 |
622 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfToBooleanTrue( | |
623 BytecodeLabel* label) { | |
624 return OutputJump(Bytecode::kJumpIfToBooleanTrue, label); | |
625 } | |
626 | |
627 | |
628 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfToBooleanFalse( | |
629 BytecodeLabel* label) { | |
630 return OutputJump(Bytecode::kJumpIfToBooleanFalse, label); | |
631 } | |
632 | |
633 | |
634 BytecodeArrayBuilder& BytecodeArrayBuilder::Throw() { | 653 BytecodeArrayBuilder& BytecodeArrayBuilder::Throw() { |
635 Output(Bytecode::kThrow); | 654 Output(Bytecode::kThrow); |
636 exit_seen_in_block_ = true; | 655 exit_seen_in_block_ = true; |
637 return *this; | 656 return *this; |
638 } | 657 } |
639 | 658 |
640 | 659 |
641 BytecodeArrayBuilder& BytecodeArrayBuilder::Return() { | 660 BytecodeArrayBuilder& BytecodeArrayBuilder::Return() { |
642 Output(Bytecode::kReturn); | 661 Output(Bytecode::kReturn); |
643 exit_seen_in_block_ = true; | 662 exit_seen_in_block_ = true; |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 DCHECK_GT(next_consecutive_count_, 0); | 1126 DCHECK_GT(next_consecutive_count_, 0); |
1108 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); | 1127 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); |
1109 allocated_.push_back(next_consecutive_register_); | 1128 allocated_.push_back(next_consecutive_register_); |
1110 next_consecutive_count_--; | 1129 next_consecutive_count_--; |
1111 return Register(next_consecutive_register_++); | 1130 return Register(next_consecutive_register_++); |
1112 } | 1131 } |
1113 | 1132 |
1114 } // namespace interpreter | 1133 } // namespace interpreter |
1115 } // namespace internal | 1134 } // namespace internal |
1116 } // namespace v8 | 1135 } // namespace v8 |
OLD | NEW |