OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 #if !defined(DART_PRECOMPILED_RUNTIME) | 4 #if !defined(DART_PRECOMPILED_RUNTIME) |
5 | 5 |
6 #include "platform/globals.h" | 6 #include "platform/globals.h" |
7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
8 #include "vm/growable_array.h" | 8 #include "vm/growable_array.h" |
9 #include "vm/kernel.h" | 9 #include "vm/kernel.h" |
10 #include "vm/kernel_to_il.h" | 10 #include "vm/kernel_to_il.h" |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 ReaderHelper* helper() { return &builder_; } | 487 ReaderHelper* helper() { return &builder_; } |
488 | 488 |
489 CanonicalName* ReadCanonicalNameReference() { | 489 CanonicalName* ReadCanonicalNameReference() { |
490 int index = ReadUInt(); | 490 int index = ReadUInt(); |
491 if (index == 0) return NULL; | 491 if (index == 0) return NULL; |
492 CanonicalName* name = builder_.GetCanonicalName(index - 1); | 492 CanonicalName* name = builder_.GetCanonicalName(index - 1); |
493 ASSERT(name != NULL); | 493 ASSERT(name != NULL); |
494 return name; | 494 return name; |
495 } | 495 } |
496 | 496 |
| 497 CanonicalName* ReadDefiningCanonicalNameReference(LinkedNode* node_to_link) { |
| 498 CanonicalName* name = ReadCanonicalNameReference(); |
| 499 ASSERT(name != NULL); |
| 500 name->BindTo(node_to_link); |
| 501 return name; |
| 502 } |
| 503 |
497 intptr_t offset() { return offset_; } | 504 intptr_t offset() { return offset_; } |
498 | 505 |
499 private: | 506 private: |
500 const uint8_t* buffer_; | 507 const uint8_t* buffer_; |
501 intptr_t size_; | 508 intptr_t size_; |
502 intptr_t offset_; | 509 intptr_t offset_; |
503 ReaderHelper builder_; | 510 ReaderHelper builder_; |
504 TokenPosition max_position_; | 511 TokenPosition max_position_; |
505 TokenPosition min_position_; | 512 TokenPosition min_position_; |
506 intptr_t current_script_id_; | 513 intptr_t current_script_id_; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 line_starts_[i] = line_starts; | 680 line_starts_[i] = line_starts; |
674 } | 681 } |
675 } | 682 } |
676 | 683 |
677 | 684 |
678 Library* Library::ReadFrom(Reader* reader) { | 685 Library* Library::ReadFrom(Reader* reader) { |
679 TRACE_READ_OFFSET(); | 686 TRACE_READ_OFFSET(); |
680 int flags = reader->ReadFlags(); | 687 int flags = reader->ReadFlags(); |
681 ASSERT(flags == 0); // external libraries not supported | 688 ASSERT(flags == 0); // external libraries not supported |
682 | 689 |
683 canonical_name_ = reader->ReadCanonicalNameReference(); | 690 CanonicalName* canonical_name = |
| 691 reader->ReadDefiningCanonicalNameReference(this); |
| 692 |
684 name_ = Reference::ReadStringFrom(reader); | 693 name_ = Reference::ReadStringFrom(reader); |
685 import_uri_ = canonical_name_->name(); | 694 import_uri_ = canonical_name->name(); |
686 source_uri_index_ = reader->ReadUInt(); | 695 source_uri_index_ = reader->ReadUInt(); |
687 reader->set_current_script_id(source_uri_index_); | 696 reader->set_current_script_id(source_uri_index_); |
688 | 697 |
689 int num_imports = reader->ReadUInt(); | 698 int num_imports = reader->ReadUInt(); |
690 if (num_imports != 0) { | 699 if (num_imports != 0) { |
691 FATAL("Deferred imports not implemented in VM"); | 700 FATAL("Deferred imports not implemented in VM"); |
692 } | 701 } |
693 int num_classes = reader->ReadUInt(); | 702 int num_classes = reader->ReadUInt(); |
694 classes().EnsureInitialized(num_classes); | 703 classes().EnsureInitialized(num_classes); |
695 for (intptr_t i = 0; i < num_classes; i++) { | 704 for (intptr_t i = 0; i < num_classes; i++) { |
696 Tag tag = reader->ReadTag(); | 705 Tag tag = reader->ReadTag(); |
697 ASSERT(tag == kClass); | 706 ASSERT(tag == kClass); |
698 NormalClass* klass = classes().GetOrCreate<NormalClass>(i, this); | 707 NormalClass* klass = classes().GetOrCreate<NormalClass>(i, this); |
699 klass->ReadFrom(reader); | 708 klass->ReadFrom(reader); |
700 } | 709 } |
701 | 710 |
702 fields().ReadFrom<Field>(reader, this); | 711 fields().ReadFrom<Field>(reader, this); |
703 procedures().ReadFrom<Procedure>(reader, this); | 712 procedures().ReadFrom<Procedure>(reader, this); |
704 return this; | 713 return this; |
705 } | 714 } |
706 | 715 |
707 | 716 |
708 Class* Class::ReadFrom(Reader* reader) { | 717 Class* Class::ReadFrom(Reader* reader) { |
709 TRACE_READ_OFFSET(); | 718 TRACE_READ_OFFSET(); |
710 | 719 |
711 canonical_name_ = reader->ReadCanonicalNameReference(); | 720 reader->ReadDefiningCanonicalNameReference(this); |
712 position_ = reader->ReadPosition(false); | 721 position_ = reader->ReadPosition(false); |
713 is_abstract_ = reader->ReadBool(); | 722 is_abstract_ = reader->ReadBool(); |
714 name_ = Reference::ReadStringFrom(reader); | 723 name_ = Reference::ReadStringFrom(reader); |
715 source_uri_index_ = reader->ReadUInt(); | 724 source_uri_index_ = reader->ReadUInt(); |
716 reader->set_current_script_id(source_uri_index_); | 725 reader->set_current_script_id(source_uri_index_); |
717 reader->record_token_position(position_); | 726 reader->record_token_position(position_); |
718 annotations_.ReadFromStatic<Expression>(reader); | 727 annotations_.ReadFromStatic<Expression>(reader); |
719 | 728 |
720 return this; | 729 return this; |
721 } | 730 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 return reader->helper()->program()->string_table().strings()[index]; | 802 return reader->helper()->program()->string_table().strings()[index]; |
794 } | 803 } |
795 | 804 |
796 | 805 |
797 Field* Field::ReadFrom(Reader* reader) { | 806 Field* Field::ReadFrom(Reader* reader) { |
798 TRACE_READ_OFFSET(); | 807 TRACE_READ_OFFSET(); |
799 kernel_offset_ = reader->offset(); // Notice the ReadTag() below. | 808 kernel_offset_ = reader->offset(); // Notice the ReadTag() below. |
800 Tag tag = reader->ReadTag(); | 809 Tag tag = reader->ReadTag(); |
801 ASSERT(tag == kField); | 810 ASSERT(tag == kField); |
802 | 811 |
803 canonical_name_ = reader->ReadCanonicalNameReference(); | 812 reader->ReadDefiningCanonicalNameReference(this); |
804 position_ = reader->ReadPosition(false); | 813 position_ = reader->ReadPosition(false); |
805 end_position_ = reader->ReadPosition(false); | 814 end_position_ = reader->ReadPosition(false); |
806 flags_ = reader->ReadFlags(); | 815 flags_ = reader->ReadFlags(); |
807 name_ = Name::ReadFrom(reader); | 816 name_ = Name::ReadFrom(reader); |
808 source_uri_index_ = reader->ReadUInt(); | 817 source_uri_index_ = reader->ReadUInt(); |
809 reader->set_current_script_id(source_uri_index_); | 818 reader->set_current_script_id(source_uri_index_); |
810 reader->record_token_position(position_); | 819 reader->record_token_position(position_); |
811 reader->record_token_position(end_position_); | 820 reader->record_token_position(end_position_); |
812 annotations_.ReadFromStatic<Expression>(reader); | 821 annotations_.ReadFromStatic<Expression>(reader); |
813 type_ = DartType::ReadFrom(reader); | 822 type_ = DartType::ReadFrom(reader); |
814 initializer_ = reader->ReadOptional<Expression>(); | 823 initializer_ = reader->ReadOptional<Expression>(); |
815 return this; | 824 return this; |
816 } | 825 } |
817 | 826 |
818 | 827 |
819 Constructor* Constructor::ReadFrom(Reader* reader) { | 828 Constructor* Constructor::ReadFrom(Reader* reader) { |
820 TRACE_READ_OFFSET(); | 829 TRACE_READ_OFFSET(); |
821 Tag tag = reader->ReadTag(); | 830 Tag tag = reader->ReadTag(); |
822 ASSERT(tag == kConstructor); | 831 ASSERT(tag == kConstructor); |
823 | 832 |
824 canonical_name_ = reader->ReadCanonicalNameReference(); | 833 reader->ReadDefiningCanonicalNameReference(this); |
825 VariableScope<ReaderHelper> parameters(reader->helper()); | 834 VariableScope<ReaderHelper> parameters(reader->helper()); |
826 position_ = reader->ReadPosition(); | 835 position_ = reader->ReadPosition(); |
827 end_position_ = reader->ReadPosition(); | 836 end_position_ = reader->ReadPosition(); |
828 flags_ = reader->ReadFlags(); | 837 flags_ = reader->ReadFlags(); |
829 name_ = Name::ReadFrom(reader); | 838 name_ = Name::ReadFrom(reader); |
830 annotations_.ReadFromStatic<Expression>(reader); | 839 annotations_.ReadFromStatic<Expression>(reader); |
831 function_ = FunctionNode::ReadFrom(reader); | 840 function_ = FunctionNode::ReadFrom(reader); |
832 initializers_.ReadFromStatic<Initializer>(reader); | 841 initializers_.ReadFromStatic<Initializer>(reader); |
833 return this; | 842 return this; |
834 } | 843 } |
835 | 844 |
836 | 845 |
837 Procedure* Procedure::ReadFrom(Reader* reader) { | 846 Procedure* Procedure::ReadFrom(Reader* reader) { |
838 TRACE_READ_OFFSET(); | 847 TRACE_READ_OFFSET(); |
839 Tag tag = reader->ReadTag(); | 848 Tag tag = reader->ReadTag(); |
840 ASSERT(tag == kProcedure); | 849 ASSERT(tag == kProcedure); |
841 | 850 |
842 canonical_name_ = reader->ReadCanonicalNameReference(); | 851 reader->ReadDefiningCanonicalNameReference(this); |
843 VariableScope<ReaderHelper> parameters(reader->helper()); | 852 VariableScope<ReaderHelper> parameters(reader->helper()); |
844 position_ = reader->ReadPosition(false); | 853 position_ = reader->ReadPosition(false); |
845 end_position_ = reader->ReadPosition(false); | 854 end_position_ = reader->ReadPosition(false); |
846 kind_ = static_cast<ProcedureKind>(reader->ReadByte()); | 855 kind_ = static_cast<ProcedureKind>(reader->ReadByte()); |
847 flags_ = reader->ReadFlags(); | 856 flags_ = reader->ReadFlags(); |
848 name_ = Name::ReadFrom(reader); | 857 name_ = Name::ReadFrom(reader); |
849 source_uri_index_ = reader->ReadUInt(); | 858 source_uri_index_ = reader->ReadUInt(); |
850 reader->set_current_script_id(source_uri_index_); | 859 reader->set_current_script_id(source_uri_index_); |
851 reader->record_token_position(position_); | 860 reader->record_token_position(position_); |
852 reader->record_token_position(end_position_); | 861 reader->record_token_position(end_position_); |
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1874 } | 1883 } |
1875 | 1884 |
1876 int libraries = reader->ReadUInt(); | 1885 int libraries = reader->ReadUInt(); |
1877 program->libraries().EnsureInitialized(libraries); | 1886 program->libraries().EnsureInitialized(libraries); |
1878 for (intptr_t i = 0; i < libraries; i++) { | 1887 for (intptr_t i = 0; i < libraries; i++) { |
1879 program->libraries().GetOrCreate<Library>(i)->ReadFrom(reader); | 1888 program->libraries().GetOrCreate<Library>(i)->ReadFrom(reader); |
1880 } | 1889 } |
1881 | 1890 |
1882 program->main_method_reference_ = Reference::ReadMemberFrom(reader); | 1891 program->main_method_reference_ = Reference::ReadMemberFrom(reader); |
1883 | 1892 |
| 1893 #ifdef DEBUG |
| 1894 for (intptr_t i = 0; i < canonical_names; ++i) { |
| 1895 CanonicalName* name = reader->helper()->GetCanonicalName(i); |
| 1896 if (name->is_referenced() && name->definition() == NULL) { |
| 1897 FATAL("Missing definition for canonical name"); |
| 1898 } |
| 1899 } |
| 1900 #endif |
| 1901 |
1884 return program; | 1902 return program; |
1885 } | 1903 } |
1886 | 1904 |
1887 | 1905 |
1888 FunctionNode* FunctionNode::ReadFrom(Reader* reader) { | 1906 FunctionNode* FunctionNode::ReadFrom(Reader* reader) { |
1889 TRACE_READ_OFFSET(); | 1907 TRACE_READ_OFFSET(); |
1890 TypeParameterScope<ReaderHelper> scope(reader->helper()); | 1908 TypeParameterScope<ReaderHelper> scope(reader->helper()); |
1891 | 1909 |
1892 FunctionNode* function = new FunctionNode(); | 1910 FunctionNode* function = new FunctionNode(); |
1893 function->kernel_offset_ = reader->offset(); // FunctionNode has no tag. | 1911 function->kernel_offset_ = reader->offset(); // FunctionNode has no tag. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1925 | 1943 |
1926 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, | 1944 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, |
1927 intptr_t buffer_length) { | 1945 intptr_t buffer_length) { |
1928 kernel::Reader reader(buffer, buffer_length); | 1946 kernel::Reader reader(buffer, buffer_length); |
1929 return kernel::Program::ReadFrom(&reader); | 1947 return kernel::Program::ReadFrom(&reader); |
1930 } | 1948 } |
1931 | 1949 |
1932 | 1950 |
1933 } // namespace dart | 1951 } // namespace dart |
1934 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1952 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |