OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 scanner().SetHarmonyScoping(true); | 560 scanner().SetHarmonyScoping(true); |
561 } | 561 } |
562 if ((parser_flags & kAllowModules) != 0) { | 562 if ((parser_flags & kAllowModules) != 0) { |
563 scanner().SetHarmonyModules(true); | 563 scanner().SetHarmonyModules(true); |
564 } | 564 } |
565 } | 565 } |
566 | 566 |
567 | 567 |
568 FunctionLiteral* Parser::ParseProgram() { | 568 FunctionLiteral* Parser::ParseProgram() { |
569 ZoneScope zone_scope(zone(), DONT_DELETE_ON_EXIT); | 569 ZoneScope zone_scope(zone(), DONT_DELETE_ON_EXIT); |
570 | |
571 HistogramTimerScope timer(isolate()->counters()->parse()); | 570 HistogramTimerScope timer(isolate()->counters()->parse()); |
572 Handle<String> source(String::cast(script_->source())); | 571 Handle<String> source(String::cast(script_->source())); |
573 isolate()->counters()->total_parse_size()->Increment(source->length()); | 572 isolate()->counters()->total_parse_size()->Increment(source->length()); |
| 573 int64_t start = FLAG_trace_parse ? OS::Ticks() : 0; |
574 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); | 574 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); |
575 | 575 |
576 // Initialize parser state. | 576 // Initialize parser state. |
577 source->TryFlatten(); | 577 source->TryFlatten(); |
| 578 FunctionLiteral* result; |
578 if (source->IsExternalTwoByteString()) { | 579 if (source->IsExternalTwoByteString()) { |
579 // Notice that the stream is destroyed at the end of the branch block. | 580 // Notice that the stream is destroyed at the end of the branch block. |
580 // The last line of the blocks can't be moved outside, even though they're | 581 // The last line of the blocks can't be moved outside, even though they're |
581 // identical calls. | 582 // identical calls. |
582 ExternalTwoByteStringUtf16CharacterStream stream( | 583 ExternalTwoByteStringUtf16CharacterStream stream( |
583 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); | 584 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); |
584 scanner_.Initialize(&stream); | 585 scanner_.Initialize(&stream); |
585 return DoParseProgram(info(), source, &zone_scope); | 586 result = DoParseProgram(info(), source, &zone_scope); |
586 } else { | 587 } else { |
587 GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 588 GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
588 scanner_.Initialize(&stream); | 589 scanner_.Initialize(&stream); |
589 return DoParseProgram(info(), source, &zone_scope); | 590 result = DoParseProgram(info(), source, &zone_scope); |
590 } | 591 } |
| 592 |
| 593 if (FLAG_trace_parse && result != NULL) { |
| 594 double ms = static_cast<double>(OS::Ticks() - start) / 1000; |
| 595 if (info()->is_eval()) { |
| 596 PrintF("[parsing eval"); |
| 597 } else if (info()->script()->name()->IsString()) { |
| 598 String* name = String::cast(info()->script()->name()); |
| 599 SmartArrayPointer<char> name_chars = name->ToCString(); |
| 600 PrintF("[parsing script: %s", *name_chars); |
| 601 } else { |
| 602 PrintF("[parsing script"); |
| 603 } |
| 604 PrintF(" - took %0.3f ms]\n", ms); |
| 605 } |
| 606 return result; |
591 } | 607 } |
592 | 608 |
593 | 609 |
594 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, | 610 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, |
595 Handle<String> source, | 611 Handle<String> source, |
596 ZoneScope* zone_scope) { | 612 ZoneScope* zone_scope) { |
597 ASSERT(top_scope_ == NULL); | 613 ASSERT(top_scope_ == NULL); |
598 ASSERT(target_stack_ == NULL); | 614 ASSERT(target_stack_ == NULL); |
599 if (pre_data_ != NULL) pre_data_->Initialize(); | 615 if (pre_data_ != NULL) pre_data_->Initialize(); |
600 | 616 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 if (result == NULL) zone_scope->DeleteOnExit(); | 677 if (result == NULL) zone_scope->DeleteOnExit(); |
662 return result; | 678 return result; |
663 } | 679 } |
664 | 680 |
665 | 681 |
666 FunctionLiteral* Parser::ParseLazy() { | 682 FunctionLiteral* Parser::ParseLazy() { |
667 ZoneScope zone_scope(zone(), DONT_DELETE_ON_EXIT); | 683 ZoneScope zone_scope(zone(), DONT_DELETE_ON_EXIT); |
668 HistogramTimerScope timer(isolate()->counters()->parse_lazy()); | 684 HistogramTimerScope timer(isolate()->counters()->parse_lazy()); |
669 Handle<String> source(String::cast(script_->source())); | 685 Handle<String> source(String::cast(script_->source())); |
670 isolate()->counters()->total_parse_size()->Increment(source->length()); | 686 isolate()->counters()->total_parse_size()->Increment(source->length()); |
| 687 int64_t start = FLAG_trace_parse ? OS::Ticks() : 0; |
| 688 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); |
671 | 689 |
672 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); | |
673 // Initialize parser state. | 690 // Initialize parser state. |
674 source->TryFlatten(); | 691 source->TryFlatten(); |
| 692 FunctionLiteral* result; |
675 if (source->IsExternalTwoByteString()) { | 693 if (source->IsExternalTwoByteString()) { |
676 ExternalTwoByteStringUtf16CharacterStream stream( | 694 ExternalTwoByteStringUtf16CharacterStream stream( |
677 Handle<ExternalTwoByteString>::cast(source), | 695 Handle<ExternalTwoByteString>::cast(source), |
678 shared_info->start_position(), | 696 shared_info->start_position(), |
679 shared_info->end_position()); | 697 shared_info->end_position()); |
680 FunctionLiteral* result = ParseLazy(&stream, &zone_scope); | 698 result = ParseLazy(&stream, &zone_scope); |
681 return result; | |
682 } else { | 699 } else { |
683 GenericStringUtf16CharacterStream stream(source, | 700 GenericStringUtf16CharacterStream stream(source, |
684 shared_info->start_position(), | 701 shared_info->start_position(), |
685 shared_info->end_position()); | 702 shared_info->end_position()); |
686 FunctionLiteral* result = ParseLazy(&stream, &zone_scope); | 703 result = ParseLazy(&stream, &zone_scope); |
687 return result; | |
688 } | 704 } |
| 705 |
| 706 if (FLAG_trace_parse && result != NULL) { |
| 707 double ms = static_cast<double>(OS::Ticks() - start) / 1000; |
| 708 SmartArrayPointer<char> name_chars = result->name()->ToCString(); |
| 709 PrintF("[parsing function: %s - took %0.3f ms]\n", *name_chars, ms); |
| 710 } |
| 711 return result; |
689 } | 712 } |
690 | 713 |
691 | 714 |
692 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source, | 715 FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source, |
693 ZoneScope* zone_scope) { | 716 ZoneScope* zone_scope) { |
694 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); | 717 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); |
695 scanner_.Initialize(source); | 718 scanner_.Initialize(source); |
696 ASSERT(top_scope_ == NULL); | 719 ASSERT(top_scope_ == NULL); |
697 ASSERT(target_stack_ == NULL); | 720 ASSERT(target_stack_ == NULL); |
698 | 721 |
(...skipping 5354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6053 ASSERT(info->isolate()->has_pending_exception()); | 6076 ASSERT(info->isolate()->has_pending_exception()); |
6054 } else { | 6077 } else { |
6055 result = parser.ParseProgram(); | 6078 result = parser.ParseProgram(); |
6056 } | 6079 } |
6057 } | 6080 } |
6058 info->SetFunction(result); | 6081 info->SetFunction(result); |
6059 return (result != NULL); | 6082 return (result != NULL); |
6060 } | 6083 } |
6061 | 6084 |
6062 } } // namespace v8::internal | 6085 } } // namespace v8::internal |
OLD | NEW |