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