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

Side by Side Diff: src/hydrogen.cc

Issue 9704054: Refactoring of code generation for declarations, in preparation for modules. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Florian's comments. Created 8 years, 8 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/hydrogen.h ('k') | src/ia32/full-codegen-ia32.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 2462 matching lines...) Expand 10 before | Expand all | Expand 10 after
2473 // not replayed by the Lithium translation. 2473 // not replayed by the Lithium translation.
2474 HEnvironment* initial_env = environment()->CopyWithoutHistory(); 2474 HEnvironment* initial_env = environment()->CopyWithoutHistory();
2475 HBasicBlock* body_entry = CreateBasicBlock(initial_env); 2475 HBasicBlock* body_entry = CreateBasicBlock(initial_env);
2476 current_block()->Goto(body_entry); 2476 current_block()->Goto(body_entry);
2477 body_entry->SetJoinId(AstNode::kFunctionEntryId); 2477 body_entry->SetJoinId(AstNode::kFunctionEntryId);
2478 set_current_block(body_entry); 2478 set_current_block(body_entry);
2479 2479
2480 // Handle implicit declaration of the function name in named function 2480 // Handle implicit declaration of the function name in named function
2481 // expressions before other declarations. 2481 // expressions before other declarations.
2482 if (scope->is_function_scope() && scope->function() != NULL) { 2482 if (scope->is_function_scope() && scope->function() != NULL) {
2483 HandleDeclaration(scope->function(), CONST, NULL, NULL); 2483 VisitVariableDeclaration(scope->function());
2484 } 2484 }
2485 VisitDeclarations(scope->declarations()); 2485 VisitDeclarations(scope->declarations());
2486 AddSimulate(AstNode::kDeclarationsId); 2486 AddSimulate(AstNode::kDeclarationsId);
2487 2487
2488 HValue* context = environment()->LookupContext(); 2488 HValue* context = environment()->LookupContext();
2489 AddInstruction( 2489 AddInstruction(
2490 new(zone()) HStackCheck(context, HStackCheck::kFunctionEntry)); 2490 new(zone()) HStackCheck(context, HStackCheck::kFunctionEntry));
2491 2491
2492 VisitStatements(info()->function()->body()); 2492 VisitStatements(info()->function()->body());
2493 if (HasStackOverflow()) return NULL; 2493 if (HasStackOverflow()) return NULL;
(...skipping 4409 matching lines...) Expand 10 before | Expand all | Expand 10 after
6903 ASSERT(current_block() != NULL); 6903 ASSERT(current_block() != NULL);
6904 ASSERT(current_block()->HasPredecessor()); 6904 ASSERT(current_block()->HasPredecessor());
6905 HThisFunction* self = new(zone()) HThisFunction( 6905 HThisFunction* self = new(zone()) HThisFunction(
6906 function_state()->compilation_info()->closure()); 6906 function_state()->compilation_info()->closure());
6907 return ast_context()->ReturnInstruction(self, expr->id()); 6907 return ast_context()->ReturnInstruction(self, expr->id());
6908 } 6908 }
6909 6909
6910 6910
6911 void HGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) { 6911 void HGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) {
6912 int length = declarations->length(); 6912 int length = declarations->length();
6913 int global_count = 0; 6913 int save_global_count = global_count_;
6914 for (int i = 0; i < declarations->length(); i++) { 6914 global_count_ = 0;
6915 Declaration* decl = declarations->at(i); 6915
6916 FunctionDeclaration* fun_decl = decl->AsFunctionDeclaration(); 6916 AstVisitor::VisitDeclarations(declarations);
6917 HandleDeclaration(decl->proxy(),
6918 decl->mode(),
6919 fun_decl != NULL ? fun_decl->fun() : NULL,
6920 &global_count);
6921 }
6922 6917
6923 // Batch declare global functions and variables. 6918 // Batch declare global functions and variables.
6924 if (global_count > 0) { 6919 if (global_count_ > 0) {
6925 Handle<FixedArray> array = 6920 Handle<FixedArray> array =
6926 isolate()->factory()->NewFixedArray(2 * global_count, TENURED); 6921 isolate()->factory()->NewFixedArray(2 * global_count_, TENURED);
6927 for (int j = 0, i = 0; i < length; i++) { 6922 for (int j = 0, i = 0; i < length; i++) {
6928 Declaration* decl = declarations->at(i); 6923 Declaration* decl = declarations->at(i);
6929 Variable* var = decl->proxy()->var(); 6924 Variable* var = decl->proxy()->var();
6930 6925
6931 if (var->IsUnallocated()) { 6926 if (var->IsUnallocated()) {
6932 array->set(j++, *(var->name())); 6927 array->set(j++, *(var->name()));
6933 FunctionDeclaration* fun_decl = decl->AsFunctionDeclaration(); 6928 FunctionDeclaration* fun_decl = decl->AsFunctionDeclaration();
6934 if (fun_decl == NULL) { 6929 if (fun_decl == NULL) {
6935 if (var->binding_needs_init()) { 6930 if (var->binding_needs_init()) {
6936 // In case this binding needs initialization use the hole. 6931 // In case this binding needs initialization use the hole.
(...skipping 15 matching lines...) Expand all
6952 } 6947 }
6953 int flags = DeclareGlobalsEvalFlag::encode(info()->is_eval()) | 6948 int flags = DeclareGlobalsEvalFlag::encode(info()->is_eval()) |
6954 DeclareGlobalsNativeFlag::encode(info()->is_native()) | 6949 DeclareGlobalsNativeFlag::encode(info()->is_native()) |
6955 DeclareGlobalsLanguageMode::encode(info()->language_mode()); 6950 DeclareGlobalsLanguageMode::encode(info()->language_mode());
6956 HInstruction* result = 6951 HInstruction* result =
6957 new(zone()) HDeclareGlobals(environment()->LookupContext(), 6952 new(zone()) HDeclareGlobals(environment()->LookupContext(),
6958 array, 6953 array,
6959 flags); 6954 flags);
6960 AddInstruction(result); 6955 AddInstruction(result);
6961 } 6956 }
6957
6958 global_count_ = save_global_count;
6962 } 6959 }
6963 6960
6964 6961
6965 void HGraphBuilder::HandleDeclaration(VariableProxy* proxy, 6962 void HGraphBuilder::VisitVariableDeclaration(VariableDeclaration* declaration) {
6966 VariableMode mode, 6963 VariableProxy* proxy = declaration->proxy();
6967 FunctionLiteral* function, 6964 VariableMode mode = declaration->mode();
6968 int* global_count) {
6969 Variable* var = proxy->var(); 6965 Variable* var = proxy->var();
6970 bool binding_needs_init = 6966 bool hole_init = mode == CONST || mode == CONST_HARMONY || mode == LET;
6971 (mode == CONST || mode == CONST_HARMONY || mode == LET);
6972 switch (var->location()) { 6967 switch (var->location()) {
6973 case Variable::UNALLOCATED: 6968 case Variable::UNALLOCATED:
6974 ++(*global_count); 6969 ++global_count_;
6975 return; 6970 return;
6976 case Variable::PARAMETER: 6971 case Variable::PARAMETER:
6977 case Variable::LOCAL: 6972 case Variable::LOCAL:
6973 if (hole_init) {
6974 HValue* value = graph()->GetConstantHole();
6975 environment()->Bind(var, value);
6976 }
6977 break;
6978 case Variable::CONTEXT: 6978 case Variable::CONTEXT:
6979 if (binding_needs_init || function != NULL) { 6979 if (hole_init) {
6980 HValue* value = NULL; 6980 HValue* value = graph()->GetConstantHole();
6981 if (function != NULL) { 6981 HValue* context = environment()->LookupContext();
6982 CHECK_ALIVE(VisitForValue(function)); 6982 HStoreContextSlot* store = new HStoreContextSlot(
6983 value = Pop(); 6983 context, var->index(), HStoreContextSlot::kNoCheck, value);
6984 } else { 6984 AddInstruction(store);
6985 value = graph()->GetConstantHole(); 6985 if (store->HasObservableSideEffects()) AddSimulate(proxy->id());
6986 }
6987 if (var->IsContextSlot()) {
6988 HValue* context = environment()->LookupContext();
6989 HStoreContextSlot* store = new HStoreContextSlot(
6990 context, var->index(), HStoreContextSlot::kNoCheck, value);
6991 AddInstruction(store);
6992 if (store->HasObservableSideEffects()) AddSimulate(proxy->id());
6993 } else {
6994 environment()->Bind(var, value);
6995 }
6996 } 6986 }
6997 break; 6987 break;
6998 case Variable::LOOKUP: 6988 case Variable::LOOKUP:
6999 return Bailout("unsupported lookup slot in declaration"); 6989 return Bailout("unsupported lookup slot in declaration");
7000 } 6990 }
7001 } 6991 }
7002 6992
7003 6993
7004 void HGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) { 6994 void HGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* declaration) {
7005 UNREACHABLE(); 6995 VariableProxy* proxy = declaration->proxy();
6996 Variable* var = proxy->var();
6997 switch (var->location()) {
6998 case Variable::UNALLOCATED:
6999 ++global_count_;
7000 return;
7001 case Variable::PARAMETER:
7002 case Variable::LOCAL: {
7003 CHECK_ALIVE(VisitForValue(declaration->fun()));
7004 HValue* value = Pop();
7005 environment()->Bind(var, value);
7006 break;
7007 }
7008 case Variable::CONTEXT: {
7009 CHECK_ALIVE(VisitForValue(declaration->fun()));
7010 HValue* value = Pop();
7011 HValue* context = environment()->LookupContext();
7012 HStoreContextSlot* store = new HStoreContextSlot(
7013 context, var->index(), HStoreContextSlot::kNoCheck, value);
7014 AddInstruction(store);
7015 if (store->HasObservableSideEffects()) AddSimulate(proxy->id());
7016 break;
7017 }
7018 case Variable::LOOKUP:
7019 return Bailout("unsupported lookup slot in declaration");
7020 }
7006 } 7021 }
7007 7022
7008 7023
7009 void HGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) { 7024 void HGraphBuilder::VisitModuleDeclaration(ModuleDeclaration* declaration) {
7010 UNREACHABLE(); 7025 VariableProxy* proxy = declaration->proxy();
7026 Variable* var = proxy->var();
7027 switch (var->location()) {
7028 case Variable::UNALLOCATED:
7029 ++global_count_;
7030 return;
7031 case Variable::CONTEXT: {
7032 // TODO(rossberg)
7033 break;
7034 }
7035 case Variable::PARAMETER:
7036 case Variable::LOCAL:
7037 case Variable::LOOKUP:
7038 UNREACHABLE();
7039 }
7011 } 7040 }
7012 7041
7013 7042
7014 void HGraphBuilder::VisitModuleDeclaration(ModuleDeclaration* decl) { 7043 void HGraphBuilder::VisitImportDeclaration(ImportDeclaration* declaration) {
7015 UNREACHABLE(); 7044 VariableProxy* proxy = declaration->proxy();
7045 Variable* var = proxy->var();
7046 switch (var->location()) {
7047 case Variable::UNALLOCATED:
7048 ++global_count_;
7049 return;
7050 case Variable::CONTEXT: {
7051 // TODO(rossberg)
7052 break;
7053 }
7054 case Variable::PARAMETER:
7055 case Variable::LOCAL:
7056 case Variable::LOOKUP:
7057 UNREACHABLE();
7058 }
7016 } 7059 }
7017 7060
7018 7061
7019 void HGraphBuilder::VisitImportDeclaration(ImportDeclaration* decl) { 7062 void HGraphBuilder::VisitExportDeclaration(ExportDeclaration* declaration) {
7020 UNREACHABLE(); 7063 // TODO(rossberg)
7021 } 7064 }
7022 7065
7023 7066
7024 void HGraphBuilder::VisitExportDeclaration(ExportDeclaration* decl) {
7025 UNREACHABLE();
7026 }
7027
7028
7029 void HGraphBuilder::VisitModuleLiteral(ModuleLiteral* module) { 7067 void HGraphBuilder::VisitModuleLiteral(ModuleLiteral* module) {
7030 // TODO(rossberg) 7068 // TODO(rossberg)
7031 } 7069 }
7032 7070
7033 7071
7034 void HGraphBuilder::VisitModuleVariable(ModuleVariable* module) { 7072 void HGraphBuilder::VisitModuleVariable(ModuleVariable* module) {
7035 // TODO(rossberg) 7073 // TODO(rossberg)
7036 } 7074 }
7037 7075
7038 7076
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
8125 } 8163 }
8126 } 8164 }
8127 8165
8128 #ifdef DEBUG 8166 #ifdef DEBUG
8129 if (graph_ != NULL) graph_->Verify(false); // No full verify. 8167 if (graph_ != NULL) graph_->Verify(false); // No full verify.
8130 if (allocator_ != NULL) allocator_->Verify(); 8168 if (allocator_ != NULL) allocator_->Verify();
8131 #endif 8169 #endif
8132 } 8170 }
8133 8171
8134 } } // namespace v8::internal 8172 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698