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 15 matching lines...) Expand all Loading... |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #include "bootstrapper.h" | 30 #include "bootstrapper.h" |
31 #include "codegen-inl.h" | 31 #include "codegen-inl.h" |
32 #include "compilation-cache.h" | 32 #include "compilation-cache.h" |
33 #include "compiler.h" | 33 #include "compiler.h" |
34 #include "data-flow.h" | 34 #include "data-flow.h" |
35 #include "debug.h" | 35 #include "debug.h" |
36 #include "flow-graph.h" | |
37 #include "full-codegen.h" | 36 #include "full-codegen.h" |
38 #include "liveedit.h" | 37 #include "liveedit.h" |
39 #include "oprofile-agent.h" | 38 #include "oprofile-agent.h" |
40 #include "rewriter.h" | 39 #include "rewriter.h" |
41 #include "scopes.h" | 40 #include "scopes.h" |
42 #include "scopeinfo.h" | 41 #include "scopeinfo.h" |
43 | 42 |
44 namespace v8 { | 43 namespace v8 { |
45 namespace internal { | 44 namespace internal { |
46 | 45 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 84 } |
86 #endif | 85 #endif |
87 | 86 |
88 // Optimize the AST. | 87 // Optimize the AST. |
89 if (!Rewriter::Optimize(function)) { | 88 if (!Rewriter::Optimize(function)) { |
90 // Signal a stack overflow by returning a null handle. The stack | 89 // Signal a stack overflow by returning a null handle. The stack |
91 // overflow exception will be thrown by the caller. | 90 // overflow exception will be thrown by the caller. |
92 return Handle<Code>::null(); | 91 return Handle<Code>::null(); |
93 } | 92 } |
94 | 93 |
95 if (function->scope()->num_parameters() > 0 || | |
96 function->scope()->num_stack_slots()) { | |
97 AssignedVariablesAnalyzer ava(function); | |
98 ava.Analyze(); | |
99 if (ava.HasStackOverflow()) { | |
100 return Handle<Code>::null(); | |
101 } | |
102 } | |
103 | |
104 if (FLAG_use_flow_graph) { | |
105 FlowGraphBuilder builder; | |
106 FlowGraph* graph = builder.Build(function); | |
107 USE(graph); | |
108 | |
109 #ifdef DEBUG | |
110 if (FLAG_print_graph_text && !builder.HasStackOverflow()) { | |
111 graph->PrintAsText(function->name()); | |
112 } | |
113 #endif | |
114 } | |
115 | |
116 // Generate code and return it. Code generator selection is governed by | 94 // Generate code and return it. Code generator selection is governed by |
117 // which backends are enabled and whether the function is considered | 95 // which backends are enabled and whether the function is considered |
118 // run-once code or not: | 96 // run-once code or not: |
119 // | 97 // |
120 // --full-compiler enables the dedicated backend for code we expect to be | 98 // --full-compiler enables the dedicated backend for code we expect to be |
121 // run once | 99 // run once |
122 // | 100 // |
123 // The normal choice of backend can be overridden with the flags | 101 // The normal choice of backend can be overridden with the flags |
124 // --always-full-compiler. | 102 // --always-full-compiler. |
125 Handle<SharedFunctionInfo> shared = info->shared_info(); | 103 Handle<SharedFunctionInfo> shared = info->shared_info(); |
126 bool is_run_once = (shared.is_null()) | 104 bool is_run_once = (shared.is_null()) |
127 ? info->scope()->is_global_scope() | 105 ? info->scope()->is_global_scope() |
128 : (shared->is_toplevel() || shared->try_full_codegen()); | 106 : (shared->is_toplevel() || shared->try_full_codegen()); |
129 | 107 |
130 if (AlwaysFullCompiler()) { | 108 if (AlwaysFullCompiler()) { |
131 return FullCodeGenerator::MakeCode(info); | 109 return FullCodeGenerator::MakeCode(info); |
132 } else if (FLAG_full_compiler && is_run_once) { | 110 } else if (FLAG_full_compiler && is_run_once) { |
133 FullCodeGenSyntaxChecker checker; | 111 FullCodeGenSyntaxChecker checker; |
134 checker.Check(function); | 112 checker.Check(function); |
135 if (checker.has_supported_syntax()) { | 113 if (checker.has_supported_syntax()) { |
136 return FullCodeGenerator::MakeCode(info); | 114 return FullCodeGenerator::MakeCode(info); |
137 } | 115 } |
138 } | 116 } |
139 | 117 |
| 118 AssignedVariablesAnalyzer ava(function); |
| 119 if (!ava.Analyze()) return Handle<Code>::null(); |
140 return CodeGenerator::MakeCode(info); | 120 return CodeGenerator::MakeCode(info); |
141 } | 121 } |
142 | 122 |
143 | 123 |
144 #ifdef ENABLE_DEBUGGER_SUPPORT | 124 #ifdef ENABLE_DEBUGGER_SUPPORT |
145 Handle<Code> MakeCodeForLiveEdit(CompilationInfo* info) { | 125 Handle<Code> MakeCodeForLiveEdit(CompilationInfo* info) { |
146 Handle<Context> context = Handle<Context>::null(); | 126 Handle<Context> context = Handle<Context>::null(); |
147 Handle<Code> code = MakeCode(context, info); | 127 Handle<Code> code = MakeCode(context, info); |
148 if (!info->shared_info().is_null()) { | 128 if (!info->shared_info().is_null()) { |
149 info->shared_info()->set_scope_info( | 129 info->shared_info()->set_scope_info( |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 Handle<Code> code; | 463 Handle<Code> code; |
484 if (FLAG_lazy && allow_lazy) { | 464 if (FLAG_lazy && allow_lazy) { |
485 code = Handle<Code>(Builtins::builtin(Builtins::LazyCompile)); | 465 code = Handle<Code>(Builtins::builtin(Builtins::LazyCompile)); |
486 } else { | 466 } else { |
487 // The bodies of function literals have not yet been visited by | 467 // The bodies of function literals have not yet been visited by |
488 // the AST optimizer/analyzer. | 468 // the AST optimizer/analyzer. |
489 if (!Rewriter::Optimize(literal)) { | 469 if (!Rewriter::Optimize(literal)) { |
490 return Handle<SharedFunctionInfo>::null(); | 470 return Handle<SharedFunctionInfo>::null(); |
491 } | 471 } |
492 | 472 |
493 if (literal->scope()->num_parameters() > 0 || | |
494 literal->scope()->num_stack_slots()) { | |
495 AssignedVariablesAnalyzer ava(literal); | |
496 ava.Analyze(); | |
497 if (ava.HasStackOverflow()) { | |
498 return Handle<SharedFunctionInfo>::null(); | |
499 } | |
500 } | |
501 | |
502 if (FLAG_use_flow_graph) { | |
503 FlowGraphBuilder builder; | |
504 FlowGraph* graph = builder.Build(literal); | |
505 USE(graph); | |
506 | |
507 #ifdef DEBUG | |
508 if (FLAG_print_graph_text && !builder.HasStackOverflow()) { | |
509 graph->PrintAsText(literal->name()); | |
510 } | |
511 #endif | |
512 } | |
513 | |
514 // Generate code and return it. The way that the compilation mode | 473 // Generate code and return it. The way that the compilation mode |
515 // is controlled by the command-line flags is described in | 474 // is controlled by the command-line flags is described in |
516 // the static helper function MakeCode. | 475 // the static helper function MakeCode. |
517 CompilationInfo info(literal, script, false); | 476 CompilationInfo info(literal, script, false); |
518 | 477 |
519 bool is_run_once = literal->try_full_codegen(); | 478 bool is_run_once = literal->try_full_codegen(); |
520 bool is_compiled = false; | 479 bool is_compiled = false; |
521 | 480 |
522 if (AlwaysFullCompiler()) { | 481 if (AlwaysFullCompiler()) { |
523 code = FullCodeGenerator::MakeCode(&info); | 482 code = FullCodeGenerator::MakeCode(&info); |
524 is_compiled = true; | 483 is_compiled = true; |
525 } else if (FLAG_full_compiler && is_run_once) { | 484 } else if (FLAG_full_compiler && is_run_once) { |
526 FullCodeGenSyntaxChecker checker; | 485 FullCodeGenSyntaxChecker checker; |
527 checker.Check(literal); | 486 checker.Check(literal); |
528 if (checker.has_supported_syntax()) { | 487 if (checker.has_supported_syntax()) { |
529 code = FullCodeGenerator::MakeCode(&info); | 488 code = FullCodeGenerator::MakeCode(&info); |
530 is_compiled = true; | 489 is_compiled = true; |
531 } | 490 } |
532 } | 491 } |
533 | 492 |
534 if (!is_compiled) { | 493 if (!is_compiled) { |
535 // We fall back to the classic V8 code generator. | 494 // We fall back to the classic V8 code generator. |
| 495 AssignedVariablesAnalyzer ava(literal); |
| 496 if (!ava.Analyze()) return Handle<SharedFunctionInfo>::null(); |
536 code = CodeGenerator::MakeCode(&info); | 497 code = CodeGenerator::MakeCode(&info); |
537 } | 498 } |
538 | 499 |
539 // Check for stack-overflow exception. | 500 // Check for stack-overflow exception. |
540 if (code.is_null()) { | 501 if (code.is_null()) { |
541 caller->SetStackOverflow(); | 502 caller->SetStackOverflow(); |
542 return Handle<SharedFunctionInfo>::null(); | 503 return Handle<SharedFunctionInfo>::null(); |
543 } | 504 } |
544 | 505 |
545 // Function compilation complete. | 506 // Function compilation complete. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 PROFILE(CodeCreateEvent(Logger::ToNativeByScript(tag, *script), | 583 PROFILE(CodeCreateEvent(Logger::ToNativeByScript(tag, *script), |
623 *code, *func_name)); | 584 *code, *func_name)); |
624 OPROFILE(CreateNativeCodeRegion(*func_name, | 585 OPROFILE(CreateNativeCodeRegion(*func_name, |
625 code->instruction_start(), | 586 code->instruction_start(), |
626 code->instruction_size())); | 587 code->instruction_size())); |
627 } | 588 } |
628 } | 589 } |
629 } | 590 } |
630 | 591 |
631 } } // namespace v8::internal | 592 } } // namespace v8::internal |
OLD | NEW |