5 #include "src/interpreter/bytecode-register.h" 9 namespace interpreter {
11 static const int kLastParamRegisterIndex =
12 (InterpreterFrameConstants::kRegisterFileFromFp -
13 InterpreterFrameConstants::kLastParamFromFp) /
15 static const int kFunctionClosureRegisterIndex =
16 (InterpreterFrameConstants::kRegisterFileFromFp -
17 StandardFrameConstants::kFunctionOffset) /
19 static const int kCurrentContextRegisterIndex =
20 (InterpreterFrameConstants::kRegisterFileFromFp -
21 StandardFrameConstants::kContextOffset) /
23 static const int kBytecodeArrayRegisterIndex =
24 (InterpreterFrameConstants::kRegisterFileFromFp -
25 InterpreterFrameConstants::kBytecodeArrayFromFp) /
27 static const int kBytecodeOffsetRegisterIndex =
28 (InterpreterFrameConstants::kRegisterFileFromFp -
29 InterpreterFrameConstants::kBytecodeOffsetFromFp) /
31 static const int kCallerPCOffsetRegisterIndex =
32 (InterpreterFrameConstants::kRegisterFileFromFp -
33 InterpreterFrameConstants::kCallerPCOffsetFromFp) /
36 Register Register::FromParameterIndex(
int index,
int parameter_count) {
38 DCHECK_LT(index, parameter_count);
39 int register_index = kLastParamRegisterIndex - parameter_count + index + 1;
40 DCHECK_LT(register_index, 0);
41 return Register(register_index);
44 int Register::ToParameterIndex(
int parameter_count)
const {
45 DCHECK(is_parameter());
46 return index() - kLastParamRegisterIndex + parameter_count - 1;
49 Register Register::function_closure() {
50 return Register(kFunctionClosureRegisterIndex);
53 bool Register::is_function_closure()
const {
54 return index() == kFunctionClosureRegisterIndex;
57 Register Register::current_context() {
58 return Register(kCurrentContextRegisterIndex);
61 bool Register::is_current_context()
const {
62 return index() == kCurrentContextRegisterIndex;
65 Register Register::bytecode_array() {
66 return Register(kBytecodeArrayRegisterIndex);
69 bool Register::is_bytecode_array()
const {
70 return index() == kBytecodeArrayRegisterIndex;
73 Register Register::bytecode_offset() {
74 return Register(kBytecodeOffsetRegisterIndex);
77 bool Register::is_bytecode_offset()
const {
78 return index() == kBytecodeOffsetRegisterIndex;
82 Register Register::virtual_accumulator() {
83 return Register(kCallerPCOffsetRegisterIndex);
86 OperandSize Register::SizeOfOperand()
const {
87 int32_t operand = ToOperand();
88 if (operand >= kMinInt8 && operand <= kMaxInt8) {
89 return OperandSize::kByte;
90 }
else if (operand >= kMinInt16 && operand <= kMaxInt16) {
91 return OperandSize::kShort;
93 return OperandSize::kQuad;
97 bool Register::AreContiguous(Register reg1, Register reg2, Register reg3,
98 Register reg4, Register reg5) {
99 if (reg1.index() + 1 != reg2.index()) {
102 if (reg3.is_valid() && reg2.index() + 1 != reg3.index()) {
105 if (reg4.is_valid() && reg3.index() + 1 != reg4.index()) {
108 if (reg5.is_valid() && reg4.index() + 1 != reg5.index()) {
114 std::string Register::ToString(
int parameter_count)
const {
115 if (is_current_context()) {
116 return std::string(
"<context>");
117 }
else if (is_function_closure()) {
118 return std::string(
"<closure>");
119 }
else if (is_parameter()) {
120 int parameter_index = ToParameterIndex(parameter_count);
121 if (parameter_index == 0) {
122 return std::string(
"<this>");
124 std::ostringstream s;
125 s <<
"a" << parameter_index - 1;
129 std::ostringstream s;