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 VM_KERNEL_READER_H_ |
| 6 #define VM_KERNEL_READER_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "vm/kernel.h" |
| 11 #include "vm/kernel_to_il.h" |
| 12 #include "vm/object.h" |
| 13 |
| 14 namespace dart { |
| 15 namespace kernel { |
| 16 |
| 17 class KernelReader; |
| 18 |
| 19 class BuildingTranslationHelper : public TranslationHelper { |
| 20 public: |
| 21 BuildingTranslationHelper(KernelReader* reader, dart::Thread* thread, |
| 22 dart::Zone* zone, Isolate* isolate) |
| 23 : TranslationHelper(thread, zone, isolate), reader_(reader) {} |
| 24 virtual ~BuildingTranslationHelper() {} |
| 25 |
| 26 virtual void SetFinalize(bool finalize); |
| 27 |
| 28 virtual RawLibrary* LookupLibraryByKernelLibrary(Library* library); |
| 29 virtual RawClass* LookupClassByKernelClass(Class* klass); |
| 30 |
| 31 private: |
| 32 KernelReader* reader_; |
| 33 }; |
| 34 |
| 35 template <typename KernelType, typename VmType> |
| 36 class Mapping { |
| 37 public: |
| 38 bool Lookup(KernelType* node, VmType** handle) { |
| 39 typename MapType::iterator value = map_.find(node); |
| 40 if (value != map_.end()) { |
| 41 *handle = value->second; |
| 42 return true; |
| 43 } |
| 44 return false; |
| 45 } |
| 46 |
| 47 void Insert(KernelType* node, VmType* object) { map_[node] = object; } |
| 48 |
| 49 private: |
| 50 typedef typename std::map<KernelType*, VmType*> MapType; |
| 51 MapType map_; |
| 52 }; |
| 53 |
| 54 class KernelReader { |
| 55 public: |
| 56 KernelReader(const uint8_t* buffer, intptr_t len, bool bootstrapping = false) |
| 57 : thread_(dart::Thread::Current()), |
| 58 zone_(thread_->zone()), |
| 59 isolate_(thread_->isolate()), |
| 60 translation_helper_(this, thread_, zone_, isolate_), |
| 61 type_translator_(&translation_helper_, &active_class_, !bootstrapping), |
| 62 bootstrapping_(bootstrapping), |
| 63 finalize_(!bootstrapping), |
| 64 buffer_(buffer), |
| 65 buffer_length_(len) {} |
| 66 |
| 67 // Returns either a library or a failure object. |
| 68 dart::Object& ReadProgram(); |
| 69 |
| 70 static void SetupFunctionParameters(TranslationHelper translation_helper_, |
| 71 DartTypeTranslator type_translator_, |
| 72 const dart::Class& owner, |
| 73 const dart::Function& function, |
| 74 FunctionNode* kernel_function, |
| 75 bool is_method, bool is_closure); |
| 76 |
| 77 void ReadLibrary(Library* kernel_library); |
| 78 |
| 79 private: |
| 80 friend class BuildingTranslationHelper; |
| 81 |
| 82 void ReadPreliminaryClass(dart::Class* klass, Class* kernel_klass); |
| 83 void ReadClass(const dart::Library& library, Class* kernel_klass); |
| 84 void ReadProcedure(const dart::Library& library, const dart::Class& owner, |
| 85 Procedure* procedure, Class* kernel_klass = NULL); |
| 86 |
| 87 void GenerateFieldAccessors(const dart::Class& klass, |
| 88 const dart::Field& field, Field* kernel_field); |
| 89 |
| 90 void SetupFieldAccessorFunction(const dart::Class& klass, |
| 91 const dart::Function& function); |
| 92 |
| 93 dart::Library& LookupLibrary(Library* library); |
| 94 dart::Class& LookupClass(Class* klass); |
| 95 |
| 96 dart::RawFunction::Kind GetFunctionType(Procedure* kernel_procedure); |
| 97 |
| 98 dart::Thread* thread_; |
| 99 dart::Zone* zone_; |
| 100 dart::Isolate* isolate_; |
| 101 ActiveClass active_class_; |
| 102 BuildingTranslationHelper translation_helper_; |
| 103 DartTypeTranslator type_translator_; |
| 104 |
| 105 bool bootstrapping_; |
| 106 |
| 107 // Should created classes be finalized when they are created? |
| 108 bool finalize_; |
| 109 |
| 110 const uint8_t* buffer_; |
| 111 intptr_t buffer_length_; |
| 112 |
| 113 Mapping<Library, dart::Library> libraries_; |
| 114 Mapping<Class, dart::Class> classes_; |
| 115 }; |
| 116 |
| 117 } // namespace kernel |
| 118 } // namespace dart |
| 119 |
| 120 #endif // VM_KERNEL_READER_H_ |
OLD | NEW |