Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "src/interpreter/bytecode-array-iterator.h" | |
| 6 | |
| 7 #include "src/objects-inl.h" | |
| 8 | |
| 9 namespace v8 { | |
| 10 namespace internal { | |
| 11 namespace interpreter { | |
| 12 | |
| 13 BytecodeArrayIterator::BytecodeArrayIterator( | |
| 14 Handle<BytecodeArray> bytecode_array) | |
| 15 : bytecode_array_(bytecode_array), bytecode_offset_(0) { | |
|
rmcilroy
2015/09/04 11:35:37
need to init operands_used_ if DEBUG
oth
2015/09/04 16:15:46
Yes, but that's what MarkOperandsUnused() does.
| |
| 16 MarkOperandsUnused(); | |
| 17 } | |
| 18 | |
| 19 | |
| 20 BytecodeArrayIterator::~BytecodeArrayIterator() { CheckOperandsUsed(); } | |
| 21 | |
| 22 | |
| 23 void BytecodeArrayIterator::Next() { | |
| 24 DCHECK(More()); | |
| 25 CheckOperandsUsed(); | |
| 26 MarkOperandsUnused(); | |
| 27 bytecode_offset_ += Bytecodes::Size(current_bytecode()); | |
| 28 } | |
| 29 | |
| 30 | |
| 31 bool BytecodeArrayIterator::More() const { | |
|
rmcilroy
2015/09/04 11:35:37
More seems a little confusing here, since it impli
oth
2015/09/04 16:15:46
Done. These were adopted from elsewhere in the tre
| |
| 32 return bytecode_offset_ < bytecode_array()->length(); | |
| 33 } | |
| 34 | |
| 35 | |
| 36 Bytecode BytecodeArrayIterator::current_bytecode() const { | |
| 37 uint8_t current_byte = bytecode_array()->get(bytecode_offset_); | |
| 38 return interpreter::Bytecodes::FromByte(current_byte); | |
| 39 } | |
| 40 | |
| 41 | |
| 42 uint8_t BytecodeArrayIterator::GetOperand(int operand_index, | |
| 43 OperandType operand_type) const { | |
| 44 DCHECK_GE(operand_index, 0); | |
| 45 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(current_bytecode())); | |
| 46 DCHECK_EQ(operand_type, | |
| 47 Bytecodes::GetOperandType(current_bytecode(), operand_index)); | |
| 48 MarkOperandUsed(operand_index); | |
| 49 int operands_start = bytecode_offset_ + 1; | |
| 50 return bytecode_array()->get(operands_start + operand_index); | |
| 51 } | |
| 52 | |
| 53 | |
| 54 int8_t BytecodeArrayIterator::GetSmi8Operand(int operand_index) const { | |
| 55 uint8_t operand = GetOperand(operand_index, OperandType::kImm8); | |
| 56 return static_cast<int8_t>(operand); | |
| 57 } | |
| 58 | |
| 59 | |
| 60 int BytecodeArrayIterator::GetIndexOperand(int operand_index) const { | |
| 61 uint8_t operand = GetOperand(operand_index, OperandType::kIdx); | |
| 62 return static_cast<int>(operand); | |
| 63 } | |
| 64 | |
| 65 | |
| 66 Register BytecodeArrayIterator::GetRegisterOperand(int operand_index) const { | |
| 67 uint8_t operand = GetOperand(operand_index, OperandType::kReg); | |
| 68 return Register::FromOperand(operand); | |
| 69 } | |
| 70 | |
| 71 | |
| 72 Handle<Object> BytecodeArrayIterator::GetConstantForIndexOperand( | |
| 73 int operand_index) const { | |
| 74 Handle<FixedArray> constants = handle(bytecode_array()->constant_pool()); | |
| 75 return FixedArray::get(constants, GetIndexOperand(operand_index)); | |
| 76 } | |
| 77 | |
| 78 | |
| 79 void BytecodeArrayIterator::MarkOperandsUnused() { | |
| 80 #ifdef DEBUG | |
| 81 operands_used_ = 0; | |
| 82 #endif // DEBUG | |
| 83 } | |
| 84 | |
| 85 | |
| 86 void BytecodeArrayIterator::CheckOperandsUsed() const { | |
|
rmcilroy
2015/09/04 11:35:37
I'm wondering how useful this will be (and whether
oth
2015/09/04 16:15:46
Gone :-)
| |
| 87 #ifdef DEBUG | |
| 88 if (More()) { | |
| 89 Bytecode bytecode = current_bytecode(); | |
| 90 int mask = (1 << Bytecodes::NumberOfOperands(bytecode)) - 1; | |
| 91 DCHECK_EQ(operands_used_, mask); | |
| 92 } | |
| 93 #endif // DEBUG | |
| 94 } | |
| 95 | |
| 96 void BytecodeArrayIterator::MarkOperandUsed(int operand_index) const { | |
| 97 #ifdef DEBUG | |
| 98 operands_used_ |= 1 << operand_index; | |
| 99 #endif // DEBUG | |
| 100 } | |
| 101 | |
| 102 } // namespace interpreter | |
| 103 } // namespace internal | |
| 104 } // namespace v8 | |
| OLD | NEW |