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) | 11 BytecodeArrayBuilder::BytecodeArrayBuilder(Isolate* isolate) |
12 : isolate_(isolate), | 12 : isolate_(isolate), |
13 bytecode_generated_(false), | 13 bytecode_generated_(false), |
| 14 parameter_count_(-1), |
14 local_register_count_(-1), | 15 local_register_count_(-1), |
15 temporary_register_count_(0), | 16 temporary_register_count_(0), |
16 temporary_register_next_(0) {} | 17 temporary_register_next_(0) {} |
17 | 18 |
18 | 19 |
19 void BytecodeArrayBuilder::set_locals_count(int number_of_locals) { | 20 void BytecodeArrayBuilder::set_locals_count(int number_of_locals) { |
20 local_register_count_ = number_of_locals; | 21 local_register_count_ = number_of_locals; |
21 temporary_register_next_ = local_register_count_; | 22 temporary_register_next_ = local_register_count_; |
22 } | 23 } |
23 | 24 |
24 | 25 |
25 int BytecodeArrayBuilder::locals_count() const { return local_register_count_; } | 26 int BytecodeArrayBuilder::locals_count() const { return local_register_count_; } |
26 | 27 |
27 | 28 |
| 29 void BytecodeArrayBuilder::set_parameter_count(int number_of_parameters) { |
| 30 parameter_count_ = number_of_parameters; |
| 31 } |
| 32 |
| 33 |
| 34 int BytecodeArrayBuilder::parameter_count() const { return parameter_count_; } |
| 35 |
| 36 |
| 37 Register BytecodeArrayBuilder::Parameter(int param_index) { |
| 38 DCHECK_GE(param_index, 0); |
| 39 DCHECK_LT(param_index, parameter_count_); |
| 40 return Register(kLastParamRegisterIndex - parameter_count_ + param_index + 1); |
| 41 } |
| 42 |
| 43 |
28 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { | 44 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { |
29 DCHECK_EQ(bytecode_generated_, false); | 45 DCHECK_EQ(bytecode_generated_, false); |
| 46 DCHECK_GE(parameter_count_, 0); |
30 DCHECK_GE(local_register_count_, 0); | 47 DCHECK_GE(local_register_count_, 0); |
31 int bytecode_size = static_cast<int>(bytecodes_.size()); | 48 int bytecode_size = static_cast<int>(bytecodes_.size()); |
32 int register_count = local_register_count_ + temporary_register_count_; | 49 int register_count = local_register_count_ + temporary_register_count_; |
33 int frame_size = register_count * kPointerSize; | 50 int frame_size = register_count * kPointerSize; |
34 Handle<BytecodeArray> output = isolate_->factory()->NewBytecodeArray( | 51 Handle<BytecodeArray> output = isolate_->factory()->NewBytecodeArray( |
35 bytecode_size, &bytecodes_.front(), frame_size); | 52 bytecode_size, &bytecodes_.front(), frame_size, parameter_count_); |
36 bytecode_generated_ = true; | 53 bytecode_generated_ = true; |
37 return output; | 54 return output; |
38 } | 55 } |
39 | 56 |
40 | 57 |
41 BytecodeArrayBuilder& BytecodeArrayBuilder::BinaryOperation(Token::Value binop, | 58 BytecodeArrayBuilder& BytecodeArrayBuilder::BinaryOperation(Token::Value binop, |
42 Register reg) { | 59 Register reg) { |
43 Output(BytecodeForBinaryOperation(binop), reg.ToOperand()); | 60 Output(BytecodeForBinaryOperation(binop), reg.ToOperand()); |
44 return *this; | 61 return *this; |
45 } | 62 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 145 |
129 | 146 |
130 bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index, | 147 bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index, |
131 uint8_t operand_value) const { | 148 uint8_t operand_value) const { |
132 OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index); | 149 OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index); |
133 switch (operand_type) { | 150 switch (operand_type) { |
134 case OperandType::kNone: | 151 case OperandType::kNone: |
135 return false; | 152 return false; |
136 case OperandType::kImm8: | 153 case OperandType::kImm8: |
137 return true; | 154 return true; |
138 case OperandType::kReg: | 155 case OperandType::kReg: { |
139 return Register::FromOperand(operand_value).index() < | 156 int reg_index = Register::FromOperand(operand_value).index(); |
140 temporary_register_next_; | 157 return (reg_index >= 0 && reg_index < temporary_register_next_) || |
| 158 (reg_index <= kLastParamRegisterIndex && |
| 159 reg_index > kLastParamRegisterIndex - parameter_count_); |
| 160 } |
141 } | 161 } |
142 UNREACHABLE(); | 162 UNREACHABLE(); |
143 return false; | 163 return false; |
144 } | 164 } |
145 | 165 |
146 | 166 |
147 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0, | 167 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0, |
148 uint8_t operand1, uint8_t operand2) { | 168 uint8_t operand1, uint8_t operand2) { |
149 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3); | 169 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3); |
150 DCHECK(OperandIsValid(bytecode, 0, operand0) && | 170 DCHECK(OperandIsValid(bytecode, 0, operand0) && |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 235 |
216 Register TemporaryRegisterScope::NewRegister() { | 236 Register TemporaryRegisterScope::NewRegister() { |
217 count_++; | 237 count_++; |
218 last_register_index_ = builder_->BorrowTemporaryRegister(); | 238 last_register_index_ = builder_->BorrowTemporaryRegister(); |
219 return Register(last_register_index_); | 239 return Register(last_register_index_); |
220 } | 240 } |
221 | 241 |
222 } // namespace interpreter | 242 } // namespace interpreter |
223 } // namespace internal | 243 } // namespace internal |
224 } // namespace v8 | 244 } // namespace v8 |
OLD | NEW |