| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 "test/cctest/interpreter/bytecode-expectations-printer.h" | 5 #include "test/cctest/interpreter/bytecode-expectations-printer.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "include/libplatform/libplatform.h" | 10 #include "include/libplatform/libplatform.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 stream << "\\\\"; | 89 stream << "\\\\"; |
| 90 break; | 90 break; |
| 91 default: | 91 default: |
| 92 stream << c; | 92 stream << c; |
| 93 break; | 93 break; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 namespace { | 98 namespace { |
| 99 i::Runtime::FunctionId IndexToFunctionId(int index) { | 99 i::Runtime::FunctionId IndexToFunctionId(uint32_t index) { |
| 100 return static_cast<i::Runtime::FunctionId>(index); | 100 return static_cast<i::Runtime::FunctionId>(index); |
| 101 } | 101 } |
| 102 } // namespace | 102 } // namespace |
| 103 | 103 |
| 104 void BytecodeExpectationsPrinter::PrintBytecodeOperand( | 104 void BytecodeExpectationsPrinter::PrintBytecodeOperand( |
| 105 std::ostream& stream, const BytecodeArrayIterator& bytecode_iter, | 105 std::ostream& stream, const BytecodeArrayIterator& bytecode_iter, |
| 106 const Bytecode& bytecode, int op_index, int parameter_count) const { | 106 const Bytecode& bytecode, int op_index, int parameter_count) const { |
| 107 OperandType op_type = Bytecodes::GetOperandType(bytecode, op_index); | 107 OperandType op_type = Bytecodes::GetOperandType(bytecode, op_index); |
| 108 OperandSize op_size = Bytecodes::GetOperandSize(bytecode, op_index); | 108 OperandSize op_size = Bytecodes::GetOperandSize( |
| 109 bytecode, op_index, bytecode_iter.current_operand_scale()); |
| 109 | 110 |
| 110 const char* size_tag; | 111 const char* size_tag; |
| 111 switch (op_size) { | 112 switch (op_size) { |
| 112 case OperandSize::kByte: | 113 case OperandSize::kByte: |
| 113 size_tag = "8"; | 114 size_tag = "8"; |
| 114 break; | 115 break; |
| 115 case OperandSize::kShort: | 116 case OperandSize::kShort: |
| 116 size_tag = "16"; | 117 size_tag = "16"; |
| 117 break; | 118 break; |
| 119 case OperandSize::kQuad: |
| 120 size_tag = "32"; |
| 121 break; |
| 118 default: | 122 default: |
| 119 UNREACHABLE(); | 123 UNREACHABLE(); |
| 120 return; | 124 return; |
| 121 } | 125 } |
| 122 | 126 |
| 123 if (Bytecodes::IsRegisterOperandType(op_type)) { | 127 if (Bytecodes::IsRegisterOperandType(op_type)) { |
| 124 Register register_value = bytecode_iter.GetRegisterOperand(op_index); | 128 Register register_value = bytecode_iter.GetRegisterOperand(op_index); |
| 125 stream << 'R'; | 129 stream << 'R'; |
| 126 if (op_size != OperandSize::kByte) stream << size_tag; | 130 if (op_size != OperandSize::kByte) stream << size_tag; |
| 127 if (register_value.is_new_target()) { | 131 if (register_value.is_new_target()) { |
| 128 stream << "(new_target)"; | 132 stream << "(new_target)"; |
| 129 } else if (register_value.is_current_context()) { | 133 } else if (register_value.is_current_context()) { |
| 130 stream << "(context)"; | 134 stream << "(context)"; |
| 131 } else if (register_value.is_function_closure()) { | 135 } else if (register_value.is_function_closure()) { |
| 132 stream << "(closure)"; | 136 stream << "(closure)"; |
| 133 } else if (register_value.is_parameter()) { | 137 } else if (register_value.is_parameter()) { |
| 134 int parameter_index = register_value.ToParameterIndex(parameter_count); | 138 int parameter_index = register_value.ToParameterIndex(parameter_count); |
| 135 if (parameter_index == 0) { | 139 if (parameter_index == 0) { |
| 136 stream << "(this)"; | 140 stream << "(this)"; |
| 137 } else { | 141 } else { |
| 138 stream << "(arg" << (parameter_index - 1) << ')'; | 142 stream << "(arg" << (parameter_index - 1) << ')'; |
| 139 } | 143 } |
| 140 } else { | 144 } else { |
| 141 stream << '(' << register_value.index() << ')'; | 145 stream << '(' << register_value.index() << ')'; |
| 142 } | 146 } |
| 143 } else { | 147 } else { |
| 144 stream << 'U' << size_tag << '('; | 148 stream << 'U' << size_tag << '('; |
| 145 | 149 |
| 146 if (op_index == 0 && Bytecodes::IsCallRuntime(bytecode)) { | 150 switch (op_type) { |
| 147 DCHECK_EQ(op_type, OperandType::kIdx16); | 151 case OperandType::kFlag8: |
| 148 int operand = bytecode_iter.GetIndexOperand(op_index); | 152 stream << bytecode_iter.GetFlagOperand(op_index); |
| 149 stream << "Runtime::k" | 153 break; |
| 150 << i::Runtime::FunctionForId(IndexToFunctionId(operand))->name; | 154 case OperandType::kIdx: |
| 151 } else if (Bytecodes::IsImmediateOperandType(op_type)) { | 155 stream << bytecode_iter.GetIndexOperand(op_index); |
| 152 // We need a cast, otherwise the result is printed as char. | 156 break; |
| 153 stream << static_cast<int>(bytecode_iter.GetImmediateOperand(op_index)); | 157 case OperandType::kImm: |
| 154 } else if (Bytecodes::IsRegisterCountOperandType(op_type)) { | 158 stream << bytecode_iter.GetImmediateOperand(op_index); |
| 155 stream << bytecode_iter.GetRegisterCountOperand(op_index); | 159 break; |
| 156 } else if (Bytecodes::IsIndexOperandType(op_type)) { | 160 case OperandType::kRegCount: |
| 157 stream << bytecode_iter.GetIndexOperand(op_index); | 161 stream << bytecode_iter.GetRegisterCountOperand(op_index); |
| 158 } else { | 162 break; |
| 159 UNREACHABLE(); | 163 case OperandType::kRuntimeId: { |
| 164 uint32_t operand = bytecode_iter.GetRuntimeIdOperand(op_index); |
| 165 stream << "Runtime::k" |
| 166 << i::Runtime::FunctionForId(IndexToFunctionId(operand))->name; |
| 167 break; |
| 168 } |
| 169 default: |
| 170 UNREACHABLE(); |
| 160 } | 171 } |
| 161 | 172 |
| 162 stream << ')'; | 173 stream << ')'; |
| 163 } | 174 } |
| 164 } | 175 } |
| 165 | 176 |
| 166 void BytecodeExpectationsPrinter::PrintBytecode( | 177 void BytecodeExpectationsPrinter::PrintBytecode( |
| 167 std::ostream& stream, const BytecodeArrayIterator& bytecode_iter, | 178 std::ostream& stream, const BytecodeArrayIterator& bytecode_iter, |
| 168 int parameter_count) const { | 179 int parameter_count) const { |
| 169 Bytecode bytecode = bytecode_iter.current_bytecode(); | 180 Bytecode bytecode = bytecode_iter.current_bytecode(); |
| 170 | 181 OperandScale operand_scale = bytecode_iter.current_operand_scale(); |
| 182 if (Bytecodes::OperandScaleRequiresPrefixBytecode(operand_scale)) { |
| 183 Bytecode prefix = Bytecodes::OperandScaleToPrefixBytecode(operand_scale); |
| 184 stream << "B(" << Bytecodes::ToString(prefix) << "), "; |
| 185 } |
| 171 stream << "B(" << Bytecodes::ToString(bytecode) << ')'; | 186 stream << "B(" << Bytecodes::ToString(bytecode) << ')'; |
| 172 | |
| 173 int operands_count = Bytecodes::NumberOfOperands(bytecode); | 187 int operands_count = Bytecodes::NumberOfOperands(bytecode); |
| 174 for (int op_index = 0; op_index < operands_count; ++op_index) { | 188 for (int op_index = 0; op_index < operands_count; ++op_index) { |
| 175 stream << ", "; | 189 stream << ", "; |
| 176 PrintBytecodeOperand(stream, bytecode_iter, bytecode, op_index, | 190 PrintBytecodeOperand(stream, bytecode_iter, bytecode, op_index, |
| 177 parameter_count); | 191 parameter_count); |
| 178 } | 192 } |
| 179 } | 193 } |
| 180 | 194 |
| 181 void BytecodeExpectationsPrinter::PrintV8String(std::ostream& stream, | 195 void BytecodeExpectationsPrinter::PrintV8String(std::ostream& stream, |
| 182 i::String* string) const { | 196 i::String* string) const { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 318 |
| 305 stream << "---\n"; | 319 stream << "---\n"; |
| 306 PrintCodeSnippet(stream, snippet); | 320 PrintCodeSnippet(stream, snippet); |
| 307 PrintBytecodeArray(stream, bytecode_array); | 321 PrintBytecodeArray(stream, bytecode_array); |
| 308 stream << '\n'; | 322 stream << '\n'; |
| 309 } | 323 } |
| 310 | 324 |
| 311 } // namespace interpreter | 325 } // namespace interpreter |
| 312 } // namespace internal | 326 } // namespace internal |
| 313 } // namespace v8 | 327 } // namespace v8 |
| OLD | NEW |