| 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 | 4 |
| 5 #ifndef RUNTIME_VM_KERNEL_READER_H_ | 5 #ifndef RUNTIME_VM_KERNEL_READER_H_ |
| 6 #define RUNTIME_VM_KERNEL_READER_H_ | 6 #define RUNTIME_VM_KERNEL_READER_H_ |
| 7 | 7 |
| 8 #if !defined(DART_PRECOMPILED_RUNTIME) | 8 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "vm/kernel.h" | 11 #include "vm/kernel.h" |
| 12 #include "vm/kernel_binary_flowgraph.h" | 12 #include "vm/kernel_binary_flowgraph.h" |
| 13 #include "vm/kernel_to_il.h" | 13 #include "vm/kernel_to_il.h" |
| 14 #include "vm/object.h" | 14 #include "vm/object.h" |
| 15 | 15 |
| 16 namespace dart { | 16 namespace dart { |
| 17 namespace kernel { | 17 namespace kernel { |
| 18 | 18 |
| 19 class KernelReader; | 19 class KernelReader; |
| 20 | 20 |
| 21 class BuildingTranslationHelper : public TranslationHelper { | 21 class BuildingTranslationHelper : public TranslationHelper { |
| 22 public: | 22 public: |
| 23 BuildingTranslationHelper(KernelReader* reader, dart::Thread* thread) | 23 BuildingTranslationHelper(KernelReader* reader, Thread* thread) |
| 24 : TranslationHelper(thread), reader_(reader) {} | 24 : TranslationHelper(thread), reader_(reader) {} |
| 25 virtual ~BuildingTranslationHelper() {} | 25 virtual ~BuildingTranslationHelper() {} |
| 26 | 26 |
| 27 virtual RawLibrary* LookupLibraryByKernelLibrary(NameIndex library); | 27 virtual RawLibrary* LookupLibraryByKernelLibrary(NameIndex library); |
| 28 virtual RawClass* LookupClassByKernelClass(NameIndex klass); | 28 virtual RawClass* LookupClassByKernelClass(NameIndex klass); |
| 29 | 29 |
| 30 private: | 30 private: |
| 31 KernelReader* reader_; | 31 KernelReader* reader_; |
| 32 }; | 32 }; |
| 33 | 33 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 51 typedef IntMap<VmType*> MapType; | 51 typedef IntMap<VmType*> MapType; |
| 52 MapType map_; | 52 MapType map_; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 class KernelReader { | 55 class KernelReader { |
| 56 public: | 56 public: |
| 57 explicit KernelReader(Program* program); | 57 explicit KernelReader(Program* program); |
| 58 | 58 |
| 59 // Returns the library containing the main procedure, null if there | 59 // Returns the library containing the main procedure, null if there |
| 60 // was no main procedure, or a failure object if there was an error. | 60 // was no main procedure, or a failure object if there was an error. |
| 61 dart::Object& ReadProgram(); | 61 Object& ReadProgram(); |
| 62 | 62 |
| 63 void ReadLibrary(intptr_t kernel_offset); | 63 void ReadLibrary(intptr_t kernel_offset); |
| 64 | 64 |
| 65 const dart::String& DartSymbol(StringIndex index) { | 65 const String& DartSymbol(StringIndex index) { |
| 66 return translation_helper_.DartSymbol(index); | 66 return translation_helper_.DartSymbol(index); |
| 67 } | 67 } |
| 68 | 68 |
| 69 const dart::String& LibraryUri(intptr_t library_index) { | 69 const String& LibraryUri(intptr_t library_index) { |
| 70 return translation_helper_.DartSymbol( | 70 return translation_helper_.DartSymbol( |
| 71 translation_helper_.CanonicalNameString( | 71 translation_helper_.CanonicalNameString( |
| 72 library_canonical_name(library_index))); | 72 library_canonical_name(library_index))); |
| 73 } | 73 } |
| 74 | 74 |
| 75 intptr_t library_offset(intptr_t index) { | 75 intptr_t library_offset(intptr_t index) { |
| 76 kernel::Reader reader(program_->kernel_data(), | 76 kernel::Reader reader(program_->kernel_data(), |
| 77 program_->kernel_data_size()); | 77 program_->kernel_data_size()); |
| 78 reader.set_offset(reader.size() - 4 - | 78 reader.set_offset(reader.size() - 4 - |
| 79 (program_->library_count() - index) * 4); | 79 (program_->library_count() - index) * 4); |
| 80 return reader.ReadUInt32(); | 80 return reader.ReadUInt32(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 NameIndex library_canonical_name(intptr_t index) { | 83 NameIndex library_canonical_name(intptr_t index) { |
| 84 kernel::Reader reader(program_->kernel_data(), | 84 kernel::Reader reader(program_->kernel_data(), |
| 85 program_->kernel_data_size()); | 85 program_->kernel_data_size()); |
| 86 reader.set_offset(reader.size() - 4 - | 86 reader.set_offset(reader.size() - 4 - |
| 87 (program_->library_count() - index) * 4); | 87 (program_->library_count() - index) * 4); |
| 88 reader.set_offset(reader.ReadUInt32()); | 88 reader.set_offset(reader.ReadUInt32()); |
| 89 | 89 |
| 90 // Start reading library. | 90 // Start reading library. |
| 91 reader.ReadFlags(); // read flags. | 91 reader.ReadFlags(); // read flags. |
| 92 return reader.ReadCanonicalNameReference(); | 92 return reader.ReadCanonicalNameReference(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 uint8_t CharacterAt(StringIndex string_index, intptr_t index); | 95 uint8_t CharacterAt(StringIndex string_index, intptr_t index); |
| 96 | 96 |
| 97 static bool FieldHasFunctionLiteralInitializer(const dart::Field& field, | 97 static bool FieldHasFunctionLiteralInitializer(const Field& field, |
| 98 TokenPosition* start, | 98 TokenPosition* start, |
| 99 TokenPosition* end); | 99 TokenPosition* end); |
| 100 | 100 |
| 101 private: | 101 private: |
| 102 friend class BuildingTranslationHelper; | 102 friend class BuildingTranslationHelper; |
| 103 | 103 |
| 104 void ReadPreliminaryClass(dart::Class* klass, | 104 void ReadPreliminaryClass(Class* klass, |
| 105 ClassHelper* class_helper, | 105 ClassHelper* class_helper, |
| 106 intptr_t type_parameter_count); | 106 intptr_t type_parameter_count); |
| 107 dart::Class& ReadClass(const dart::Library& library, | 107 Class& ReadClass(const Library& library, const Class& toplevel_class); |
| 108 const dart::Class& toplevel_class); | 108 void ReadProcedure(const Library& library, const Class& owner, bool in_class); |
| 109 void ReadProcedure(const dart::Library& library, | |
| 110 const dart::Class& owner, | |
| 111 bool in_class); | |
| 112 | 109 |
| 113 void ReadAndSetupTypeParameters(const Object& set_on, | 110 void ReadAndSetupTypeParameters(const Object& set_on, |
| 114 intptr_t type_parameter_count, | 111 intptr_t type_parameter_count, |
| 115 const Class& parameterized_class, | 112 const Class& parameterized_class, |
| 116 const Function& parameterized_function); | 113 const Function& parameterized_function); |
| 117 | 114 |
| 118 RawArray* MakeFunctionsArray(); | 115 RawArray* MakeFunctionsArray(); |
| 119 | 116 |
| 120 // If klass's script is not the script at the uri index, return a PatchClass | 117 // If klass's script is not the script at the uri index, return a PatchClass |
| 121 // for klass whose script corresponds to the uri index. | 118 // for klass whose script corresponds to the uri index. |
| 122 // Otherwise return klass. | 119 // Otherwise return klass. |
| 123 const Object& ClassForScriptAt(const dart::Class& klass, | 120 const Object& ClassForScriptAt(const Class& klass, intptr_t source_uri_index); |
| 124 intptr_t source_uri_index); | |
| 125 Script& ScriptAt(intptr_t source_uri_index, | 121 Script& ScriptAt(intptr_t source_uri_index, |
| 126 StringIndex import_uri = StringIndex()); | 122 StringIndex import_uri = StringIndex()); |
| 127 | 123 |
| 128 void GenerateFieldAccessors(const dart::Class& klass, | 124 void GenerateFieldAccessors(const Class& klass, |
| 129 const dart::Field& field, | 125 const Field& field, |
| 130 FieldHelper* field_helper, | 126 FieldHelper* field_helper, |
| 131 intptr_t field_offset); | 127 intptr_t field_offset); |
| 132 | 128 |
| 133 void SetupFieldAccessorFunction(const dart::Class& klass, | 129 void SetupFieldAccessorFunction(const Class& klass, const Function& function); |
| 134 const dart::Function& function); | |
| 135 | 130 |
| 136 dart::Library& LookupLibrary(NameIndex library); | 131 Library& LookupLibrary(NameIndex library); |
| 137 dart::Class& LookupClass(NameIndex klass); | 132 Class& LookupClass(NameIndex klass); |
| 138 | 133 |
| 139 dart::RawFunction::Kind GetFunctionType(ProcedureHelper::Kind procedure_kind); | 134 RawFunction::Kind GetFunctionType(ProcedureHelper::Kind procedure_kind); |
| 140 | 135 |
| 141 Program* program_; | 136 Program* program_; |
| 142 | 137 |
| 143 dart::Thread* thread_; | 138 Thread* thread_; |
| 144 dart::Zone* zone_; | 139 Zone* zone_; |
| 145 dart::Isolate* isolate_; | 140 Isolate* isolate_; |
| 146 Array& scripts_; | 141 Array& scripts_; |
| 147 Array& patch_classes_; | 142 Array& patch_classes_; |
| 148 ActiveClass active_class_; | 143 ActiveClass active_class_; |
| 149 BuildingTranslationHelper translation_helper_; | 144 BuildingTranslationHelper translation_helper_; |
| 150 StreamingFlowGraphBuilder builder_; | 145 StreamingFlowGraphBuilder builder_; |
| 151 | 146 |
| 152 Mapping<dart::Library> libraries_; | 147 Mapping<Library> libraries_; |
| 153 Mapping<dart::Class> classes_; | 148 Mapping<Class> classes_; |
| 154 | 149 |
| 155 GrowableArray<const dart::Function*> functions_; | 150 GrowableArray<const Function*> functions_; |
| 156 GrowableArray<const dart::Field*> fields_; | 151 GrowableArray<const Field*> fields_; |
| 157 }; | 152 }; |
| 158 | 153 |
| 159 } // namespace kernel | 154 } // namespace kernel |
| 160 } // namespace dart | 155 } // namespace dart |
| 161 | 156 |
| 162 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 157 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| 163 #endif // RUNTIME_VM_KERNEL_READER_H_ | 158 #endif // RUNTIME_VM_KERNEL_READER_H_ |
| OLD | NEW |