OLD | NEW |
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 void* SnapshotCreateCallback(void* data) { | 93 static void* SnapshotCreateCallback(void* data) { |
94 const char* script_name = reinterpret_cast<const char*>(data); | 94 const char* script_name = reinterpret_cast<const char*>(data); |
95 Dart_Handle result; | 95 Dart_Handle result; |
| 96 Dart_Handle library; |
96 Dart_EnterScope(); | 97 Dart_EnterScope(); |
97 | 98 |
98 ASSERT(snapshot_filename != NULL); | 99 ASSERT(snapshot_filename != NULL); |
99 | 100 |
100 // If a file is specified on the command line, load it up before a snapshot | 101 // Load up the script before a snapshot is created. |
101 // is created. | |
102 if (script_name != NULL) { | 102 if (script_name != NULL) { |
103 // Load the specified script. | 103 // Load the specified script. |
104 Dart_Handle library = LoadSnapshotCreationScript(script_name); | 104 library = LoadSnapshotCreationScript(script_name); |
105 if (Dart_IsError(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 { | 105 } else { |
120 // Implicitly load builtin library. | 106 // This is a generic dart snapshot which needs builtin library setup. |
121 Builtin_LoadLibrary(); | 107 library = Builtin_LoadLibrary(); |
122 // Setup the native resolver for built in library functions. | |
123 Builtin_SetNativeResolver(); | |
124 } | 108 } |
125 | 109 if (Dart_IsError(library)) { |
| 110 const char* err_msg = Dart_GetError(library); |
| 111 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg); |
| 112 Dart_ExitScope(); |
| 113 exit(255); |
| 114 } |
| 115 ASSERT(Dart_IsLibrary(library)); |
126 uint8_t* buffer = NULL; | 116 uint8_t* buffer = NULL; |
127 intptr_t size = 0; | 117 intptr_t size = 0; |
128 // First create the snapshot. | 118 // First create the snapshot. |
129 result = Dart_CreateSnapshot(&buffer, &size); | 119 result = Dart_CreateSnapshot(&buffer, &size); |
130 if (Dart_IsError(result)) { | 120 if (Dart_IsError(result)) { |
131 const char* err_msg = Dart_GetError(result); | 121 const char* err_msg = Dart_GetError(result); |
132 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg); | 122 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg); |
133 Dart_ExitScope(); | 123 Dart_ExitScope(); |
134 exit(255); | 124 exit(255); |
135 } | 125 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // and writes out a snapshot. | 165 // and writes out a snapshot. |
176 Dart_Isolate isolate = Dart_CreateIsolate(NULL, script_name); | 166 Dart_Isolate isolate = Dart_CreateIsolate(NULL, script_name); |
177 if (isolate == NULL) { | 167 if (isolate == NULL) { |
178 return 255; | 168 return 255; |
179 } | 169 } |
180 | 170 |
181 // Shutdown the isolate. | 171 // Shutdown the isolate. |
182 Dart_ShutdownIsolate(); | 172 Dart_ShutdownIsolate(); |
183 return 0; | 173 return 0; |
184 } | 174 } |
OLD | NEW |