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) {} | |
| 16 | |
| 17 | |
| 18 void BytecodeArrayIterator::Advance() { | |
| 19 bytecode_offset_ += Bytecodes::Size(current_bytecode()); | |
| 20 } | |
| 21 | |
| 22 | |
| 23 bool BytecodeArrayIterator::done() const { | |
| 24 return bytecode_offset_ >= bytecode_array()->length(); | |
| 25 } | |
| 26 | |
| 27 | |
| 28 Bytecode BytecodeArrayIterator::current_bytecode() const { | |
| 29 DCHECK(!done()); | |
| 30 uint8_t current_byte = bytecode_array()->get(bytecode_offset_); | |
| 31 return interpreter::Bytecodes::FromByte(current_byte); | |
| 32 } | |
| 33 | |
| 34 | |
| 35 uint8_t BytecodeArrayIterator::GetOperand(int operand_index, | |
| 36 OperandType operand_type) const { | |
| 37 DCHECK_GE(operand_index, 0); | |
| 38 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(current_bytecode())); | |
| 39 DCHECK_EQ(operand_type, | |
| 40 Bytecodes::GetOperandType(current_bytecode(), operand_index)); | |
| 41 int operands_start = bytecode_offset_ + 1; | |
| 42 return bytecode_array()->get(operands_start + operand_index); | |
| 43 } | |
| 44 | |
| 45 | |
| 46 int8_t BytecodeArrayIterator::GetSmi8Operand(int operand_index) const { | |
| 47 uint8_t operand = GetOperand(operand_index, OperandType::kImm8); | |
| 48 return static_cast<int8_t>(operand); | |
| 49 } | |
| 50 | |
| 51 | |
| 52 int BytecodeArrayIterator::GetIndexOperand(int operand_index) const { | |
| 53 uint8_t operand = GetOperand(operand_index, OperandType::kIdx); | |
| 54 return static_cast<int>(operand); | |
| 55 } | |
| 56 | |
| 57 | |
| 58 Register BytecodeArrayIterator::GetRegisterOperand(int operand_index) const { | |
| 59 uint8_t operand = GetOperand(operand_index, OperandType::kReg); | |
| 60 return Register::FromOperand(operand); | |
| 61 } | |
| 62 | |
| 63 | |
| 64 Handle<Object> BytecodeArrayIterator::GetConstantForIndexOperand( | |
| 65 int operand_index) const { | |
| 66 Handle<FixedArray> constants = handle(bytecode_array()->constant_pool()); | |
| 67 return FixedArray::get(constants, GetIndexOperand(operand_index)); | |
|
rmcilroy
2015/09/10 10:19:43
this should be "constants->get(GetIndexOperand(ope
oth
2015/09/10 13:59:06
The static version returns a handle for the elemen
rmcilroy
2015/09/10 14:06:28
Ahh you're right sorry. Strange that this is a sta
| |
| 68 } | |
| 69 | |
| 70 } // namespace interpreter | |
| 71 } // namespace internal | |
| 72 } // namespace v8 | |
| OLD | NEW |