Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 CompilationZoneScope zone_scope(DELETE_ON_EXIT); | 139 CompilationZoneScope zone_scope(DELETE_ON_EXIT); | 
| 140 | 140 | 
| 141 PostponeInterruptsScope postpone; | 141 PostponeInterruptsScope postpone; | 
| 142 | 142 | 
| 143 ASSERT(!i::Top::global_context().is_null()); | 143 ASSERT(!i::Top::global_context().is_null()); | 
| 144 script->set_context_data((*i::Top::global_context())->data()); | 144 script->set_context_data((*i::Top::global_context())->data()); | 
| 145 | 145 | 
| 146 bool is_json = (validate == Compiler::VALIDATE_JSON); | 146 bool is_json = (validate == Compiler::VALIDATE_JSON); | 
| 147 #ifdef ENABLE_DEBUGGER_SUPPORT | 147 #ifdef ENABLE_DEBUGGER_SUPPORT | 
| 148 if (is_eval || is_json) { | 148 if (is_eval || is_json) { | 
| 149 script->set_compilation_type( | 149 Script::CompilationType compilation_type = is_json | 
| 150 is_json ? Smi::FromInt(Script::COMPILATION_TYPE_JSON) : | 150 ? Script::COMPILATION_TYPE_JSON | 
| 151 Smi::FromInt(Script::COMPILATION_TYPE_EVAL)); | 151 : Script::COMPILATION_TYPE_EVAL; | 
| 152 script->set_compilation_type(Smi::FromInt(compilation_type)); | |
| 152 // For eval scripts add information on the function from which eval was | 153 // For eval scripts add information on the function from which eval was | 
| 153 // called. | 154 // called. | 
| 154 if (is_eval) { | 155 if (is_eval) { | 
| 155 StackTraceFrameIterator it; | 156 StackTraceFrameIterator it; | 
| 156 if (!it.done()) { | 157 if (!it.done()) { | 
| 157 script->set_eval_from_shared( | 158 script->set_eval_from_shared( | 
| 158 JSFunction::cast(it.frame()->function())->shared()); | 159 JSFunction::cast(it.frame()->function())->shared()); | 
| 159 int offset = static_cast<int>( | 160 int offset = static_cast<int>( | 
| 160 it.frame()->pc() - it.frame()->code()->instruction_start()); | 161 it.frame()->pc() - it.frame()->code()->instruction_start()); | 
| 161 script->set_eval_from_instructions_offset(Smi::FromInt(offset)); | 162 script->set_eval_from_instructions_offset(Smi::FromInt(offset)); | 
| 162 } | 163 } | 
| 163 } | 164 } | 
| 164 } | 165 } | 
| 165 | 166 | 
| 166 // Notify debugger | 167 // Notify debugger | 
| 167 Debugger::OnBeforeCompile(script); | 168 Debugger::OnBeforeCompile(script); | 
| 168 #endif | 169 #endif | 
| 169 | 170 | 
| 170 // Only allow non-global compiles for eval. | 171 // Only allow non-global compiles for eval. | 
| 171 ASSERT(is_eval || is_global); | 172 ASSERT(is_eval || is_global); | 
| 172 | 173 | 
| 173 // Build AST. | 174 // Build AST. | 
| 175 EagerCompilationInfo info(script, is_eval); | |
| 174 FunctionLiteral* lit = | 176 FunctionLiteral* lit = | 
| 175 MakeAST(is_global, script, extension, pre_data, is_json); | 177 MakeAST(is_global, script, extension, pre_data, is_json); | 
| 176 | 178 | 
| 177 LiveEditFunctionTracker live_edit_tracker(lit); | |
| 178 | |
| 179 // Check for parse errors. | 179 // Check for parse errors. | 
| 180 if (lit == NULL) { | 180 if (lit == NULL) { | 
| 181 ASSERT(Top::has_pending_exception()); | 181 ASSERT(Top::has_pending_exception()); | 
| 182 return Handle<SharedFunctionInfo>::null(); | 182 return Handle<SharedFunctionInfo>::null(); | 
| 183 } | 183 } | 
| 184 info.set_function(lit); | |
| 
 
Søren Thygesen Gjesse
2010/09/30 08:41:49
Why not pass the function literal to the EagerComp
 
Kevin Millikin (Google)
2010/09/30 08:47:21
I plan to refactor the parser entry points to take
 
 | |
| 184 | 185 | 
| 185 // Measure how long it takes to do the compilation; only take the | 186 // Measure how long it takes to do the compilation; only take the | 
| 186 // rest of the function into account to avoid overlap with the | 187 // rest of the function into account to avoid overlap with the | 
| 187 // parsing statistics. | 188 // parsing statistics. | 
| 188 HistogramTimer* rate = is_eval | 189 HistogramTimer* rate = is_eval | 
| 189 ? &Counters::compile_eval | 190 ? &Counters::compile_eval | 
| 190 : &Counters::compile; | 191 : &Counters::compile; | 
| 191 HistogramTimerScope timer(rate); | 192 HistogramTimerScope timer(rate); | 
| 192 | 193 | 
| 193 // Compile the code. | 194 // Compile the code. | 
| 194 CompilationInfo info(lit, script, is_eval); | 195 LiveEditFunctionTracker live_edit_tracker(lit); | 
| 195 Handle<Code> code = MakeCode(context, &info); | 196 Handle<Code> code = MakeCode(context, &info); | 
| 196 | 197 | 
| 197 // Check for stack-overflow exceptions. | 198 // Check for stack-overflow exceptions. | 
| 198 if (code.is_null()) { | 199 if (code.is_null()) { | 
| 199 Top::StackOverflow(); | 200 Top::StackOverflow(); | 
| 200 return Handle<SharedFunctionInfo>::null(); | 201 return Handle<SharedFunctionInfo>::null(); | 
| 201 } | 202 } | 
| 202 | 203 | 
| 203 if (script->name()->IsString()) { | 204 if (script->name()->IsString()) { | 
| 204 PROFILE(CodeCreateEvent( | 205 PROFILE(CodeCreateEvent( | 
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 } else { | 476 } else { | 
| 476 // The bodies of function literals have not yet been visited by | 477 // The bodies of function literals have not yet been visited by | 
| 477 // the AST optimizer/analyzer. | 478 // the AST optimizer/analyzer. | 
| 478 if (!Rewriter::Optimize(literal)) { | 479 if (!Rewriter::Optimize(literal)) { | 
| 479 return Handle<SharedFunctionInfo>::null(); | 480 return Handle<SharedFunctionInfo>::null(); | 
| 480 } | 481 } | 
| 481 | 482 | 
| 482 // Generate code and return it. The way that the compilation mode | 483 // Generate code and return it. The way that the compilation mode | 
| 483 // is controlled by the command-line flags is described in | 484 // is controlled by the command-line flags is described in | 
| 484 // the static helper function MakeCode. | 485 // the static helper function MakeCode. | 
| 485 CompilationInfo info(literal, script, false); | 486 EagerCompilationInfo info(script, false); | 
| 487 info.set_function(literal); | |
| 486 | 488 | 
| 487 bool is_run_once = literal->try_full_codegen(); | 489 bool is_run_once = literal->try_full_codegen(); | 
| 488 bool use_full = FLAG_full_compiler && !literal->contains_loops(); | 490 bool use_full = FLAG_full_compiler && !literal->contains_loops(); | 
| 489 if (AlwaysFullCompiler() || (use_full && is_run_once)) { | 491 if (AlwaysFullCompiler() || (use_full && is_run_once)) { | 
| 490 code = FullCodeGenerator::MakeCode(&info); | 492 code = FullCodeGenerator::MakeCode(&info); | 
| 491 } else { | 493 } else { | 
| 492 // We fall back to the classic V8 code generator. | 494 // We fall back to the classic V8 code generator. | 
| 493 AssignedVariablesAnalyzer ava(literal); | 495 AssignedVariablesAnalyzer ava(literal); | 
| 494 if (!ava.Analyze()) return Handle<SharedFunctionInfo>::null(); | 496 if (!ava.Analyze()) return Handle<SharedFunctionInfo>::null(); | 
| 495 code = CodeGenerator::MakeCode(&info); | 497 code = CodeGenerator::MakeCode(&info); | 
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 PROFILE(CodeCreateEvent(Logger::ToNativeByScript(tag, *script), | 583 PROFILE(CodeCreateEvent(Logger::ToNativeByScript(tag, *script), | 
| 582 *code, *func_name)); | 584 *code, *func_name)); | 
| 583 OPROFILE(CreateNativeCodeRegion(*func_name, | 585 OPROFILE(CreateNativeCodeRegion(*func_name, | 
| 584 code->instruction_start(), | 586 code->instruction_start(), | 
| 585 code->instruction_size())); | 587 code->instruction_size())); | 
| 586 } | 588 } | 
| 587 } | 589 } | 
| 588 } | 590 } | 
| 589 | 591 | 
| 590 } } // namespace v8::internal | 592 } } // namespace v8::internal | 
| OLD | NEW |