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

Side by Side Diff: runtime/bin/dfe.cc

Issue 3002733002: [vm,aot,kernel] Fix AOT snapshot creation with kernel front-end (Closed)
Patch Set: Created 3 years, 4 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 unified diff | Download patch
« no previous file with comments | « runtime/bin/dfe.h ('k') | runtime/bin/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 "bin/dfe.h" 5 #include "bin/dfe.h"
6 #include "bin/dartutils.h" 6 #include "bin/dartutils.h"
7 #include "bin/error_exit.h" 7 #include "bin/error_exit.h"
8 #include "bin/file.h" 8 #include "bin/file.h"
9 9
10 #include "vm/kernel.h" 10 #include "vm/kernel.h"
11 11
12 namespace dart { 12 namespace dart {
13 namespace bin { 13 namespace bin {
14 14
15 const char kPlatformBinaryName[] = "platform.dill"; 15 const char kPlatformBinaryName[] = "platform.dill";
16 const char kVMServiceIOBinaryName[] = "vmservice_io.dill"; 16 const char kVMServiceIOBinaryName[] = "vmservice_io.dill";
17 17
18 DFE::DFE() 18 DFE::DFE()
19 : frontend_filename_(NULL), 19 : frontend_filename_(NULL),
20 platform_binary_filename_(NULL), 20 platform_binary_filename_(NULL),
21 vmservice_io_binary_filename_(NULL), 21 vmservice_io_binary_filename_(NULL),
22 kernel_platform_(NULL), 22 kernel_platform_(NULL),
23 kernel_vmservice_io_(NULL),
24 kernel_file_specified_(false) {} 23 kernel_file_specified_(false) {}
25 24
26 DFE::~DFE() { 25 DFE::~DFE() {
27 frontend_filename_ = NULL; 26 frontend_filename_ = NULL;
28 27
29 if (platform_binary_filename_ != NULL) { 28 if (platform_binary_filename_ != NULL) {
30 delete platform_binary_filename_; 29 delete platform_binary_filename_;
31 platform_binary_filename_ = NULL; 30 platform_binary_filename_ = NULL;
32 } 31 }
33 32
34 if (kernel_platform_ != NULL) { 33 if (kernel_platform_ != NULL) {
35 delete reinterpret_cast<kernel::Program*>(kernel_platform_); 34 delete reinterpret_cast<kernel::Program*>(kernel_platform_);
36 kernel_platform_ = NULL; 35 kernel_platform_ = NULL;
37 } 36 }
38
39 if (kernel_vmservice_io_ != NULL) {
40 delete reinterpret_cast<kernel::Program*>(kernel_vmservice_io_);
41 kernel_vmservice_io_ = NULL;
42 }
43 }
44
45 void DFE::clear_kernel_vmservice_io() {
46 kernel_vmservice_io_ = NULL;
47 } 37 }
48 38
49 void DFE::SetKernelBinaries(const char* name) { 39 void DFE::SetKernelBinaries(const char* name) {
50 intptr_t len = snprintf(NULL, 0, "%s%s%s", name, File::PathSeparator(), 40 intptr_t len = snprintf(NULL, 0, "%s%s%s", name, File::PathSeparator(),
51 kPlatformBinaryName) + 41 kPlatformBinaryName) +
52 1; 42 1;
53 platform_binary_filename_ = new char[len]; 43 platform_binary_filename_ = new char[len];
54 snprintf(platform_binary_filename_, len, "%s%s%s", name, 44 snprintf(platform_binary_filename_, len, "%s%s%s", name,
55 File::PathSeparator(), kPlatformBinaryName); 45 File::PathSeparator(), kPlatformBinaryName);
56 46
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 *exit_code = kDartFrontendErrorExitCode; 101 *exit_code = kDartFrontendErrorExitCode;
112 break; 102 break;
113 case Dart_KernelCompilationStatus_Unknown: 103 case Dart_KernelCompilationStatus_Unknown:
114 *error = result.error; // Copy error message. 104 *error = result.error; // Copy error message.
115 *exit_code = kErrorExitCode; 105 *exit_code = kErrorExitCode;
116 break; 106 break;
117 } 107 }
118 return NULL; 108 return NULL;
119 } 109 }
120 110
121 void* DFE::ReadPlatform() { 111 void* DFE::ReadPlatform() const {
122 return kernel_platform_ = ReadScript(platform_binary_filename_); 112 return ReadScript(platform_binary_filename_);
123 } 113 }
124 114
125 void* DFE::ReadVMServiceIO() { 115 void* DFE::ReadVMServiceIO() const {
126 return kernel_vmservice_io_ = ReadScript(vmservice_io_binary_filename_); 116 return ReadScript(vmservice_io_binary_filename_);
127 } 117 }
128 118
129 void* DFE::ReadScript(const char* script_uri) { 119 void* DFE::ReadScript(const char* script_uri) const {
130 const uint8_t* buffer = NULL; 120 const uint8_t* buffer = NULL;
131 intptr_t buffer_length = -1; 121 intptr_t buffer_length = -1;
132 bool result = TryReadKernelFile(script_uri, &buffer, &buffer_length); 122 bool result = TryReadKernelFile(script_uri, &buffer, &buffer_length);
133 if (result) { 123 if (result) {
134 return Dart_ReadKernelBinary(buffer, buffer_length); 124 return Dart_ReadKernelBinary(buffer, buffer_length);
135 } 125 }
136 return NULL; 126 return NULL;
137 } 127 }
138 128
139 bool DFE::TryReadKernelFile(const char* script_uri, 129 bool DFE::TryReadKernelFile(const char* script_uri,
140 const uint8_t** kernel_ir, 130 const uint8_t** kernel_ir,
141 intptr_t* kernel_ir_size) { 131 intptr_t* kernel_ir_size) const {
142 *kernel_ir = NULL; 132 *kernel_ir = NULL;
143 *kernel_ir_size = -1; 133 *kernel_ir_size = -1;
144 void* script_file = DartUtils::OpenFile(script_uri, false); 134 void* script_file = DartUtils::OpenFile(script_uri, false);
145 if (script_file != NULL) { 135 if (script_file != NULL) {
146 const uint8_t* buffer = NULL; 136 const uint8_t* buffer = NULL;
147 DartUtils::ReadFile(&buffer, kernel_ir_size, script_file); 137 DartUtils::ReadFile(&buffer, kernel_ir_size, script_file);
148 DartUtils::CloseFile(script_file); 138 DartUtils::CloseFile(script_file);
149 if (*kernel_ir_size > 0 && buffer != NULL) { 139 if (*kernel_ir_size > 0 && buffer != NULL) {
150 if (DartUtils::SniffForMagicNumber(buffer, *kernel_ir_size) != 140 if (DartUtils::SniffForMagicNumber(buffer, *kernel_ir_size) !=
151 DartUtils::kKernelMagicNumber) { 141 DartUtils::kKernelMagicNumber) {
152 free(const_cast<uint8_t*>(buffer)); 142 free(const_cast<uint8_t*>(buffer));
153 *kernel_ir = NULL; 143 *kernel_ir = NULL;
154 *kernel_ir_size = -1; 144 *kernel_ir_size = -1;
155 return false; 145 return false;
156 } else { 146 } else {
157 // Do not free buffer if this is a kernel file - kernel_file will be 147 // Do not free buffer if this is a kernel file - kernel_file will be
158 // backed by the same memory as the buffer and caller will own it. 148 // backed by the same memory as the buffer and caller will own it.
159 // Caller is responsible for freeing the buffer when this function 149 // Caller is responsible for freeing the buffer when this function
160 // returns true. 150 // returns true.
161 *kernel_ir = buffer; 151 *kernel_ir = buffer;
162 return true; 152 return true;
163 } 153 }
164 } 154 }
165 } 155 }
166 return false; 156 return false;
167 } 157 }
168 158
169 } // namespace bin 159 } // namespace bin
170 } // namespace dart 160 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/dfe.h ('k') | runtime/bin/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698