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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 int8_t BytecodeArrayIterator::GetImmediateOperand(int operand_index) const { | 61 int8_t BytecodeArrayIterator::GetImmediateOperand(int operand_index) const { |
62 uint32_t operand = GetRawOperand(operand_index, OperandType::kImm8); | 62 uint32_t operand = GetRawOperand(operand_index, OperandType::kImm8); |
63 return static_cast<int8_t>(operand); | 63 return static_cast<int8_t>(operand); |
64 } | 64 } |
65 | 65 |
66 | 66 |
67 int BytecodeArrayIterator::GetCountOperand(int operand_index) const { | 67 int BytecodeArrayIterator::GetCountOperand(int operand_index) const { |
68 OperandSize size = | 68 OperandSize size = |
69 Bytecodes::GetOperandSize(current_bytecode(), operand_index); | 69 Bytecodes::GetOperandSize(current_bytecode(), operand_index); |
70 OperandType type = (size == OperandSize::kByte) ? OperandType::kCount8 | 70 OperandType type = (size == OperandSize::kByte) ? OperandType::kRegCount8 |
71 : OperandType::kCount16; | 71 : OperandType::kRegCount16; |
72 uint32_t operand = GetRawOperand(operand_index, type); | 72 uint32_t operand = GetRawOperand(operand_index, type); |
73 return static_cast<int>(operand); | 73 return static_cast<int>(operand); |
74 } | 74 } |
75 | 75 |
76 | 76 |
77 int BytecodeArrayIterator::GetIndexOperand(int operand_index) const { | 77 int BytecodeArrayIterator::GetIndexOperand(int operand_index) const { |
78 OperandType operand_type = | 78 OperandType operand_type = |
79 Bytecodes::GetOperandType(current_bytecode(), operand_index); | 79 Bytecodes::GetOperandType(current_bytecode(), operand_index); |
80 DCHECK(operand_type == OperandType::kIdx8 || | 80 DCHECK(operand_type == OperandType::kIdx8 || |
81 operand_type == OperandType::kIdx16); | 81 operand_type == OperandType::kIdx16); |
82 uint32_t operand = GetRawOperand(operand_index, operand_type); | 82 uint32_t operand = GetRawOperand(operand_index, operand_type); |
83 return static_cast<int>(operand); | 83 return static_cast<int>(operand); |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 Register BytecodeArrayIterator::GetRegisterOperand(int operand_index) const { | 87 Register BytecodeArrayIterator::GetRegisterOperand(int operand_index) const { |
88 OperandType operand_type = | 88 OperandType operand_type = |
89 Bytecodes::GetOperandType(current_bytecode(), operand_index); | 89 Bytecodes::GetOperandType(current_bytecode(), operand_index); |
90 DCHECK(operand_type == OperandType::kReg8 || | 90 DCHECK(operand_type == OperandType::kReg8 || |
91 operand_type == OperandType::kRegPair8 || | 91 operand_type == OperandType::kRegPair8 || |
92 operand_type == OperandType::kRegTriple8 || | 92 operand_type == OperandType::kRegTriple8 || |
93 operand_type == OperandType::kMaybeReg8 || | 93 operand_type == OperandType::kMaybeReg8 || |
94 operand_type == OperandType::kReg16); | 94 operand_type == OperandType::kReg16); |
95 uint32_t operand = GetRawOperand(operand_index, operand_type); | 95 uint32_t operand = GetRawOperand(operand_index, operand_type); |
96 return Register::FromOperand(operand); | 96 switch (Bytecodes::GetOperandSize(current_bytecode(), operand_index)) { |
| 97 case OperandSize::kByte: |
| 98 return Register::FromOperand(static_cast<uint8_t>(operand)); |
| 99 case OperandSize::kShort: |
| 100 return Register::FromWideOperand(static_cast<uint16_t>(operand)); |
| 101 case OperandSize::kNone: |
| 102 UNREACHABLE(); |
| 103 } |
| 104 return Register(); |
97 } | 105 } |
98 | 106 |
99 | 107 |
100 Handle<Object> BytecodeArrayIterator::GetConstantForIndexOperand( | 108 Handle<Object> BytecodeArrayIterator::GetConstantForIndexOperand( |
101 int operand_index) const { | 109 int operand_index) const { |
102 Handle<FixedArray> constants = handle(bytecode_array()->constant_pool()); | 110 Handle<FixedArray> constants = handle(bytecode_array()->constant_pool()); |
103 return FixedArray::get(constants, GetIndexOperand(operand_index)); | 111 return FixedArray::get(constants, GetIndexOperand(operand_index)); |
104 } | 112 } |
105 | 113 |
106 | 114 |
107 int BytecodeArrayIterator::GetJumpTargetOffset() const { | 115 int BytecodeArrayIterator::GetJumpTargetOffset() const { |
108 Bytecode bytecode = current_bytecode(); | 116 Bytecode bytecode = current_bytecode(); |
109 if (interpreter::Bytecodes::IsJumpImmediate(bytecode)) { | 117 if (interpreter::Bytecodes::IsJumpImmediate(bytecode)) { |
110 int relative_offset = GetImmediateOperand(0); | 118 int relative_offset = GetImmediateOperand(0); |
111 return current_offset() + relative_offset; | 119 return current_offset() + relative_offset; |
112 } else if (interpreter::Bytecodes::IsJumpConstant(bytecode) || | 120 } else if (interpreter::Bytecodes::IsJumpConstant(bytecode) || |
113 interpreter::Bytecodes::IsJumpConstantWide(bytecode)) { | 121 interpreter::Bytecodes::IsJumpConstantWide(bytecode)) { |
114 Smi* smi = Smi::cast(*GetConstantForIndexOperand(0)); | 122 Smi* smi = Smi::cast(*GetConstantForIndexOperand(0)); |
115 return current_offset() + smi->value(); | 123 return current_offset() + smi->value(); |
116 } else { | 124 } else { |
117 UNREACHABLE(); | 125 UNREACHABLE(); |
118 return kMinInt; | 126 return kMinInt; |
119 } | 127 } |
120 } | 128 } |
121 | 129 |
122 } // namespace interpreter | 130 } // namespace interpreter |
123 } // namespace internal | 131 } // namespace internal |
124 } // namespace v8 | 132 } // namespace v8 |
OLD | NEW |