Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(687)

Side by Side Diff: src/interpreter/bytecodes.cc

Issue 1325983002: [Intepreter] Extend and move Register class. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test, bug spotted by bots. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/interpreter/bytecodes.h ('k') | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "src/interpreter/bytecode-array-builder.h" 7 #include "src/frames.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
11 namespace interpreter { 11 namespace interpreter {
12 12
13 // Maximum number of operands a bytecode may have. 13 // Maximum number of operands a bytecode may have.
14 static const int kMaxOperands = 3; 14 static const int kMaxOperands = 3;
15 15
16 // kBytecodeTable relies on kNone being the same as zero to detect length. 16 // kBytecodeTable relies on kNone being the same as zero to detect length.
17 STATIC_ASSERT(static_cast<int>(OperandType::kNone) == 0); 17 STATIC_ASSERT(static_cast<int>(OperandType::kNone) == 0);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 // static 97 // static
98 int Bytecodes::MaximumNumberOfOperands() { return kMaxOperands; } 98 int Bytecodes::MaximumNumberOfOperands() { return kMaxOperands; }
99 99
100 100
101 // static 101 // static
102 int Bytecodes::MaximumSize() { return 1 + kMaxOperands; } 102 int Bytecodes::MaximumSize() { return 1 + kMaxOperands; }
103 103
104 104
105 // static 105 // static
106 std::ostream& Bytecodes::Decode(std::ostream& os, 106 std::ostream& Bytecodes::Decode(std::ostream& os, const uint8_t* bytecode_start,
107 const uint8_t* bytecode_start) { 107 int parameter_count) {
108 Vector<char> buf = Vector<char>::New(50); 108 Vector<char> buf = Vector<char>::New(50);
109 109
110 Bytecode bytecode = Bytecodes::FromByte(bytecode_start[0]); 110 Bytecode bytecode = Bytecodes::FromByte(bytecode_start[0]);
111 int bytecode_size = Bytecodes::Size(bytecode); 111 int bytecode_size = Bytecodes::Size(bytecode);
112 112
113 for (int i = 0; i < bytecode_size; i++) { 113 for (int i = 0; i < bytecode_size; i++) {
114 SNPrintF(buf, "%02x ", bytecode_start[i]); 114 SNPrintF(buf, "%02x ", bytecode_start[i]);
115 os << buf.start(); 115 os << buf.start();
116 } 116 }
117 for (int i = bytecode_size; i < Bytecodes::MaximumSize(); i++) { 117 for (int i = bytecode_size; i < Bytecodes::MaximumSize(); i++) {
118 os << " "; 118 os << " ";
119 } 119 }
120 120
121 os << bytecode << " "; 121 os << bytecode << " ";
122 122
123 const uint8_t* operands_start = bytecode_start + 1; 123 const uint8_t* operands_start = bytecode_start + 1;
124 int operands_size = bytecode_size - 1; 124 int operands_size = bytecode_size - 1;
125 for (int i = 0; i < operands_size; i++) { 125 for (int i = 0; i < operands_size; i++) {
126 OperandType op_type = GetOperandType(bytecode, i); 126 OperandType op_type = GetOperandType(bytecode, i);
127 uint8_t operand = operands_start[i]; 127 uint8_t operand = operands_start[i];
128 switch (op_type) { 128 switch (op_type) {
129 case interpreter::OperandType::kIdx: 129 case interpreter::OperandType::kIdx:
130 os << "[" << static_cast<unsigned int>(operand) << "]"; 130 os << "[" << static_cast<unsigned int>(operand) << "]";
131 break; 131 break;
132 case interpreter::OperandType::kImm8: 132 case interpreter::OperandType::kImm8:
133 os << "#" << static_cast<int>(operand); 133 os << "#" << static_cast<int>(operand);
134 break; 134 break;
135 case interpreter::OperandType::kReg: 135 case interpreter::OperandType::kReg: {
136 os << "r" << Register::FromOperand(operand).index(); 136 Register reg = Register::FromOperand(operand);
137 if (reg.is_parameter()) {
138 int parameter_index = reg.ToParameterIndex(parameter_count);
139 if (parameter_index == 0) {
140 os << "<this>";
141 } else {
142 os << "a" << parameter_index - 1;
143 }
144 } else {
145 os << "r" << reg.index();
146 }
137 break; 147 break;
148 }
138 case interpreter::OperandType::kNone: 149 case interpreter::OperandType::kNone:
139 UNREACHABLE(); 150 UNREACHABLE();
140 break; 151 break;
141 } 152 }
142 if (i != operands_size - 1) { 153 if (i != operands_size - 1) {
143 os << ", "; 154 os << ", ";
144 } 155 }
145 } 156 }
146 return os; 157 return os;
147 } 158 }
148 159
149 160
150 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode) { 161 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode) {
151 return os << Bytecodes::ToString(bytecode); 162 return os << Bytecodes::ToString(bytecode);
152 } 163 }
153 164
154 165
155 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type) { 166 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type) {
156 return os << Bytecodes::OperandTypeToString(operand_type); 167 return os << Bytecodes::OperandTypeToString(operand_type);
157 } 168 }
158 169
170
171 static const int kLastParamRegisterIndex =
172 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize;
173
174
175 // Registers occupy range 0-127 in 8-bit value leaving 128 unused values.
176 // Parameter indices are biased with the negative value kLastParamRegisterIndex
177 // for ease of access in the interpreter.
178 static const int kMaxParameterIndex = 128 + kLastParamRegisterIndex;
179
180
181 Register Register::FromParameterIndex(int index, int parameter_count) {
182 DCHECK_GE(index, 0);
183 DCHECK_LT(index, parameter_count);
184 DCHECK_LE(parameter_count, kMaxParameterIndex + 1);
185 int register_index = kLastParamRegisterIndex - parameter_count + index + 1;
186 DCHECK_LT(register_index, 0);
187 DCHECK_GE(register_index, Register::kMinRegisterIndex);
188 return Register(register_index);
189 }
190
191
192 int Register::ToParameterIndex(int parameter_count) const {
193 DCHECK(is_parameter());
194 return index() - kLastParamRegisterIndex + parameter_count - 1;
195 }
196
197
198 int Register::MaxParameterIndex() { return kMaxParameterIndex; }
199
200
201 uint8_t Register::ToOperand() const { return static_cast<uint8_t>(-index_); }
202
203
204 Register Register::FromOperand(uint8_t operand) {
205 return Register(-static_cast<int8_t>(operand));
206 }
207
159 } // namespace interpreter 208 } // namespace interpreter
160 } // namespace internal 209 } // namespace internal
161 } // namespace v8 210 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecodes.h ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698