| 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 #include "vm/kernel_reader.h" | 5 #include "vm/kernel_reader.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 ReadLibrary(kernel_library); | 149 ReadLibrary(kernel_library); |
| 150 } | 150 } |
| 151 | 151 |
| 152 for (intptr_t i = 0; i < length; i++) { | 152 for (intptr_t i = 0; i < length; i++) { |
| 153 dart::Library& library = | 153 dart::Library& library = |
| 154 LookupLibrary(program_->libraries()[i]->canonical_name()); | 154 LookupLibrary(program_->libraries()[i]->canonical_name()); |
| 155 if (!library.Loaded()) library.SetLoaded(); | 155 if (!library.Loaded()) library.SetLoaded(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { | 158 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { |
| 159 // There is a function _getMainClosure in dart:_builtin that returns the |
| 160 // main procedure. Since the platform libraries are compiled before the |
| 161 // program script, this function might need to be patched here. |
| 162 |
| 163 // If there is no main method then we have compiled a partial Kernel file |
| 164 // and do not need to patch here. |
| 159 CanonicalName* main = program_->main_method(); | 165 CanonicalName* main = program_->main_method(); |
| 160 if (main == NULL) { | 166 if (main == NULL) { |
| 161 return dart::Library::Handle(Z); | 167 return dart::Library::Handle(Z); |
| 162 } | 168 } |
| 163 | 169 |
| 170 // If the builtin library is not set in the object store, then we are |
| 171 // bootstrapping and do not need to patch here. |
| 172 dart::Library& builtin_library = |
| 173 dart::Library::Handle(Z, I->object_store()->builtin_library()); |
| 174 if (builtin_library.IsNull()) { |
| 175 return dart::Library::Handle(Z); |
| 176 } |
| 177 |
| 164 CanonicalName* main_library = H.EnclosingName(main); | 178 CanonicalName* main_library = H.EnclosingName(main); |
| 165 dart::Library& library = LookupLibrary(main_library); | 179 dart::Library& library = LookupLibrary(main_library); |
| 166 // Sanity check that we can find the main entrypoint. | 180 // Sanity check that we can find the main entrypoint. |
| 167 Object& main_obj = Object::Handle( | 181 Object& main_obj = Object::Handle( |
| 168 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main"))); | 182 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main"))); |
| 169 ASSERT(!main_obj.IsNull()); | 183 ASSERT(!main_obj.IsNull()); |
| 170 | 184 |
| 171 // There is a function _getMainClosure in dart:_builtin that returns the | |
| 172 // main procedure. Since the platform libraries are compiled before the | |
| 173 // program script, this function is patched here. | |
| 174 // | |
| 175 // TODO(kmillikin): we are leaking the function body. Find a way to | |
| 176 // deallocate it. | |
| 177 dart::Library& builtin_library = | |
| 178 dart::Library::Handle(Z, I->object_store()->builtin_library()); | |
| 179 Function& to_patch = Function::Handle( | 185 Function& to_patch = Function::Handle( |
| 180 Z, builtin_library.LookupFunctionAllowPrivate( | 186 Z, builtin_library.LookupFunctionAllowPrivate( |
| 181 dart::String::Handle(dart::String::New("_getMainClosure")))); | 187 dart::String::Handle(dart::String::New("_getMainClosure")))); |
| 182 | 188 |
| 183 // We will handle the StaticGet specially and will not use the name. | |
| 184 Procedure* procedure = | 189 Procedure* procedure = |
| 185 reinterpret_cast<Procedure*>(to_patch.kernel_function()); | 190 reinterpret_cast<Procedure*>(to_patch.kernel_function()); |
| 186 procedure->function()->set_body(new ReturnStatement(new StaticGet(NULL))); | 191 // If dart:_builtin was not compiled from Kernel at all or if it was |
| 187 | 192 // linked with a script, it does not need to be patched. |
| 193 if ((procedure != NULL) && (procedure->function()->body() == NULL)) { |
| 194 // We will handle the StaticGet specially and will not use the name. |
| 195 // |
| 196 // TODO(kmillikin): we are leaking the function body. Find a way to |
| 197 // deallocate it. |
| 198 procedure->function()->set_body( |
| 199 new ReturnStatement(new StaticGet(NULL))); |
| 200 } |
| 188 return library; | 201 return library; |
| 189 } | 202 } |
| 190 } | 203 } |
| 191 | 204 |
| 192 // Either class finalization failed or we caught a compile error. | 205 // Either class finalization failed or we caught a compile error. |
| 193 // In both cases sticky error would be set. | 206 // In both cases sticky error would be set. |
| 194 Error& error = Error::Handle(Z); | 207 Error& error = Error::Handle(Z); |
| 195 error = thread_->sticky_error(); | 208 error = thread_->sticky_error(); |
| 196 thread_->clear_sticky_error(); | 209 thread_->clear_sticky_error(); |
| 197 return error; | 210 return error; |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 initializer_fun.set_is_debuggable(false); | 917 initializer_fun.set_is_debuggable(false); |
| 905 initializer_fun.set_is_reflectable(false); | 918 initializer_fun.set_is_reflectable(false); |
| 906 initializer_fun.set_is_inlinable(false); | 919 initializer_fun.set_is_inlinable(false); |
| 907 return new (zone) ParsedFunction(thread, initializer_fun); | 920 return new (zone) ParsedFunction(thread, initializer_fun); |
| 908 } | 921 } |
| 909 | 922 |
| 910 | 923 |
| 911 } // namespace kernel | 924 } // namespace kernel |
| 912 } // namespace dart | 925 } // namespace dart |
| 913 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 926 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |