Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 | 40 |
| 41 static int CompareLocal(Variable* const* v, Variable* const* w) { | 41 static int CompareLocal(Variable* const* v, Variable* const* w) { |
| 42 int x = (*v)->index(); | 42 int x = (*v)->index(); |
| 43 int y = (*w)->index(); | 43 int y = (*w)->index(); |
| 44 // Consider sorting them according to type as well? | 44 // Consider sorting them according to type as well? |
| 45 return x - y; | 45 return x - y; |
| 46 } | 46 } |
| 47 | 47 |
| 48 | 48 |
| 49 Handle<ScopeInfo> ScopeInfo::Create(Scope* scope) { | 49 Handle<ScopeInfo> ScopeInfo::Create(Scope* scope) { |
| 50 ZoneList<Variable*> variables(32); // 32 is a wild guess | |
| 51 ASSERT(variables.is_empty()); | |
| 52 scope->CollectUsedVariables(&variables); | |
| 53 | |
| 54 ZoneList<Variable*> stack_locals(scope->num_stack_slots()); | |
| 55 ZoneList<Variable*> context_locals(scope->num_heap_slots()); | |
| 56 | |
| 57 // Collect stack and context locals. | 50 // Collect stack and context locals. |
| 58 for (int i = 0; i < variables.length(); i++) { | 51 const int stack_local_count = scope->StackLocalCount(); |
| 59 Variable* var = variables[i]; | 52 const int context_local_count = scope->ContextLocalCount(); |
| 60 ASSERT(var->is_used()); | 53 ZoneList<Variable*> stack_locals(stack_local_count); |
| 61 switch (var->location()) { | 54 ZoneList<Variable*> context_locals(context_local_count); |
| 62 case Variable::UNALLOCATED: | 55 scope->CollectStackAndContextLocals(&stack_locals, &context_locals); |
| 63 case Variable::PARAMETER: | 56 // Make sure we allocate the correct amount. |
| 64 break; | 57 ASSERT(stack_locals.length() == stack_local_count); |
| 65 | 58 ASSERT(context_locals.length() == context_local_count); |
|
Kevin Millikin (Chromium)
2011/11/03 13:12:20
Are these asserts true for the case where some var
Steven
2011/11/03 14:55:59
Yep. Those counts actually reflect how many times
| |
| 66 case Variable::LOCAL: | |
| 67 stack_locals.Add(var); | |
| 68 break; | |
| 69 | |
| 70 case Variable::CONTEXT: | |
| 71 context_locals.Add(var); | |
| 72 break; | |
| 73 | |
| 74 case Variable::LOOKUP: | |
| 75 // We don't expect lookup variables in the locals list. | |
| 76 UNREACHABLE(); | |
| 77 break; | |
| 78 } | |
| 79 } | |
| 80 | 59 |
| 81 // Determine use and location of the function variable if it is present. | 60 // Determine use and location of the function variable if it is present. |
| 82 FunctionVariableInfo function_name_info; | 61 FunctionVariableInfo function_name_info; |
| 83 VariableMode function_variable_mode; | 62 VariableMode function_variable_mode; |
| 84 if (scope->is_function_scope() && scope->function() != NULL) { | 63 if (scope->is_function_scope() && scope->function() != NULL) { |
| 85 Variable* var = scope->function()->var(); | 64 Variable* var = scope->function()->var(); |
| 86 if (!var->is_used()) { | 65 if (!var->is_used()) { |
| 87 function_name_info = UNUSED; | 66 function_name_info = UNUSED; |
| 88 } else if (var->IsContextSlot()) { | 67 } else if (var->IsContextSlot()) { |
| 89 function_name_info = CONTEXT; | 68 function_name_info = CONTEXT; |
| 90 } else { | 69 } else { |
| 91 ASSERT(var->IsStackLocal()); | 70 ASSERT(var->IsStackLocal()); |
| 92 function_name_info = STACK; | 71 function_name_info = STACK; |
| 93 } | 72 } |
| 94 function_variable_mode = var->mode(); | 73 function_variable_mode = var->mode(); |
| 95 } else { | 74 } else { |
| 96 function_name_info = NONE; | 75 function_name_info = NONE; |
| 97 function_variable_mode = VAR; | 76 function_variable_mode = VAR; |
| 98 } | 77 } |
| 99 | 78 |
| 100 const bool has_function_name = function_name_info != NONE; | 79 const bool has_function_name = function_name_info != NONE; |
| 101 const int parameter_count = scope->num_parameters(); | 80 const int parameter_count = scope->num_parameters(); |
| 102 const int stack_local_count = stack_locals.length(); | |
| 103 const int context_local_count = context_locals.length(); | |
| 104 const int length = kVariablePartIndex | 81 const int length = kVariablePartIndex |
| 105 + parameter_count + stack_local_count + 2 * context_local_count | 82 + parameter_count + stack_local_count + 2 * context_local_count |
| 106 + (has_function_name ? 2 : 0); | 83 + (has_function_name ? 2 : 0); |
| 107 | 84 |
| 108 Handle<ScopeInfo> scope_info = FACTORY->NewScopeInfo(length); | 85 Handle<ScopeInfo> scope_info = FACTORY->NewScopeInfo(length); |
| 109 | 86 |
| 110 // Encode the flags. | 87 // Encode the flags. |
| 111 int flags = TypeField::encode(scope->type()) | | 88 int flags = TypeField::encode(scope->type()) | |
| 112 CallsEvalField::encode(scope->calls_eval()) | | 89 CallsEvalField::encode(scope->calls_eval()) | |
| 113 StrictModeField::encode(scope->is_strict_mode()) | | 90 StrictModeField::encode(scope->is_strict_mode()) | |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 Context::MIN_CONTEXT_SLOTS, | 507 Context::MIN_CONTEXT_SLOTS, |
| 531 ContextLocalNameEntriesIndex(), | 508 ContextLocalNameEntriesIndex(), |
| 532 ContextLocalNameEntriesIndex() + ContextLocalCount(), | 509 ContextLocalNameEntriesIndex() + ContextLocalCount(), |
| 533 this); | 510 this); |
| 534 | 511 |
| 535 PrintF("}\n"); | 512 PrintF("}\n"); |
| 536 } | 513 } |
| 537 #endif // DEBUG | 514 #endif // DEBUG |
| 538 | 515 |
| 539 } } // namespace v8::internal | 516 } } // namespace v8::internal |
| OLD | NEW |