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

Side by Side Diff: src/parser.cc

Issue 389573006: Change ScriptCompiler::CompileOptions and add d8 --cache. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 months 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 | Annotate | Revision Log
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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 return Data()[PreparseDataConstants::kVersionOffset]; 247 return Data()[PreparseDataConstants::kVersionOffset];
248 } 248 }
249 249
250 250
251 int ParseData::FunctionsSize() { 251 int ParseData::FunctionsSize() {
252 return static_cast<int>(Data()[PreparseDataConstants::kFunctionsSizeOffset]); 252 return static_cast<int>(Data()[PreparseDataConstants::kFunctionsSizeOffset]);
253 } 253 }
254 254
255 255
256 void Parser::SetCachedData() { 256 void Parser::SetCachedData() {
257 if (cached_data_mode() == NO_CACHED_DATA) { 257 if (compile_options() == ScriptCompiler::kNoCompileOptions) {
258 cached_parse_data_ = NULL; 258 cached_parse_data_ = NULL;
259 } else { 259 } else {
260 ASSERT(info_->cached_data() != NULL); 260 ASSERT(info_->cached_data() != NULL);
261 if (cached_data_mode() == CONSUME_CACHED_DATA) { 261 if (compile_options() == ScriptCompiler::kConsumeParserCache) {
262 cached_parse_data_ = new ParseData(*info_->cached_data()); 262 cached_parse_data_ = new ParseData(*info_->cached_data());
263 } 263 }
264 } 264 }
265 } 265 }
266 266
267 267
268 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { 268 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) {
269 ASSERT(ast_value_factory_); 269 ASSERT(ast_value_factory_);
270 Scope* result = 270 Scope* result =
271 new (zone()) Scope(parent, scope_type, ast_value_factory_, zone()); 271 new (zone()) Scope(parent, scope_type, ast_value_factory_, zone());
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 Handle<String> source(String::cast(script_->source())); 733 Handle<String> source(String::cast(script_->source()));
734 isolate()->counters()->total_parse_size()->Increment(source->length()); 734 isolate()->counters()->total_parse_size()->Increment(source->length());
735 base::ElapsedTimer timer; 735 base::ElapsedTimer timer;
736 if (FLAG_trace_parse) { 736 if (FLAG_trace_parse) {
737 timer.Start(); 737 timer.Start();
738 } 738 }
739 fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone()); 739 fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone());
740 740
741 // Initialize parser state. 741 // Initialize parser state.
742 CompleteParserRecorder recorder; 742 CompleteParserRecorder recorder;
743 if (cached_data_mode() == PRODUCE_CACHED_DATA) { 743
744 if (compile_options_ == ScriptCompiler::kProduceParserCache) {
744 log_ = &recorder; 745 log_ = &recorder;
745 } else if (cached_data_mode() == CONSUME_CACHED_DATA) { 746 } else if (compile_options_ == ScriptCompiler::kConsumeParserCache) {
746 cached_parse_data_->Initialize(); 747 cached_parse_data_->Initialize();
747 } 748 }
748 749
749 source = String::Flatten(source); 750 source = String::Flatten(source);
750 FunctionLiteral* result; 751 FunctionLiteral* result;
751 if (source->IsExternalTwoByteString()) { 752 if (source->IsExternalTwoByteString()) {
752 // Notice that the stream is destroyed at the end of the branch block. 753 // Notice that the stream is destroyed at the end of the branch block.
753 // The last line of the blocks can't be moved outside, even though they're 754 // The last line of the blocks can't be moved outside, even though they're
754 // identical calls. 755 // identical calls.
755 ExternalTwoByteStringUtf16CharacterStream stream( 756 ExternalTwoByteStringUtf16CharacterStream stream(
(...skipping 12 matching lines...) Expand all
768 PrintF("[parsing eval"); 769 PrintF("[parsing eval");
769 } else if (info()->script()->name()->IsString()) { 770 } else if (info()->script()->name()->IsString()) {
770 String* name = String::cast(info()->script()->name()); 771 String* name = String::cast(info()->script()->name());
771 SmartArrayPointer<char> name_chars = name->ToCString(); 772 SmartArrayPointer<char> name_chars = name->ToCString();
772 PrintF("[parsing script: %s", name_chars.get()); 773 PrintF("[parsing script: %s", name_chars.get());
773 } else { 774 } else {
774 PrintF("[parsing script"); 775 PrintF("[parsing script");
775 } 776 }
776 PrintF(" - took %0.3f ms]\n", ms); 777 PrintF(" - took %0.3f ms]\n", ms);
777 } 778 }
778 if (cached_data_mode() == PRODUCE_CACHED_DATA) { 779 if (compile_options_ == ScriptCompiler::kConsumeParserCache) {
779 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); 780 if (result != NULL) *info_->cached_data() = recorder.GetScriptData();
780 log_ = NULL; 781 log_ = NULL;
781 } 782 }
782 return result; 783 return result;
783 } 784 }
784 785
785 786
786 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, 787 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
787 Handle<String> source) { 788 Handle<String> source) {
788 ASSERT(scope_ == NULL); 789 ASSERT(scope_ == NULL);
(...skipping 2744 matching lines...) Expand 10 before | Expand all | Expand 10 after
3533 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); 3534 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
3534 return function_literal; 3535 return function_literal;
3535 } 3536 }
3536 3537
3537 3538
3538 void Parser::SkipLazyFunctionBody(const AstRawString* function_name, 3539 void Parser::SkipLazyFunctionBody(const AstRawString* function_name,
3539 int* materialized_literal_count, 3540 int* materialized_literal_count,
3540 int* expected_property_count, 3541 int* expected_property_count,
3541 bool* ok) { 3542 bool* ok) {
3542 int function_block_pos = position(); 3543 int function_block_pos = position();
3543 if (cached_data_mode() == CONSUME_CACHED_DATA) { 3544 if (compile_options_ == ScriptCompiler::kConsumeParserCache) {
3544 // If we have cached data, we use it to skip parsing the function body. The 3545 // If we have cached data, we use it to skip parsing the function body. The
3545 // data contains the information we need to construct the lazy function. 3546 // data contains the information we need to construct the lazy function.
3546 FunctionEntry entry = 3547 FunctionEntry entry =
3547 cached_parse_data_->GetFunctionEntry(function_block_pos); 3548 cached_parse_data_->GetFunctionEntry(function_block_pos);
3548 // Check that cached data is valid. 3549 // Check that cached data is valid.
3549 CHECK(entry.is_valid()); 3550 CHECK(entry.is_valid());
3550 // End position greater than end of stream is safe, and hard to check. 3551 // End position greater than end of stream is safe, and hard to check.
3551 CHECK(entry.end_pos() > function_block_pos); 3552 CHECK(entry.end_pos() > function_block_pos);
3552 scanner()->SeekForward(entry.end_pos() - 1); 3553 scanner()->SeekForward(entry.end_pos() - 1);
3553 3554
(...skipping 29 matching lines...) Expand all
3583 scope_->set_end_position(logger.end()); 3584 scope_->set_end_position(logger.end());
3584 Expect(Token::RBRACE, ok); 3585 Expect(Token::RBRACE, ok);
3585 if (!*ok) { 3586 if (!*ok) {
3586 return; 3587 return;
3587 } 3588 }
3588 isolate()->counters()->total_preparse_skipped()->Increment( 3589 isolate()->counters()->total_preparse_skipped()->Increment(
3589 scope_->end_position() - function_block_pos); 3590 scope_->end_position() - function_block_pos);
3590 *materialized_literal_count = logger.literals(); 3591 *materialized_literal_count = logger.literals();
3591 *expected_property_count = logger.properties(); 3592 *expected_property_count = logger.properties();
3592 scope_->SetStrictMode(logger.strict_mode()); 3593 scope_->SetStrictMode(logger.strict_mode());
3593 if (cached_data_mode() == PRODUCE_CACHED_DATA) { 3594 if (compile_options_ == ScriptCompiler::kProduceParserCache) {
3594 ASSERT(log_); 3595 ASSERT(log_);
3595 // Position right after terminal '}'. 3596 // Position right after terminal '}'.
3596 int body_end = scanner()->location().end_pos; 3597 int body_end = scanner()->location().end_pos;
3597 log_->LogFunction(function_block_pos, body_end, 3598 log_->LogFunction(function_block_pos, body_end,
3598 *materialized_literal_count, 3599 *materialized_literal_count,
3599 *expected_property_count, 3600 *expected_property_count,
3600 scope_->strict_mode()); 3601 scope_->strict_mode());
3601 } 3602 }
3602 } 3603 }
3603 } 3604 }
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
4738 info()->SetAstValueFactory(ast_value_factory_); 4739 info()->SetAstValueFactory(ast_value_factory_);
4739 } 4740 }
4740 ast_value_factory_ = NULL; 4741 ast_value_factory_ = NULL;
4741 4742
4742 InternalizeUseCounts(); 4743 InternalizeUseCounts();
4743 4744
4744 return (result != NULL); 4745 return (result != NULL);
4745 } 4746 }
4746 4747
4747 } } // namespace v8::internal 4748 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698