OLD | NEW |
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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 for (int i = 0; i < inner_scopes_.length(); i++) { | 587 for (int i = 0; i < inner_scopes_.length(); i++) { |
588 VariableProxy* proxy = inner_scopes_[i]->CheckAssignmentToConst(); | 588 VariableProxy* proxy = inner_scopes_[i]->CheckAssignmentToConst(); |
589 if (proxy != NULL) return proxy; | 589 if (proxy != NULL) return proxy; |
590 } | 590 } |
591 | 591 |
592 // No assignments to const found. | 592 // No assignments to const found. |
593 return NULL; | 593 return NULL; |
594 } | 594 } |
595 | 595 |
596 | 596 |
| 597 class VarAndOrder { |
| 598 public: |
| 599 VarAndOrder(Variable* var, int order) : var_(var), order_(order) { } |
| 600 Variable* var() const { return var_; } |
| 601 int order() const { return order_; } |
| 602 static int Compare(const VarAndOrder* a, const VarAndOrder* b) { |
| 603 return a->order_ - b->order_; |
| 604 } |
| 605 |
| 606 private: |
| 607 Variable* var_; |
| 608 int order_; |
| 609 }; |
| 610 |
| 611 |
597 void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, | 612 void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, |
598 ZoneList<Variable*>* context_locals) { | 613 ZoneList<Variable*>* context_locals) { |
599 ASSERT(stack_locals != NULL); | 614 ASSERT(stack_locals != NULL); |
600 ASSERT(context_locals != NULL); | 615 ASSERT(context_locals != NULL); |
601 | 616 |
602 // Collect temporaries which are always allocated on the stack. | 617 // Collect temporaries which are always allocated on the stack. |
603 for (int i = 0; i < temps_.length(); i++) { | 618 for (int i = 0; i < temps_.length(); i++) { |
604 Variable* var = temps_[i]; | 619 Variable* var = temps_[i]; |
605 if (var->is_used()) { | 620 if (var->is_used()) { |
606 ASSERT(var->IsStackLocal()); | 621 ASSERT(var->IsStackLocal()); |
607 stack_locals->Add(var, zone()); | 622 stack_locals->Add(var, zone()); |
608 } | 623 } |
609 } | 624 } |
610 | 625 |
| 626 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); |
| 627 |
611 // Collect declared local variables. | 628 // Collect declared local variables. |
612 for (VariableMap::Entry* p = variables_.Start(); | 629 for (VariableMap::Entry* p = variables_.Start(); |
613 p != NULL; | 630 p != NULL; |
614 p = variables_.Next(p)) { | 631 p = variables_.Next(p)) { |
615 Variable* var = reinterpret_cast<Variable*>(p->value); | 632 Variable* var = reinterpret_cast<Variable*>(p->value); |
616 if (var->is_used()) { | 633 if (var->is_used()) { |
617 if (var->IsStackLocal()) { | 634 vars.Add(VarAndOrder(var, p->order), zone()); |
618 stack_locals->Add(var, zone()); | 635 } |
619 } else if (var->IsContextSlot()) { | 636 } |
620 context_locals->Add(var, zone()); | 637 vars.Sort(VarAndOrder::Compare); |
621 } | 638 int var_count = vars.length(); |
| 639 for (int i = 0; i < var_count; i++) { |
| 640 Variable* var = vars[i].var(); |
| 641 if (var->IsStackLocal()) { |
| 642 stack_locals->Add(var, zone()); |
| 643 } else if (var->IsContextSlot()) { |
| 644 context_locals->Add(var, zone()); |
622 } | 645 } |
623 } | 646 } |
624 } | 647 } |
625 | 648 |
626 | 649 |
627 bool Scope::AllocateVariables(CompilationInfo* info, | 650 bool Scope::AllocateVariables(CompilationInfo* info, |
628 AstNodeFactory<AstNullVisitor>* factory) { | 651 AstNodeFactory<AstNullVisitor>* factory) { |
629 // 1) Propagate scope information. | 652 // 1) Propagate scope information. |
630 bool outer_scope_calls_non_strict_eval = false; | 653 bool outer_scope_calls_non_strict_eval = false; |
631 if (outer_scope_ != NULL) { | 654 if (outer_scope_ != NULL) { |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 } | 1272 } |
1250 } | 1273 } |
1251 | 1274 |
1252 | 1275 |
1253 void Scope::AllocateNonParameterLocals() { | 1276 void Scope::AllocateNonParameterLocals() { |
1254 // All variables that have no rewrite yet are non-parameter locals. | 1277 // All variables that have no rewrite yet are non-parameter locals. |
1255 for (int i = 0; i < temps_.length(); i++) { | 1278 for (int i = 0; i < temps_.length(); i++) { |
1256 AllocateNonParameterLocal(temps_[i]); | 1279 AllocateNonParameterLocal(temps_[i]); |
1257 } | 1280 } |
1258 | 1281 |
| 1282 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); |
| 1283 |
1259 for (VariableMap::Entry* p = variables_.Start(); | 1284 for (VariableMap::Entry* p = variables_.Start(); |
1260 p != NULL; | 1285 p != NULL; |
1261 p = variables_.Next(p)) { | 1286 p = variables_.Next(p)) { |
1262 Variable* var = reinterpret_cast<Variable*>(p->value); | 1287 Variable* var = reinterpret_cast<Variable*>(p->value); |
1263 AllocateNonParameterLocal(var); | 1288 vars.Add(VarAndOrder(var, p->order), zone()); |
| 1289 } |
| 1290 |
| 1291 vars.Sort(VarAndOrder::Compare); |
| 1292 int var_count = vars.length(); |
| 1293 for (int i = 0; i < var_count; i++) { |
| 1294 AllocateNonParameterLocal(vars[i].var()); |
1264 } | 1295 } |
1265 | 1296 |
1266 // For now, function_ must be allocated at the very end. If it gets | 1297 // For now, function_ must be allocated at the very end. If it gets |
1267 // allocated in the context, it must be the last slot in the context, | 1298 // allocated in the context, it must be the last slot in the context, |
1268 // because of the current ScopeInfo implementation (see | 1299 // because of the current ScopeInfo implementation (see |
1269 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). | 1300 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). |
1270 if (function_ != NULL) { | 1301 if (function_ != NULL) { |
1271 AllocateNonParameterLocal(function_->proxy()->var()); | 1302 AllocateNonParameterLocal(function_->proxy()->var()); |
1272 } | 1303 } |
1273 } | 1304 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 for (int i = 0; i < inner_scopes_.length(); i++) { | 1419 for (int i = 0; i < inner_scopes_.length(); i++) { |
1389 Scope* inner_scope = inner_scopes_.at(i); | 1420 Scope* inner_scope = inner_scopes_.at(i); |
1390 if (inner_scope->is_module_scope()) { | 1421 if (inner_scope->is_module_scope()) { |
1391 inner_scope->LinkModules(info); | 1422 inner_scope->LinkModules(info); |
1392 } | 1423 } |
1393 } | 1424 } |
1394 } | 1425 } |
1395 | 1426 |
1396 | 1427 |
1397 } } // namespace v8::internal | 1428 } } // namespace v8::internal |
OLD | NEW |