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 |
| 64 |
| 65 Register BytecodeArrayBuilder::Parameter(int parameter_index) const { |
45 DCHECK_GE(parameter_index, 0); | 66 DCHECK_GE(parameter_index, 0); |
46 DCHECK_LT(parameter_index, parameter_count_); | 67 DCHECK_LT(parameter_index, parameter_count_); |
47 return Register::FromParameterIndex(parameter_index, parameter_count_); | 68 return Register::FromParameterIndex(parameter_index, parameter_count_); |
48 } | 69 } |
49 | 70 |
50 | 71 |
51 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { | 72 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { |
52 DCHECK_EQ(bytecode_generated_, false); | 73 DCHECK_EQ(bytecode_generated_, false); |
53 DCHECK_GE(parameter_count_, 0); | 74 DCHECK_GE(parameter_count_, 0); |
54 DCHECK_GE(local_register_count_, 0); | 75 DCHECK_GE(local_register_count_, 0); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 344 |
324 | 345 |
325 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateClosure( | 346 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateClosure( |
326 PretenureFlag tenured) { | 347 PretenureFlag tenured) { |
327 DCHECK(FitsInImm8Operand(tenured)); | 348 DCHECK(FitsInImm8Operand(tenured)); |
328 Output(Bytecode::kCreateClosure, static_cast<uint8_t>(tenured)); | 349 Output(Bytecode::kCreateClosure, static_cast<uint8_t>(tenured)); |
329 return *this; | 350 return *this; |
330 } | 351 } |
331 | 352 |
332 | 353 |
| 354 BytecodeArrayBuilder& BytecodeArrayBuilder::PushContext(Register context) { |
| 355 Output(Bytecode::kPushContext, context.ToOperand()); |
| 356 return *this; |
| 357 } |
| 358 |
| 359 |
| 360 BytecodeArrayBuilder& BytecodeArrayBuilder::PopContext(Register context) { |
| 361 Output(Bytecode::kPopContext, context.ToOperand()); |
| 362 return *this; |
| 363 } |
| 364 |
| 365 |
333 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToBoolean() { | 366 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToBoolean() { |
334 if (LastBytecodeInSameBlock()) { | 367 if (LastBytecodeInSameBlock()) { |
335 // If the previous bytecode puts a boolean in the accumulator | 368 // If the previous bytecode puts a boolean in the accumulator |
336 // there is no need to emit an instruction. | 369 // there is no need to emit an instruction. |
337 switch (Bytecodes::FromByte(bytecodes()->at(last_bytecode_start_))) { | 370 switch (Bytecodes::FromByte(bytecodes()->at(last_bytecode_start_))) { |
338 case Bytecode::kToBoolean: | 371 case Bytecode::kToBoolean: |
339 UNREACHABLE(); | 372 UNREACHABLE(); |
340 case Bytecode::kLdaTrue: | 373 case Bytecode::kLdaTrue: |
341 case Bytecode::kLdaFalse: | 374 case Bytecode::kLdaFalse: |
342 case Bytecode::kLogicalNot: | 375 case Bytecode::kLogicalNot: |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 case OperandType::kNone: | 605 case OperandType::kNone: |
573 return false; | 606 return false; |
574 case OperandType::kIdx16: | 607 case OperandType::kIdx16: |
575 return static_cast<uint16_t>(operand_value) == operand_value; | 608 return static_cast<uint16_t>(operand_value) == operand_value; |
576 case OperandType::kCount8: | 609 case OperandType::kCount8: |
577 case OperandType::kImm8: | 610 case OperandType::kImm8: |
578 case OperandType::kIdx8: | 611 case OperandType::kIdx8: |
579 return static_cast<uint8_t>(operand_value) == operand_value; | 612 return static_cast<uint8_t>(operand_value) == operand_value; |
580 case OperandType::kReg8: { | 613 case OperandType::kReg8: { |
581 Register reg = Register::FromOperand(static_cast<uint8_t>(operand_value)); | 614 Register reg = Register::FromOperand(static_cast<uint8_t>(operand_value)); |
582 if (reg.is_function_context()) { | 615 if (reg.is_function_context() || reg.is_function_closure()) { |
583 return true; | 616 return true; |
584 } else if (reg.is_parameter()) { | 617 } else if (reg.is_parameter()) { |
585 int parameter_index = reg.ToParameterIndex(parameter_count_); | 618 int parameter_index = reg.ToParameterIndex(parameter_count_); |
586 return parameter_index >= 0 && parameter_index < parameter_count_; | 619 return parameter_index >= 0 && parameter_index < parameter_count_; |
587 } else { | 620 } else { |
588 return (reg.index() >= 0 && reg.index() < temporary_register_next_); | 621 return (reg.index() >= 0 && reg.index() < temporary_register_next_); |
589 } | 622 } |
590 } | 623 } |
591 } | 624 } |
592 UNREACHABLE(); | 625 UNREACHABLE(); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 | 797 |
765 Register TemporaryRegisterScope::NewRegister() { | 798 Register TemporaryRegisterScope::NewRegister() { |
766 count_++; | 799 count_++; |
767 last_register_index_ = builder_->BorrowTemporaryRegister(); | 800 last_register_index_ = builder_->BorrowTemporaryRegister(); |
768 return Register(last_register_index_); | 801 return Register(last_register_index_); |
769 } | 802 } |
770 | 803 |
771 } // namespace interpreter | 804 } // namespace interpreter |
772 } // namespace internal | 805 } // namespace internal |
773 } // namespace v8 | 806 } // namespace v8 |
OLD | NEW |