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

Side by Side Diff: bin/gen_snapshot.cc

Issue 8537023: Implement automatic loading of dart:core_native_fields library (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years, 1 month 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 const bool kWritable = true; 83 const bool kWritable = true;
84 File* file = File::Open(snapshot_filename, kWritable); 84 File* file = File::Open(snapshot_filename, kWritable);
85 ASSERT(file != NULL); 85 ASSERT(file != NULL);
86 for (intptr_t i = 0; i < size; i++) { 86 for (intptr_t i = 0; i < size; i++) {
87 file->WriteByte(buffer[i]); 87 file->WriteByte(buffer[i]);
88 } 88 }
89 delete file; 89 delete file;
90 } 90 }
91 91
92 92
93 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
94 Dart_Handle library,
95 Dart_Handle url) {
96 const bool kDontImportBuiltinLib = false; // Do not import builtin lib.
97 return LibraryTagHandlerHelper(tag, library, url, kDontImportBuiltinLib);
98 }
99
100
93 static void* SnapshotCreateCallback(void* data) { 101 static void* SnapshotCreateCallback(void* data) {
94 const char* script_name = reinterpret_cast<const char*>(data); 102 const char* script_name = reinterpret_cast<const char*>(data);
95 Dart_Handle result; 103 Dart_Handle result;
104 Dart_Handle library;
96 Dart_EnterScope(); 105 Dart_EnterScope();
97 106
98 ASSERT(snapshot_filename != NULL); 107 ASSERT(snapshot_filename != NULL);
99 108
100 // If a file is specified on the command line, load it up before a snapshot 109 // load up the script before a snapshot is created.
Anton Muhin 2011/11/13 16:19:32 nit: [L]oad the script
siva 2011/11/15 02:16:52 Done.
101 // is created.
102 if (script_name != NULL) { 110 if (script_name != NULL) {
103 // Load the specified script. 111 // Load the specified script.
104 Dart_Handle library = LoadSnapshotCreationScript(script_name); 112 library = LoadSnapshotCreationScript(script_name, LibraryTagHandler);
105 if (!Dart_IsValid(library)) {
106 const char* err_msg = Dart_GetError(library);
107 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg);
108 Dart_ExitScope();
109 exit(255);
110 }
111
112 if (!Dart_IsLibrary(library)) {
113 fprintf(stderr,
114 "Expected a library when loading script: %s",
115 script_name);
116 Dart_ExitScope();
117 exit(255);
118 }
119 } else { 113 } else {
120 // Implicitly load builtin library. 114 // This is a generic dart snapshot which needs builtin library
121 Builtin_LoadLibrary(); 115 // setup.
122 // Setup the native resolver for built in library functions. 116 library = Builtin_LoadLibrary(LibraryTagHandler);
Anton Muhin 2011/11/13 16:19:32 cannot you migrate to the common infrastructure fo
siva 2011/11/15 02:16:52 I would have if we had a 'builtin.dart' file to us
Anton Muhin 2011/11/15 12:22:23 sure On 2011/11/15 02:16:52, asiva wrote:
123 Builtin_SetNativeResolver(); 117 }
118 if (!Dart_IsValid(library)) {
119 const char* err_msg = Dart_GetError(library);
120 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg);
121 Dart_ExitScope();
122 exit(255);
123 }
124 if (!Dart_IsLibrary(library)) {
Anton Muhin 2011/11/13 16:19:32 should it be an assert? esp. with new API.
siva 2011/11/15 02:16:52 No we want to fail if we don't find a library obje
Anton Muhin 2011/11/15 12:22:23 Is it a possible case when Builtin_LoadLibrary suc
siva 2011/11/15 19:42:49 I see what you are saying. Changed to an ASSERT.
125 fprintf(stderr, "Expected a library when loading script: %s", script_name);
126 Dart_ExitScope();
127 exit(255);
124 } 128 }
125 129
126 uint8_t* buffer = NULL; 130 uint8_t* buffer = NULL;
127 intptr_t size = 0; 131 intptr_t size = 0;
128 // First create the snapshot. 132 // First create the snapshot.
129 result = Dart_CreateSnapshot(&buffer, &size); 133 result = Dart_CreateSnapshot(&buffer, &size);
130 if (!Dart_IsValid(result)) { 134 if (!Dart_IsValid(result)) {
131 const char* err_msg = Dart_GetError(result); 135 const char* err_msg = Dart_GetError(result);
132 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg); 136 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg);
133 Dart_ExitScope(); 137 Dart_ExitScope();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // and writes out a snapshot. 179 // and writes out a snapshot.
176 Dart_Isolate isolate = Dart_CreateIsolate(NULL, script_name); 180 Dart_Isolate isolate = Dart_CreateIsolate(NULL, script_name);
177 if (isolate == NULL) { 181 if (isolate == NULL) {
178 return 255; 182 return 255;
179 } 183 }
180 184
181 // Shutdown the isolate. 185 // Shutdown the isolate.
182 Dart_ShutdownIsolate(); 186 Dart_ShutdownIsolate();
183 return 0; 187 return 0;
184 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698