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 local_register_count_(-1), | 14 local_register_count_(-1), |
15 temporary_register_count_(0), | 15 temporary_register_count_(0), |
16 temporary_register_next_(0) {} | 16 temporary_register_next_(0) {} |
17 | 17 |
18 | 18 |
19 void BytecodeArrayBuilder::set_locals_count(int number_of_locals) { | 19 void BytecodeArrayBuilder::set_locals_count(int number_of_locals) { |
20 local_register_count_ = number_of_locals; | 20 local_register_count_ = number_of_locals; |
21 temporary_register_next_ = local_register_count_; | 21 temporary_register_next_ = local_register_count_; |
22 } | 22 } |
23 | 23 |
24 | 24 |
25 int BytecodeArrayBuilder::locals_count() const { return local_register_count_; } | 25 int BytecodeArrayBuilder::locals_count() const { return local_register_count_; } |
26 | 26 |
| 27 |
27 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { | 28 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { |
28 DCHECK_EQ(bytecode_generated_, false); | 29 DCHECK_EQ(bytecode_generated_, false); |
29 DCHECK_GE(local_register_count_, 0); | 30 DCHECK_GE(local_register_count_, 0); |
30 int bytecode_size = static_cast<int>(bytecodes_.size()); | 31 int bytecode_size = static_cast<int>(bytecodes_.size()); |
31 int register_count = local_register_count_ + temporary_register_count_; | 32 int register_count = local_register_count_ + temporary_register_count_; |
32 int frame_size = register_count * kPointerSize; | 33 int frame_size = register_count * kPointerSize; |
33 Handle<BytecodeArray> output = isolate_->factory()->NewBytecodeArray( | 34 Handle<BytecodeArray> output = isolate_->factory()->NewBytecodeArray( |
34 bytecode_size, &bytecodes_.front(), frame_size); | 35 bytecode_size, &bytecodes_.front(), frame_size); |
35 bytecode_generated_ = true; | 36 bytecode_generated_ = true; |
36 return output; | 37 return output; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 OperandIsValid(bytecode, 2, operand2)); | 151 OperandIsValid(bytecode, 2, operand2)); |
151 bytecodes_.push_back(Bytecodes::ToByte(bytecode)); | 152 bytecodes_.push_back(Bytecodes::ToByte(bytecode)); |
152 bytecodes_.push_back(operand0); | 153 bytecodes_.push_back(operand0); |
153 bytecodes_.push_back(operand1); | 154 bytecodes_.push_back(operand1); |
154 bytecodes_.push_back(operand2); | 155 bytecodes_.push_back(operand2); |
155 } | 156 } |
156 | 157 |
157 | 158 |
158 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0, | 159 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0, |
159 uint8_t operand1) { | 160 uint8_t operand1) { |
160 DCHECK(Bytecodes::NumberOfOperands(bytecode) == 2); | 161 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2); |
161 DCHECK(OperandIsValid(bytecode, 0, operand0) && | 162 DCHECK(OperandIsValid(bytecode, 0, operand0) && |
162 OperandIsValid(bytecode, 1, operand1)); | 163 OperandIsValid(bytecode, 1, operand1)); |
163 bytecodes_.push_back(Bytecodes::ToByte(bytecode)); | 164 bytecodes_.push_back(Bytecodes::ToByte(bytecode)); |
164 bytecodes_.push_back(operand0); | 165 bytecodes_.push_back(operand0); |
165 bytecodes_.push_back(operand1); | 166 bytecodes_.push_back(operand1); |
166 } | 167 } |
167 | 168 |
168 | 169 |
169 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0) { | 170 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0) { |
170 DCHECK(Bytecodes::NumberOfOperands(bytecode) == 1); | 171 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1); |
171 DCHECK(OperandIsValid(bytecode, 0, operand0)); | 172 DCHECK(OperandIsValid(bytecode, 0, operand0)); |
172 bytecodes_.push_back(Bytecodes::ToByte(bytecode)); | 173 bytecodes_.push_back(Bytecodes::ToByte(bytecode)); |
173 bytecodes_.push_back(operand0); | 174 bytecodes_.push_back(operand0); |
174 } | 175 } |
175 | 176 |
176 | 177 |
177 void BytecodeArrayBuilder::Output(Bytecode bytecode) { | 178 void BytecodeArrayBuilder::Output(Bytecode bytecode) { |
178 DCHECK(Bytecodes::NumberOfOperands(bytecode) == 0); | 179 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0); |
179 bytecodes_.push_back(Bytecodes::ToByte(bytecode)); | 180 bytecodes_.push_back(Bytecodes::ToByte(bytecode)); |
180 } | 181 } |
181 | 182 |
182 | 183 |
183 // static | 184 // static |
184 Bytecode BytecodeArrayBuilder::BytecodeForBinaryOperation(Token::Value op) { | 185 Bytecode BytecodeArrayBuilder::BytecodeForBinaryOperation(Token::Value op) { |
185 switch (op) { | 186 switch (op) { |
186 case Token::Value::ADD: | 187 case Token::Value::ADD: |
187 return Bytecode::kAdd; | 188 return Bytecode::kAdd; |
188 case Token::Value::SUB: | 189 case Token::Value::SUB: |
(...skipping 22 matching lines...) Expand all Loading... |
211 | 212 |
212 int TemporaryRegisterScope::NewRegister() { | 213 int TemporaryRegisterScope::NewRegister() { |
213 count_++; | 214 count_++; |
214 register_ = builder_->BorrowTemporaryRegister(); | 215 register_ = builder_->BorrowTemporaryRegister(); |
215 return register_; | 216 return register_; |
216 } | 217 } |
217 | 218 |
218 } // namespace interpreter | 219 } // namespace interpreter |
219 } // namespace internal | 220 } // namespace internal |
220 } // namespace v8 | 221 } // namespace v8 |
OLD | NEW |