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/bytecode-array-builder.h" | 5 #include "src/interpreter/bytecode-array-builder.h" |
6 | 6 |
7 namespace v8 { | 7 namespace v8 { |
8 namespace internal { | 8 namespace internal { |
9 namespace interpreter { | 9 namespace interpreter { |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 Output(Bytecode::kLdaSmi8, static_cast<uint8_t>(raw_smi)); | 84 Output(Bytecode::kLdaSmi8, static_cast<uint8_t>(raw_smi)); |
85 } else { | 85 } else { |
86 LoadLiteral(Handle<Object>(smi, isolate_)); | 86 LoadLiteral(Handle<Object>(smi, isolate_)); |
87 } | 87 } |
88 return *this; | 88 return *this; |
89 } | 89 } |
90 | 90 |
91 | 91 |
92 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLiteral(Handle<Object> object) { | 92 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLiteral(Handle<Object> object) { |
93 size_t entry = GetConstantPoolEntry(object); | 93 size_t entry = GetConstantPoolEntry(object); |
94 if (entry <= 255) { | 94 if (FitsByteOperand(entry)) { |
95 Output(Bytecode::kLdaConstant, static_cast<uint8_t>(entry)); | 95 Output(Bytecode::kLdaConstant, static_cast<uint8_t>(entry)); |
96 } else { | 96 } else { |
97 UNIMPLEMENTED(); | 97 UNIMPLEMENTED(); |
98 } | 98 } |
99 return *this; | 99 return *this; |
100 } | 100 } |
101 | 101 |
102 | 102 |
103 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadUndefined() { | 103 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadUndefined() { |
104 Output(Bytecode::kLdaUndefined); | 104 Output(Bytecode::kLdaUndefined); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 } | 137 } |
138 | 138 |
139 | 139 |
140 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreAccumulatorInRegister( | 140 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreAccumulatorInRegister( |
141 Register reg) { | 141 Register reg) { |
142 Output(Bytecode::kStar, reg.ToOperand()); | 142 Output(Bytecode::kStar, reg.ToOperand()); |
143 return *this; | 143 return *this; |
144 } | 144 } |
145 | 145 |
146 | 146 |
147 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadNamedProperty( | |
148 Register name, int feedback_slot, LanguageMode language_mode) { | |
149 if (is_strong(language_mode)) { | |
150 UNIMPLEMENTED(); | |
151 } | |
152 | |
153 if (FitsByteOperand(feedback_slot)) { | |
154 Output(Bytecode::kLoadIC, name.ToOperand(), | |
155 static_cast<uint8_t>(feedback_slot)); | |
156 } else { | |
157 UNIMPLEMENTED(); | |
158 } | |
159 return *this; | |
160 } | |
161 | |
162 | |
163 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadKeyedProperty( | |
164 Register key, int feedback_slot, LanguageMode language_mode) { | |
165 if (is_strong(language_mode)) { | |
166 UNIMPLEMENTED(); | |
167 } | |
168 | |
169 if (FitsByteOperand(feedback_slot)) { | |
170 Output(Bytecode::kKeyedLoadIC, key.ToOperand(), | |
171 static_cast<uint8_t>(feedback_slot)); | |
172 } else { | |
173 UNIMPLEMENTED(); | |
174 } | |
175 return *this; | |
176 } | |
177 | |
178 | |
147 BytecodeArrayBuilder& BytecodeArrayBuilder::Return() { | 179 BytecodeArrayBuilder& BytecodeArrayBuilder::Return() { |
148 Output(Bytecode::kReturn); | 180 Output(Bytecode::kReturn); |
149 return *this; | 181 return *this; |
150 } | 182 } |
151 | 183 |
152 | 184 |
153 size_t BytecodeArrayBuilder::GetConstantPoolEntry(Handle<Object> object) { | 185 size_t BytecodeArrayBuilder::GetConstantPoolEntry(Handle<Object> object) { |
154 // These constants shouldn't be added to the constant pool, the should use | 186 // These constants shouldn't be added to the constant pool, the should use |
155 // specialzed bytecodes instead. | 187 // specialzed bytecodes instead. |
156 DCHECK(!object.is_identical_to(isolate_->factory()->undefined_value())); | 188 DCHECK(!object.is_identical_to(isolate_->factory()->undefined_value())); |
(...skipping 30 matching lines...) Expand all Loading... | |
187 } | 219 } |
188 | 220 |
189 | 221 |
190 bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index, | 222 bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index, |
191 uint8_t operand_value) const { | 223 uint8_t operand_value) const { |
192 OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index); | 224 OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index); |
193 switch (operand_type) { | 225 switch (operand_type) { |
194 case OperandType::kNone: | 226 case OperandType::kNone: |
195 return false; | 227 return false; |
196 case OperandType::kImm8: | 228 case OperandType::kImm8: |
229 case OperandType::kIdx: | |
197 return true; | 230 return true; |
198 case OperandType::kIdx: | |
199 return operand_value < constants_.size(); | |
200 case OperandType::kReg: { | 231 case OperandType::kReg: { |
201 int reg_index = Register::FromOperand(operand_value).index(); | 232 int reg_index = Register::FromOperand(operand_value).index(); |
202 return (reg_index >= 0 && reg_index < temporary_register_next_) || | 233 return (reg_index >= 0 && reg_index < temporary_register_next_) || |
203 (reg_index <= kLastParamRegisterIndex && | 234 (reg_index <= kLastParamRegisterIndex && |
204 reg_index > kLastParamRegisterIndex - parameter_count_); | 235 reg_index > kLastParamRegisterIndex - parameter_count_); |
205 } | 236 } |
206 } | 237 } |
207 UNREACHABLE(); | 238 UNREACHABLE(); |
208 return false; | 239 return false; |
209 } | 240 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 return Bytecode::kDiv; | 291 return Bytecode::kDiv; |
261 case Token::Value::MOD: | 292 case Token::Value::MOD: |
262 return Bytecode::kMod; | 293 return Bytecode::kMod; |
263 default: | 294 default: |
264 UNIMPLEMENTED(); | 295 UNIMPLEMENTED(); |
265 return static_cast<Bytecode>(-1); | 296 return static_cast<Bytecode>(-1); |
266 } | 297 } |
267 } | 298 } |
268 | 299 |
269 | 300 |
301 // static | |
302 template <typename T> | |
303 bool BytecodeArrayBuilder::FitsByteOperand(T value) { | |
oth
2015/09/01 14:01:54
Template seems a bit gratuitous here - it's invoke
rmcilroy
2015/09/01 15:53:36
Ahh, is_integral is exactly what I wanted, thanks.
| |
304 return 0 <= value <= 255; | |
305 } | |
306 | |
307 | |
270 TemporaryRegisterScope::TemporaryRegisterScope(BytecodeArrayBuilder* builder) | 308 TemporaryRegisterScope::TemporaryRegisterScope(BytecodeArrayBuilder* builder) |
271 : builder_(builder), count_(0), last_register_index_(-1) {} | 309 : builder_(builder), count_(0), last_register_index_(-1) {} |
272 | 310 |
273 | 311 |
274 TemporaryRegisterScope::~TemporaryRegisterScope() { | 312 TemporaryRegisterScope::~TemporaryRegisterScope() { |
275 while (count_-- != 0) { | 313 while (count_-- != 0) { |
276 builder_->ReturnTemporaryRegister(last_register_index_--); | 314 builder_->ReturnTemporaryRegister(last_register_index_--); |
277 } | 315 } |
278 } | 316 } |
279 | 317 |
280 | 318 |
281 Register TemporaryRegisterScope::NewRegister() { | 319 Register TemporaryRegisterScope::NewRegister() { |
282 count_++; | 320 count_++; |
283 last_register_index_ = builder_->BorrowTemporaryRegister(); | 321 last_register_index_ = builder_->BorrowTemporaryRegister(); |
284 return Register(last_register_index_); | 322 return Register(last_register_index_); |
285 } | 323 } |
286 | 324 |
287 } // namespace interpreter | 325 } // namespace interpreter |
288 } // namespace internal | 326 } // namespace internal |
289 } // namespace v8 | 327 } // namespace v8 |
OLD | NEW |