Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(527)

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 2411823003: VM support for running Kernel binaries. (Closed)
Patch Set: Address comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/dart_entry.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index f6f3ab841fbf2278defc14a570a591ded15f02dd..490d95f715c24c923ccf522a49d184a06b642fba 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -17,6 +17,9 @@
#include "vm/dart_api_state.h"
#include "vm/dart_entry.h"
#include "vm/debugger.h"
+#if !defined(DART_PRECOMPILED_RUNTIME)
+#include "vm/kernel_reader.h"
+#endif
#include "vm/exceptions.h"
#include "vm/flags.h"
#include "vm/growable_array.h"
@@ -5392,6 +5395,41 @@ DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer,
}
+DART_EXPORT Dart_Handle Dart_LoadKernel(const uint8_t* buffer,
+ intptr_t buffer_len) {
+ API_TIMELINE_DURATION;
+ DARTSCOPE(Thread::Current());
+ StackZone zone(T);
+
+#if defined(DART_PRECOMPILED_RUNTIME) && !defined(DART_PRECOMPILER)
+ return Api::NewError("%s: Can't load Kernel files from precompiled runtime.",
+ CURRENT_FUNC);
+#else
+ Isolate* I = T->isolate();
+
+ Library& library = Library::Handle(Z, I->object_store()->root_library());
+ if (!library.IsNull()) {
+ const String& library_url = String::Handle(Z, library.url());
+ return Api::NewError("%s: A script has already been loaded from '%s'.",
+ CURRENT_FUNC, library_url.ToCString());
+ }
+ CHECK_CALLBACK_STATE(T);
+ CHECK_COMPILATION_ALLOWED(I);
+
+ // TODO(27588): Memory leak!
+ kernel::KernelReader* reader = new kernel::KernelReader(buffer, buffer_len);
+ const Object& tmp = reader->ReadProgram();
+ if (tmp.IsError()) {
+ return Api::NewHandle(T, tmp.raw());
+ }
+ library ^= tmp.raw();
+ library.set_debuggable(false);
+ I->object_store()->set_root_library(library);
+ return Api::NewHandle(T, library.raw());
+#endif
+}
+
+
DART_EXPORT Dart_Handle Dart_RootLibrary() {
Thread* thread = Thread::Current();
Isolate* isolate = thread->isolate();
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/dart_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698