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/frames.h" | 7 #include "src/frames.h" |
8 #include "src/interpreter/bytecode-traits.h" | 8 #include "src/interpreter/bytecode-traits.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 break; | 218 break; |
219 case interpreter::OperandType::kIdx16: { | 219 case interpreter::OperandType::kIdx16: { |
220 os << "[" << Bytecodes::ShortOperandFromBytes(operand_start) << "]"; | 220 os << "[" << Bytecodes::ShortOperandFromBytes(operand_start) << "]"; |
221 break; | 221 break; |
222 } | 222 } |
223 case interpreter::OperandType::kImm8: | 223 case interpreter::OperandType::kImm8: |
224 os << "#" << static_cast<int>(static_cast<int8_t>(*operand_start)); | 224 os << "#" << static_cast<int>(static_cast<int8_t>(*operand_start)); |
225 break; | 225 break; |
226 case interpreter::OperandType::kReg8: { | 226 case interpreter::OperandType::kReg8: { |
227 Register reg = Register::FromOperand(*operand_start); | 227 Register reg = Register::FromOperand(*operand_start); |
228 if (reg.is_parameter()) { | 228 if (reg.is_function_context()) { |
| 229 os << "<context>"; |
| 230 } else if (reg.is_function_closure()) { |
| 231 os << "<closure>"; |
| 232 } else if (reg.is_parameter()) { |
229 int parameter_index = reg.ToParameterIndex(parameter_count); | 233 int parameter_index = reg.ToParameterIndex(parameter_count); |
230 if (parameter_index == 0) { | 234 if (parameter_index == 0) { |
231 os << "<this>"; | 235 os << "<this>"; |
232 } else { | 236 } else { |
233 os << "a" << parameter_index - 1; | 237 os << "a" << parameter_index - 1; |
234 } | 238 } |
235 } else { | 239 } else { |
236 os << "r" << reg.index(); | 240 os << "r" << reg.index(); |
237 } | 241 } |
238 break; | 242 break; |
(...skipping 20 matching lines...) Expand all Loading... |
259 } | 263 } |
260 | 264 |
261 | 265 |
262 std::ostream& operator<<(std::ostream& os, const OperandSize& operand_size) { | 266 std::ostream& operator<<(std::ostream& os, const OperandSize& operand_size) { |
263 return os << Bytecodes::OperandSizeToString(operand_size); | 267 return os << Bytecodes::OperandSizeToString(operand_size); |
264 } | 268 } |
265 | 269 |
266 | 270 |
267 static const int kLastParamRegisterIndex = | 271 static const int kLastParamRegisterIndex = |
268 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; | 272 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; |
| 273 static const int kFunctionClosureRegisterIndex = |
| 274 -InterpreterFrameConstants::kFunctionFromRegisterPointer / kPointerSize; |
269 static const int kFunctionContextRegisterIndex = | 275 static const int kFunctionContextRegisterIndex = |
270 -InterpreterFrameConstants::kContextFromRegisterPointer / kPointerSize; | 276 -InterpreterFrameConstants::kContextFromRegisterPointer / kPointerSize; |
271 | 277 |
272 | 278 |
273 // Registers occupy range 0-127 in 8-bit value leaving 128 unused values. | 279 // Registers occupy range 0-127 in 8-bit value leaving 128 unused values. |
274 // Parameter indices are biased with the negative value kLastParamRegisterIndex | 280 // Parameter indices are biased with the negative value kLastParamRegisterIndex |
275 // for ease of access in the interpreter. | 281 // for ease of access in the interpreter. |
276 static const int kMaxParameterIndex = 128 + kLastParamRegisterIndex; | 282 static const int kMaxParameterIndex = 128 + kLastParamRegisterIndex; |
277 | 283 |
278 | 284 |
279 Register Register::FromParameterIndex(int index, int parameter_count) { | 285 Register Register::FromParameterIndex(int index, int parameter_count) { |
280 DCHECK_GE(index, 0); | 286 DCHECK_GE(index, 0); |
281 DCHECK_LT(index, parameter_count); | 287 DCHECK_LT(index, parameter_count); |
282 DCHECK_LE(parameter_count, kMaxParameterIndex + 1); | 288 DCHECK_LE(parameter_count, kMaxParameterIndex + 1); |
283 int register_index = kLastParamRegisterIndex - parameter_count + index + 1; | 289 int register_index = kLastParamRegisterIndex - parameter_count + index + 1; |
284 DCHECK_LT(register_index, 0); | 290 DCHECK_LT(register_index, 0); |
285 DCHECK_GE(register_index, Register::kMinRegisterIndex); | 291 DCHECK_GE(register_index, Register::kMinRegisterIndex); |
286 return Register(register_index); | 292 return Register(register_index); |
287 } | 293 } |
288 | 294 |
289 | 295 |
290 int Register::ToParameterIndex(int parameter_count) const { | 296 int Register::ToParameterIndex(int parameter_count) const { |
291 DCHECK(is_parameter()); | 297 DCHECK(is_parameter()); |
292 return index() - kLastParamRegisterIndex + parameter_count - 1; | 298 return index() - kLastParamRegisterIndex + parameter_count - 1; |
293 } | 299 } |
294 | 300 |
295 | 301 |
| 302 Register Register::function_closure() { |
| 303 return Register(kFunctionClosureRegisterIndex); |
| 304 } |
| 305 |
| 306 |
| 307 bool Register::is_function_closure() const { |
| 308 return index() == kFunctionClosureRegisterIndex; |
| 309 } |
| 310 |
| 311 |
296 Register Register::function_context() { | 312 Register Register::function_context() { |
297 return Register(kFunctionContextRegisterIndex); | 313 return Register(kFunctionContextRegisterIndex); |
298 } | 314 } |
299 | 315 |
300 | 316 |
301 bool Register::is_function_context() const { | 317 bool Register::is_function_context() const { |
302 return index() == kFunctionContextRegisterIndex; | 318 return index() == kFunctionContextRegisterIndex; |
303 } | 319 } |
304 | 320 |
305 | 321 |
306 int Register::MaxParameterIndex() { return kMaxParameterIndex; } | 322 int Register::MaxParameterIndex() { return kMaxParameterIndex; } |
307 | 323 |
308 | 324 |
309 uint8_t Register::ToOperand() const { return static_cast<uint8_t>(-index_); } | 325 uint8_t Register::ToOperand() const { return static_cast<uint8_t>(-index_); } |
310 | 326 |
311 | 327 |
312 Register Register::FromOperand(uint8_t operand) { | 328 Register Register::FromOperand(uint8_t operand) { |
313 return Register(-static_cast<int8_t>(operand)); | 329 return Register(-static_cast<int8_t>(operand)); |
314 } | 330 } |
315 | 331 |
316 } // namespace interpreter | 332 } // namespace interpreter |
317 } // namespace internal | 333 } // namespace internal |
318 } // namespace v8 | 334 } // namespace v8 |
OLD | NEW |