OLD | NEW |
1 // Copyright 2011 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 |
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 // If crankshaft is not supported fall back to full code generator | 329 |
330 // for all compilation. | 330 // Generate code and return it. Code generator selection is governed by |
331 return FullCodeGenerator::MakeCode(info); | 331 // which backends are enabled and whether the function is considered |
| 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 } |
332 } | 353 } |
333 | 354 |
334 return false; | 355 return false; |
335 } | 356 } |
336 | 357 |
337 | 358 |
338 #ifdef ENABLE_DEBUGGER_SUPPORT | 359 #ifdef ENABLE_DEBUGGER_SUPPORT |
339 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { | 360 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { |
340 // Precondition: code has been parsed. Postcondition: the code field in | 361 // Precondition: code has been parsed. Postcondition: the code field in |
341 // the compilation info is set if compilation succeeded. | 362 // the compilation info is set if compilation succeeded. |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 // parser records. | 714 // parser records. |
694 bool allow_lazy = literal->AllowsLazyCompilation() && | 715 bool allow_lazy = literal->AllowsLazyCompilation() && |
695 !LiveEditFunctionTracker::IsActive(info.isolate()); | 716 !LiveEditFunctionTracker::IsActive(info.isolate()); |
696 | 717 |
697 Handle<SerializedScopeInfo> scope_info(SerializedScopeInfo::Empty()); | 718 Handle<SerializedScopeInfo> scope_info(SerializedScopeInfo::Empty()); |
698 | 719 |
699 // Generate code | 720 // Generate code |
700 if (FLAG_lazy && allow_lazy) { | 721 if (FLAG_lazy && allow_lazy) { |
701 Handle<Code> code = info.isolate()->builtins()->LazyCompile(); | 722 Handle<Code> code = info.isolate()->builtins()->LazyCompile(); |
702 info.SetCode(code); | 723 info.SetCode(code); |
703 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) || | 724 } else { |
704 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) { | 725 if (V8::UseCrankshaft()) { |
| 726 if (!MakeCrankshaftCode(&info)) { |
| 727 return Handle<SharedFunctionInfo>::null(); |
| 728 } |
| 729 } else { |
| 730 // The bodies of function literals have not yet been visited by the |
| 731 // AST optimizer/analyzer. |
| 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 } |
| 748 } |
705 ASSERT(!info.code().is_null()); | 749 ASSERT(!info.code().is_null()); |
| 750 |
| 751 // Function compilation complete. |
706 scope_info = SerializedScopeInfo::Create(info.scope()); | 752 scope_info = SerializedScopeInfo::Create(info.scope()); |
707 } else { | |
708 return Handle<SharedFunctionInfo>::null(); | |
709 } | 753 } |
710 | 754 |
711 // Create a shared function info object. | 755 // Create a shared function info object. |
712 Handle<SharedFunctionInfo> result = | 756 Handle<SharedFunctionInfo> result = |
713 FACTORY->NewSharedFunctionInfo(literal->name(), | 757 FACTORY->NewSharedFunctionInfo(literal->name(), |
714 literal->materialized_literal_count(), | 758 literal->materialized_literal_count(), |
715 info.code(), | 759 info.code(), |
716 scope_info); | 760 scope_info); |
717 SetFunctionInfo(result, literal, false, script); | 761 SetFunctionInfo(result, literal, false, script); |
718 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); | 762 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); |
(...skipping 21 matching lines...) Expand all Loading... |
740 function_info->set_script(*script); | 784 function_info->set_script(*script); |
741 function_info->set_function_token_position(lit->function_token_position()); | 785 function_info->set_function_token_position(lit->function_token_position()); |
742 function_info->set_start_position(lit->start_position()); | 786 function_info->set_start_position(lit->start_position()); |
743 function_info->set_end_position(lit->end_position()); | 787 function_info->set_end_position(lit->end_position()); |
744 function_info->set_is_expression(lit->is_expression()); | 788 function_info->set_is_expression(lit->is_expression()); |
745 function_info->set_is_toplevel(is_toplevel); | 789 function_info->set_is_toplevel(is_toplevel); |
746 function_info->set_inferred_name(*lit->inferred_name()); | 790 function_info->set_inferred_name(*lit->inferred_name()); |
747 function_info->SetThisPropertyAssignmentsInfo( | 791 function_info->SetThisPropertyAssignmentsInfo( |
748 lit->has_only_simple_this_property_assignments(), | 792 lit->has_only_simple_this_property_assignments(), |
749 *lit->this_property_assignments()); | 793 *lit->this_property_assignments()); |
| 794 function_info->set_try_full_codegen(lit->try_full_codegen()); |
750 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | 795 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
751 function_info->set_strict_mode(lit->strict_mode()); | 796 function_info->set_strict_mode(lit->strict_mode()); |
752 } | 797 } |
753 | 798 |
754 | 799 |
755 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 800 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
756 CompilationInfo* info, | 801 CompilationInfo* info, |
757 Handle<SharedFunctionInfo> shared) { | 802 Handle<SharedFunctionInfo> shared) { |
758 // SharedFunctionInfo is passed separately, because if CompilationInfo | 803 // SharedFunctionInfo is passed separately, because if CompilationInfo |
759 // was created using Script object, it will not have it. | 804 // was created using Script object, it will not have it. |
(...skipping 23 matching lines...) Expand all Loading... |
783 shared->DebugName())); | 828 shared->DebugName())); |
784 } | 829 } |
785 } | 830 } |
786 | 831 |
787 GDBJIT(AddCode(name, | 832 GDBJIT(AddCode(name, |
788 Handle<Script>(info->script()), | 833 Handle<Script>(info->script()), |
789 Handle<Code>(info->code()))); | 834 Handle<Code>(info->code()))); |
790 } | 835 } |
791 | 836 |
792 } } // namespace v8::internal | 837 } } // namespace v8::internal |
OLD | NEW |