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