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 e0bc03c9f997a26691c728df7a374ae12ba4969d..b4615a557f61335e9ffd8119c584b3bc9bbcf978 100644 |
| --- a/src/interpreter/bytecode-array-builder.cc |
| +++ b/src/interpreter/bytecode-array-builder.cc |
| @@ -75,40 +75,54 @@ Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { |
| template <size_t N> |
| -void BytecodeArrayBuilder::Output(uint8_t(&bytes)[N]) { |
| - DCHECK_EQ(Bytecodes::NumberOfOperands(Bytecodes::FromByte(bytes[0])), |
| - static_cast<int>(N) - 1); |
| +void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t(&operands)[N]) { |
| + DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), N); |
| last_bytecode_start_ = bytecodes()->size(); |
| - for (int i = 1; i < static_cast<int>(N); i++) { |
| - DCHECK(OperandIsValid(Bytecodes::FromByte(bytes[0]), i - 1, bytes[i])); |
| + bytecodes()->push_back(Bytecodes::ToByte(bytecode)); |
| + for (int i = 0; i < static_cast<int>(N); i++) { |
| + DCHECK(OperandIsValid(bytecode, i, operands[i])); |
| + switch (Bytecodes::SizeOfOperand(Bytecodes::GetOperandType(bytecode, i))) { |
| + case OperandSize::kNone: |
| + UNREACHABLE(); |
| + case OperandSize::kByte: |
| + bytecodes()->push_back(static_cast<uint8_t>(operands[i])); |
| + break; |
| + case OperandSize::kWide: { |
| + uint8_t operand_bytes[2]; |
| + Bytecodes::WideOperandToBytes(operands[i], operand_bytes); |
| + bytecodes()->insert(bytecodes()->end(), operand_bytes, |
| + operand_bytes + 2); |
| + break; |
| + } |
| + } |
| } |
| - bytecodes()->insert(bytecodes()->end(), bytes, bytes + N); |
| } |
| -void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0, |
| - uint8_t operand1, uint8_t operand2) { |
| - uint8_t bytes[] = {Bytecodes::ToByte(bytecode), operand0, operand1, operand2}; |
| - Output(bytes); |
| +void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t operand0, |
| + uint32_t operand1, uint32_t operand2) { |
| + uint32_t operands[] = {operand0, operand1, operand2}; |
| + Output(bytecode, operands); |
| } |
| -void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0, |
| - uint8_t operand1) { |
| - uint8_t bytes[] = {Bytecodes::ToByte(bytecode), operand0, operand1}; |
| - Output(bytes); |
| +void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t operand0, |
| + uint32_t operand1) { |
| + uint32_t operands[] = {operand0, operand1}; |
| + Output(bytecode, operands); |
| } |
| -void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0) { |
| - uint8_t bytes[] = {Bytecodes::ToByte(bytecode), operand0}; |
| - Output(bytes); |
| +void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t operand0) { |
| + uint32_t operands[] = {operand0}; |
| + Output(bytecode, operands); |
| } |
| void BytecodeArrayBuilder::Output(Bytecode bytecode) { |
| - uint8_t bytes[] = {Bytecodes::ToByte(bytecode)}; |
| - Output(bytes); |
| + DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0); |
| + last_bytecode_start_ = bytecodes()->size(); |
| + bytecodes()->push_back(Bytecodes::ToByte(bytecode)); |
| } |
| @@ -294,11 +308,14 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToBoolean() { |
| case Bytecode::kTestGreaterThanEqual: |
| case Bytecode::kTestInstanceOf: |
| case Bytecode::kTestIn: |
| - break; |
| + return *this; |
| default: |
| - Output(Bytecode::kToBoolean); |
| + // Fall through to output kToBoolean. |
| + break; |
| } |
| } |
| + Output(Bytecode::kToBoolean); |
| + |
|
oth
2015/09/28 09:21:25
Nit - empty line.
rmcilroy
2015/10/01 14:09:14
Done.
|
| return *this; |
| } |
| @@ -495,17 +512,19 @@ void BytecodeArrayBuilder::ReturnTemporaryRegister(int reg_index) { |
| bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index, |
| - uint8_t operand_value) const { |
| + uint32_t operand_value) const { |
| OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index); |
| switch (operand_type) { |
| case OperandType::kNone: |
| return false; |
| + case OperandType::kWideIdx: |
| + return static_cast<uint16_t>(operand_value) == operand_value; |
| case OperandType::kCount: |
| case OperandType::kImm8: |
| case OperandType::kIdx: |
| - return true; |
| + return static_cast<uint8_t>(operand_value) == operand_value; |
| case OperandType::kReg: { |
| - Register reg = Register::FromOperand(operand_value); |
| + Register reg = Register::FromOperand(static_cast<uint8_t>(operand_value)); |
| if (reg.is_parameter()) { |
| int parameter_index = reg.ToParameterIndex(parameter_count_); |
| return parameter_index >= 0 && parameter_index < parameter_count_; |