| 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/kernel_binary.h" | 10 #include "vm/kernel_binary.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 ReadLibrary(kernel_library); | 169 ReadLibrary(kernel_library); |
| 170 } | 170 } |
| 171 | 171 |
| 172 for (intptr_t i = 0; i < length; i++) { | 172 for (intptr_t i = 0; i < length; i++) { |
| 173 dart::Library& library = | 173 dart::Library& library = |
| 174 LookupLibrary(program_->libraries()[i]->canonical_name()); | 174 LookupLibrary(program_->libraries()[i]->canonical_name()); |
| 175 if (!library.Loaded()) library.SetLoaded(); | 175 if (!library.Loaded()) library.SetLoaded(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { | 178 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { |
| 179 // There is a function _getMainClosure in dart:_builtin that returns the | 179 // If 'main' is not found return a null library, this is the case |
| 180 // main procedure. Since the platform libraries are compiled before the | 180 // when bootstrapping is in progress. |
| 181 // program script, this function might need to be patched here. | |
| 182 | |
| 183 // If there is no main method then we have compiled a partial Kernel file | |
| 184 // and do not need to patch here. | |
| 185 NameIndex main = program_->main_method(); | 181 NameIndex main = program_->main_method(); |
| 186 if (main == -1) { | 182 if (main == -1) { |
| 187 return dart::Library::Handle(Z); | 183 return dart::Library::Handle(Z); |
| 188 } | 184 } |
| 189 | 185 |
| 190 // If the builtin library is not set in the object store, then we are | |
| 191 // bootstrapping and do not need to patch here. | |
| 192 dart::Library& builtin_library = | |
| 193 dart::Library::Handle(Z, I->object_store()->builtin_library()); | |
| 194 if (builtin_library.IsNull()) { | |
| 195 return dart::Library::Handle(Z); | |
| 196 } | |
| 197 | |
| 198 NameIndex main_library = H.EnclosingName(main); | 186 NameIndex main_library = H.EnclosingName(main); |
| 199 dart::Library& library = LookupLibrary(main_library); | 187 dart::Library& library = LookupLibrary(main_library); |
| 200 // Sanity check that we can find the main entrypoint. | 188 // Sanity check that we can find the main entrypoint. |
| 201 Object& main_obj = Object::Handle( | 189 ASSERT(library.LookupObjectAllowPrivate(H.DartSymbol("main")) != |
| 202 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main"))); | 190 Object::null()); |
| 203 ASSERT(!main_obj.IsNull()); | |
| 204 | |
| 205 Function& to_patch = Function::Handle( | |
| 206 Z, builtin_library.LookupFunctionAllowPrivate( | |
| 207 dart::String::Handle(dart::String::New("_getMainClosure")))); | |
| 208 | |
| 209 Procedure* procedure = | |
| 210 reinterpret_cast<Procedure*>(to_patch.kernel_function()); | |
| 211 // If dart:_builtin was not compiled from Kernel at all it does not need | |
| 212 // to be patched. | |
| 213 if (procedure != NULL) { | |
| 214 // We will handle the StaticGet specially and will not use the name. | |
| 215 // Note that we pass "true" in cannot_stream to avoid trying to stream | |
| 216 // a non-existing part of the binary. | |
| 217 // | |
| 218 // TODO(kmillikin): we are leaking the new function body. Find a way to | |
| 219 // deallocate it. | |
| 220 procedure->function()->ReplaceBody( | |
| 221 new ReturnStatement(new StaticGet(NameIndex(), false), false)); | |
| 222 } | |
| 223 return library; | 191 return library; |
| 224 } | 192 } |
| 225 } | 193 } |
| 226 | 194 |
| 227 // Either class finalization failed or we caught a compile error. | 195 // Either class finalization failed or we caught a compile error. |
| 228 // In both cases sticky error would be set. | 196 // In both cases sticky error would be set. |
| 229 Error& error = Error::Handle(Z); | 197 Error& error = Error::Handle(Z); |
| 230 error = thread_->sticky_error(); | 198 error = thread_->sticky_error(); |
| 231 thread_->clear_sticky_error(); | 199 thread_->clear_sticky_error(); |
| 232 return error; | 200 return error; |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 initializer_fun.set_is_debuggable(false); | 910 initializer_fun.set_is_debuggable(false); |
| 943 initializer_fun.set_is_reflectable(false); | 911 initializer_fun.set_is_reflectable(false); |
| 944 initializer_fun.set_is_inlinable(false); | 912 initializer_fun.set_is_inlinable(false); |
| 945 return new (zone) ParsedFunction(thread, initializer_fun); | 913 return new (zone) ParsedFunction(thread, initializer_fun); |
| 946 } | 914 } |
| 947 | 915 |
| 948 | 916 |
| 949 } // namespace kernel | 917 } // namespace kernel |
| 950 } // namespace dart | 918 } // namespace dart |
| 951 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 919 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |