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/bytecodes.h" | 5 #include "src/interpreter/bytecodes.h" |
6 | 6 |
7 #include "src/interpreter/bytecode-array-builder.h" | 7 #include "src/frames.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
11 namespace interpreter { | 11 namespace interpreter { |
12 | 12 |
13 // Maximum number of operands a bytecode may have. | 13 // Maximum number of operands a bytecode may have. |
14 static const int kMaxOperands = 3; | 14 static const int kMaxOperands = 3; |
15 | 15 |
16 // kBytecodeTable relies on kNone being the same as zero to detect length. | 16 // kBytecodeTable relies on kNone being the same as zero to detect length. |
17 STATIC_ASSERT(static_cast<int>(OperandType::kNone) == 0); | 17 STATIC_ASSERT(static_cast<int>(OperandType::kNone) == 0); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 | 96 |
97 // static | 97 // static |
98 int Bytecodes::MaximumNumberOfOperands() { return kMaxOperands; } | 98 int Bytecodes::MaximumNumberOfOperands() { return kMaxOperands; } |
99 | 99 |
100 | 100 |
101 // static | 101 // static |
102 int Bytecodes::MaximumSize() { return 1 + kMaxOperands; } | 102 int Bytecodes::MaximumSize() { return 1 + kMaxOperands; } |
103 | 103 |
104 | 104 |
105 // static | 105 // static |
106 std::ostream& Bytecodes::Decode(std::ostream& os, | 106 uint8_t Bytecodes::RegisterIndexToOperand(int index) { |
107 const uint8_t* bytecode_start) { | 107 return static_cast<uint8_t>(-index); |
108 } | |
109 | |
110 | |
111 // static | |
112 int Bytecodes::RegisterIndexFromOperand(uint8_t operand) { | |
113 int8_t index = -static_cast<int8_t>(operand); | |
114 return index; | |
115 } | |
116 | |
117 | |
118 static const int kLastParamRegisterIndex = | |
119 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; | |
120 | |
121 | |
122 // static | |
123 uint8_t Bytecodes::ParameterIndexToOperand(int index, int parameter_count) { | |
rmcilroy
2015/09/02 11:42:42
Could we make this a Register::FromParameterIndex(
oth
2015/09/02 14:02:20
Done.
| |
124 // Parameters share the same space as registers | |
125 DCHECK_LE(parameter_count, MaximumNumberOfParameters()); | |
126 DCHECK_GE(index, 0); | |
rmcilroy
2015/09/02 11:42:41
nit - DCHECK_LT(index, parameter_count)
oth
2015/09/02 14:02:20
Done.
| |
127 int register_index = kLastParamRegisterIndex - parameter_count + index + 1; | |
128 DCHECK_LT(register_index, 0); | |
129 return RegisterIndexToOperand(register_index); | |
130 } | |
131 | |
132 | |
133 // static | |
134 int Bytecodes::ParameterIndexFromOperand(uint8_t operand, int parameter_count) { | |
135 // Parameters share the same space as registers | |
136 DCHECK_LE(parameter_count, MaximumNumberOfParameters()); | |
137 int register_index = RegisterIndexFromOperand(operand); | |
138 return register_index - kLastParamRegisterIndex + parameter_count - 1; | |
139 } | |
140 | |
141 | |
142 // static | |
143 int Bytecodes::MaximumNumberOfParameters() { | |
144 return 128 + kLastParamRegisterIndex; | |
rmcilroy
2015/09/02 11:42:41
This is a bit confusing. Could you use kMinRegiste
oth
2015/09/02 14:02:20
Comment added.
| |
145 } | |
146 | |
147 | |
148 // static | |
149 std::ostream& Bytecodes::Decode(std::ostream& os, const uint8_t* bytecode_start, | |
150 int parameter_count) { | |
108 Vector<char> buf = Vector<char>::New(50); | 151 Vector<char> buf = Vector<char>::New(50); |
109 | 152 |
110 Bytecode bytecode = Bytecodes::FromByte(bytecode_start[0]); | 153 Bytecode bytecode = Bytecodes::FromByte(bytecode_start[0]); |
111 int bytecode_size = Bytecodes::Size(bytecode); | 154 int bytecode_size = Bytecodes::Size(bytecode); |
112 | 155 |
113 for (int i = 0; i < bytecode_size; i++) { | 156 for (int i = 0; i < bytecode_size; i++) { |
114 SNPrintF(buf, "%02x ", bytecode_start[i]); | 157 SNPrintF(buf, "%02x ", bytecode_start[i]); |
115 os << buf.start(); | 158 os << buf.start(); |
116 } | 159 } |
117 for (int i = bytecode_size; i < Bytecodes::MaximumSize(); i++) { | 160 for (int i = bytecode_size; i < Bytecodes::MaximumSize(); i++) { |
118 os << " "; | 161 os << " "; |
119 } | 162 } |
120 | 163 |
121 os << bytecode << " "; | 164 os << bytecode << " "; |
122 | 165 |
123 const uint8_t* operands_start = bytecode_start + 1; | 166 const uint8_t* operands_start = bytecode_start + 1; |
124 int operands_size = bytecode_size - 1; | 167 int operands_size = bytecode_size - 1; |
125 for (int i = 0; i < operands_size; i++) { | 168 for (int i = 0; i < operands_size; i++) { |
126 OperandType op_type = GetOperandType(bytecode, i); | 169 OperandType op_type = GetOperandType(bytecode, i); |
127 uint8_t operand = operands_start[i]; | 170 uint8_t operand = operands_start[i]; |
128 switch (op_type) { | 171 switch (op_type) { |
129 case interpreter::OperandType::kIdx: | 172 case interpreter::OperandType::kIdx: |
130 os << "[" << static_cast<unsigned int>(operand) << "]"; | 173 os << "[" << static_cast<unsigned int>(operand) << "]"; |
131 break; | 174 break; |
132 case interpreter::OperandType::kImm8: | 175 case interpreter::OperandType::kImm8: |
133 os << "#" << static_cast<int>(operand); | 176 os << "#" << static_cast<int>(operand); |
134 break; | 177 break; |
135 case interpreter::OperandType::kReg: | 178 case interpreter::OperandType::kReg: { |
136 os << "r" << Register::FromOperand(operand).index(); | 179 int register_index = RegisterIndexFromOperand(operand); |
180 if (register_index >= 0) { | |
181 os << "r" << register_index; | |
182 } else { | |
183 int parameter_index = | |
184 ParameterIndexFromOperand(operand, parameter_count); | |
185 if (parameter_index == 0) { | |
186 os << "this"; | |
rmcilroy
2015/09/02 11:42:42
nit - could we make it "<this>" or "|this|" or som
oth
2015/09/02 14:02:20
Done <this>.
Prefer current consistency of r0, r1
| |
187 } else { | |
188 os << "a" << parameter_index - 1; | |
189 } | |
190 } | |
137 break; | 191 break; |
192 } | |
138 case interpreter::OperandType::kNone: | 193 case interpreter::OperandType::kNone: |
139 UNREACHABLE(); | 194 UNREACHABLE(); |
140 break; | 195 break; |
141 } | 196 } |
142 if (i != operands_size - 1) { | 197 if (i != operands_size - 1) { |
143 os << ", "; | 198 os << ", "; |
144 } | 199 } |
145 } | 200 } |
146 return os; | 201 return os; |
147 } | 202 } |
148 | 203 |
149 | 204 |
150 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode) { | 205 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode) { |
151 return os << Bytecodes::ToString(bytecode); | 206 return os << Bytecodes::ToString(bytecode); |
152 } | 207 } |
153 | 208 |
154 | 209 |
155 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type) { | 210 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type) { |
156 return os << Bytecodes::OperandTypeToString(operand_type); | 211 return os << Bytecodes::OperandTypeToString(operand_type); |
157 } | 212 } |
158 | 213 |
159 } // namespace interpreter | 214 } // namespace interpreter |
160 } // namespace internal | 215 } // namespace internal |
161 } // namespace v8 | 216 } // namespace v8 |
OLD | NEW |