Chromium Code Reviews| Index: src/interpreter/bytecode-array-builder.cc |
| diff --git a/src/interpreter/bytecode-array-builder.cc b/src/interpreter/bytecode-array-builder.cc |
| index 2ce9d51377571c58f027bc3e3f07ff983e4e0eee..03330ea2c7b5885abdd7094531d518feb15a2588 100644 |
| --- a/src/interpreter/bytecode-array-builder.cc |
| +++ b/src/interpreter/bytecode-array-builder.cc |
| @@ -450,33 +450,43 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::PopContext(Register context) { |
| } |
| +bool BytecodeArrayBuilder::IsAccumulatorBoolean() { |
| + if (!LastBytecodeInSameBlock()) { |
| + // If the previous bytecode was from a different block return false. |
| + return false; |
| + } |
| + |
| + // If the previous bytecode puts a boolean in |
| + // 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.
|
| + switch (Bytecodes::FromByte(bytecodes()->at(last_bytecode_start_))) { |
| + case Bytecode::kToBoolean: |
| + UNREACHABLE(); |
| + case Bytecode::kLdaTrue: |
| + case Bytecode::kLdaFalse: |
| + case Bytecode::kLogicalNot: |
| + case Bytecode::kTestEqual: |
| + case Bytecode::kTestNotEqual: |
| + case Bytecode::kTestEqualStrict: |
| + case Bytecode::kTestNotEqualStrict: |
| + case Bytecode::kTestLessThan: |
| + case Bytecode::kTestLessThanOrEqual: |
| + case Bytecode::kTestGreaterThan: |
| + case Bytecode::kTestGreaterThanOrEqual: |
| + case Bytecode::kTestInstanceOf: |
| + case Bytecode::kTestIn: |
| + return true; |
| + default: |
| + return false; |
| + } |
| +} |
| + |
| + |
| BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToBoolean() { |
| - if (LastBytecodeInSameBlock()) { |
| - // If the previous bytecode puts a boolean in the accumulator |
| - // there is no need to emit an instruction. |
| - switch (Bytecodes::FromByte(bytecodes()->at(last_bytecode_start_))) { |
| - case Bytecode::kToBoolean: |
| - UNREACHABLE(); |
| - case Bytecode::kLdaTrue: |
| - case Bytecode::kLdaFalse: |
| - case Bytecode::kLogicalNot: |
| - case Bytecode::kTestEqual: |
| - case Bytecode::kTestNotEqual: |
| - case Bytecode::kTestEqualStrict: |
| - case Bytecode::kTestNotEqualStrict: |
| - case Bytecode::kTestLessThan: |
| - case Bytecode::kTestLessThanOrEqual: |
| - case Bytecode::kTestGreaterThan: |
| - case Bytecode::kTestGreaterThanOrEqual: |
| - case Bytecode::kTestInstanceOf: |
| - case Bytecode::kTestIn: |
| - return *this; |
| - default: |
| - // Fall through to output kToBoolean. |
| - break; |
| - } |
| + // If the previous bytecode puts a boolean in the accumulator |
| + // there is no need to emit an instruction. |
| + if (!IsAccumulatorBoolean()) { |
| + Output(Bytecode::kToBoolean); |
| } |
| - Output(Bytecode::kToBoolean); |
| return *this; |
| } |
| @@ -573,8 +583,29 @@ void BytecodeArrayBuilder::PatchJump( |
| } |
| +// static |
| +Bytecode BytecodeArrayBuilder::GetJumpWithToBoolean(Bytecode jump_bytecode) { |
| + switch (jump_bytecode) { |
| + case Bytecode::kJump: |
| + return Bytecode::kJump; |
| + case Bytecode::kJumpIfTrue: |
| + return Bytecode::kJumpIfToBooleanTrue; |
| + case Bytecode::kJumpIfFalse: |
| + return Bytecode::kJumpIfToBooleanFalse; |
| + default: |
| + UNREACHABLE(); |
| + } |
|
rmcilroy
2015/10/30 10:36:00
You probably need to return return static_cast<Byt
mythria
2015/10/30 11:44:47
Done.
|
| +} |
| + |
| + |
| BytecodeArrayBuilder& BytecodeArrayBuilder::OutputJump(Bytecode jump_bytecode, |
| BytecodeLabel* label) { |
| + // Check if the value in accumulator is boolean, if not choose an |
| + // appropriate JumpIfToBoolean bytecode. |
| + if (!IsAccumulatorBoolean()) { |
| + jump_bytecode = GetJumpWithToBoolean(jump_bytecode); |
| + } |
| + |
| int delta; |
| if (label->is_bound()) { |
| // Label has been bound already so this is a backwards jump. |
| @@ -619,18 +650,6 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfFalse(BytecodeLabel* label) { |
| } |
| -BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfToBooleanTrue( |
| - BytecodeLabel* label) { |
| - return OutputJump(Bytecode::kJumpIfToBooleanTrue, label); |
| -} |
| - |
| - |
| -BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfToBooleanFalse( |
| - BytecodeLabel* label) { |
| - return OutputJump(Bytecode::kJumpIfToBooleanFalse, label); |
| -} |
| - |
| - |
| BytecodeArrayBuilder& BytecodeArrayBuilder::Throw() { |
| Output(Bytecode::kThrow); |
| exit_seen_in_block_ = true; |