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

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

Issue 9254026: Split dart:builtin into dart:builtin and dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment and add binaries. Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/bin/io.dart » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // Generate a snapshot file after loading all the scripts specified on the 5 // Generate a snapshot file after loading all the scripts specified on the
6 // command line. 6 // command line.
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 if (DartUtils::IsDartSchemeURL(url_string)) { 170 if (DartUtils::IsDartSchemeURL(url_string)) {
171 if (tag == kCanonicalizeUrl) { 171 if (tag == kCanonicalizeUrl) {
172 return url; 172 return url;
173 } 173 }
174 return Dart_Error("unsupported url encountered %s", url_string); 174 return Dart_Error("unsupported url encountered %s", url_string);
175 } 175 }
176 return Dart_Error("unexpected tag encountered %d", tag); 176 return Dart_Error("unexpected tag encountered %d", tag);
177 } 177 }
178 178
179 179
180 static Dart_Handle LoadGenericSnapshotCreationScript() { 180 static Dart_Handle LoadGenericSnapshotCreationScript(
181 Dart_Handle source = Builtin::Source(); 181 Builtin::BuiltinLibraryId id) {
182 Dart_Handle source = Builtin::Source(id);
182 if (Dart_IsError(source)) { 183 if (Dart_IsError(source)) {
183 return source; // source contains the error string. 184 return source; // source contains the error string.
184 } 185 }
185 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); 186 Dart_Handle lib;
186 Dart_Handle lib = Dart_LoadScript(url, source, BuiltinLibraryTagHandler); 187 if (id == Builtin::kBuiltinLibrary) {
188 // Load the dart:builtin library as the script.
189 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL);
190 lib = Dart_LoadScript(url, source, BuiltinLibraryTagHandler);
191 } else {
192 ASSERT(id == Builtin::kIOLibrary);
193 // Load the dart:io library to make it available in the snapshot
194 // for importing.
195 lib = Builtin::LoadLibrary(Builtin::kIOLibrary);
196 }
187 if (!Dart_IsError(lib)) { 197 if (!Dart_IsError(lib)) {
188 Builtin::SetupLibrary(lib); 198 Builtin::SetupLibrary(lib, id);
189 } 199 }
190 return lib; 200 return lib;
191 } 201 }
192 202
193 203
194 static void PrintUsage() { 204 static void PrintUsage() {
195 fprintf(stderr, 205 fprintf(stderr,
196 "dart [<vm-flags>] " 206 "dart [<vm-flags>] "
197 "[<dart-script-file>]\n"); 207 "[<dart-script-file>]\n");
198 } 208 }
199 209
200 210
211 static void VerifyLoaded(Dart_Handle library) {
212 if (Dart_IsError(library)) {
213 const char* err_msg = Dart_GetError(library);
214 fprintf(stderr, "Errors encountered while loading: %s\n", err_msg);
215 Dart_ExitScope();
216 Dart_ShutdownIsolate();
217 exit(255);
218 }
219 ASSERT(Dart_IsLibrary(library));
220 }
221
222
201 int main(int argc, char** argv) { 223 int main(int argc, char** argv) {
202 CommandLineOptions vm_options(argc); 224 CommandLineOptions vm_options(argc);
203 225
204 // Initialize the URL mapping array. 226 // Initialize the URL mapping array.
205 CommandLineOptions url_mapping_array(argc); 227 CommandLineOptions url_mapping_array(argc);
206 url_mapping = &url_mapping_array; 228 url_mapping = &url_mapping_array;
207 229
208 // Parse command line arguments. 230 // Parse command line arguments.
209 if (ParseArguments(argc, 231 if (ParseArguments(argc,
210 argv, 232 argv,
(...skipping 25 matching lines...) Expand all
236 258
237 Dart_Handle result; 259 Dart_Handle result;
238 Dart_Handle library; 260 Dart_Handle library;
239 Dart_EnterScope(); 261 Dart_EnterScope();
240 262
241 ASSERT(snapshot_filename != NULL); 263 ASSERT(snapshot_filename != NULL);
242 // Load up the script before a snapshot is created. 264 // Load up the script before a snapshot is created.
243 if (app_script_name != NULL) { 265 if (app_script_name != NULL) {
244 // Load the specified script. 266 // Load the specified script.
245 library = LoadSnapshotCreationScript(app_script_name); 267 library = LoadSnapshotCreationScript(app_script_name);
268 VerifyLoaded(library);
246 } else { 269 } else {
247 // This is a generic dart snapshot which needs builtin library setup. 270 // This is a generic dart snapshot which needs builtin library setup.
248 library = LoadGenericSnapshotCreationScript(); 271 library = LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary);
272 VerifyLoaded(library);
273 library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary);
274 VerifyLoaded(library);
249 } 275 }
250 if (Dart_IsError(library)) { 276
251 const char* err_msg = Dart_GetError(library);
252 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg);
253 Dart_ExitScope();
254 Dart_ShutdownIsolate();
255 exit(255);
256 }
257 ASSERT(Dart_IsLibrary(library));
258 uint8_t* buffer = NULL; 277 uint8_t* buffer = NULL;
259 intptr_t size = 0; 278 intptr_t size = 0;
260 // First create the snapshot. 279 // First create the snapshot.
261 result = Dart_CreateSnapshot(&buffer, &size); 280 result = Dart_CreateSnapshot(&buffer, &size);
262 if (Dart_IsError(result)) { 281 if (Dart_IsError(result)) {
263 const char* err_msg = Dart_GetError(result); 282 const char* err_msg = Dart_GetError(result);
264 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg); 283 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg);
265 Dart_ExitScope(); 284 Dart_ExitScope();
266 Dart_ShutdownIsolate(); 285 Dart_ShutdownIsolate();
267 exit(255); 286 exit(255);
268 } 287 }
269 // Now write the snapshot out to specified file and exit. 288 // Now write the snapshot out to specified file and exit.
270 WriteSnapshotFile(buffer, size); 289 WriteSnapshotFile(buffer, size);
271 Dart_ExitScope(); 290 Dart_ExitScope();
272 291
273 // Shutdown the isolate. 292 // Shutdown the isolate.
274 Dart_ShutdownIsolate(); 293 Dart_ShutdownIsolate();
275 return 0; 294 return 0;
276 } 295 }
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/bin/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698