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 namespace v8 { | 7 namespace v8 { |
8 namespace internal { | 8 namespace internal { |
9 namespace interpreter { | 9 namespace interpreter { |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 | 80 |
81 // static | 81 // static |
82 int Bytecodes::MaximumNumberOfOperands() { return kMaxOperands; } | 82 int Bytecodes::MaximumNumberOfOperands() { return kMaxOperands; } |
83 | 83 |
84 | 84 |
85 // static | 85 // static |
86 int Bytecodes::MaximumSize() { return 1 + kMaxOperands; } | 86 int Bytecodes::MaximumSize() { return 1 + kMaxOperands; } |
87 | 87 |
88 | 88 |
| 89 // static |
| 90 std::ostream& Bytecodes::Decode(std::ostream& os, const uint8_t* bytecode_start, |
| 91 const uint8_t* bytecode_end) { |
| 92 Vector<char> buf = Vector<char>::New(50); |
| 93 |
| 94 DCHECK_NE(bytecode_start, bytecode_end); |
| 95 Bytecode bytecode = Bytecodes::FromByte(bytecode_start[0]); |
| 96 int bytecode_size = Bytecodes::Size(bytecode); |
| 97 DCHECK_EQ(bytecode_end, bytecode_start + bytecode_size); |
| 98 |
| 99 for (int i = 0; i < bytecode_size; i++) { |
| 100 SNPrintF(buf, "%02x ", bytecode_start[i]); |
| 101 os << buf.start(); |
| 102 } |
| 103 for (int i = bytecode_size; i < Bytecodes::MaximumSize(); i++) { |
| 104 os << " "; |
| 105 } |
| 106 |
| 107 os << bytecode << " "; |
| 108 |
| 109 const uint8_t* operands_start = bytecode_start + 1; |
| 110 int operands_size = bytecode_size - 1; |
| 111 for (int i = 0; i < operands_size; i++) { |
| 112 OperandType op_type = GetOperandType(bytecode, i); |
| 113 uint8_t operand = operands_start[i]; |
| 114 switch (op_type) { |
| 115 case interpreter::OperandType::kImm8: |
| 116 os << "#" << static_cast<int>(operand); |
| 117 break; |
| 118 case interpreter::OperandType::kReg: |
| 119 os << "r" << static_cast<int>(operand); |
| 120 break; |
| 121 case interpreter::OperandType::kNone: |
| 122 UNREACHABLE(); |
| 123 break; |
| 124 } |
| 125 if (i != operands_size - 1) { |
| 126 os << ", "; |
| 127 } |
| 128 } |
| 129 return os; |
| 130 } |
| 131 |
| 132 |
89 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode) { | 133 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode) { |
90 return os << Bytecodes::ToString(bytecode); | 134 return os << Bytecodes::ToString(bytecode); |
91 } | 135 } |
92 | 136 |
93 } // namespace interpreter | 137 } // namespace interpreter |
94 } // namespace internal | 138 } // namespace internal |
95 } // namespace v8 | 139 } // namespace v8 |
OLD | NEW |