| 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 <iomanip> | 7 #include <iomanip> |
| 8 | 8 |
| 9 #include "src/frames.h" | 9 #include "src/frames.h" |
| 10 #include "src/interpreter/bytecode-traits.h" | 10 #include "src/interpreter/bytecode-traits.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 if (operand_scale > OperandScale::kSingle) { | 35 if (operand_scale > OperandScale::kSingle) { |
| 36 Bytecode prefix_bytecode = OperandScaleToPrefixBytecode(operand_scale); | 36 Bytecode prefix_bytecode = OperandScaleToPrefixBytecode(operand_scale); |
| 37 std::string suffix = ToString(prefix_bytecode); | 37 std::string suffix = ToString(prefix_bytecode); |
| 38 return value.append(1, kSeparator).append(suffix); | 38 return value.append(1, kSeparator).append(suffix); |
| 39 } else { | 39 } else { |
| 40 return value; | 40 return value; |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 // static | 44 // static |
| 45 const char* Bytecodes::AccumulatorUseToString(AccumulatorUse accumulator_use) { |
| 46 switch (accumulator_use) { |
| 47 case AccumulatorUse::kNone: |
| 48 return "None"; |
| 49 case AccumulatorUse::kRead: |
| 50 return "Read"; |
| 51 case AccumulatorUse::kWrite: |
| 52 return "Write"; |
| 53 case AccumulatorUse::kReadWrite: |
| 54 return "ReadWrite"; |
| 55 } |
| 56 UNREACHABLE(); |
| 57 return ""; |
| 58 } |
| 59 |
| 60 // static |
| 45 const char* Bytecodes::OperandTypeToString(OperandType operand_type) { | 61 const char* Bytecodes::OperandTypeToString(OperandType operand_type) { |
| 46 switch (operand_type) { | 62 switch (operand_type) { |
| 47 #define CASE(Name, _) \ | 63 #define CASE(Name, _) \ |
| 48 case OperandType::k##Name: \ | 64 case OperandType::k##Name: \ |
| 49 return #Name; | 65 return #Name; |
| 50 OPERAND_TYPE_LIST(CASE) | 66 OPERAND_TYPE_LIST(CASE) |
| 51 #undef CASE | 67 #undef CASE |
| 52 } | 68 } |
| 53 UNREACHABLE(); | 69 UNREACHABLE(); |
| 54 return ""; | 70 return ""; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 return size; | 149 return size; |
| 134 } | 150 } |
| 135 | 151 |
| 136 | 152 |
| 137 // static | 153 // static |
| 138 int Bytecodes::NumberOfOperands(Bytecode bytecode) { | 154 int Bytecodes::NumberOfOperands(Bytecode bytecode) { |
| 139 DCHECK(bytecode <= Bytecode::kLast); | 155 DCHECK(bytecode <= Bytecode::kLast); |
| 140 switch (bytecode) { | 156 switch (bytecode) { |
| 141 #define CASE(Name, ...) \ | 157 #define CASE(Name, ...) \ |
| 142 case Bytecode::k##Name: \ | 158 case Bytecode::k##Name: \ |
| 143 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::kOperandCount; | 159 return BytecodeTraits<__VA_ARGS__>::kOperandCount; |
| 144 BYTECODE_LIST(CASE) | 160 BYTECODE_LIST(CASE) |
| 145 #undef CASE | 161 #undef CASE |
| 146 } | 162 } |
| 147 UNREACHABLE(); | 163 UNREACHABLE(); |
| 148 return 0; | 164 return 0; |
| 149 } | 165 } |
| 150 | 166 |
| 151 | 167 |
| 152 // static | 168 // static |
| 153 int Bytecodes::NumberOfRegisterOperands(Bytecode bytecode) { | 169 int Bytecodes::NumberOfRegisterOperands(Bytecode bytecode) { |
| 154 DCHECK(bytecode <= Bytecode::kLast); | 170 DCHECK(bytecode <= Bytecode::kLast); |
| 155 switch (bytecode) { | 171 switch (bytecode) { |
| 156 #define CASE(Name, ...) \ | 172 #define CASE(Name, ...) \ |
| 157 case Bytecode::k##Name: \ | 173 case Bytecode::k##Name: \ |
| 158 typedef BytecodeTraits<__VA_ARGS__, OPERAND_TERM> Name##Trait; \ | 174 typedef BytecodeTraits<__VA_ARGS__> Name##Trait; \ |
| 159 return Name##Trait::kRegisterOperandCount; | 175 return Name##Trait::kRegisterOperandCount; |
| 160 BYTECODE_LIST(CASE) | 176 BYTECODE_LIST(CASE) |
| 161 #undef CASE | 177 #undef CASE |
| 162 } | 178 } |
| 163 UNREACHABLE(); | 179 UNREACHABLE(); |
| 164 return false; | 180 return false; |
| 165 } | 181 } |
| 166 | 182 |
| 167 // static | 183 // static |
| 168 Bytecode Bytecodes::OperandScaleToPrefixBytecode(OperandScale operand_scale) { | 184 Bytecode Bytecodes::OperandScaleToPrefixBytecode(OperandScale operand_scale) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 191 case Bytecode::kWide: | 207 case Bytecode::kWide: |
| 192 case Bytecode::kDebugBreakWide: | 208 case Bytecode::kDebugBreakWide: |
| 193 return OperandScale::kDouble; | 209 return OperandScale::kDouble; |
| 194 default: | 210 default: |
| 195 UNREACHABLE(); | 211 UNREACHABLE(); |
| 196 return OperandScale::kSingle; | 212 return OperandScale::kSingle; |
| 197 } | 213 } |
| 198 } | 214 } |
| 199 | 215 |
| 200 // static | 216 // static |
| 217 AccumulatorUse Bytecodes::GetAccumulatorUse(Bytecode bytecode) { |
| 218 DCHECK(bytecode <= Bytecode::kLast); |
| 219 switch (bytecode) { |
| 220 #define CASE(Name, ...) \ |
| 221 case Bytecode::k##Name: \ |
| 222 return BytecodeTraits<__VA_ARGS__>::kAccumulatorUse; |
| 223 BYTECODE_LIST(CASE) |
| 224 #undef CASE |
| 225 } |
| 226 UNREACHABLE(); |
| 227 return AccumulatorUse::kNone; |
| 228 } |
| 229 |
| 230 // static |
| 231 bool Bytecodes::ReadsAccumulator(Bytecode bytecode) { |
| 232 return (GetAccumulatorUse(bytecode) & AccumulatorUse::kRead) == |
| 233 AccumulatorUse::kRead; |
| 234 } |
| 235 |
| 236 // static |
| 237 bool Bytecodes::WritesAccumulator(Bytecode bytecode) { |
| 238 return (GetAccumulatorUse(bytecode) & AccumulatorUse::kWrite) == |
| 239 AccumulatorUse::kWrite; |
| 240 } |
| 241 |
| 242 // static |
| 201 OperandType Bytecodes::GetOperandType(Bytecode bytecode, int i) { | 243 OperandType Bytecodes::GetOperandType(Bytecode bytecode, int i) { |
| 202 DCHECK(bytecode <= Bytecode::kLast); | 244 DCHECK(bytecode <= Bytecode::kLast); |
| 203 switch (bytecode) { | 245 switch (bytecode) { |
| 204 #define CASE(Name, ...) \ | 246 #define CASE(Name, ...) \ |
| 205 case Bytecode::k##Name: \ | 247 case Bytecode::k##Name: \ |
| 206 return BytecodeTraits<__VA_ARGS__, OPERAND_TERM>::GetOperandType(i); | 248 return BytecodeTraits<__VA_ARGS__>::GetOperandType(i); |
| 207 BYTECODE_LIST(CASE) | 249 BYTECODE_LIST(CASE) |
| 208 #undef CASE | 250 #undef CASE |
| 209 } | 251 } |
| 210 UNREACHABLE(); | 252 UNREACHABLE(); |
| 211 return OperandType::kNone; | 253 return OperandType::kNone; |
| 212 } | 254 } |
| 213 | 255 |
| 214 // static | 256 // static |
| 215 OperandSize Bytecodes::GetOperandSize(Bytecode bytecode, int i, | 257 OperandSize Bytecodes::GetOperandSize(Bytecode bytecode, int i, |
| 216 OperandScale operand_scale) { | 258 OperandScale operand_scale) { |
| 217 OperandType op_type = GetOperandType(bytecode, i); | 259 OperandType op_type = GetOperandType(bytecode, i); |
| 218 return ScaledOperandSize(op_type, operand_scale); | 260 return ScaledOperandSize(op_type, operand_scale); |
| 219 } | 261 } |
| 220 | 262 |
| 221 // static | 263 // static |
| 222 int Bytecodes::GetRegisterOperandBitmap(Bytecode bytecode) { | 264 int Bytecodes::GetRegisterOperandBitmap(Bytecode bytecode) { |
| 223 DCHECK(bytecode <= Bytecode::kLast); | 265 DCHECK(bytecode <= Bytecode::kLast); |
| 224 switch (bytecode) { | 266 switch (bytecode) { |
| 225 #define CASE(Name, ...) \ | 267 #define CASE(Name, ...) \ |
| 226 case Bytecode::k##Name: \ | 268 case Bytecode::k##Name: \ |
| 227 typedef BytecodeTraits<__VA_ARGS__, OPERAND_TERM> Name##Trait; \ | 269 typedef BytecodeTraits<__VA_ARGS__> Name##Trait; \ |
| 228 return Name##Trait::kRegisterOperandBitmap; | 270 return Name##Trait::kRegisterOperandBitmap; |
| 229 BYTECODE_LIST(CASE) | 271 BYTECODE_LIST(CASE) |
| 230 #undef CASE | 272 #undef CASE |
| 231 } | 273 } |
| 232 UNREACHABLE(); | 274 UNREACHABLE(); |
| 233 return false; | 275 return false; |
| 234 } | 276 } |
| 235 | 277 |
| 236 // static | 278 // static |
| 237 int Bytecodes::GetOperandOffset(Bytecode bytecode, int i, | 279 int Bytecodes::GetOperandOffset(Bytecode bytecode, int i, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 return true; | 365 return true; |
| 324 default: | 366 default: |
| 325 break; | 367 break; |
| 326 } | 368 } |
| 327 return false; | 369 return false; |
| 328 } | 370 } |
| 329 | 371 |
| 330 // static | 372 // static |
| 331 bool Bytecodes::IsBytecodeWithScalableOperands(Bytecode bytecode) { | 373 bool Bytecodes::IsBytecodeWithScalableOperands(Bytecode bytecode) { |
| 332 switch (bytecode) { | 374 switch (bytecode) { |
| 333 #define CASE(Name, ...) \ | 375 #define CASE(Name, ...) \ |
| 334 case Bytecode::k##Name: \ | 376 case Bytecode::k##Name: \ |
| 335 typedef BytecodeTraits<__VA_ARGS__, OPERAND_TERM> Name##Trait; \ | 377 typedef BytecodeTraits<__VA_ARGS__> Name##Trait; \ |
| 336 return Name##Trait::IsScalable(); | 378 return Name##Trait::IsScalable(); |
| 337 BYTECODE_LIST(CASE) | 379 BYTECODE_LIST(CASE) |
| 338 #undef CASE | 380 #undef CASE |
| 339 } | 381 } |
| 340 UNREACHABLE(); | 382 UNREACHABLE(); |
| 341 return false; | 383 return false; |
| 342 } | 384 } |
| 343 | 385 |
| 344 // static | 386 // static |
| 345 bool Bytecodes::IsPrefixScalingBytecode(Bytecode bytecode) { | 387 bool Bytecodes::IsPrefixScalingBytecode(Bytecode bytecode) { |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 os << ", "; | 613 os << ", "; |
| 572 } | 614 } |
| 573 } | 615 } |
| 574 return os; | 616 return os; |
| 575 } | 617 } |
| 576 | 618 |
| 577 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode) { | 619 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode) { |
| 578 return os << Bytecodes::ToString(bytecode); | 620 return os << Bytecodes::ToString(bytecode); |
| 579 } | 621 } |
| 580 | 622 |
| 623 std::ostream& operator<<(std::ostream& os, const AccumulatorUse& use) { |
| 624 return os << Bytecodes::AccumulatorUseToString(use); |
| 625 } |
| 626 |
| 581 std::ostream& operator<<(std::ostream& os, const OperandSize& operand_size) { | 627 std::ostream& operator<<(std::ostream& os, const OperandSize& operand_size) { |
| 582 return os << Bytecodes::OperandSizeToString(operand_size); | 628 return os << Bytecodes::OperandSizeToString(operand_size); |
| 583 } | 629 } |
| 584 | 630 |
| 585 std::ostream& operator<<(std::ostream& os, const OperandScale& operand_scale) { | 631 std::ostream& operator<<(std::ostream& os, const OperandScale& operand_scale) { |
| 586 return os << Bytecodes::OperandScaleToString(operand_scale); | 632 return os << Bytecodes::OperandScaleToString(operand_scale); |
| 587 } | 633 } |
| 588 | 634 |
| 589 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type) { | 635 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type) { |
| 590 return os << Bytecodes::OperandTypeToString(operand_type); | 636 return os << Bytecodes::OperandTypeToString(operand_type); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 } else { | 731 } else { |
| 686 std::ostringstream s; | 732 std::ostringstream s; |
| 687 s << "r" << index(); | 733 s << "r" << index(); |
| 688 return s.str(); | 734 return s.str(); |
| 689 } | 735 } |
| 690 } | 736 } |
| 691 | 737 |
| 692 } // namespace interpreter | 738 } // namespace interpreter |
| 693 } // namespace internal | 739 } // namespace internal |
| 694 } // namespace v8 | 740 } // namespace v8 |
| OLD | NEW |