| 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 2255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2266 { | 2266 { |
| 2267 HPhase phase("Block building"); | 2267 HPhase phase("Block building"); |
| 2268 current_block_ = graph()->entry_block(); | 2268 current_block_ = graph()->entry_block(); |
| 2269 | 2269 |
| 2270 Scope* scope = info()->scope(); | 2270 Scope* scope = info()->scope(); |
| 2271 if (scope->HasIllegalRedeclaration()) { | 2271 if (scope->HasIllegalRedeclaration()) { |
| 2272 Bailout("function with illegal redeclaration"); | 2272 Bailout("function with illegal redeclaration"); |
| 2273 return NULL; | 2273 return NULL; |
| 2274 } | 2274 } |
| 2275 SetupScope(scope); | 2275 SetupScope(scope); |
| 2276 VisitDeclarations(scope->declarations()); | |
| 2277 HValue* context = environment()->LookupContext(); | |
| 2278 AddInstruction( | |
| 2279 new(zone()) HStackCheck(context, HStackCheck::kFunctionEntry)); | |
| 2280 | 2276 |
| 2281 // Add an edge to the body entry. This is warty: the graph's start | 2277 // Add an edge to the body entry. This is warty: the graph's start |
| 2282 // environment will be used by the Lithium translation as the initial | 2278 // environment will be used by the Lithium translation as the initial |
| 2283 // environment on graph entry, but it has now been mutated by the | 2279 // environment on graph entry, but it has now been mutated by the |
| 2284 // Hydrogen translation of the instructions in the start block. This | 2280 // Hydrogen translation of the instructions in the start block. This |
| 2285 // environment uses values which have not been defined yet. These | 2281 // environment uses values which have not been defined yet. These |
| 2286 // Hydrogen instructions will then be replayed by the Lithium | 2282 // Hydrogen instructions will then be replayed by the Lithium |
| 2287 // translation, so they cannot have an environment effect. The edge to | 2283 // translation, so they cannot have an environment effect. The edge to |
| 2288 // the body's entry block (along with some special logic for the start | 2284 // the body's entry block (along with some special logic for the start |
| 2289 // block in HInstruction::InsertAfter) seals the start block from | 2285 // block in HInstruction::InsertAfter) seals the start block from |
| 2290 // getting unwanted instructions inserted. | 2286 // getting unwanted instructions inserted. |
| 2291 // | 2287 // |
| 2292 // TODO(kmillikin): Fix this. Stop mutating the initial environment. | 2288 // TODO(kmillikin): Fix this. Stop mutating the initial environment. |
| 2293 // Make the Hydrogen instructions in the initial block into Hydrogen | 2289 // Make the Hydrogen instructions in the initial block into Hydrogen |
| 2294 // values (but not instructions), present in the initial environment and | 2290 // values (but not instructions), present in the initial environment and |
| 2295 // not replayed by the Lithium translation. | 2291 // not replayed by the Lithium translation. |
| 2296 HEnvironment* initial_env = environment()->CopyWithoutHistory(); | 2292 HEnvironment* initial_env = environment()->CopyWithoutHistory(); |
| 2297 HBasicBlock* body_entry = CreateBasicBlock(initial_env); | 2293 HBasicBlock* body_entry = CreateBasicBlock(initial_env); |
| 2298 current_block()->Goto(body_entry); | 2294 current_block()->Goto(body_entry); |
| 2299 body_entry->SetJoinId(AstNode::kFunctionEntryId); | 2295 body_entry->SetJoinId(AstNode::kFunctionEntryId); |
| 2300 set_current_block(body_entry); | 2296 set_current_block(body_entry); |
| 2297 |
| 2298 // Handle implicit declaration of the function name in named function |
| 2299 // expressions before other declarations. |
| 2300 if (scope->is_function_scope() && scope->function() != NULL) { |
| 2301 if (!scope->function()->IsStackAllocated()) { |
| 2302 Bailout("unsupported declaration"); |
| 2303 return NULL; |
| 2304 } |
| 2305 environment()->Bind(scope->function(), graph()->GetConstantHole()); |
| 2306 } |
| 2307 VisitDeclarations(scope->declarations()); |
| 2308 AddSimulate(AstNode::kDeclarationsId); |
| 2309 |
| 2310 HValue* context = environment()->LookupContext(); |
| 2311 AddInstruction( |
| 2312 new(zone()) HStackCheck(context, HStackCheck::kFunctionEntry)); |
| 2313 |
| 2301 VisitStatements(info()->function()->body()); | 2314 VisitStatements(info()->function()->body()); |
| 2302 if (HasStackOverflow()) return NULL; | 2315 if (HasStackOverflow()) return NULL; |
| 2303 | 2316 |
| 2304 if (current_block() != NULL) { | 2317 if (current_block() != NULL) { |
| 2305 HReturn* instr = new(zone()) HReturn(graph()->GetConstantUndefined()); | 2318 HReturn* instr = new(zone()) HReturn(graph()->GetConstantUndefined()); |
| 2306 current_block()->FinishExit(instr); | 2319 current_block()->FinishExit(instr); |
| 2307 set_current_block(NULL); | 2320 set_current_block(NULL); |
| 2308 } | 2321 } |
| 2309 } | 2322 } |
| 2310 | 2323 |
| (...skipping 3486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5797 ASSERT(current_block() != NULL); | 5810 ASSERT(current_block() != NULL); |
| 5798 ASSERT(current_block()->HasPredecessor()); | 5811 ASSERT(current_block()->HasPredecessor()); |
| 5799 HThisFunction* self = new(zone()) HThisFunction; | 5812 HThisFunction* self = new(zone()) HThisFunction; |
| 5800 return ast_context()->ReturnInstruction(self, expr->id()); | 5813 return ast_context()->ReturnInstruction(self, expr->id()); |
| 5801 } | 5814 } |
| 5802 | 5815 |
| 5803 | 5816 |
| 5804 void HGraphBuilder::VisitDeclaration(Declaration* decl) { | 5817 void HGraphBuilder::VisitDeclaration(Declaration* decl) { |
| 5805 // We support only declarations that do not require code generation. | 5818 // We support only declarations that do not require code generation. |
| 5806 Variable* var = decl->proxy()->var(); | 5819 Variable* var = decl->proxy()->var(); |
| 5807 if (!var->IsStackAllocated() || decl->fun() != NULL) { | 5820 if (!var->IsStackAllocated()) { |
| 5808 return Bailout("unsupported declaration"); | 5821 return Bailout("unsupported declaration"); |
| 5809 } | 5822 } |
| 5810 | 5823 |
| 5811 if (decl->mode() == Variable::CONST) { | 5824 if (decl->mode() == Variable::CONST) { |
| 5812 ASSERT(var->IsStackAllocated()); | 5825 ASSERT(var->IsStackAllocated()); |
| 5813 environment()->Bind(var, graph()->GetConstantHole()); | 5826 environment()->Bind(var, graph()->GetConstantHole()); |
| 5827 } else if (decl->fun() != NULL) { |
| 5828 VisitForValue(decl->fun()); |
| 5829 HValue* function = Pop(); |
| 5830 environment()->Bind(var, function); |
| 5814 } | 5831 } |
| 5815 } | 5832 } |
| 5816 | 5833 |
| 5817 | 5834 |
| 5818 // Generators for inline runtime functions. | 5835 // Generators for inline runtime functions. |
| 5819 // Support for types. | 5836 // Support for types. |
| 5820 void HGraphBuilder::GenerateIsSmi(CallRuntime* call) { | 5837 void HGraphBuilder::GenerateIsSmi(CallRuntime* call) { |
| 5821 ASSERT(call->arguments()->length() == 1); | 5838 ASSERT(call->arguments()->length() == 1); |
| 5822 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); | 5839 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
| 5823 HValue* value = Pop(); | 5840 HValue* value = Pop(); |
| (...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6740 } | 6757 } |
| 6741 } | 6758 } |
| 6742 | 6759 |
| 6743 #ifdef DEBUG | 6760 #ifdef DEBUG |
| 6744 if (graph_ != NULL) graph_->Verify(); | 6761 if (graph_ != NULL) graph_->Verify(); |
| 6745 if (allocator_ != NULL) allocator_->Verify(); | 6762 if (allocator_ != NULL) allocator_->Verify(); |
| 6746 #endif | 6763 #endif |
| 6747 } | 6764 } |
| 6748 | 6765 |
| 6749 } } // namespace v8::internal | 6766 } } // namespace v8::internal |
| OLD | NEW |