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

Side by Side Diff: src/codegen-ia32.cc

Issue 46089: Revert 1469 and 1472 on trunk. (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: '' Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/codegen-arm.cc ('k') | src/heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 14 matching lines...) Expand all
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "bootstrapper.h" 30 #include "bootstrapper.h"
31 #include "codegen-inl.h" 31 #include "codegen-inl.h"
32 #include "debug.h" 32 #include "debug.h"
33 #include "scopes.h" 33 #include "scopes.h"
34 #include "runtime.h" 34 #include "runtime.h"
35 #include "parser.h"
36 35
37 namespace v8 { namespace internal { 36 namespace v8 { namespace internal {
38 37
39 #define __ masm_-> 38 #define __ masm_->
40 39
41 // ------------------------------------------------------------------------- 40 // -------------------------------------------------------------------------
42 // CodeGenState implementation. 41 // CodeGenState implementation.
43 42
44 CodeGenState::CodeGenState(CodeGenerator* owner) 43 CodeGenState::CodeGenState(CodeGenerator* owner)
45 : owner_(owner), 44 : owner_(owner),
(...skipping 3431 matching lines...) Expand 10 before | Expand all | Expand 10 after
3477 deferred->enter()->Branch(equal, &literals, not_taken); 3476 deferred->enter()->Branch(equal, &literals, not_taken);
3478 3477
3479 literals.Unuse(); 3478 literals.Unuse();
3480 // The deferred code returns the boilerplate object. 3479 // The deferred code returns the boilerplate object.
3481 deferred->BindExit(&boilerplate); 3480 deferred->BindExit(&boilerplate);
3482 3481
3483 // Push the boilerplate object. 3482 // Push the boilerplate object.
3484 frame_->Push(&boilerplate); 3483 frame_->Push(&boilerplate);
3485 // Clone the boilerplate object. 3484 // Clone the boilerplate object.
3486 Result clone = 3485 Result clone =
3487 frame_->CallRuntime(Runtime::kCloneLiteralBoilerplate, 1); 3486 frame_->CallRuntime(Runtime::kCloneObjectLiteralBoilerplate, 1);
3488 // Push the newly cloned literal object as the result. 3487 // Push the newly cloned literal object as the result.
3489 frame_->Push(&clone); 3488 frame_->Push(&clone);
3490 3489
3491 for (int i = 0; i < node->properties()->length(); i++) { 3490 for (int i = 0; i < node->properties()->length(); i++) {
3492 ObjectLiteral::Property* property = node->properties()->at(i); 3491 ObjectLiteral::Property* property = node->properties()->at(i);
3493 switch (property->kind()) { 3492 switch (property->kind()) {
3494 case ObjectLiteral::Property::CONSTANT: 3493 case ObjectLiteral::Property::CONSTANT: break;
3495 break;
3496 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
3497 if (CompileTimeValue::IsCompileTimeValue(property->value())) break;
3498 // else fall through.
3499 case ObjectLiteral::Property::COMPUTED: { 3494 case ObjectLiteral::Property::COMPUTED: {
3500 Handle<Object> key(property->key()->handle()); 3495 Handle<Object> key(property->key()->handle());
3501 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); 3496 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize));
3502 if (key->IsSymbol()) { 3497 if (key->IsSymbol()) {
3503 // Duplicate the object as the IC receiver. 3498 // Duplicate the object as the IC receiver.
3504 frame_->Dup(); 3499 frame_->Dup();
3505 Load(property->value()); 3500 Load(property->value());
3506 Result value = frame_->Pop(); 3501 Result value = frame_->Pop();
3507 value.ToRegister(eax); 3502 value.ToRegister(eax);
3508 3503
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3546 Result ignored = frame_->CallRuntime(Runtime::kDefineAccessor, 4); 3541 Result ignored = frame_->CallRuntime(Runtime::kDefineAccessor, 4);
3547 // Ignore the result. 3542 // Ignore the result.
3548 break; 3543 break;
3549 } 3544 }
3550 default: UNREACHABLE(); 3545 default: UNREACHABLE();
3551 } 3546 }
3552 } 3547 }
3553 } 3548 }
3554 3549
3555 3550
3556 // This deferred code stub will be used for creating the boilerplate
3557 // by calling Runtime_CreateArrayLiteralBoilerplate.
3558 // Each created boilerplate is stored in the JSFunction and they are
3559 // therefore context dependent.
3560 class DeferredArrayLiteral: public DeferredCode {
3561 public:
3562 DeferredArrayLiteral(CodeGenerator* generator,
3563 ArrayLiteral* node)
3564 : DeferredCode(generator), node_(node) {
3565 set_comment("[ DeferredArrayLiteral");
3566 }
3567
3568 virtual void Generate();
3569
3570 private:
3571 ArrayLiteral* node_;
3572 };
3573
3574
3575 void DeferredArrayLiteral::Generate() {
3576 Result literals(generator());
3577 enter()->Bind(&literals);
3578 // Since the entry is undefined we call the runtime system to
3579 // compute the literal.
3580
3581 VirtualFrame* frame = generator()->frame();
3582 // Literal array (0).
3583 frame->Push(&literals);
3584 // Literal index (1).
3585 frame->Push(Smi::FromInt(node_->literal_index()));
3586 // Constant properties (2).
3587 frame->Push(node_->literals());
3588 Result boilerplate =
3589 frame->CallRuntime(Runtime::kCreateArrayLiteralBoilerplate, 3);
3590 exit_.Jump(&boilerplate);
3591 }
3592
3593
3594 void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) { 3551 void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) {
3595 Comment cmnt(masm_, "[ ArrayLiteral"); 3552 Comment cmnt(masm_, "[ ArrayLiteral");
3596 DeferredArrayLiteral* deferred = new DeferredArrayLiteral(this, node);
3597 3553
3598 // Retrieve the literals array and check the allocated entry. Begin 3554 // Call the runtime to create the array literal.
3599 // with a writable copy of the function of this activation in a 3555 frame_->Push(node->literals());
3600 // register. 3556 // Load the literals array of the current function.
3601 frame_->PushFunction(); 3557 frame_->PushFunction();
3602 Result literals = frame_->Pop(); 3558 Result literals = frame_->Pop();
3603 literals.ToRegister(); 3559 literals.ToRegister();
3604 frame_->Spill(literals.reg()); 3560 frame_->Spill(literals.reg()); // Make it writable.
3605
3606 // Load the literals array of the function.
3607 __ mov(literals.reg(), 3561 __ mov(literals.reg(),
3608 FieldOperand(literals.reg(), JSFunction::kLiteralsOffset)); 3562 FieldOperand(literals.reg(), JSFunction::kLiteralsOffset));
3609 3563 frame_->Push(&literals);
3610 // Load the literal at the ast saved index. 3564 Result array = frame_->CallRuntime(Runtime::kCreateArrayLiteral, 2);
3611 int literal_offset =
3612 FixedArray::kHeaderSize + node->literal_index() * kPointerSize;
3613 Result boilerplate = allocator_->Allocate();
3614 ASSERT(boilerplate.is_valid());
3615 __ mov(boilerplate.reg(), FieldOperand(literals.reg(), literal_offset));
3616
3617 // Check whether we need to materialize the object literal boilerplate.
3618 // If so, jump to the deferred code passing the literals array.
3619 __ cmp(boilerplate.reg(), Factory::undefined_value());
3620 deferred->enter()->Branch(equal, &literals, not_taken);
3621
3622 literals.Unuse();
3623 // The deferred code returns the boilerplate object.
3624 deferred->BindExit(&boilerplate);
3625 3565
3626 // Push the resulting array literal on the stack. 3566 // Push the resulting array literal on the stack.
3627 frame_->Push(&boilerplate); 3567 frame_->Push(&array);
3628
3629 // Clone the boilerplate object.
3630 Result clone =
3631 frame_->CallRuntime(Runtime::kCloneLiteralBoilerplate, 1);
3632 // Push the newly cloned literal object as the result.
3633 frame_->Push(&clone);
3634 3568
3635 // Generate code to set the elements in the array that are not 3569 // Generate code to set the elements in the array that are not
3636 // literals. 3570 // literals.
3637 for (int i = 0; i < node->values()->length(); i++) { 3571 for (int i = 0; i < node->values()->length(); i++) {
3638 Expression* value = node->values()->at(i); 3572 Expression* value = node->values()->at(i);
3639 3573
3640 // If value is a literal the property value is already set in the 3574 // If value is literal the property value is already set in the
3641 // boilerplate object. 3575 // boilerplate object.
3642 if (value->AsLiteral() != NULL) continue; 3576 if (value->AsLiteral() == NULL) {
3643 // If value is a materialized literal the property value is already set 3577 // The property must be set by generated code.
3644 // in the boilerplate object if it is simple. 3578 Load(value);
3645 if (CompileTimeValue::IsCompileTimeValue(value)) continue;
3646 3579
3647 // The property must be set by generated code. 3580 // Get the property value off the stack.
3648 Load(value); 3581 Result prop_value = frame_->Pop();
3582 prop_value.ToRegister();
3649 3583
3650 // Get the property value off the stack. 3584 // Fetch the array literal while leaving a copy on the stack and
3651 Result prop_value = frame_->Pop(); 3585 // use it to get the elements array.
3652 prop_value.ToRegister(); 3586 frame_->Dup();
3587 Result elements = frame_->Pop();
3588 elements.ToRegister();
3589 frame_->Spill(elements.reg());
3590 // Get the elements array.
3591 __ mov(elements.reg(),
3592 FieldOperand(elements.reg(), JSObject::kElementsOffset));
3653 3593
3654 // Fetch the array literal while leaving a copy on the stack and 3594 // Write to the indexed properties array.
3655 // use it to get the elements array. 3595 int offset = i * kPointerSize + Array::kHeaderSize;
3656 frame_->Dup(); 3596 __ mov(FieldOperand(elements.reg(), offset), prop_value.reg());
3657 Result elements = frame_->Pop();
3658 elements.ToRegister();
3659 frame_->Spill(elements.reg());
3660 // Get the elements array.
3661 __ mov(elements.reg(),
3662 FieldOperand(elements.reg(), JSObject::kElementsOffset));
3663 3597
3664 // Write to the indexed properties array. 3598 // Update the write barrier for the array address.
3665 int offset = i * kPointerSize + Array::kHeaderSize; 3599 frame_->Spill(prop_value.reg()); // Overwritten by the write barrier.
3666 __ mov(FieldOperand(elements.reg(), offset), prop_value.reg()); 3600 Result scratch = allocator_->Allocate();
3667 3601 ASSERT(scratch.is_valid());
3668 // Update the write barrier for the array address. 3602 __ RecordWrite(elements.reg(), offset, prop_value.reg(), scratch.reg());
3669 frame_->Spill(prop_value.reg()); // Overwritten by the write barrier. 3603 }
3670 Result scratch = allocator_->Allocate();
3671 ASSERT(scratch.is_valid());
3672 __ RecordWrite(elements.reg(), offset, prop_value.reg(), scratch.reg());
3673 } 3604 }
3674 } 3605 }
3675 3606
3676 3607
3677 void CodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* node) { 3608 void CodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* node) {
3678 ASSERT(!in_spilled_code()); 3609 ASSERT(!in_spilled_code());
3679 // Call runtime routine to allocate the catch extension object and 3610 // Call runtime routine to allocate the catch extension object and
3680 // assign the exception value to the catch variable. 3611 // assign the exception value to the catch variable.
3681 Comment cmnt(masm_, "[ CatchExtensionObject"); 3612 Comment cmnt(masm_, "[ CatchExtensionObject");
3682 Load(node->key()); 3613 Load(node->key());
(...skipping 3252 matching lines...) Expand 10 before | Expand all | Expand 10 after
6935 6866
6936 // Slow-case: Go through the JavaScript implementation. 6867 // Slow-case: Go through the JavaScript implementation.
6937 __ bind(&slow); 6868 __ bind(&slow);
6938 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); 6869 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
6939 } 6870 }
6940 6871
6941 6872
6942 #undef __ 6873 #undef __
6943 6874
6944 } } // namespace v8::internal 6875 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/codegen-arm.cc ('k') | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698