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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 return IsJumpImmediate(bytecode) || IsJumpConstant(bytecode) || | 255 return IsJumpImmediate(bytecode) || IsJumpConstant(bytecode) || |
256 IsJumpConstantWide(bytecode); | 256 IsJumpConstantWide(bytecode); |
257 } | 257 } |
258 | 258 |
259 | 259 |
260 // static | 260 // static |
261 bool Bytecodes::IsJumpOrReturn(Bytecode bytecode) { | 261 bool Bytecodes::IsJumpOrReturn(Bytecode bytecode) { |
262 return bytecode == Bytecode::kReturn || IsJump(bytecode); | 262 return bytecode == Bytecode::kReturn || IsJump(bytecode); |
263 } | 263 } |
264 | 264 |
| 265 // static |
| 266 bool Bytecodes::IsRegisterOperandType(OperandType operand_type) { |
| 267 switch (operand_type) { |
| 268 #define CASE(Name, _) \ |
| 269 case OperandType::k##Name: \ |
| 270 return true; |
| 271 REGISTER_OPERAND_TYPE_LIST(CASE) |
| 272 #undef CASE |
| 273 #define CASE(Name, _) \ |
| 274 case OperandType::k##Name: \ |
| 275 break; |
| 276 NON_REGISTER_OPERAND_TYPE_LIST(CASE) |
| 277 #undef CASE |
| 278 } |
| 279 return false; |
| 280 } |
| 281 |
| 282 // static |
| 283 bool Bytecodes::IsRegisterInputOperandType(OperandType operand_type) { |
| 284 switch (operand_type) { |
| 285 #define CASE(Name, _) \ |
| 286 case OperandType::k##Name: \ |
| 287 return true; |
| 288 REGISTER_INPUT_OPERAND_TYPE_LIST(CASE) |
| 289 #undef CASE |
| 290 #define CASE(Name, _) \ |
| 291 case OperandType::k##Name: \ |
| 292 break; |
| 293 NON_REGISTER_OPERAND_TYPE_LIST(CASE) |
| 294 REGISTER_OUTPUT_OPERAND_TYPE_LIST(CASE) |
| 295 #undef CASE |
| 296 } |
| 297 return false; |
| 298 } |
| 299 |
| 300 // static |
| 301 bool Bytecodes::IsRegisterOutputOperandType(OperandType operand_type) { |
| 302 switch (operand_type) { |
| 303 #define CASE(Name, _) \ |
| 304 case OperandType::k##Name: \ |
| 305 return true; |
| 306 REGISTER_OUTPUT_OPERAND_TYPE_LIST(CASE) |
| 307 #undef CASE |
| 308 #define CASE(Name, _) \ |
| 309 case OperandType::k##Name: \ |
| 310 break; |
| 311 NON_REGISTER_OPERAND_TYPE_LIST(CASE) |
| 312 REGISTER_INPUT_OPERAND_TYPE_LIST(CASE) |
| 313 #undef CASE |
| 314 } |
| 315 return false; |
| 316 } |
265 | 317 |
266 namespace { | 318 namespace { |
267 static Register DecodeRegister(const uint8_t* operand_start, | 319 static Register DecodeRegister(const uint8_t* operand_start, |
268 OperandType operand_type) { | 320 OperandType operand_type) { |
269 switch (Bytecodes::SizeOfOperand(operand_type)) { | 321 switch (Bytecodes::SizeOfOperand(operand_type)) { |
270 case OperandSize::kByte: | 322 case OperandSize::kByte: |
271 return Register::FromOperand(*operand_start); | 323 return Register::FromOperand(*operand_start); |
272 case OperandSize::kShort: | 324 case OperandSize::kShort: |
273 return Register::FromWideOperand(ReadUnalignedUInt16(operand_start)); | 325 return Register::FromWideOperand(ReadUnalignedUInt16(operand_start)); |
274 case OperandSize::kNone: { | 326 case OperandSize::kNone: { |
(...skipping 18 matching lines...) Expand all Loading... |
293 os << buf.start(); | 345 os << buf.start(); |
294 } | 346 } |
295 const int kBytecodeColumnSize = 6; | 347 const int kBytecodeColumnSize = 6; |
296 for (int i = bytecode_size; i < kBytecodeColumnSize; i++) { | 348 for (int i = bytecode_size; i < kBytecodeColumnSize; i++) { |
297 os << " "; | 349 os << " "; |
298 } | 350 } |
299 | 351 |
300 os << bytecode << " "; | 352 os << bytecode << " "; |
301 | 353 |
302 int number_of_operands = NumberOfOperands(bytecode); | 354 int number_of_operands = NumberOfOperands(bytecode); |
| 355 int range = 0; |
303 for (int i = 0; i < number_of_operands; i++) { | 356 for (int i = 0; i < number_of_operands; i++) { |
304 OperandType op_type = GetOperandType(bytecode, i); | 357 OperandType op_type = GetOperandType(bytecode, i); |
305 const uint8_t* operand_start = | 358 const uint8_t* operand_start = |
306 &bytecode_start[GetOperandOffset(bytecode, i)]; | 359 &bytecode_start[GetOperandOffset(bytecode, i)]; |
307 switch (op_type) { | 360 switch (op_type) { |
308 case interpreter::OperandType::kRegCount8: | 361 case interpreter::OperandType::kRegCount8: |
309 os << "#" << static_cast<unsigned int>(*operand_start); | 362 os << "#" << static_cast<unsigned int>(*operand_start); |
310 break; | 363 break; |
311 case interpreter::OperandType::kRegCount16: | 364 case interpreter::OperandType::kRegCount16: |
312 os << '#' << ReadUnalignedUInt16(operand_start); | 365 os << '#' << ReadUnalignedUInt16(operand_start); |
313 break; | 366 break; |
314 case interpreter::OperandType::kIdx8: | 367 case interpreter::OperandType::kIdx8: |
315 os << "[" << static_cast<unsigned int>(*operand_start) << "]"; | 368 os << "[" << static_cast<unsigned int>(*operand_start) << "]"; |
316 break; | 369 break; |
317 case interpreter::OperandType::kIdx16: | 370 case interpreter::OperandType::kIdx16: |
318 os << "[" << ReadUnalignedUInt16(operand_start) << "]"; | 371 os << "[" << ReadUnalignedUInt16(operand_start) << "]"; |
319 break; | 372 break; |
320 case interpreter::OperandType::kImm8: | 373 case interpreter::OperandType::kImm8: |
321 os << "#" << static_cast<int>(static_cast<int8_t>(*operand_start)); | 374 os << "#" << static_cast<int>(static_cast<int8_t>(*operand_start)); |
322 break; | 375 break; |
323 case interpreter::OperandType::kMaybeReg8: | 376 case interpreter::OperandType::kMaybeReg8: |
324 case interpreter::OperandType::kMaybeReg16: | 377 case interpreter::OperandType::kMaybeReg16: |
325 case interpreter::OperandType::kReg8: | 378 case interpreter::OperandType::kReg8: |
326 case interpreter::OperandType::kReg16: { | 379 case interpreter::OperandType::kReg16: |
| 380 case interpreter::OperandType::kRegOut8: |
| 381 case interpreter::OperandType::kRegOut16: { |
327 Register reg = DecodeRegister(operand_start, op_type); | 382 Register reg = DecodeRegister(operand_start, op_type); |
328 if (reg.is_current_context()) { | 383 if (reg.is_current_context()) { |
329 os << "<context>"; | 384 os << "<context>"; |
330 } else if (reg.is_function_closure()) { | 385 } else if (reg.is_function_closure()) { |
331 os << "<closure>"; | 386 os << "<closure>"; |
332 } else if (reg.is_new_target()) { | 387 } else if (reg.is_new_target()) { |
333 os << "<new.target>"; | 388 os << "<new.target>"; |
334 } else if (reg.is_parameter()) { | 389 } else if (reg.is_parameter()) { |
335 int parameter_index = reg.ToParameterIndex(parameter_count); | 390 int parameter_index = reg.ToParameterIndex(parameter_count); |
336 if (parameter_index == 0) { | 391 if (parameter_index == 0) { |
337 os << "<this>"; | 392 os << "<this>"; |
338 } else { | 393 } else { |
339 os << "a" << parameter_index - 1; | 394 os << "a" << parameter_index - 1; |
340 } | 395 } |
341 } else { | 396 } else { |
342 os << "r" << reg.index(); | 397 os << "r" << reg.index(); |
343 } | 398 } |
344 break; | 399 break; |
345 } | 400 } |
| 401 case interpreter::OperandType::kRegOutTriple8: |
| 402 case interpreter::OperandType::kRegOutTriple16: |
| 403 range += 1; |
| 404 case interpreter::OperandType::kRegOutPair8: |
| 405 case interpreter::OperandType::kRegOutPair16: |
346 case interpreter::OperandType::kRegPair8: | 406 case interpreter::OperandType::kRegPair8: |
347 case interpreter::OperandType::kRegTriple8: | 407 case interpreter::OperandType::kRegPair16: { |
348 case interpreter::OperandType::kRegPair16: | 408 range += 1; |
349 case interpreter::OperandType::kRegTriple16: { | |
350 Register reg = DecodeRegister(operand_start, op_type); | 409 Register reg = DecodeRegister(operand_start, op_type); |
351 int range = op_type == interpreter::OperandType::kRegPair8 ? 1 : 2; | |
352 if (reg.is_parameter()) { | 410 if (reg.is_parameter()) { |
353 int parameter_index = reg.ToParameterIndex(parameter_count); | 411 int parameter_index = reg.ToParameterIndex(parameter_count); |
354 DCHECK_GT(parameter_index, 0); | 412 DCHECK_GT(parameter_index, 0); |
355 os << "a" << parameter_index - range << "-" << parameter_index; | 413 os << "a" << parameter_index - range << "-" << parameter_index; |
356 } else { | 414 } else { |
357 os << "r" << reg.index() << "-" << reg.index() + range; | 415 os << "r" << reg.index() << "-" << reg.index() + range; |
358 } | 416 } |
359 break; | 417 break; |
360 } | 418 } |
361 case interpreter::OperandType::kNone: | 419 case interpreter::OperandType::kNone: |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 } | 507 } |
450 | 508 |
451 | 509 |
452 Register Register::new_target() { return Register(kNewTargetRegisterIndex); } | 510 Register Register::new_target() { return Register(kNewTargetRegisterIndex); } |
453 | 511 |
454 | 512 |
455 bool Register::is_new_target() const { | 513 bool Register::is_new_target() const { |
456 return index() == kNewTargetRegisterIndex; | 514 return index() == kNewTargetRegisterIndex; |
457 } | 515 } |
458 | 516 |
459 | |
460 int Register::MaxParameterIndex() { return kMaxParameterIndex; } | 517 int Register::MaxParameterIndex() { return kMaxParameterIndex; } |
461 | 518 |
462 int Register::MaxRegisterIndex() { return kMaxRegisterIndex; } | 519 int Register::MaxRegisterIndex() { return kMaxRegisterIndex; } |
463 | 520 |
464 int Register::MaxRegisterIndexForByteOperand() { return kMaxReg8Index; } | 521 int Register::MaxRegisterIndexForByteOperand() { return kMaxReg8Index; } |
465 | 522 |
466 uint8_t Register::ToOperand() const { | 523 uint8_t Register::ToOperand() const { |
467 DCHECK(is_byte_operand()); | 524 DCHECK(is_byte_operand()); |
468 return static_cast<uint8_t>(-index_); | 525 return static_cast<uint8_t>(-index_); |
469 } | 526 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 } | 565 } |
509 if (reg5.is_valid() && reg4.index() + 1 != reg5.index()) { | 566 if (reg5.is_valid() && reg4.index() + 1 != reg5.index()) { |
510 return false; | 567 return false; |
511 } | 568 } |
512 return true; | 569 return true; |
513 } | 570 } |
514 | 571 |
515 } // namespace interpreter | 572 } // namespace interpreter |
516 } // namespace internal | 573 } // namespace internal |
517 } // namespace v8 | 574 } // namespace v8 |
OLD | NEW |