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 if (Bytecodes::IsRuntimeIdOperandType(op_type)) { |
147 DCHECK_EQ(op_type, OperandType::kIdx16); | 151 uint32_t operand = bytecode_iter.GetRuntimeIdOperand(op_index); |
148 int operand = bytecode_iter.GetIndexOperand(op_index); | |
149 stream << "Runtime::k" | 152 stream << "Runtime::k" |
150 << i::Runtime::FunctionForId(IndexToFunctionId(operand))->name; | 153 << i::Runtime::FunctionForId(IndexToFunctionId(operand))->name; |
151 } else if (Bytecodes::IsImmediateOperandType(op_type)) { | 154 } else if (Bytecodes::IsImmediateOperandType(op_type)) { |
152 // We need a cast, otherwise the result is printed as char. | 155 stream << bytecode_iter.GetImmediateOperand(op_index); |
153 stream << static_cast<int>(bytecode_iter.GetImmediateOperand(op_index)); | |
154 } else if (Bytecodes::IsRegisterCountOperandType(op_type)) { | 156 } else if (Bytecodes::IsRegisterCountOperandType(op_type)) { |
155 stream << bytecode_iter.GetRegisterCountOperand(op_index); | 157 stream << bytecode_iter.GetRegisterCountOperand(op_index); |
| 158 } else if (Bytecodes::IsFlagOperandType(op_type)) { |
| 159 stream << bytecode_iter.GetFlagOperand(op_index); |
156 } else if (Bytecodes::IsIndexOperandType(op_type)) { | 160 } else if (Bytecodes::IsIndexOperandType(op_type)) { |
157 stream << bytecode_iter.GetIndexOperand(op_index); | 161 stream << bytecode_iter.GetIndexOperand(op_index); |
158 } else { | 162 } else { |
159 UNREACHABLE(); | 163 UNREACHABLE(); |
160 } | 164 } |
161 | 165 |
162 stream << ')'; | 166 stream << ')'; |
163 } | 167 } |
164 } | 168 } |
165 | 169 |
166 void BytecodeExpectationsPrinter::PrintBytecode( | 170 void BytecodeExpectationsPrinter::PrintBytecode( |
167 std::ostream& stream, const BytecodeArrayIterator& bytecode_iter, | 171 std::ostream& stream, const BytecodeArrayIterator& bytecode_iter, |
168 int parameter_count) const { | 172 int parameter_count) const { |
169 Bytecode bytecode = bytecode_iter.current_bytecode(); | 173 Bytecode bytecode = bytecode_iter.current_bytecode(); |
170 | 174 |
| 175 switch (bytecode_iter.current_operand_scale()) { |
| 176 case 1: |
| 177 break; |
| 178 case 2: |
| 179 stream << "B(" << Bytecodes::ToString(Bytecode::kWide) << "), "; |
| 180 break; |
| 181 case 4: |
| 182 stream << "B(" << Bytecodes::ToString(Bytecode::kExtraWide) << "), "; |
| 183 break; |
| 184 default: |
| 185 UNREACHABLE(); |
| 186 break; |
| 187 } |
171 stream << "B(" << Bytecodes::ToString(bytecode) << ')'; | 188 stream << "B(" << Bytecodes::ToString(bytecode) << ')'; |
172 | 189 |
173 int operands_count = Bytecodes::NumberOfOperands(bytecode); | 190 int operands_count = Bytecodes::NumberOfOperands(bytecode); |
174 for (int op_index = 0; op_index < operands_count; ++op_index) { | 191 for (int op_index = 0; op_index < operands_count; ++op_index) { |
175 stream << ", "; | 192 stream << ", "; |
176 PrintBytecodeOperand(stream, bytecode_iter, bytecode, op_index, | 193 PrintBytecodeOperand(stream, bytecode_iter, bytecode, op_index, |
177 parameter_count); | 194 parameter_count); |
178 } | 195 } |
179 } | 196 } |
180 | 197 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 321 |
305 stream << "---\n"; | 322 stream << "---\n"; |
306 PrintCodeSnippet(stream, snippet); | 323 PrintCodeSnippet(stream, snippet); |
307 PrintBytecodeArray(stream, bytecode_array); | 324 PrintBytecodeArray(stream, bytecode_array); |
308 stream << '\n'; | 325 stream << '\n'; |
309 } | 326 } |
310 | 327 |
311 } // namespace interpreter | 328 } // namespace interpreter |
312 } // namespace internal | 329 } // namespace internal |
313 } // namespace v8 | 330 } // namespace v8 |
OLD | NEW |