| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 return ""; | 100 return ""; |
| 101 } | 101 } |
| 102 | 102 |
| 103 // static | 103 // static |
| 104 Bytecode Bytecodes::FromByte(uint8_t value) { | 104 Bytecode Bytecodes::FromByte(uint8_t value) { |
| 105 Bytecode bytecode = static_cast<Bytecode>(value); | 105 Bytecode bytecode = static_cast<Bytecode>(value); |
| 106 DCHECK(bytecode <= Bytecode::kLast); | 106 DCHECK(bytecode <= Bytecode::kLast); |
| 107 return bytecode; | 107 return bytecode; |
| 108 } | 108 } |
| 109 | 109 |
| 110 | |
| 111 // static | 110 // static |
| 112 Bytecode Bytecodes::GetDebugBreak(Bytecode bytecode) { | 111 Bytecode Bytecodes::GetDebugBreak(Bytecode bytecode) { |
| 113 DCHECK(!IsDebugBreak(bytecode)); | 112 DCHECK(!IsDebugBreak(bytecode)); |
| 114 if (bytecode == Bytecode::kWide) { | 113 if (bytecode == Bytecode::kWide) { |
| 115 return Bytecode::kDebugBreakWide; | 114 return Bytecode::kDebugBreakWide; |
| 116 } | 115 } |
| 117 if (bytecode == Bytecode::kExtraWide) { | 116 if (bytecode == Bytecode::kExtraWide) { |
| 118 return Bytecode::kDebugBreakExtraWide; | 117 return Bytecode::kDebugBreakExtraWide; |
| 119 } | 118 } |
| 120 int bytecode_size = Size(bytecode, OperandScale::kSingle); | 119 int bytecode_size = Size(bytecode, OperandScale::kSingle); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 133 int size = 1; | 132 int size = 1; |
| 134 for (int i = 0; i < NumberOfOperands(bytecode); i++) { | 133 for (int i = 0; i < NumberOfOperands(bytecode); i++) { |
| 135 OperandSize operand_size = GetOperandSize(bytecode, i, operand_scale); | 134 OperandSize operand_size = GetOperandSize(bytecode, i, operand_scale); |
| 136 int delta = static_cast<int>(operand_size); | 135 int delta = static_cast<int>(operand_size); |
| 137 DCHECK(base::bits::IsPowerOfTwo32(static_cast<uint32_t>(delta))); | 136 DCHECK(base::bits::IsPowerOfTwo32(static_cast<uint32_t>(delta))); |
| 138 size += delta; | 137 size += delta; |
| 139 } | 138 } |
| 140 return size; | 139 return size; |
| 141 } | 140 } |
| 142 | 141 |
| 143 | |
| 144 // static | 142 // static |
| 145 size_t Bytecodes::ReturnCount(Bytecode bytecode) { | 143 size_t Bytecodes::ReturnCount(Bytecode bytecode) { |
| 146 return bytecode == Bytecode::kReturn ? 1 : 0; | 144 return bytecode == Bytecode::kReturn ? 1 : 0; |
| 147 } | 145 } |
| 148 | 146 |
| 149 // static | 147 // static |
| 150 int Bytecodes::NumberOfOperands(Bytecode bytecode) { | 148 int Bytecodes::NumberOfOperands(Bytecode bytecode) { |
| 151 DCHECK(bytecode <= Bytecode::kLast); | 149 DCHECK(bytecode <= Bytecode::kLast); |
| 152 switch (bytecode) { | 150 switch (bytecode) { |
| 153 #define CASE(Name, ...) \ | 151 #define CASE(Name, ...) \ |
| 154 case Bytecode::k##Name: \ | 152 case Bytecode::k##Name: \ |
| 155 return BytecodeTraits<__VA_ARGS__>::kOperandCount; | 153 return BytecodeTraits<__VA_ARGS__>::kOperandCount; |
| 156 BYTECODE_LIST(CASE) | 154 BYTECODE_LIST(CASE) |
| 157 #undef CASE | 155 #undef CASE |
| 158 } | 156 } |
| 159 UNREACHABLE(); | 157 UNREACHABLE(); |
| 160 return 0; | 158 return 0; |
| 161 } | 159 } |
| 162 | 160 |
| 163 | |
| 164 // static | 161 // static |
| 165 int Bytecodes::NumberOfRegisterOperands(Bytecode bytecode) { | 162 int Bytecodes::NumberOfRegisterOperands(Bytecode bytecode) { |
| 166 DCHECK(bytecode <= Bytecode::kLast); | 163 DCHECK(bytecode <= Bytecode::kLast); |
| 167 switch (bytecode) { | 164 switch (bytecode) { |
| 168 #define CASE(Name, ...) \ | 165 #define CASE(Name, ...) \ |
| 169 case Bytecode::k##Name: \ | 166 case Bytecode::k##Name: \ |
| 170 typedef BytecodeTraits<__VA_ARGS__> Name##Trait; \ | 167 typedef BytecodeTraits<__VA_ARGS__> Name##Trait; \ |
| 171 return Name##Trait::kRegisterOperandCount; | 168 return Name##Trait::kRegisterOperandCount; |
| 172 BYTECODE_LIST(CASE) | 169 BYTECODE_LIST(CASE) |
| 173 #undef CASE | 170 #undef CASE |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 case Bytecode::kLdaFalse: | 267 case Bytecode::kLdaFalse: |
| 271 case Bytecode::kLdaConstant: | 268 case Bytecode::kLdaConstant: |
| 272 case Bytecode::kLdar: | 269 case Bytecode::kLdar: |
| 273 return true; | 270 return true; |
| 274 default: | 271 default: |
| 275 return false; | 272 return false; |
| 276 } | 273 } |
| 277 } | 274 } |
| 278 | 275 |
| 279 // static | 276 // static |
| 277 bool Bytecodes::IsJumpWithoutEffects(Bytecode bytecode) { |
| 278 return IsJump(bytecode) && !IsJumpIfToBoolean(bytecode); |
| 279 } |
| 280 |
| 281 // static |
| 282 bool Bytecodes::IsRegisterLoadWithoutEffects(Bytecode bytecode) { |
| 283 switch (bytecode) { |
| 284 case Bytecode::kMov: |
| 285 case Bytecode::kPopContext: |
| 286 case Bytecode::kPushContext: |
| 287 case Bytecode::kStar: |
| 288 case Bytecode::kLdrUndefined: |
| 289 return true; |
| 290 default: |
| 291 return false; |
| 292 } |
| 293 } |
| 294 |
| 295 // static |
| 296 bool Bytecodes::IsWithoutExternalSideEffects(Bytecode bytecode) { |
| 297 // These bytecodes only manipulate interpreter frame state and will |
| 298 // never throw. |
| 299 return (IsAccumulatorLoadWithoutEffects(bytecode) || |
| 300 IsRegisterLoadWithoutEffects(bytecode) || |
| 301 bytecode == Bytecode::kNop || IsJumpWithoutEffects(bytecode)); |
| 302 } |
| 303 |
| 304 // static |
| 280 OperandType Bytecodes::GetOperandType(Bytecode bytecode, int i) { | 305 OperandType Bytecodes::GetOperandType(Bytecode bytecode, int i) { |
| 281 DCHECK_LE(bytecode, Bytecode::kLast); | 306 DCHECK_LE(bytecode, Bytecode::kLast); |
| 282 DCHECK_LT(i, NumberOfOperands(bytecode)); | 307 DCHECK_LT(i, NumberOfOperands(bytecode)); |
| 283 DCHECK_GE(i, 0); | 308 DCHECK_GE(i, 0); |
| 284 return GetOperandTypes(bytecode)[i]; | 309 return GetOperandTypes(bytecode)[i]; |
| 285 } | 310 } |
| 286 | 311 |
| 287 // static | 312 // static |
| 288 const OperandType* Bytecodes::GetOperandTypes(Bytecode bytecode) { | 313 const OperandType* Bytecodes::GetOperandTypes(Bytecode bytecode) { |
| 289 DCHECK(bytecode <= Bytecode::kLast); | 314 DCHECK(bytecode <= Bytecode::kLast); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 case Bytecode::kDebugBreakExtraWide: | 506 case Bytecode::kDebugBreakExtraWide: |
| 482 case Bytecode::kWide: | 507 case Bytecode::kWide: |
| 483 case Bytecode::kDebugBreakWide: | 508 case Bytecode::kDebugBreakWide: |
| 484 return true; | 509 return true; |
| 485 default: | 510 default: |
| 486 return false; | 511 return false; |
| 487 } | 512 } |
| 488 } | 513 } |
| 489 | 514 |
| 490 // static | 515 // static |
| 491 bool Bytecodes::IsWithoutExternalSideEffects(Bytecode bytecode) { | |
| 492 // These bytecodes only manipulate interpreter frame state and will | |
| 493 // never throw. | |
| 494 return (IsAccumulatorLoadWithoutEffects(bytecode) || IsLdarOrStar(bytecode) || | |
| 495 bytecode == Bytecode::kMov || bytecode == Bytecode::kNop || | |
| 496 IsJump(bytecode)); | |
| 497 } | |
| 498 | |
| 499 // static | |
| 500 bool Bytecodes::IsJumpOrReturn(Bytecode bytecode) { | 516 bool Bytecodes::IsJumpOrReturn(Bytecode bytecode) { |
| 501 return bytecode == Bytecode::kReturn || IsJump(bytecode); | 517 return bytecode == Bytecode::kReturn || IsJump(bytecode); |
| 502 } | 518 } |
| 503 | 519 |
| 504 // static | 520 // static |
| 505 bool Bytecodes::IsMaybeRegisterOperandType(OperandType operand_type) { | 521 bool Bytecodes::IsMaybeRegisterOperandType(OperandType operand_type) { |
| 506 return operand_type == OperandType::kMaybeReg; | 522 return operand_type == OperandType::kMaybeReg; |
| 507 } | 523 } |
| 508 | 524 |
| 509 // static | 525 // static |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 } else { | 988 } else { |
| 973 std::ostringstream s; | 989 std::ostringstream s; |
| 974 s << "r" << index(); | 990 s << "r" << index(); |
| 975 return s.str(); | 991 return s.str(); |
| 976 } | 992 } |
| 977 } | 993 } |
| 978 | 994 |
| 979 } // namespace interpreter | 995 } // namespace interpreter |
| 980 } // namespace internal | 996 } // namespace internal |
| 981 } // namespace v8 | 997 } // namespace v8 |
| OLD | NEW |