Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: src/interpreter/bytecode-array-builder.cc

Issue 1373903005: [Interpreter] Add for/while/do support to the bytecode generator. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate comments / re-work IfBuilder. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 bytecodes_(zone), 14 bytecodes_(zone),
14 bytecode_generated_(false), 15 bytecode_generated_(false),
15 last_block_end_(0), 16 last_block_end_(0),
16 last_bytecode_start_(~0), 17 last_bytecode_start_(~0),
17 return_seen_in_block_(false), 18 return_seen_in_block_(false),
18 constants_map_(isolate->heap(), zone), 19 constants_map_(isolate->heap(), zone),
19 constants_(zone), 20 constants_(zone),
20 parameter_count_(-1), 21 parameter_count_(-1),
21 local_register_count_(-1), 22 local_register_count_(-1),
22 temporary_register_count_(0), 23 temporary_register_count_(0),
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 if (label->is_forward_target()) { 308 if (label->is_forward_target()) {
308 // An earlier jump instruction refers to this label. Update it's location. 309 // An earlier jump instruction refers to this label. Update it's location.
309 PatchJump(bytecodes()->end(), bytecodes()->begin() + label->offset()); 310 PatchJump(bytecodes()->end(), bytecodes()->begin() + label->offset());
310 // Now treat as if the label will only be back referred to. 311 // Now treat as if the label will only be back referred to.
311 } 312 }
312 label->bind_to(bytecodes()->size()); 313 label->bind_to(bytecodes()->size());
313 return *this; 314 return *this;
314 } 315 }
315 316
316 317
318 BytecodeArrayBuilder& BytecodeArrayBuilder::Bind(
319 BytecodeLabel* unbound, const BytecodeLabel* const bound) {
320 DCHECK_EQ(unbound->is_bound(), false);
321 DCHECK_EQ(bound->is_bound(), true);
322 PatchJump(bytecodes()->begin() + bound->offset(),
323 bytecodes()->begin() + unbound->offset());
324 unbound->bind_to(bound->offset());
325 return *this;
326 }
327
328
317 // static 329 // static
318 bool BytecodeArrayBuilder::IsJumpWithImm8Operand(Bytecode jump_bytecode) { 330 bool BytecodeArrayBuilder::IsJumpWithImm8Operand(Bytecode jump_bytecode) {
rmcilroy 2015/10/01 12:12:07 replace this with your newly added Bytecodes::IsJu
oth 2015/10/01 13:13:56 Done.
319 return jump_bytecode == Bytecode::kJump || 331 return jump_bytecode == Bytecode::kJump ||
320 jump_bytecode == Bytecode::kJumpIfTrue || 332 jump_bytecode == Bytecode::kJumpIfTrue ||
321 jump_bytecode == Bytecode::kJumpIfFalse; 333 jump_bytecode == Bytecode::kJumpIfFalse;
322 } 334 }
323 335
324 336
325 // static 337 // static
326 Bytecode BytecodeArrayBuilder::GetJumpWithConstantOperand( 338 Bytecode BytecodeArrayBuilder::GetJumpWithConstantOperand(
327 Bytecode jump_bytecode) { 339 Bytecode jump_bytecode) {
328 switch (jump_bytecode) { 340 switch (jump_bytecode) {
(...skipping 11 matching lines...) Expand all
340 352
341 353
342 void BytecodeArrayBuilder::PatchJump( 354 void BytecodeArrayBuilder::PatchJump(
343 const ZoneVector<uint8_t>::iterator& jump_target, 355 const ZoneVector<uint8_t>::iterator& jump_target,
344 ZoneVector<uint8_t>::iterator jump_location) { 356 ZoneVector<uint8_t>::iterator jump_location) {
345 Bytecode jump_bytecode = Bytecodes::FromByte(*jump_location); 357 Bytecode jump_bytecode = Bytecodes::FromByte(*jump_location);
346 int delta = static_cast<int>(jump_target - jump_location); 358 int delta = static_cast<int>(jump_target - jump_location);
347 359
348 DCHECK(IsJumpWithImm8Operand(jump_bytecode)); 360 DCHECK(IsJumpWithImm8Operand(jump_bytecode));
349 DCHECK_EQ(Bytecodes::Size(jump_bytecode), 2); 361 DCHECK_EQ(Bytecodes::Size(jump_bytecode), 2);
350 DCHECK_GE(delta, 0);
rmcilroy 2015/10/01 12:12:07 Maybe make this DCHECK_NE(delta, 0) instead of rem
oth 2015/10/01 13:13:56 Done.
351 362
352 if (FitsInImm8Operand(delta)) { 363 if (FitsInImm8Operand(delta)) {
353 // Just update the operand 364 // Just update the operand
354 jump_location++; 365 jump_location++;
355 *jump_location = static_cast<uint8_t>(delta); 366 *jump_location = static_cast<uint8_t>(delta);
356 } else { 367 } else {
357 // Update the jump type and operand 368 // Update the jump type and operand
358 size_t entry = GetConstantPoolEntry(handle(Smi::FromInt(delta), isolate())); 369 size_t entry = GetConstantPoolEntry(handle(Smi::FromInt(delta), isolate()));
359 if (FitsInIdxOperand(entry)) { 370 if (FitsInIdxOperand(entry)) {
360 *jump_location++ = 371 *jump_location++ =
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 616
606 Register TemporaryRegisterScope::NewRegister() { 617 Register TemporaryRegisterScope::NewRegister() {
607 count_++; 618 count_++;
608 last_register_index_ = builder_->BorrowTemporaryRegister(); 619 last_register_index_ = builder_->BorrowTemporaryRegister();
609 return Register(last_register_index_); 620 return Register(last_register_index_);
610 } 621 }
611 622
612 } // namespace interpreter 623 } // namespace interpreter
613 } // namespace internal 624 } // namespace internal
614 } // namespace v8 625 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698