Chromium Code Reviews| 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 |
| 11 BytecodeArrayBuilder::BytecodeArrayBuilder(Isolate* isolate, Zone* zone) | 11 BytecodeArrayBuilder::BytecodeArrayBuilder(Isolate* isolate, Zone* zone) |
| 12 : isolate_(isolate), | 12 : isolate_(isolate), |
| 13 zone_(zone), | 13 zone_(zone), |
| 14 bytecodes_(zone), | 14 bytecodes_(zone), |
| 15 bytecode_generated_(false), | 15 bytecode_generated_(false), |
| 16 last_block_end_(0), | 16 last_block_end_(0), |
| 17 last_bytecode_start_(~0), | 17 last_bytecode_start_(~0), |
| 18 return_seen_in_block_(false), | 18 return_seen_in_block_(false), |
| 19 constants_map_(isolate->heap(), zone), | 19 constants_map_(isolate->heap(), zone), |
| 20 constants_(zone), | 20 constants_(zone), |
| 21 parameter_count_(-1), | 21 parameter_count_(-1), |
| 22 local_register_count_(-1), | 22 local_register_count_(-1), |
| 23 context_register_count_(-1), | |
| 23 temporary_register_count_(0), | 24 temporary_register_count_(0), |
| 24 temporary_register_next_(0) {} | 25 temporary_register_next_(0) {} |
| 25 | 26 |
| 26 | 27 |
| 27 void BytecodeArrayBuilder::set_locals_count(int number_of_locals) { | 28 void BytecodeArrayBuilder::set_locals_count(int number_of_locals) { |
| 28 local_register_count_ = number_of_locals; | 29 local_register_count_ = number_of_locals; |
| 30 DCHECK_LE(context_register_count_, 0); | |
| 29 temporary_register_next_ = local_register_count_; | 31 temporary_register_next_ = local_register_count_; |
| 30 } | 32 } |
| 31 | 33 |
| 32 | 34 |
| 33 int BytecodeArrayBuilder::locals_count() const { return local_register_count_; } | 35 int BytecodeArrayBuilder::locals_count() const { return local_register_count_; } |
| 34 | 36 |
| 35 | 37 |
| 36 void BytecodeArrayBuilder::set_parameter_count(int number_of_parameters) { | 38 void BytecodeArrayBuilder::set_parameter_count(int number_of_parameters) { |
| 37 parameter_count_ = number_of_parameters; | 39 parameter_count_ = number_of_parameters; |
| 38 } | 40 } |
| 39 | 41 |
| 40 | 42 |
| 41 int BytecodeArrayBuilder::parameter_count() const { return parameter_count_; } | 43 int BytecodeArrayBuilder::parameter_count() const { return parameter_count_; } |
| 42 | 44 |
| 43 | 45 |
| 44 Register BytecodeArrayBuilder::Parameter(int parameter_index) { | 46 void BytecodeArrayBuilder::set_context_count(int number_of_contexts) { |
| 47 context_register_count_ = number_of_contexts; | |
| 48 DCHECK_GE(local_register_count_, 0); | |
| 49 temporary_register_next_ = local_register_count_ + context_register_count_; | |
| 50 } | |
| 51 | |
| 52 | |
| 53 Register BytecodeArrayBuilder::first_context_register() const { | |
| 54 DCHECK_GT(context_register_count_, 0); | |
| 55 return Register(local_register_count_); | |
| 56 } | |
| 57 | |
| 58 | |
| 59 Register BytecodeArrayBuilder::last_context_register() const { | |
| 60 DCHECK_GT(context_register_count_, 0); | |
| 61 return Register(local_register_count_ + context_register_count_ - 1); | |
| 62 } | |
| 63 | |
|
Michael Starzinger
2015/10/13 09:38:43
nit: Two empty newlines.
rmcilroy
2015/10/13 10:35:22
Done.
| |
| 64 Register BytecodeArrayBuilder::Parameter(int parameter_index) const { | |
| 45 DCHECK_GE(parameter_index, 0); | 65 DCHECK_GE(parameter_index, 0); |
| 46 DCHECK_LT(parameter_index, parameter_count_); | 66 DCHECK_LT(parameter_index, parameter_count_); |
| 47 return Register::FromParameterIndex(parameter_index, parameter_count_); | 67 return Register::FromParameterIndex(parameter_index, parameter_count_); |
| 48 } | 68 } |
| 49 | 69 |
| 50 | 70 |
| 51 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { | 71 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { |
| 52 DCHECK_EQ(bytecode_generated_, false); | 72 DCHECK_EQ(bytecode_generated_, false); |
| 53 DCHECK_GE(parameter_count_, 0); | 73 DCHECK_GE(parameter_count_, 0); |
| 54 DCHECK_GE(local_register_count_, 0); | 74 DCHECK_GE(local_register_count_, 0); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 if (FitsInIdx8Operand(feedback_slot)) { | 335 if (FitsInIdx8Operand(feedback_slot)) { |
| 316 Output(bytecode, object.ToOperand(), key.ToOperand(), | 336 Output(bytecode, object.ToOperand(), key.ToOperand(), |
| 317 static_cast<uint8_t>(feedback_slot)); | 337 static_cast<uint8_t>(feedback_slot)); |
| 318 } else { | 338 } else { |
| 319 UNIMPLEMENTED(); | 339 UNIMPLEMENTED(); |
| 320 } | 340 } |
| 321 return *this; | 341 return *this; |
| 322 } | 342 } |
| 323 | 343 |
| 324 | 344 |
| 345 BytecodeArrayBuilder& BytecodeArrayBuilder::PushContext(Register context) { | |
| 346 Output(Bytecode::kPushContext, context.ToOperand()); | |
| 347 return *this; | |
| 348 } | |
| 349 | |
| 350 | |
| 351 BytecodeArrayBuilder& BytecodeArrayBuilder::PopContext(Register context) { | |
| 352 Output(Bytecode::kPopContext, context.ToOperand()); | |
| 353 return *this; | |
| 354 } | |
| 355 | |
| 356 | |
| 325 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToBoolean() { | 357 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToBoolean() { |
| 326 if (LastBytecodeInSameBlock()) { | 358 if (LastBytecodeInSameBlock()) { |
| 327 // If the previous bytecode puts a boolean in the accumulator | 359 // If the previous bytecode puts a boolean in the accumulator |
| 328 // there is no need to emit an instruction. | 360 // there is no need to emit an instruction. |
| 329 switch (Bytecodes::FromByte(bytecodes()->at(last_bytecode_start_))) { | 361 switch (Bytecodes::FromByte(bytecodes()->at(last_bytecode_start_))) { |
| 330 case Bytecode::kToBoolean: | 362 case Bytecode::kToBoolean: |
| 331 UNREACHABLE(); | 363 UNREACHABLE(); |
| 332 case Bytecode::kLdaTrue: | 364 case Bytecode::kLdaTrue: |
| 333 case Bytecode::kLdaFalse: | 365 case Bytecode::kLdaFalse: |
| 334 case Bytecode::kLogicalNot: | 366 case Bytecode::kLogicalNot: |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 case OperandType::kNone: | 596 case OperandType::kNone: |
| 565 return false; | 597 return false; |
| 566 case OperandType::kIdx16: | 598 case OperandType::kIdx16: |
| 567 return static_cast<uint16_t>(operand_value) == operand_value; | 599 return static_cast<uint16_t>(operand_value) == operand_value; |
| 568 case OperandType::kCount8: | 600 case OperandType::kCount8: |
| 569 case OperandType::kImm8: | 601 case OperandType::kImm8: |
| 570 case OperandType::kIdx8: | 602 case OperandType::kIdx8: |
| 571 return static_cast<uint8_t>(operand_value) == operand_value; | 603 return static_cast<uint8_t>(operand_value) == operand_value; |
| 572 case OperandType::kReg8: { | 604 case OperandType::kReg8: { |
| 573 Register reg = Register::FromOperand(static_cast<uint8_t>(operand_value)); | 605 Register reg = Register::FromOperand(static_cast<uint8_t>(operand_value)); |
| 574 if (reg.is_function_context()) { | 606 if (reg.is_function_context() || reg.is_function_closure()) { |
| 575 return true; | 607 return true; |
| 576 } else if (reg.is_parameter()) { | 608 } else if (reg.is_parameter()) { |
| 577 int parameter_index = reg.ToParameterIndex(parameter_count_); | 609 int parameter_index = reg.ToParameterIndex(parameter_count_); |
| 578 return parameter_index >= 0 && parameter_index < parameter_count_; | 610 return parameter_index >= 0 && parameter_index < parameter_count_; |
| 579 } else { | 611 } else { |
| 580 return (reg.index() >= 0 && reg.index() < temporary_register_next_); | 612 return (reg.index() >= 0 && reg.index() < temporary_register_next_); |
| 581 } | 613 } |
| 582 } | 614 } |
| 583 } | 615 } |
| 584 UNREACHABLE(); | 616 UNREACHABLE(); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 744 | 776 |
| 745 Register TemporaryRegisterScope::NewRegister() { | 777 Register TemporaryRegisterScope::NewRegister() { |
| 746 count_++; | 778 count_++; |
| 747 last_register_index_ = builder_->BorrowTemporaryRegister(); | 779 last_register_index_ = builder_->BorrowTemporaryRegister(); |
| 748 return Register(last_register_index_); | 780 return Register(last_register_index_); |
| 749 } | 781 } |
| 750 | 782 |
| 751 } // namespace interpreter | 783 } // namespace interpreter |
| 752 } // namespace internal | 784 } // namespace internal |
| 753 } // namespace v8 | 785 } // namespace v8 |
| OLD | NEW |