| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "src/interpreter/bytecode-register.h" | |
| 6 | |
| 7 #include "src/frames.h" | |
| 8 | |
| 9 namespace v8 { | |
| 10 namespace internal { | |
| 11 namespace interpreter { | |
| 12 | |
| 13 static const int kLastParamRegisterIndex = | |
| 14 (InterpreterFrameConstants::kRegisterFileFromFp - | |
| 15 InterpreterFrameConstants::kLastParamFromFp) / | |
| 16 kPointerSize; | |
| 17 static const int kFunctionClosureRegisterIndex = | |
| 18 (InterpreterFrameConstants::kRegisterFileFromFp - | |
| 19 StandardFrameConstants::kFunctionOffset) / | |
| 20 kPointerSize; | |
| 21 static const int kCurrentContextRegisterIndex = | |
| 22 (InterpreterFrameConstants::kRegisterFileFromFp - | |
| 23 StandardFrameConstants::kContextOffset) / | |
| 24 kPointerSize; | |
| 25 static const int kNewTargetRegisterIndex = | |
| 26 (InterpreterFrameConstants::kRegisterFileFromFp - | |
| 27 InterpreterFrameConstants::kNewTargetFromFp) / | |
| 28 kPointerSize; | |
| 29 static const int kBytecodeArrayRegisterIndex = | |
| 30 (InterpreterFrameConstants::kRegisterFileFromFp - | |
| 31 InterpreterFrameConstants::kBytecodeArrayFromFp) / | |
| 32 kPointerSize; | |
| 33 static const int kBytecodeOffsetRegisterIndex = | |
| 34 (InterpreterFrameConstants::kRegisterFileFromFp - | |
| 35 InterpreterFrameConstants::kBytecodeOffsetFromFp) / | |
| 36 kPointerSize; | |
| 37 static const int kCallerPCOffsetRegisterIndex = | |
| 38 (InterpreterFrameConstants::kRegisterFileFromFp - | |
| 39 InterpreterFrameConstants::kCallerPCOffsetFromFp) / | |
| 40 kPointerSize; | |
| 41 | |
| 42 STATIC_CONST_MEMBER_DEFINITION const int Register::kInvalidIndex = kMaxInt; | |
| 43 STATIC_CONST_MEMBER_DEFINITION const int Register::kRegisterFileStartOffset = | |
| 44 InterpreterFrameConstants::kRegisterFileFromFp / kPointerSize; | |
| 45 | |
| 46 Register Register::FromParameterIndex(int index, int parameter_count) { | |
| 47 DCHECK_GE(index, 0); | |
| 48 DCHECK_LT(index, parameter_count); | |
| 49 int register_index = kLastParamRegisterIndex - parameter_count + index + 1; | |
| 50 DCHECK_LT(register_index, 0); | |
| 51 return Register(register_index); | |
| 52 } | |
| 53 | |
| 54 int Register::ToParameterIndex(int parameter_count) const { | |
| 55 DCHECK(is_parameter()); | |
| 56 return index() - kLastParamRegisterIndex + parameter_count - 1; | |
| 57 } | |
| 58 | |
| 59 Register Register::function_closure() { | |
| 60 return Register(kFunctionClosureRegisterIndex); | |
| 61 } | |
| 62 | |
| 63 bool Register::is_function_closure() const { | |
| 64 return index() == kFunctionClosureRegisterIndex; | |
| 65 } | |
| 66 | |
| 67 Register Register::current_context() { | |
| 68 return Register(kCurrentContextRegisterIndex); | |
| 69 } | |
| 70 | |
| 71 bool Register::is_current_context() const { | |
| 72 return index() == kCurrentContextRegisterIndex; | |
| 73 } | |
| 74 | |
| 75 Register Register::new_target() { return Register(kNewTargetRegisterIndex); } | |
| 76 | |
| 77 bool Register::is_new_target() const { | |
| 78 return index() == kNewTargetRegisterIndex; | |
| 79 } | |
| 80 | |
| 81 Register Register::bytecode_array() { | |
| 82 return Register(kBytecodeArrayRegisterIndex); | |
| 83 } | |
| 84 | |
| 85 bool Register::is_bytecode_array() const { | |
| 86 return index() == kBytecodeArrayRegisterIndex; | |
| 87 } | |
| 88 | |
| 89 Register Register::bytecode_offset() { | |
| 90 return Register(kBytecodeOffsetRegisterIndex); | |
| 91 } | |
| 92 | |
| 93 bool Register::is_bytecode_offset() const { | |
| 94 return index() == kBytecodeOffsetRegisterIndex; | |
| 95 } | |
| 96 | |
| 97 // static | |
| 98 Register Register::virtual_accumulator() { | |
| 99 return Register(kCallerPCOffsetRegisterIndex); | |
| 100 } | |
| 101 | |
| 102 OperandSize Register::SizeOfOperand() const { | |
| 103 int32_t operand = ToOperand(); | |
| 104 if (operand >= kMinInt8 && operand <= kMaxInt8) { | |
| 105 return OperandSize::kByte; | |
| 106 } else if (operand >= kMinInt16 && operand <= kMaxInt16) { | |
| 107 return OperandSize::kShort; | |
| 108 } else { | |
| 109 return OperandSize::kQuad; | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 bool Register::AreContiguous(Register reg1, Register reg2, Register reg3, | |
| 114 Register reg4, Register reg5) { | |
| 115 if (reg1.index() + 1 != reg2.index()) { | |
| 116 return false; | |
| 117 } | |
| 118 if (reg3.is_valid() && reg2.index() + 1 != reg3.index()) { | |
| 119 return false; | |
| 120 } | |
| 121 if (reg4.is_valid() && reg3.index() + 1 != reg4.index()) { | |
| 122 return false; | |
| 123 } | |
| 124 if (reg5.is_valid() && reg4.index() + 1 != reg5.index()) { | |
| 125 return false; | |
| 126 } | |
| 127 return true; | |
| 128 } | |
| 129 | |
| 130 std::string Register::ToString(int parameter_count) { | |
| 131 if (is_current_context()) { | |
| 132 return std::string("<context>"); | |
| 133 } else if (is_function_closure()) { | |
| 134 return std::string("<closure>"); | |
| 135 } else if (is_new_target()) { | |
| 136 return std::string("<new.target>"); | |
| 137 } else if (is_parameter()) { | |
| 138 int parameter_index = ToParameterIndex(parameter_count); | |
| 139 if (parameter_index == 0) { | |
| 140 return std::string("<this>"); | |
| 141 } else { | |
| 142 std::ostringstream s; | |
| 143 s << "a" << parameter_index - 1; | |
| 144 return s.str(); | |
| 145 } | |
| 146 } else { | |
| 147 std::ostringstream s; | |
| 148 s << "r" << index(); | |
| 149 return s.str(); | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 } // namespace interpreter | |
| 154 } // namespace internal | |
| 155 } // namespace v8 | |
| OLD | NEW |