OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler.h" | 5 #include "src/compiler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "src/asmjs/asm-js.h" | 10 #include "src/asmjs/asm-js.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "src/debug/debug.h" | 21 #include "src/debug/debug.h" |
22 #include "src/debug/liveedit.h" | 22 #include "src/debug/liveedit.h" |
23 #include "src/frames-inl.h" | 23 #include "src/frames-inl.h" |
24 #include "src/full-codegen/full-codegen.h" | 24 #include "src/full-codegen/full-codegen.h" |
25 #include "src/globals.h" | 25 #include "src/globals.h" |
26 #include "src/heap/heap.h" | 26 #include "src/heap/heap.h" |
27 #include "src/interpreter/interpreter.h" | 27 #include "src/interpreter/interpreter.h" |
28 #include "src/isolate-inl.h" | 28 #include "src/isolate-inl.h" |
29 #include "src/log-inl.h" | 29 #include "src/log-inl.h" |
30 #include "src/messages.h" | 30 #include "src/messages.h" |
31 #include "src/parsing/parser.h" | 31 #include "src/parsing/parsing.h" |
32 #include "src/parsing/rewriter.h" | 32 #include "src/parsing/rewriter.h" |
33 #include "src/parsing/scanner-character-streams.h" | 33 #include "src/parsing/scanner-character-streams.h" |
34 #include "src/runtime-profiler.h" | 34 #include "src/runtime-profiler.h" |
35 #include "src/snapshot/code-serializer.h" | 35 #include "src/snapshot/code-serializer.h" |
36 #include "src/vm-state-inl.h" | 36 #include "src/vm-state-inl.h" |
37 | 37 |
38 namespace v8 { | 38 namespace v8 { |
39 namespace internal { | 39 namespace internal { |
40 | 40 |
41 | 41 |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 return false; | 458 return false; |
459 } | 459 } |
460 return true; | 460 return true; |
461 } | 461 } |
462 | 462 |
463 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) { | 463 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) { |
464 VMState<COMPILER> state(info->isolate()); | 464 VMState<COMPILER> state(info->isolate()); |
465 PostponeInterruptsScope postpone(info->isolate()); | 465 PostponeInterruptsScope postpone(info->isolate()); |
466 | 466 |
467 // Parse and update CompilationInfo with the results. | 467 // Parse and update CompilationInfo with the results. |
468 if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>(); | 468 if (info->parse_info()->is_toplevel()) { |
| 469 if (!parsing::ParseProgram(info->parse_info())) return MaybeHandle<Code>(); |
| 470 } else { |
| 471 if (!parsing::ParseFunction(info->parse_info())) return MaybeHandle<Code>(); |
| 472 } |
469 DCHECK_EQ(info->shared_info()->language_mode(), | 473 DCHECK_EQ(info->shared_info()->language_mode(), |
470 info->literal()->language_mode()); | 474 info->literal()->language_mode()); |
471 | 475 |
472 // Compile either unoptimized code or bytecode for the interpreter. | 476 // Compile either unoptimized code or bytecode for the interpreter. |
473 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); | 477 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); |
474 | 478 |
475 // Record the function compilation event. | 479 // Record the function compilation event. |
476 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); | 480 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); |
477 | 481 |
478 return info->code(); | 482 return info->code(); |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 } | 832 } |
829 DCHECK(!IsResumableFunction(function->shared()->kind())); | 833 DCHECK(!IsResumableFunction(function->shared()->kind())); |
830 | 834 |
831 if (FLAG_trace_opt) { | 835 if (FLAG_trace_opt) { |
832 OFStream os(stdout); | 836 OFStream os(stdout); |
833 os << "[switching method " << Brief(*function) << " to baseline code]" | 837 os << "[switching method " << Brief(*function) << " to baseline code]" |
834 << std::endl; | 838 << std::endl; |
835 } | 839 } |
836 | 840 |
837 // Parse and update CompilationInfo with the results. | 841 // Parse and update CompilationInfo with the results. |
838 if (!Parser::ParseStatic(info.parse_info())) return MaybeHandle<Code>(); | 842 if (!parsing::ParseFunction(info.parse_info())) return MaybeHandle<Code>(); |
839 Handle<SharedFunctionInfo> shared = info.shared_info(); | 843 Handle<SharedFunctionInfo> shared = info.shared_info(); |
840 DCHECK_EQ(shared->language_mode(), info.literal()->language_mode()); | 844 DCHECK_EQ(shared->language_mode(), info.literal()->language_mode()); |
841 | 845 |
842 // Compile baseline code using the full code generator. | 846 // Compile baseline code using the full code generator. |
843 if (!Compiler::Analyze(info.parse_info()) || | 847 if (!Compiler::Analyze(info.parse_info()) || |
844 !FullCodeGenerator::MakeCode(&info)) { | 848 !FullCodeGenerator::MakeCode(&info)) { |
845 if (!isolate->has_pending_exception()) isolate->StackOverflow(); | 849 if (!isolate->has_pending_exception()) isolate->StackOverflow(); |
846 return MaybeHandle<Code>(); | 850 return MaybeHandle<Code>(); |
847 } | 851 } |
848 | 852 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 ParseInfo* parse_info = info->parse_info(); | 962 ParseInfo* parse_info = info->parse_info(); |
959 Handle<Script> script = parse_info->script(); | 963 Handle<Script> script = parse_info->script(); |
960 | 964 |
961 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? | 965 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? |
962 FixedArray* array = isolate->native_context()->embedder_data(); | 966 FixedArray* array = isolate->native_context()->embedder_data(); |
963 script->set_context_data(array->get(v8::Context::kDebugIdIndex)); | 967 script->set_context_data(array->get(v8::Context::kDebugIdIndex)); |
964 | 968 |
965 Handle<SharedFunctionInfo> result; | 969 Handle<SharedFunctionInfo> result; |
966 | 970 |
967 { VMState<COMPILER> state(info->isolate()); | 971 { VMState<COMPILER> state(info->isolate()); |
968 if (parse_info->literal() == nullptr && !Parser::ParseStatic(parse_info)) { | 972 if (parse_info->literal() == nullptr && |
| 973 !parsing::ParseProgram(parse_info)) { |
969 return Handle<SharedFunctionInfo>::null(); | 974 return Handle<SharedFunctionInfo>::null(); |
970 } | 975 } |
971 | 976 |
972 FunctionLiteral* lit = parse_info->literal(); | 977 FunctionLiteral* lit = parse_info->literal(); |
973 | 978 |
974 // Measure how long it takes to do the compilation; only take the | 979 // Measure how long it takes to do the compilation; only take the |
975 // rest of the function into account to avoid overlap with the | 980 // rest of the function into account to avoid overlap with the |
976 // parsing statistics. | 981 // parsing statistics. |
977 RuntimeCallTimerScope runtimeTimer( | 982 RuntimeCallTimerScope runtimeTimer( |
978 isolate, parse_info->is_eval() ? &RuntimeCallStats::CompileEval | 983 isolate, parse_info->is_eval() ? &RuntimeCallStats::CompileEval |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 bool Compiler::Analyze(ParseInfo* info) { | 1028 bool Compiler::Analyze(ParseInfo* info) { |
1024 DCHECK_NOT_NULL(info->literal()); | 1029 DCHECK_NOT_NULL(info->literal()); |
1025 if (!Rewriter::Rewrite(info)) return false; | 1030 if (!Rewriter::Rewrite(info)) return false; |
1026 DeclarationScope::Analyze(info, AnalyzeMode::kRegular); | 1031 DeclarationScope::Analyze(info, AnalyzeMode::kRegular); |
1027 if (!Renumber(info)) return false; | 1032 if (!Renumber(info)) return false; |
1028 DCHECK_NOT_NULL(info->scope()); | 1033 DCHECK_NOT_NULL(info->scope()); |
1029 return true; | 1034 return true; |
1030 } | 1035 } |
1031 | 1036 |
1032 bool Compiler::ParseAndAnalyze(ParseInfo* info) { | 1037 bool Compiler::ParseAndAnalyze(ParseInfo* info) { |
1033 if (!Parser::ParseStatic(info)) return false; | 1038 if (info->is_toplevel()) { |
| 1039 if (!parsing::ParseProgram(info)) return false; |
| 1040 } else { |
| 1041 if (!parsing::ParseFunction(info)) return false; |
| 1042 } |
1034 if (!Compiler::Analyze(info)) return false; | 1043 if (!Compiler::Analyze(info)) return false; |
1035 DCHECK_NOT_NULL(info->literal()); | 1044 DCHECK_NOT_NULL(info->literal()); |
1036 DCHECK_NOT_NULL(info->scope()); | 1045 DCHECK_NOT_NULL(info->scope()); |
1037 return true; | 1046 return true; |
1038 } | 1047 } |
1039 | 1048 |
1040 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { | 1049 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { |
1041 if (function->is_compiled()) return true; | 1050 if (function->is_compiled()) return true; |
1042 Isolate* isolate = function->GetIsolate(); | 1051 Isolate* isolate = function->GetIsolate(); |
1043 DCHECK(AllowCompilation::IsAllowed(isolate)); | 1052 DCHECK(AllowCompilation::IsAllowed(isolate)); |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1720 DCHECK(shared->is_compiled()); | 1729 DCHECK(shared->is_compiled()); |
1721 function->set_literals(cached.literals); | 1730 function->set_literals(cached.literals); |
1722 } else if (shared->is_compiled()) { | 1731 } else if (shared->is_compiled()) { |
1723 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1732 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
1724 JSFunction::EnsureLiterals(function); | 1733 JSFunction::EnsureLiterals(function); |
1725 } | 1734 } |
1726 } | 1735 } |
1727 | 1736 |
1728 } // namespace internal | 1737 } // namespace internal |
1729 } // namespace v8 | 1738 } // namespace v8 |
OLD | NEW |