OLD | NEW |
---|---|
1 // Copyright 2010 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 } | 319 } |
320 | 320 |
321 | 321 |
322 static bool MakeCode(CompilationInfo* info) { | 322 static bool MakeCode(CompilationInfo* info) { |
323 // Precondition: code has been parsed. Postcondition: the code field in | 323 // Precondition: code has been parsed. Postcondition: the code field in |
324 // the compilation info is set if compilation succeeded. | 324 // the compilation info is set if compilation succeeded. |
325 ASSERT(info->function() != NULL); | 325 ASSERT(info->function() != NULL); |
326 | 326 |
327 if (Rewriter::Rewrite(info) && Scope::Analyze(info)) { | 327 if (Rewriter::Rewrite(info) && Scope::Analyze(info)) { |
328 if (V8::UseCrankshaft()) return MakeCrankshaftCode(info); | 328 if (V8::UseCrankshaft()) return MakeCrankshaftCode(info); |
329 | 329 // If crankshaft is not supported fall back to full code generator |
330 // Generate code and return it. Code generator selection is governed by | 330 // for all compilation. |
331 // which backends are enabled and whether the function is considered | 331 return FullCodeGenerator::MakeCode(info); |
332 // run-once code or not. | |
333 // | |
334 // --full-compiler enables the dedicated backend for code we expect to | |
335 // be run once | |
336 // | |
337 // The normal choice of backend can be overridden with the flags | |
338 // --always-full-compiler. | |
339 if (Rewriter::Analyze(info)) { | |
340 Handle<SharedFunctionInfo> shared = info->shared_info(); | |
341 bool is_run_once = (shared.is_null()) | |
342 ? info->scope()->is_global_scope() | |
343 : (shared->is_toplevel() || shared->try_full_codegen()); | |
344 bool can_use_full = | |
345 FLAG_full_compiler && !info->function()->contains_loops(); | |
346 if (AlwaysFullCompiler() || (is_run_once && can_use_full)) { | |
347 return FullCodeGenerator::MakeCode(info); | |
348 } else { | |
349 return AssignedVariablesAnalyzer::Analyze(info) && | |
350 CodeGenerator::MakeCode(info); | |
351 } | |
352 } | |
353 } | 332 } |
354 | 333 |
355 return false; | 334 return false; |
356 } | 335 } |
357 | 336 |
358 | 337 |
359 #ifdef ENABLE_DEBUGGER_SUPPORT | 338 #ifdef ENABLE_DEBUGGER_SUPPORT |
360 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { | 339 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { |
361 // Precondition: code has been parsed. Postcondition: the code field in | 340 // Precondition: code has been parsed. Postcondition: the code field in |
362 // the compilation info is set if compilation succeeded. | 341 // the compilation info is set if compilation succeeded. |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 // allow some of our builtin JS files to be lazily compiled. These | 690 // allow some of our builtin JS files to be lazily compiled. These |
712 // builtins cannot be handled lazily by the parser, since we have to know | 691 // builtins cannot be handled lazily by the parser, since we have to know |
713 // if a function uses the special natives syntax, which is something the | 692 // if a function uses the special natives syntax, which is something the |
714 // parser records. | 693 // parser records. |
715 bool allow_lazy = literal->AllowsLazyCompilation() && | 694 bool allow_lazy = literal->AllowsLazyCompilation() && |
716 !LiveEditFunctionTracker::IsActive(info.isolate()); | 695 !LiveEditFunctionTracker::IsActive(info.isolate()); |
717 | 696 |
718 Handle<SerializedScopeInfo> scope_info(SerializedScopeInfo::Empty()); | 697 Handle<SerializedScopeInfo> scope_info(SerializedScopeInfo::Empty()); |
719 | 698 |
720 // Generate code | 699 // Generate code |
721 if (FLAG_lazy && allow_lazy) { | 700 if (FLAG_lazy && allow_lazy) { |
Kevin Millikin (Chromium)
2011/04/01 09:45:43
I think this whole conditional could be simpler:
Mads Ager (chromium)
2011/04/01 09:54:17
Done.
| |
722 Handle<Code> code = info.isolate()->builtins()->LazyCompile(); | 701 Handle<Code> code = info.isolate()->builtins()->LazyCompile(); |
723 info.SetCode(code); | 702 info.SetCode(code); |
724 } else { | 703 } else { |
725 if (V8::UseCrankshaft()) { | 704 if (V8::UseCrankshaft()) { |
726 if (!MakeCrankshaftCode(&info)) { | 705 if (!MakeCrankshaftCode(&info)) { |
727 return Handle<SharedFunctionInfo>::null(); | 706 return Handle<SharedFunctionInfo>::null(); |
728 } | 707 } |
729 } else { | 708 } else { |
730 // The bodies of function literals have not yet been visited by the | 709 if (!FullCodeGenerator::MakeCode(&info)) { |
731 // AST optimizer/analyzer. | 710 return Handle<SharedFunctionInfo>::null(); |
732 if (!Rewriter::Analyze(&info)) return Handle<SharedFunctionInfo>::null(); | |
733 | |
734 bool is_run_once = literal->try_full_codegen(); | |
735 bool can_use_full = FLAG_full_compiler && !literal->contains_loops(); | |
736 | |
737 if (AlwaysFullCompiler() || (is_run_once && can_use_full)) { | |
738 if (!FullCodeGenerator::MakeCode(&info)) { | |
739 return Handle<SharedFunctionInfo>::null(); | |
740 } | |
741 } else { | |
742 // We fall back to the classic V8 code generator. | |
743 if (!AssignedVariablesAnalyzer::Analyze(&info) || | |
744 !CodeGenerator::MakeCode(&info)) { | |
745 return Handle<SharedFunctionInfo>::null(); | |
746 } | |
747 } | 711 } |
748 } | 712 } |
749 ASSERT(!info.code().is_null()); | 713 ASSERT(!info.code().is_null()); |
750 | 714 |
751 // Function compilation complete. | 715 // Function compilation complete. |
752 scope_info = SerializedScopeInfo::Create(info.scope()); | 716 scope_info = SerializedScopeInfo::Create(info.scope()); |
753 } | 717 } |
754 | 718 |
755 // Create a shared function info object. | 719 // Create a shared function info object. |
756 Handle<SharedFunctionInfo> result = | 720 Handle<SharedFunctionInfo> result = |
(...skipping 27 matching lines...) Expand all Loading... | |
784 function_info->set_script(*script); | 748 function_info->set_script(*script); |
785 function_info->set_function_token_position(lit->function_token_position()); | 749 function_info->set_function_token_position(lit->function_token_position()); |
786 function_info->set_start_position(lit->start_position()); | 750 function_info->set_start_position(lit->start_position()); |
787 function_info->set_end_position(lit->end_position()); | 751 function_info->set_end_position(lit->end_position()); |
788 function_info->set_is_expression(lit->is_expression()); | 752 function_info->set_is_expression(lit->is_expression()); |
789 function_info->set_is_toplevel(is_toplevel); | 753 function_info->set_is_toplevel(is_toplevel); |
790 function_info->set_inferred_name(*lit->inferred_name()); | 754 function_info->set_inferred_name(*lit->inferred_name()); |
791 function_info->SetThisPropertyAssignmentsInfo( | 755 function_info->SetThisPropertyAssignmentsInfo( |
792 lit->has_only_simple_this_property_assignments(), | 756 lit->has_only_simple_this_property_assignments(), |
793 *lit->this_property_assignments()); | 757 *lit->this_property_assignments()); |
794 function_info->set_try_full_codegen(lit->try_full_codegen()); | |
795 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | 758 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
796 function_info->set_strict_mode(lit->strict_mode()); | 759 function_info->set_strict_mode(lit->strict_mode()); |
797 } | 760 } |
798 | 761 |
799 | 762 |
800 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 763 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
801 CompilationInfo* info, | 764 CompilationInfo* info, |
802 Handle<SharedFunctionInfo> shared) { | 765 Handle<SharedFunctionInfo> shared) { |
803 // SharedFunctionInfo is passed separately, because if CompilationInfo | 766 // SharedFunctionInfo is passed separately, because if CompilationInfo |
804 // was created using Script object, it will not have it. | 767 // was created using Script object, it will not have it. |
(...skipping 23 matching lines...) Expand all Loading... | |
828 shared->DebugName())); | 791 shared->DebugName())); |
829 } | 792 } |
830 } | 793 } |
831 | 794 |
832 GDBJIT(AddCode(name, | 795 GDBJIT(AddCode(name, |
833 Handle<Script>(info->script()), | 796 Handle<Script>(info->script()), |
834 Handle<Code>(info->code()))); | 797 Handle<Code>(info->code()))); |
835 } | 798 } |
836 | 799 |
837 } } // namespace v8::internal | 800 } } // namespace v8::internal |
OLD | NEW |