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

Unified Diff: runtime/bin/dfe.cc

Issue 2927493002: Restructure code to enable reloading when a kernel dill file is specified on the command line inste… (Closed)
Patch Set: fix format error. Created 3 years, 6 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/bin/dfe.h ('k') | runtime/bin/gen_snapshot.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/dfe.cc
diff --git a/runtime/bin/dfe.cc b/runtime/bin/dfe.cc
index 0ba2da5a529cd7badab5ed761ce6b420d70e56aa..45d81aeded9261d824c946c8f341b0da7155a238 100644
--- a/runtime/bin/dfe.cc
+++ b/runtime/bin/dfe.cc
@@ -4,25 +4,30 @@
#include "bin/dfe.h"
#include "bin/dartutils.h"
+#include "bin/error_exit.h"
+
+#include "vm/kernel.h"
namespace dart {
namespace bin {
-DFE::DFE() : frontend_filename_(NULL), platform_binary_filename_(NULL) {}
+DFE::DFE()
+ : frontend_filename_(NULL),
+ platform_binary_filename_(NULL),
+ kernel_platform_(NULL) {}
DFE::~DFE() {
frontend_filename_ = NULL;
platform_binary_filename_ = NULL;
+ if (kernel_platform_ != NULL) {
+ delete reinterpret_cast<kernel::Program*>(kernel_platform_);
+ }
+ kernel_platform_ = NULL;
}
-Dart_Handle DFE::ReloadScript(Dart_Isolate isolate, Dart_Handle url) {
+Dart_Handle DFE::ReloadScript(Dart_Isolate isolate, const char* url_string) {
ASSERT(!Dart_IsServiceIsolate(isolate) && !Dart_IsKernelIsolate(isolate));
- const char* url_string = NULL;
- Dart_Handle result = Dart_StringToCString(url, &url_string);
- if (Dart_IsError(result)) {
- return result;
- }
// First check if the URL points to a Kernel IR file in which case we
// skip the compilation step and directly reload the file.
const uint8_t* kernel_ir = NULL;
@@ -41,7 +46,7 @@ Dart_Handle DFE::ReloadScript(Dart_Isolate isolate, Dart_Handle url) {
}
void* kernel_program = Dart_ReadKernelBinary(kernel_ir, kernel_ir_size);
ASSERT(kernel_program != NULL);
- result = Dart_LoadKernel(kernel_program);
+ Dart_Handle result = Dart_LoadKernel(kernel_program);
if (Dart_IsError(result)) {
return result;
}
@@ -55,6 +60,54 @@ Dart_Handle DFE::ReloadScript(Dart_Isolate isolate, Dart_Handle url) {
}
+void* DFE::CompileAndReadScript(const char* script_uri,
+ char** error,
+ int* exit_code) {
+ Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri);
+ switch (result.status) {
+ case Dart_KernelCompilationStatus_Ok:
+ return Dart_ReadKernelBinary(result.kernel, result.kernel_size);
+ case Dart_KernelCompilationStatus_Error:
+ *error = result.error; // Copy error message.
+ *exit_code = kCompilationErrorExitCode;
+ break;
+ case Dart_KernelCompilationStatus_Crash:
+ *error = result.error; // Copy error message.
+ *exit_code = kDartFrontendErrorExitCode;
+ break;
+ case Dart_KernelCompilationStatus_Unknown:
+ *error = result.error; // Copy error message.
+ *exit_code = kErrorExitCode;
+ break;
+ }
+ return NULL;
+}
+
+
+void* DFE::ReadPlatform() {
+ const uint8_t* buffer = NULL;
+ intptr_t buffer_length = -1;
+ bool result =
+ TryReadKernelFile(platform_binary_filename_, &buffer, &buffer_length);
+ if (result) {
+ kernel_platform_ = Dart_ReadKernelBinary(buffer, buffer_length);
+ return kernel_platform_;
+ }
+ return NULL;
+}
+
+
+void* DFE::ReadScript(const char* script_uri) {
+ const uint8_t* buffer = NULL;
+ intptr_t buffer_length = -1;
+ bool result = TryReadKernelFile(script_uri, &buffer, &buffer_length);
+ if (result) {
+ return Dart_ReadKernelBinary(buffer, buffer_length);
+ }
+ return NULL;
+}
+
+
bool DFE::TryReadKernelFile(const char* script_uri,
const uint8_t** kernel_ir,
intptr_t* kernel_ir_size) {
« no previous file with comments | « runtime/bin/dfe.h ('k') | runtime/bin/gen_snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698