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

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: 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
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 // Load the dart:io library with dependencies as a library to make
Ivan Posva 2012/01/21 20:24:55 ASSERT(id == Builtin::kIOLibrary);
Mads Ager (google) 2012/01/23 11:35:38 Done.
193 // it available in the snapshot for importing.
194 lib = Builtin::LoadLibrary(Builtin::kIOLibrary);
195 Builtin::ImportLibrary(lib, Builtin::kNativeWrappersLibrary);
196 Builtin::ImportLibrary(lib, Builtin::kCoreImplLibrary);
197 }
187 if (!Dart_IsError(lib)) { 198 if (!Dart_IsError(lib)) {
188 Builtin::SetupLibrary(lib); 199 Builtin::SetupLibrary(lib, id);
189 } 200 }
190 return lib; 201 return lib;
191 } 202 }
192 203
193 204
194 static void PrintUsage() { 205 static void PrintUsage() {
195 fprintf(stderr, 206 fprintf(stderr,
196 "dart [<vm-flags>] " 207 "dart [<vm-flags>] "
197 "[<dart-script-file>]\n"); 208 "[<dart-script-file>]\n");
198 } 209 }
199 210
200 211
212 static void VerifyLoaded(Dart_Handle library) {
213 if (Dart_IsError(library)) {
214 const char* err_msg = Dart_GetError(library);
215 fprintf(stderr, "Errors encountered while loading: %s\n", err_msg);
216 Dart_ExitScope();
217 Dart_ShutdownIsolate();
218 exit(255);
219 }
220 ASSERT(Dart_IsLibrary(library));
221 }
222
223
201 int main(int argc, char** argv) { 224 int main(int argc, char** argv) {
202 CommandLineOptions vm_options(argc); 225 CommandLineOptions vm_options(argc);
203 226
204 // Initialize the URL mapping array. 227 // Initialize the URL mapping array.
205 CommandLineOptions url_mapping_array(argc); 228 CommandLineOptions url_mapping_array(argc);
206 url_mapping = &url_mapping_array; 229 url_mapping = &url_mapping_array;
207 230
208 // Parse command line arguments. 231 // Parse command line arguments.
209 if (ParseArguments(argc, 232 if (ParseArguments(argc,
210 argv, 233 argv,
(...skipping 25 matching lines...) Expand all
236 259
237 Dart_Handle result; 260 Dart_Handle result;
238 Dart_Handle library; 261 Dart_Handle library;
239 Dart_EnterScope(); 262 Dart_EnterScope();
240 263
241 ASSERT(snapshot_filename != NULL); 264 ASSERT(snapshot_filename != NULL);
242 // Load up the script before a snapshot is created. 265 // Load up the script before a snapshot is created.
243 if (app_script_name != NULL) { 266 if (app_script_name != NULL) {
244 // Load the specified script. 267 // Load the specified script.
245 library = LoadSnapshotCreationScript(app_script_name); 268 library = LoadSnapshotCreationScript(app_script_name);
269 VerifyLoaded(library);
246 } else { 270 } else {
247 // This is a generic dart snapshot which needs builtin library setup. 271 // This is a generic dart snapshot which needs builtin library setup.
248 library = LoadGenericSnapshotCreationScript(); 272 library = LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary);
273 VerifyLoaded(library);
274 library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary);
275 VerifyLoaded(library);
249 } 276 }
250 if (Dart_IsError(library)) { 277
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; 278 uint8_t* buffer = NULL;
259 intptr_t size = 0; 279 intptr_t size = 0;
260 // First create the snapshot. 280 // First create the snapshot.
261 result = Dart_CreateSnapshot(&buffer, &size); 281 result = Dart_CreateSnapshot(&buffer, &size);
262 if (Dart_IsError(result)) { 282 if (Dart_IsError(result)) {
263 const char* err_msg = Dart_GetError(result); 283 const char* err_msg = Dart_GetError(result);
264 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg); 284 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg);
265 Dart_ExitScope(); 285 Dart_ExitScope();
266 Dart_ShutdownIsolate(); 286 Dart_ShutdownIsolate();
267 exit(255); 287 exit(255);
268 } 288 }
269 // Now write the snapshot out to specified file and exit. 289 // Now write the snapshot out to specified file and exit.
270 WriteSnapshotFile(buffer, size); 290 WriteSnapshotFile(buffer, size);
271 Dart_ExitScope(); 291 Dart_ExitScope();
272 292
273 // Shutdown the isolate. 293 // Shutdown the isolate.
274 Dart_ShutdownIsolate(); 294 Dart_ShutdownIsolate();
275 return 0; 295 return 0;
276 } 296 }
OLDNEW
« runtime/bin/builtin.cc ('K') | « runtime/bin/dartutils.cc ('k') | runtime/bin/io_in.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698