Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/parsing/parser.cc

Issue 2398023002: [wasm] asm.js - Parse and convert asm.js to wasm a function at a time. (Closed)
Patch Set: git cl try Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast-expression-rewriter.h" 10 #include "src/ast/ast-expression-rewriter.h"
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 &RuntimeCallStats::ParseFunction); 852 &RuntimeCallStats::ParseFunction);
853 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseFunction"); 853 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseFunction");
854 Handle<String> source(String::cast(info->script()->source())); 854 Handle<String> source(String::cast(info->script()->source()));
855 isolate->counters()->total_parse_size()->Increment(source->length()); 855 isolate->counters()->total_parse_size()->Increment(source->length());
856 base::ElapsedTimer timer; 856 base::ElapsedTimer timer;
857 if (FLAG_trace_parse) { 857 if (FLAG_trace_parse) {
858 timer.Start(); 858 timer.Start();
859 } 859 }
860 Handle<SharedFunctionInfo> shared_info = info->shared_info(); 860 Handle<SharedFunctionInfo> shared_info = info->shared_info();
861 DeserializeScopeChain(info, info->maybe_outer_scope_info()); 861 DeserializeScopeChain(info, info->maybe_outer_scope_info());
862 if (info->asm_function_scope()) {
863 original_scope_ = info->asm_function_scope();
864 }
862 865
863 // Initialize parser state. 866 // Initialize parser state.
864 source = String::Flatten(source); 867 source = String::Flatten(source);
865 FunctionLiteral* result; 868 FunctionLiteral* result;
866 { 869 {
867 std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For( 870 std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(
868 source, shared_info->start_position(), shared_info->end_position())); 871 source, shared_info->start_position(), shared_info->end_position()));
869 Handle<String> name(String::cast(shared_info->name())); 872 Handle<String> name(String::cast(shared_info->name()));
870 result = DoParseFunction(info, ast_value_factory()->GetString(name), 873 result = DoParseFunction(info, ast_value_factory()->GetString(name),
871 stream.get()); 874 stream.get());
(...skipping 29 matching lines...) Expand all
901 const AstRawString* raw_name, 904 const AstRawString* raw_name,
902 Utf16CharacterStream* source) { 905 Utf16CharacterStream* source) {
903 scanner_.Initialize(source); 906 scanner_.Initialize(source);
904 DCHECK_NULL(scope_state_); 907 DCHECK_NULL(scope_state_);
905 DCHECK_NULL(target_stack_); 908 DCHECK_NULL(target_stack_);
906 909
907 DCHECK(ast_value_factory()); 910 DCHECK(ast_value_factory());
908 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); 911 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone());
909 fni_->PushEnclosingName(raw_name); 912 fni_->PushEnclosingName(raw_name);
910 913
911 ResetFunctionLiteralId(); 914 // Asm functions don't get IDs.
912 DCHECK_LT(0, info->function_literal_id()); 915 if (!info->asm_function_scope()) {
913 SkipFunctionLiterals(info->function_literal_id() - 1); 916 ResetFunctionLiteralId();
917 DCHECK_LT(0, info->function_literal_id());
918 SkipFunctionLiterals(info->function_literal_id() - 1);
919 }
914 920
915 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 921 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
916 922
917 // Place holder for the result. 923 // Place holder for the result.
918 FunctionLiteral* result = nullptr; 924 FunctionLiteral* result = nullptr;
919 925
920 { 926 {
921 // Parse the function literal. 927 // Parse the function literal.
922 Scope* outer = original_scope_; 928 Scope* outer = original_scope_;
923 DeclarationScope* outer_function = outer->GetClosureScope(); 929 DeclarationScope* outer_function = outer->GetClosureScope();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind, 1042 raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind,
1037 kNoSourcePosition, function_type, info->language_mode(), &ok); 1043 kNoSourcePosition, function_type, info->language_mode(), &ok);
1038 if (info->requires_class_field_init()) { 1044 if (info->requires_class_field_init()) {
1039 result = InsertClassFieldInitializer(result); 1045 result = InsertClassFieldInitializer(result);
1040 } 1046 }
1041 } 1047 }
1042 // Make sure the results agree. 1048 // Make sure the results agree.
1043 DCHECK(ok == (result != nullptr)); 1049 DCHECK(ok == (result != nullptr));
1044 } 1050 }
1045 1051
1046 // Make sure the target stack is empty. 1052 // Asm functions don't get IDs.
1047 DCHECK_NULL(target_stack_); 1053 if (!info->asm_function_scope()) {
1048 DCHECK_IMPLIES(result, 1054 // Make sure the target stack is empty.
1049 info->function_literal_id() == result->function_literal_id()); 1055 DCHECK_NULL(target_stack_);
1056 DCHECK_IMPLIES(
1057 result, info->function_literal_id() == result->function_literal_id());
1058 }
1050 return result; 1059 return result;
1051 } 1060 }
1052 1061
1053 Statement* Parser::ParseModuleItem(bool* ok) { 1062 Statement* Parser::ParseModuleItem(bool* ok) {
1054 // ecma262/#prod-ModuleItem 1063 // ecma262/#prod-ModuleItem
1055 // ModuleItem : 1064 // ModuleItem :
1056 // ImportDeclaration 1065 // ImportDeclaration
1057 // ExportDeclaration 1066 // ExportDeclaration
1058 // StatementListItem 1067 // StatementListItem
1059 1068
(...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after
2624 // - Neither V8 natives nor native function declarations can be allowed, 2633 // - Neither V8 natives nor native function declarations can be allowed,
2625 // since parsing one would retroactively force the function to be 2634 // since parsing one would retroactively force the function to be
2626 // eagerly compiled. 2635 // eagerly compiled.
2627 // - The invoker of this parser can't depend on the AST being eagerly 2636 // - The invoker of this parser can't depend on the AST being eagerly
2628 // built (either because the function is about to be compiled, or 2637 // built (either because the function is about to be compiled, or
2629 // because the AST is going to be inspected for some reason). 2638 // because the AST is going to be inspected for some reason).
2630 // - Because of the above, we can't be attempting to parse a 2639 // - Because of the above, we can't be attempting to parse a
2631 // FunctionExpression; even without enclosing parentheses it might be 2640 // FunctionExpression; even without enclosing parentheses it might be
2632 // immediately invoked. 2641 // immediately invoked.
2633 // - The function literal shouldn't be hinted to eagerly compile. 2642 // - The function literal shouldn't be hinted to eagerly compile.
2634 // - For asm.js functions the body needs to be available when module
2635 // validation is active, because we examine the entire module at once.
2636 2643
2637 // Inner functions will be parsed using a temporary Zone. After parsing, we 2644 // Inner functions will be parsed using a temporary Zone. After parsing, we
2638 // will migrate unresolved variable into a Scope in the main Zone. 2645 // will migrate unresolved variable into a Scope in the main Zone.
2639 // TODO(marja): Refactor parsing modes: simplify this. 2646 // TODO(marja): Refactor parsing modes: simplify this.
2640 bool use_temp_zone = 2647 bool use_temp_zone =
2641 (FLAG_lazy_inner_functions 2648 (FLAG_lazy_inner_functions
2642 ? can_preparse 2649 ? can_preparse
2643 : (is_lazy_top_level_function || 2650 : (is_lazy_top_level_function ||
2644 (allow_lazy_ && function_type == FunctionLiteral::kDeclaration && 2651 (allow_lazy_ && function_type == FunctionLiteral::kDeclaration &&
2645 eager_compile_hint == FunctionLiteral::kShouldLazyCompile))) && 2652 eager_compile_hint == FunctionLiteral::kShouldLazyCompile)));
2646 !(FLAG_validate_asm && scope()->IsAsmModule());
2647 bool is_lazy_inner_function = 2653 bool is_lazy_inner_function =
2648 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; 2654 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function;
2649 2655
2650 ZoneList<Statement*>* body = nullptr; 2656 ZoneList<Statement*>* body = nullptr;
2651 int materialized_literal_count = -1; 2657 int materialized_literal_count = -1;
2652 int expected_property_count = -1; 2658 int expected_property_count = -1;
2653 bool should_be_used_once_hint = false; 2659 bool should_be_used_once_hint = false;
2654 int num_parameters = -1; 2660 int num_parameters = -1;
2655 int function_length = -1; 2661 int function_length = -1;
2656 bool has_duplicate_parameters = false; 2662 bool has_duplicate_parameters = false;
(...skipping 2840 matching lines...) Expand 10 before | Expand all | Expand 10 after
5497 5503
5498 return final_loop; 5504 return final_loop;
5499 } 5505 }
5500 5506
5501 #undef CHECK_OK 5507 #undef CHECK_OK
5502 #undef CHECK_OK_VOID 5508 #undef CHECK_OK_VOID
5503 #undef CHECK_FAILED 5509 #undef CHECK_FAILED
5504 5510
5505 } // namespace internal 5511 } // namespace internal
5506 } // namespace v8 5512 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698