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-iterator.h" | 5 #include "src/interpreter/bytecode-array-iterator.h" |
6 | 6 |
7 #include "src/objects-inl.h" | 7 #include "src/objects-inl.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 14 matching lines...) Expand all Loading... |
25 } | 25 } |
26 | 26 |
27 | 27 |
28 Bytecode BytecodeArrayIterator::current_bytecode() const { | 28 Bytecode BytecodeArrayIterator::current_bytecode() const { |
29 DCHECK(!done()); | 29 DCHECK(!done()); |
30 uint8_t current_byte = bytecode_array()->get(bytecode_offset_); | 30 uint8_t current_byte = bytecode_array()->get(bytecode_offset_); |
31 return interpreter::Bytecodes::FromByte(current_byte); | 31 return interpreter::Bytecodes::FromByte(current_byte); |
32 } | 32 } |
33 | 33 |
34 | 34 |
35 uint8_t BytecodeArrayIterator::GetRawOperand(int operand_index, | 35 uint32_t BytecodeArrayIterator::GetRawOperand(int operand_index, |
36 OperandType operand_type) const { | 36 OperandType operand_type) const { |
37 DCHECK_GE(operand_index, 0); | 37 DCHECK_GE(operand_index, 0); |
38 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(current_bytecode())); | 38 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(current_bytecode())); |
39 DCHECK_EQ(operand_type, | 39 DCHECK_EQ(operand_type, |
40 Bytecodes::GetOperandType(current_bytecode(), operand_index)); | 40 Bytecodes::GetOperandType(current_bytecode(), operand_index)); |
41 int operands_start = bytecode_offset_ + 1; | 41 uint8_t* operand_start = |
42 return bytecode_array()->get(operands_start + operand_index); | 42 bytecode_array()->GetFirstBytecodeAddress() + bytecode_offset_ + |
| 43 Bytecodes::GetOperandOffset(current_bytecode(), operand_index); |
| 44 switch (Bytecodes::SizeOfOperand(operand_type)) { |
| 45 default: |
| 46 case OperandSize::kNone: |
| 47 UNREACHABLE(); |
| 48 case OperandSize::kByte: |
| 49 return static_cast<uint32_t>(*operand_start); |
| 50 case OperandSize::kShort: |
| 51 return Bytecodes::ShortOperandFromBytes(operand_start); |
| 52 } |
43 } | 53 } |
44 | 54 |
45 | 55 |
46 int8_t BytecodeArrayIterator::GetSmi8Operand(int operand_index) const { | 56 int8_t BytecodeArrayIterator::GetImmediateOperand(int operand_index) const { |
47 uint8_t operand = GetRawOperand(operand_index, OperandType::kImm8); | 57 uint32_t operand = GetRawOperand(operand_index, OperandType::kImm8); |
48 return static_cast<int8_t>(operand); | 58 return static_cast<int8_t>(operand); |
49 } | 59 } |
50 | 60 |
51 | 61 |
52 int BytecodeArrayIterator::GetIndexOperand(int operand_index) const { | 62 int BytecodeArrayIterator::GetIndexOperand(int operand_index) const { |
53 uint8_t operand = GetRawOperand(operand_index, OperandType::kIdx); | 63 OperandSize size = |
| 64 Bytecodes::GetOperandSize(current_bytecode(), operand_index); |
| 65 OperandType type = |
| 66 (size == OperandSize::kByte) ? OperandType::kIdx8 : OperandType::kIdx16; |
| 67 uint32_t operand = GetRawOperand(operand_index, type); |
54 return static_cast<int>(operand); | 68 return static_cast<int>(operand); |
55 } | 69 } |
56 | 70 |
57 | 71 |
58 Register BytecodeArrayIterator::GetRegisterOperand(int operand_index) const { | 72 Register BytecodeArrayIterator::GetRegisterOperand(int operand_index) const { |
59 uint8_t operand = GetRawOperand(operand_index, OperandType::kReg); | 73 uint32_t operand = GetRawOperand(operand_index, OperandType::kReg8); |
60 return Register::FromOperand(operand); | 74 return Register::FromOperand(operand); |
61 } | 75 } |
62 | 76 |
63 | 77 |
64 Handle<Object> BytecodeArrayIterator::GetConstantForIndexOperand( | 78 Handle<Object> BytecodeArrayIterator::GetConstantForIndexOperand( |
65 int operand_index) const { | 79 int operand_index) const { |
66 Handle<FixedArray> constants = handle(bytecode_array()->constant_pool()); | 80 Handle<FixedArray> constants = handle(bytecode_array()->constant_pool()); |
67 return FixedArray::get(constants, GetIndexOperand(operand_index)); | 81 return FixedArray::get(constants, GetIndexOperand(operand_index)); |
68 } | 82 } |
69 | 83 |
70 } // namespace interpreter | 84 } // namespace interpreter |
71 } // namespace internal | 85 } // namespace internal |
72 } // namespace v8 | 86 } // namespace v8 |
OLD | NEW |