| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 2293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2304 // not replayed by the Lithium translation. | 2304 // not replayed by the Lithium translation. |
| 2305 HEnvironment* initial_env = environment()->CopyWithoutHistory(); | 2305 HEnvironment* initial_env = environment()->CopyWithoutHistory(); |
| 2306 HBasicBlock* body_entry = CreateBasicBlock(initial_env); | 2306 HBasicBlock* body_entry = CreateBasicBlock(initial_env); |
| 2307 current_block()->Goto(body_entry); | 2307 current_block()->Goto(body_entry); |
| 2308 body_entry->SetJoinId(AstNode::kFunctionEntryId); | 2308 body_entry->SetJoinId(AstNode::kFunctionEntryId); |
| 2309 set_current_block(body_entry); | 2309 set_current_block(body_entry); |
| 2310 | 2310 |
| 2311 // Handle implicit declaration of the function name in named function | 2311 // Handle implicit declaration of the function name in named function |
| 2312 // expressions before other declarations. | 2312 // expressions before other declarations. |
| 2313 if (scope->is_function_scope() && scope->function() != NULL) { | 2313 if (scope->is_function_scope() && scope->function() != NULL) { |
| 2314 HandleDeclaration(scope->function(), Variable::CONST, NULL); | 2314 HandleDeclaration(scope->function(), CONST, NULL); |
| 2315 } | 2315 } |
| 2316 VisitDeclarations(scope->declarations()); | 2316 VisitDeclarations(scope->declarations()); |
| 2317 AddSimulate(AstNode::kDeclarationsId); | 2317 AddSimulate(AstNode::kDeclarationsId); |
| 2318 | 2318 |
| 2319 HValue* context = environment()->LookupContext(); | 2319 HValue* context = environment()->LookupContext(); |
| 2320 AddInstruction( | 2320 AddInstruction( |
| 2321 new(zone()) HStackCheck(context, HStackCheck::kFunctionEntry)); | 2321 new(zone()) HStackCheck(context, HStackCheck::kFunctionEntry)); |
| 2322 | 2322 |
| 2323 VisitStatements(info()->function()->body()); | 2323 VisitStatements(info()->function()->body()); |
| 2324 if (HasStackOverflow()) return NULL; | 2324 if (HasStackOverflow()) return NULL; |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3134 } | 3134 } |
| 3135 return context; | 3135 return context; |
| 3136 } | 3136 } |
| 3137 | 3137 |
| 3138 | 3138 |
| 3139 void HGraphBuilder::VisitVariableProxy(VariableProxy* expr) { | 3139 void HGraphBuilder::VisitVariableProxy(VariableProxy* expr) { |
| 3140 ASSERT(!HasStackOverflow()); | 3140 ASSERT(!HasStackOverflow()); |
| 3141 ASSERT(current_block() != NULL); | 3141 ASSERT(current_block() != NULL); |
| 3142 ASSERT(current_block()->HasPredecessor()); | 3142 ASSERT(current_block()->HasPredecessor()); |
| 3143 Variable* variable = expr->var(); | 3143 Variable* variable = expr->var(); |
| 3144 if (variable->mode() == Variable::LET) { | 3144 if (variable->mode() == LET) { |
| 3145 return Bailout("reference to let variable"); | 3145 return Bailout("reference to let variable"); |
| 3146 } | 3146 } |
| 3147 switch (variable->location()) { | 3147 switch (variable->location()) { |
| 3148 case Variable::UNALLOCATED: { | 3148 case Variable::UNALLOCATED: { |
| 3149 // Handle known global constants like 'undefined' specially to avoid a | 3149 // Handle known global constants like 'undefined' specially to avoid a |
| 3150 // load from a global cell for them. | 3150 // load from a global cell for them. |
| 3151 Handle<Object> constant_value = | 3151 Handle<Object> constant_value = |
| 3152 isolate()->factory()->GlobalConstantFor(variable->name()); | 3152 isolate()->factory()->GlobalConstantFor(variable->name()); |
| 3153 if (!constant_value.is_null()) { | 3153 if (!constant_value.is_null()) { |
| 3154 HConstant* instr = | 3154 HConstant* instr = |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3181 variable->name(), | 3181 variable->name(), |
| 3182 ast_context()->is_for_typeof()); | 3182 ast_context()->is_for_typeof()); |
| 3183 instr->set_position(expr->position()); | 3183 instr->set_position(expr->position()); |
| 3184 return ast_context()->ReturnInstruction(instr, expr->id()); | 3184 return ast_context()->ReturnInstruction(instr, expr->id()); |
| 3185 } | 3185 } |
| 3186 } | 3186 } |
| 3187 | 3187 |
| 3188 case Variable::PARAMETER: | 3188 case Variable::PARAMETER: |
| 3189 case Variable::LOCAL: { | 3189 case Variable::LOCAL: { |
| 3190 HValue* value = environment()->Lookup(variable); | 3190 HValue* value = environment()->Lookup(variable); |
| 3191 if (variable->mode() == Variable::CONST && | 3191 if (variable->mode() == CONST && |
| 3192 value == graph()->GetConstantHole()) { | 3192 value == graph()->GetConstantHole()) { |
| 3193 return Bailout("reference to uninitialized const variable"); | 3193 return Bailout("reference to uninitialized const variable"); |
| 3194 } | 3194 } |
| 3195 return ast_context()->ReturnValue(value); | 3195 return ast_context()->ReturnValue(value); |
| 3196 } | 3196 } |
| 3197 | 3197 |
| 3198 case Variable::CONTEXT: { | 3198 case Variable::CONTEXT: { |
| 3199 if (variable->mode() == Variable::CONST) { | 3199 if (variable->mode() == CONST) { |
| 3200 return Bailout("reference to const context slot"); | 3200 return Bailout("reference to const context slot"); |
| 3201 } | 3201 } |
| 3202 HValue* context = BuildContextChainWalk(variable); | 3202 HValue* context = BuildContextChainWalk(variable); |
| 3203 HLoadContextSlot* instr = | 3203 HLoadContextSlot* instr = |
| 3204 new(zone()) HLoadContextSlot(context, variable->index()); | 3204 new(zone()) HLoadContextSlot(context, variable->index()); |
| 3205 return ast_context()->ReturnInstruction(instr, expr->id()); | 3205 return ast_context()->ReturnInstruction(instr, expr->id()); |
| 3206 } | 3206 } |
| 3207 | 3207 |
| 3208 case Variable::LOOKUP: | 3208 case Variable::LOOKUP: |
| 3209 return Bailout("reference to a variable which requires dynamic lookup"); | 3209 return Bailout("reference to a variable which requires dynamic lookup"); |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3656 VariableProxy* proxy = target->AsVariableProxy(); | 3656 VariableProxy* proxy = target->AsVariableProxy(); |
| 3657 Property* prop = target->AsProperty(); | 3657 Property* prop = target->AsProperty(); |
| 3658 ASSERT(proxy == NULL || prop == NULL); | 3658 ASSERT(proxy == NULL || prop == NULL); |
| 3659 | 3659 |
| 3660 // We have a second position recorded in the FullCodeGenerator to have | 3660 // We have a second position recorded in the FullCodeGenerator to have |
| 3661 // type feedback for the binary operation. | 3661 // type feedback for the binary operation. |
| 3662 BinaryOperation* operation = expr->binary_operation(); | 3662 BinaryOperation* operation = expr->binary_operation(); |
| 3663 | 3663 |
| 3664 if (proxy != NULL) { | 3664 if (proxy != NULL) { |
| 3665 Variable* var = proxy->var(); | 3665 Variable* var = proxy->var(); |
| 3666 if (var->mode() == Variable::CONST || var->mode() == Variable::LET) { | 3666 if (var->mode() == CONST || var->mode() == LET) { |
| 3667 return Bailout("unsupported let or const compound assignment"); | 3667 return Bailout("unsupported let or const compound assignment"); |
| 3668 } | 3668 } |
| 3669 | 3669 |
| 3670 CHECK_ALIVE(VisitForValue(operation)); | 3670 CHECK_ALIVE(VisitForValue(operation)); |
| 3671 | 3671 |
| 3672 switch (var->location()) { | 3672 switch (var->location()) { |
| 3673 case Variable::UNALLOCATED: | 3673 case Variable::UNALLOCATED: |
| 3674 HandleGlobalVariableAssignment(var, | 3674 HandleGlobalVariableAssignment(var, |
| 3675 Top(), | 3675 Top(), |
| 3676 expr->position(), | 3676 expr->position(), |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3801 | 3801 |
| 3802 if (expr->is_compound()) { | 3802 if (expr->is_compound()) { |
| 3803 HandleCompoundAssignment(expr); | 3803 HandleCompoundAssignment(expr); |
| 3804 return; | 3804 return; |
| 3805 } | 3805 } |
| 3806 | 3806 |
| 3807 if (prop != NULL) { | 3807 if (prop != NULL) { |
| 3808 HandlePropertyAssignment(expr); | 3808 HandlePropertyAssignment(expr); |
| 3809 } else if (proxy != NULL) { | 3809 } else if (proxy != NULL) { |
| 3810 Variable* var = proxy->var(); | 3810 Variable* var = proxy->var(); |
| 3811 if (var->mode() == Variable::CONST) { | 3811 if (var->mode() == CONST) { |
| 3812 if (expr->op() != Token::INIT_CONST) { | 3812 if (expr->op() != Token::INIT_CONST) { |
| 3813 return Bailout("non-initializer assignment to const"); | 3813 return Bailout("non-initializer assignment to const"); |
| 3814 } | 3814 } |
| 3815 if (!var->IsStackAllocated()) { | 3815 if (!var->IsStackAllocated()) { |
| 3816 return Bailout("assignment to const context slot"); | 3816 return Bailout("assignment to const context slot"); |
| 3817 } | 3817 } |
| 3818 // We insert a use of the old value to detect unsupported uses of const | 3818 // We insert a use of the old value to detect unsupported uses of const |
| 3819 // variables (e.g. initialization inside a loop). | 3819 // variables (e.g. initialization inside a loop). |
| 3820 HValue* old_value = environment()->Lookup(var); | 3820 HValue* old_value = environment()->Lookup(var); |
| 3821 AddInstruction(new HUseConst(old_value)); | 3821 AddInstruction(new HUseConst(old_value)); |
| 3822 } else if (var->mode() == Variable::LET) { | 3822 } else if (var->mode() == LET) { |
| 3823 return Bailout("unsupported assignment to let"); | 3823 return Bailout("unsupported assignment to let"); |
| 3824 } | 3824 } |
| 3825 | 3825 |
| 3826 if (proxy->IsArguments()) return Bailout("assignment to arguments"); | 3826 if (proxy->IsArguments()) return Bailout("assignment to arguments"); |
| 3827 | 3827 |
| 3828 // Handle the assignment. | 3828 // Handle the assignment. |
| 3829 switch (var->location()) { | 3829 switch (var->location()) { |
| 3830 case Variable::UNALLOCATED: | 3830 case Variable::UNALLOCATED: |
| 3831 CHECK_ALIVE(VisitForValue(expr->value())); | 3831 CHECK_ALIVE(VisitForValue(expr->value())); |
| 3832 HandleGlobalVariableAssignment(var, | 3832 HandleGlobalVariableAssignment(var, |
| 3833 Top(), | 3833 Top(), |
| 3834 expr->position(), | 3834 expr->position(), |
| 3835 expr->AssignmentId()); | 3835 expr->AssignmentId()); |
| 3836 return ast_context()->ReturnValue(Pop()); | 3836 return ast_context()->ReturnValue(Pop()); |
| 3837 | 3837 |
| 3838 case Variable::PARAMETER: | 3838 case Variable::PARAMETER: |
| 3839 case Variable::LOCAL: { | 3839 case Variable::LOCAL: { |
| 3840 // We do not allow the arguments object to occur in a context where it | 3840 // We do not allow the arguments object to occur in a context where it |
| 3841 // may escape, but assignments to stack-allocated locals are | 3841 // may escape, but assignments to stack-allocated locals are |
| 3842 // permitted. | 3842 // permitted. |
| 3843 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED)); | 3843 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED)); |
| 3844 HValue* value = Pop(); | 3844 HValue* value = Pop(); |
| 3845 Bind(var, value); | 3845 Bind(var, value); |
| 3846 return ast_context()->ReturnValue(value); | 3846 return ast_context()->ReturnValue(value); |
| 3847 } | 3847 } |
| 3848 | 3848 |
| 3849 case Variable::CONTEXT: { | 3849 case Variable::CONTEXT: { |
| 3850 ASSERT(var->mode() != Variable::CONST); | 3850 ASSERT(var->mode() != CONST); |
| 3851 // Bail out if we try to mutate a parameter value in a function using | 3851 // Bail out if we try to mutate a parameter value in a function using |
| 3852 // the arguments object. We do not (yet) correctly handle the | 3852 // the arguments object. We do not (yet) correctly handle the |
| 3853 // arguments property of the function. | 3853 // arguments property of the function. |
| 3854 if (info()->scope()->arguments() != NULL) { | 3854 if (info()->scope()->arguments() != NULL) { |
| 3855 // Parameters will rewrite to context slots. We have no direct way | 3855 // Parameters will rewrite to context slots. We have no direct way |
| 3856 // to detect that the variable is a parameter. | 3856 // to detect that the variable is a parameter. |
| 3857 int count = info()->scope()->num_parameters(); | 3857 int count = info()->scope()->num_parameters(); |
| 3858 for (int i = 0; i < count; ++i) { | 3858 for (int i = 0; i < count; ++i) { |
| 3859 if (var == info()->scope()->parameter(i)) { | 3859 if (var == info()->scope()->parameter(i)) { |
| 3860 return Bailout("assignment to parameter in arguments object"); | 3860 return Bailout("assignment to parameter in arguments object"); |
| (...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5396 // Match the full code generator stack by simulating an extra stack | 5396 // Match the full code generator stack by simulating an extra stack |
| 5397 // element for postfix operations in a non-effect context. The return | 5397 // element for postfix operations in a non-effect context. The return |
| 5398 // value is ToNumber(input). | 5398 // value is ToNumber(input). |
| 5399 bool returns_original_input = | 5399 bool returns_original_input = |
| 5400 expr->is_postfix() && !ast_context()->IsEffect(); | 5400 expr->is_postfix() && !ast_context()->IsEffect(); |
| 5401 HValue* input = NULL; // ToNumber(original_input). | 5401 HValue* input = NULL; // ToNumber(original_input). |
| 5402 HValue* after = NULL; // The result after incrementing or decrementing. | 5402 HValue* after = NULL; // The result after incrementing or decrementing. |
| 5403 | 5403 |
| 5404 if (proxy != NULL) { | 5404 if (proxy != NULL) { |
| 5405 Variable* var = proxy->var(); | 5405 Variable* var = proxy->var(); |
| 5406 if (var->mode() == Variable::CONST) { | 5406 if (var->mode() == CONST) { |
| 5407 return Bailout("unsupported count operation with const"); | 5407 return Bailout("unsupported count operation with const"); |
| 5408 } | 5408 } |
| 5409 // Argument of the count operation is a variable, not a property. | 5409 // Argument of the count operation is a variable, not a property. |
| 5410 ASSERT(prop == NULL); | 5410 ASSERT(prop == NULL); |
| 5411 CHECK_ALIVE(VisitForValue(target)); | 5411 CHECK_ALIVE(VisitForValue(target)); |
| 5412 | 5412 |
| 5413 after = BuildIncrement(returns_original_input, expr); | 5413 after = BuildIncrement(returns_original_input, expr); |
| 5414 input = returns_original_input ? Top() : Pop(); | 5414 input = returns_original_input ? Top() : Pop(); |
| 5415 Push(after); | 5415 Push(after); |
| 5416 | 5416 |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5970 return ast_context()->ReturnInstruction(self, expr->id()); | 5970 return ast_context()->ReturnInstruction(self, expr->id()); |
| 5971 } | 5971 } |
| 5972 | 5972 |
| 5973 | 5973 |
| 5974 void HGraphBuilder::VisitDeclaration(Declaration* decl) { | 5974 void HGraphBuilder::VisitDeclaration(Declaration* decl) { |
| 5975 HandleDeclaration(decl->proxy(), decl->mode(), decl->fun()); | 5975 HandleDeclaration(decl->proxy(), decl->mode(), decl->fun()); |
| 5976 } | 5976 } |
| 5977 | 5977 |
| 5978 | 5978 |
| 5979 void HGraphBuilder::HandleDeclaration(VariableProxy* proxy, | 5979 void HGraphBuilder::HandleDeclaration(VariableProxy* proxy, |
| 5980 Variable::Mode mode, | 5980 VariableMode mode, |
| 5981 FunctionLiteral* function) { | 5981 FunctionLiteral* function) { |
| 5982 if (mode == Variable::LET) return Bailout("unsupported let declaration"); | 5982 if (mode == LET) return Bailout("unsupported let declaration"); |
| 5983 Variable* var = proxy->var(); | 5983 Variable* var = proxy->var(); |
| 5984 switch (var->location()) { | 5984 switch (var->location()) { |
| 5985 case Variable::UNALLOCATED: | 5985 case Variable::UNALLOCATED: |
| 5986 return Bailout("unsupported global declaration"); | 5986 return Bailout("unsupported global declaration"); |
| 5987 case Variable::PARAMETER: | 5987 case Variable::PARAMETER: |
| 5988 case Variable::LOCAL: | 5988 case Variable::LOCAL: |
| 5989 case Variable::CONTEXT: | 5989 case Variable::CONTEXT: |
| 5990 if (mode == Variable::CONST || function != NULL) { | 5990 if (mode == CONST || function != NULL) { |
| 5991 HValue* value = NULL; | 5991 HValue* value = NULL; |
| 5992 if (mode == Variable::CONST) { | 5992 if (mode == CONST) { |
| 5993 value = graph()->GetConstantHole(); | 5993 value = graph()->GetConstantHole(); |
| 5994 } else { | 5994 } else { |
| 5995 VisitForValue(function); | 5995 VisitForValue(function); |
| 5996 value = Pop(); | 5996 value = Pop(); |
| 5997 } | 5997 } |
| 5998 if (var->IsContextSlot()) { | 5998 if (var->IsContextSlot()) { |
| 5999 HValue* context = environment()->LookupContext(); | 5999 HValue* context = environment()->LookupContext(); |
| 6000 HStoreContextSlot* store = | 6000 HStoreContextSlot* store = |
| 6001 new HStoreContextSlot(context, var->index(), value); | 6001 new HStoreContextSlot(context, var->index(), value); |
| 6002 AddInstruction(store); | 6002 AddInstruction(store); |
| (...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6939 } | 6939 } |
| 6940 } | 6940 } |
| 6941 | 6941 |
| 6942 #ifdef DEBUG | 6942 #ifdef DEBUG |
| 6943 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 6943 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 6944 if (allocator_ != NULL) allocator_->Verify(); | 6944 if (allocator_ != NULL) allocator_->Verify(); |
| 6945 #endif | 6945 #endif |
| 6946 } | 6946 } |
| 6947 | 6947 |
| 6948 } } // namespace v8::internal | 6948 } } // namespace v8::internal |
| OLD | NEW |