| 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 <map> | 6 #include <map> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "platform/globals.h" | 9 #include "platform/globals.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 strings_.WriteToStatic<StringImpl>(writer); | 821 strings_.WriteToStatic<StringImpl>(writer); |
| 822 | 822 |
| 823 // Build up the "String* -> index" table. | 823 // Build up the "String* -> index" table. |
| 824 WriterHelper* helper = writer->helper(); | 824 WriterHelper* helper = writer->helper(); |
| 825 for (int i = 0; i < strings_.length(); i++) { | 825 for (int i = 0; i < strings_.length(); i++) { |
| 826 helper->strings().Push(strings_[i]); | 826 helper->strings().Push(strings_[i]); |
| 827 } | 827 } |
| 828 } | 828 } |
| 829 | 829 |
| 830 | 830 |
| 831 void LineStartingTable::ReadFrom(Reader* reader) { | 831 void SourceTable::ReadFrom(Reader* reader) { |
| 832 size_ = reader->helper()->program()->source_uri_table().strings().length(); | 832 size_ = reader->helper()->program()->source_uri_table().strings().length(); |
| 833 values_ = new intptr_t*[size_]; | 833 source_code_ = new String*[size_]; |
| 834 line_starts_ = new intptr_t*[size_]; |
| 835 line_count_ = new intptr_t[size_]; |
| 834 for (intptr_t i = 0; i < size_; ++i) { | 836 for (intptr_t i = 0; i < size_; ++i) { |
| 837 source_code_[i] = StringImpl::ReadFrom(reader); |
| 835 intptr_t line_count = reader->ReadUInt(); | 838 intptr_t line_count = reader->ReadUInt(); |
| 836 intptr_t* line_starts = new intptr_t[line_count + 1]; | 839 intptr_t* line_starts = new intptr_t[line_count]; |
| 837 line_starts[0] = line_count; | 840 line_count_[i] = line_count; |
| 838 intptr_t previous_line_start = 0; | 841 intptr_t previous_line_start = 0; |
| 839 for (intptr_t j = 0; j < line_count; ++j) { | 842 for (intptr_t j = 0; j < line_count; ++j) { |
| 840 intptr_t line_start = reader->ReadUInt() + previous_line_start; | 843 intptr_t line_start = reader->ReadUInt() + previous_line_start; |
| 841 line_starts[j + 1] = line_start; | 844 line_starts[j] = line_start; |
| 842 previous_line_start = line_start; | 845 previous_line_start = line_start; |
| 843 } | 846 } |
| 844 values_[i] = line_starts; | 847 line_starts_[i] = line_starts; |
| 845 } | 848 } |
| 846 } | 849 } |
| 847 | 850 |
| 848 | 851 |
| 849 void LineStartingTable::WriteTo(Writer* writer) { | 852 void SourceTable::WriteTo(Writer* writer) { |
| 850 for (intptr_t i = 0; i < size_; ++i) { | 853 for (intptr_t i = 0; i < size_; ++i) { |
| 851 intptr_t* line_starts = values_[i]; | 854 StringImpl::WriteTo(writer, source_code_[i]); |
| 852 intptr_t line_count = line_starts[0]; | 855 intptr_t* line_starts = line_starts_[i]; |
| 856 intptr_t line_count = line_count_[i]; |
| 853 writer->WriteUInt(line_count); | 857 writer->WriteUInt(line_count); |
| 854 | 858 |
| 855 intptr_t previous_line_start = 0; | 859 intptr_t previous_line_start = 0; |
| 856 for (intptr_t j = 0; j < line_count; ++j) { | 860 for (intptr_t j = 0; j < line_count; ++j) { |
| 857 intptr_t line_start = line_starts[j + 1]; | 861 intptr_t line_start = line_starts[j]; |
| 858 writer->WriteUInt(line_start - previous_line_start); | 862 writer->WriteUInt(line_start - previous_line_start); |
| 859 previous_line_start = line_start; | 863 previous_line_start = line_start; |
| 860 } | 864 } |
| 861 } | 865 } |
| 862 } | 866 } |
| 863 | 867 |
| 864 | 868 |
| 865 Library* Library::ReadFrom(Reader* reader) { | 869 Library* Library::ReadFrom(Reader* reader) { |
| 866 TRACE_READ_OFFSET(); | 870 TRACE_READ_OFFSET(); |
| 867 int flags = reader->ReadFlags(); | 871 int flags = reader->ReadFlags(); |
| (...skipping 1953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2821 Program* Program::ReadFrom(Reader* reader) { | 2825 Program* Program::ReadFrom(Reader* reader) { |
| 2822 TRACE_READ_OFFSET(); | 2826 TRACE_READ_OFFSET(); |
| 2823 uint32_t magic = reader->ReadUInt32(); | 2827 uint32_t magic = reader->ReadUInt32(); |
| 2824 if (magic != kMagicProgramFile) FATAL("Invalid magic identifier"); | 2828 if (magic != kMagicProgramFile) FATAL("Invalid magic identifier"); |
| 2825 | 2829 |
| 2826 Program* program = new Program(); | 2830 Program* program = new Program(); |
| 2827 reader->helper()->set_program(program); | 2831 reader->helper()->set_program(program); |
| 2828 | 2832 |
| 2829 program->string_table_.ReadFrom(reader); | 2833 program->string_table_.ReadFrom(reader); |
| 2830 program->source_uri_table_.ReadFrom(reader); | 2834 program->source_uri_table_.ReadFrom(reader); |
| 2831 program->line_starting_table_.ReadFrom(reader); | 2835 program->source_table_.ReadFrom(reader); |
| 2832 | 2836 |
| 2833 int libraries = reader->ReadUInt(); | 2837 int libraries = reader->ReadUInt(); |
| 2834 program->libraries().EnsureInitialized(libraries); | 2838 program->libraries().EnsureInitialized(libraries); |
| 2835 for (int i = 0; i < libraries; i++) { | 2839 for (int i = 0; i < libraries; i++) { |
| 2836 program->libraries().GetOrCreate<Library>(i)->ReadFrom(reader); | 2840 program->libraries().GetOrCreate<Library>(i)->ReadFrom(reader); |
| 2837 } | 2841 } |
| 2838 | 2842 |
| 2839 program->main_method_ = Procedure::Cast(Reference::ReadMemberFrom(reader)); | 2843 program->main_method_ = Procedure::Cast(Reference::ReadMemberFrom(reader)); |
| 2840 | 2844 |
| 2841 return program; | 2845 return program; |
| 2842 } | 2846 } |
| 2843 | 2847 |
| 2844 | 2848 |
| 2845 void Program::WriteTo(Writer* writer) { | 2849 void Program::WriteTo(Writer* writer) { |
| 2846 TRACE_WRITE_OFFSET(); | 2850 TRACE_WRITE_OFFSET(); |
| 2847 | 2851 |
| 2848 writer->helper()->SetProgram(this); | 2852 writer->helper()->SetProgram(this); |
| 2849 | 2853 |
| 2850 writer->WriteUInt32(kMagicProgramFile); | 2854 writer->WriteUInt32(kMagicProgramFile); |
| 2851 | 2855 |
| 2852 // NOTE: Currently we don't GC strings and we require that all referenced | 2856 // NOTE: Currently we don't GC strings and we require that all referenced |
| 2853 // strings in nodes are present in [string_table_]. | 2857 // strings in nodes are present in [string_table_]. |
| 2854 string_table_.WriteTo(writer); | 2858 string_table_.WriteTo(writer); |
| 2855 source_uri_table_.WriteTo(writer); | 2859 source_uri_table_.WriteTo(writer); |
| 2856 line_starting_table_.WriteTo(writer); | 2860 source_table_.WriteTo(writer); |
| 2857 | 2861 |
| 2858 libraries_.WriteTo(writer); | 2862 libraries_.WriteTo(writer); |
| 2859 Reference::WriteMemberTo(writer, main_method_); | 2863 Reference::WriteMemberTo(writer, main_method_); |
| 2860 } | 2864 } |
| 2861 | 2865 |
| 2862 | 2866 |
| 2863 FunctionNode* FunctionNode::ReadFrom(Reader* reader) { | 2867 FunctionNode* FunctionNode::ReadFrom(Reader* reader) { |
| 2864 TRACE_READ_OFFSET(); | 2868 TRACE_READ_OFFSET(); |
| 2865 TypeParameterScope<ReaderHelper> scope(reader->helper()); | 2869 TypeParameterScope<ReaderHelper> scope(reader->helper()); |
| 2866 | 2870 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2930 void WritePrecompiledKernel(ByteWriter* byte_writer, kernel::Program* program) { | 2934 void WritePrecompiledKernel(ByteWriter* byte_writer, kernel::Program* program) { |
| 2931 ASSERT(byte_writer != NULL); | 2935 ASSERT(byte_writer != NULL); |
| 2932 | 2936 |
| 2933 kernel::Writer writer(byte_writer); | 2937 kernel::Writer writer(byte_writer); |
| 2934 program->WriteTo(&writer); | 2938 program->WriteTo(&writer); |
| 2935 } | 2939 } |
| 2936 | 2940 |
| 2937 | 2941 |
| 2938 } // namespace dart | 2942 } // namespace dart |
| 2939 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 2943 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |