Line data Source code
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 : namespace v8 {
8 : namespace internal {
9 : namespace interpreter {
10 :
11 : static const int kLastParamRegisterIndex =
12 : (InterpreterFrameConstants::kRegisterFileFromFp -
13 : InterpreterFrameConstants::kLastParamFromFp) /
14 : kSystemPointerSize;
15 : static const int kFunctionClosureRegisterIndex =
16 : (InterpreterFrameConstants::kRegisterFileFromFp -
17 : StandardFrameConstants::kFunctionOffset) /
18 : kSystemPointerSize;
19 : static const int kCurrentContextRegisterIndex =
20 : (InterpreterFrameConstants::kRegisterFileFromFp -
21 : StandardFrameConstants::kContextOffset) /
22 : kSystemPointerSize;
23 : static const int kBytecodeArrayRegisterIndex =
24 : (InterpreterFrameConstants::kRegisterFileFromFp -
25 : InterpreterFrameConstants::kBytecodeArrayFromFp) /
26 : kSystemPointerSize;
27 : static const int kBytecodeOffsetRegisterIndex =
28 : (InterpreterFrameConstants::kRegisterFileFromFp -
29 : InterpreterFrameConstants::kBytecodeOffsetFromFp) /
30 : kSystemPointerSize;
31 : static const int kCallerPCOffsetRegisterIndex =
32 : (InterpreterFrameConstants::kRegisterFileFromFp -
33 : InterpreterFrameConstants::kCallerPCOffsetFromFp) /
34 : kSystemPointerSize;
35 :
36 6145389 : Register Register::FromParameterIndex(int index, int parameter_count) {
37 : DCHECK_GE(index, 0);
38 : DCHECK_LT(index, parameter_count);
39 6145389 : int register_index = kLastParamRegisterIndex - parameter_count + index + 1;
40 : DCHECK_LT(register_index, 0);
41 6145389 : return Register(register_index);
42 : }
43 :
44 941694 : int Register::ToParameterIndex(int parameter_count) const {
45 : DCHECK(is_parameter());
46 941695 : return index() - kLastParamRegisterIndex + parameter_count - 1;
47 : }
48 :
49 284420 : Register Register::function_closure() {
50 284420 : return Register(kFunctionClosureRegisterIndex);
51 : }
52 :
53 5249319 : bool Register::is_function_closure() const {
54 5249319 : return index() == kFunctionClosureRegisterIndex;
55 : }
56 :
57 2624488 : Register Register::current_context() {
58 2624488 : return Register(kCurrentContextRegisterIndex);
59 : }
60 :
61 9272065 : bool Register::is_current_context() const {
62 9272065 : return index() == kCurrentContextRegisterIndex;
63 : }
64 :
65 26208 : Register Register::bytecode_array() {
66 26208 : return Register(kBytecodeArrayRegisterIndex);
67 : }
68 :
69 0 : bool Register::is_bytecode_array() const {
70 0 : return index() == kBytecodeArrayRegisterIndex;
71 : }
72 :
73 58589 : Register Register::bytecode_offset() {
74 58589 : return Register(kBytecodeOffsetRegisterIndex);
75 : }
76 :
77 0 : bool Register::is_bytecode_offset() const {
78 0 : return index() == kBytecodeOffsetRegisterIndex;
79 : }
80 :
81 : // static
82 2135951 : Register Register::virtual_accumulator() {
83 2135951 : return Register(kCallerPCOffsetRegisterIndex);
84 : }
85 :
86 0 : OperandSize Register::SizeOfOperand() const {
87 : int32_t operand = ToOperand();
88 0 : if (operand >= kMinInt8 && operand <= kMaxInt8) {
89 : return OperandSize::kByte;
90 0 : } else if (operand >= kMinInt16 && operand <= kMaxInt16) {
91 : return OperandSize::kShort;
92 : } else {
93 0 : return OperandSize::kQuad;
94 : }
95 : }
96 :
97 0 : bool Register::AreContiguous(Register reg1, Register reg2, Register reg3,
98 : Register reg4, Register reg5) {
99 0 : if (reg1.index() + 1 != reg2.index()) {
100 : return false;
101 : }
102 0 : if (reg3.is_valid() && reg2.index() + 1 != reg3.index()) {
103 : return false;
104 : }
105 0 : if (reg4.is_valid() && reg3.index() + 1 != reg4.index()) {
106 : return false;
107 : }
108 0 : if (reg5.is_valid() && reg4.index() + 1 != reg5.index()) {
109 : return false;
110 : }
111 0 : return true;
112 : }
113 :
114 49 : std::string Register::ToString(int parameter_count) const {
115 49 : if (is_current_context()) {
116 0 : return std::string("<context>");
117 49 : } else if (is_function_closure()) {
118 0 : return std::string("<closure>");
119 49 : } else if (is_parameter()) {
120 : int parameter_index = ToParameterIndex(parameter_count);
121 1 : if (parameter_index == 0) {
122 0 : return std::string("<this>");
123 : } else {
124 2 : std::ostringstream s;
125 2 : s << "a" << parameter_index - 1;
126 : return s.str();
127 : }
128 : } else {
129 96 : std::ostringstream s;
130 48 : s << "r" << index();
131 : return s.str();
132 : }
133 : }
134 :
135 : } // namespace interpreter
136 : } // namespace internal
137 121996 : } // namespace v8
|