| 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 <assert.h> | 8 #include <assert.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 ASSERT(file != NULL); | 86 ASSERT(file != NULL); |
| 87 for (intptr_t i = 0; i < size; i++) { | 87 for (intptr_t i = 0; i < size; i++) { |
| 88 file->WriteByte(buffer[i]); | 88 file->WriteByte(buffer[i]); |
| 89 } | 89 } |
| 90 delete file; | 90 delete file; |
| 91 } | 91 } |
| 92 | 92 |
| 93 | 93 |
| 94 static void* SnapshotCreateCallback(void* data) { | 94 static void* SnapshotCreateCallback(void* data) { |
| 95 const char* script_name = reinterpret_cast<const char*>(data); | 95 const char* script_name = reinterpret_cast<const char*>(data); |
| 96 Dart_Result result; | 96 Dart_Handle result; |
| 97 Dart_EnterScope(); | 97 Dart_EnterScope(); |
| 98 | 98 |
| 99 ASSERT(snapshot_filename != NULL); | 99 ASSERT(snapshot_filename != NULL); |
| 100 | 100 |
| 101 // If a file is specified on the command line, load it up before a snapshot | 101 // If a file is specified on the command line, load it up before a snapshot |
| 102 // is created. | 102 // is created. |
| 103 if (script_name != NULL) { | 103 if (script_name != NULL) { |
| 104 // Load the specified script. | 104 // Load the specified script. |
| 105 result = LoadScript(script_name); | 105 Dart_Handle library = LoadScript(script_name); |
| 106 if (!Dart_IsValidResult(result)) { | 106 if (!Dart_IsValid(library)) { |
| 107 const char* err_msg = Dart_GetErrorCString(result); | 107 const char* err_msg = Dart_GetError(library); |
| 108 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg); | 108 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg); |
| 109 Dart_ExitScope(); | 109 Dart_ExitScope(); |
| 110 exit(255); | 110 exit(255); |
| 111 } | 111 } |
| 112 | 112 |
| 113 Dart_Handle library = Dart_GetResult(result); | |
| 114 if (!Dart_IsLibrary(library)) { | 113 if (!Dart_IsLibrary(library)) { |
| 115 fprintf(stderr, | 114 fprintf(stderr, |
| 116 "Expected a library when loading script: %s", | 115 "Expected a library when loading script: %s", |
| 117 script_name); | 116 script_name); |
| 118 Dart_ExitScope(); | 117 Dart_ExitScope(); |
| 119 exit(255); | 118 exit(255); |
| 120 } | 119 } |
| 121 Builtin_ImportLibrary(library); | 120 Builtin_ImportLibrary(library); |
| 122 } else { | 121 } else { |
| 123 Builtin_LoadLibrary(); | 122 Builtin_LoadLibrary(); |
| 124 } | 123 } |
| 125 // Setup the native resolver for built in library functions. | 124 // Setup the native resolver for built in library functions. |
| 126 Builtin_SetNativeResolver(); | 125 Builtin_SetNativeResolver(); |
| 127 | 126 |
| 128 uint8_t* buffer = NULL; | 127 uint8_t* buffer = NULL; |
| 129 intptr_t size = 0; | 128 intptr_t size = 0; |
| 130 // First create the snapshot. | 129 // First create the snapshot. |
| 131 result = Dart_CreateSnapshot(&buffer, &size); | 130 result = Dart_CreateSnapshot(&buffer, &size); |
| 132 if (!Dart_IsValidResult(result)) { | 131 if (!Dart_IsValid(result)) { |
| 133 const char* err_msg = Dart_GetErrorCString(result); | 132 const char* err_msg = Dart_GetError(result); |
| 134 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg); | 133 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg); |
| 135 Dart_ExitScope(); | 134 Dart_ExitScope(); |
| 136 exit(255); | 135 exit(255); |
| 137 } | 136 } |
| 138 // Now write the snapshot out to specified file and exit. | 137 // Now write the snapshot out to specified file and exit. |
| 139 WriteSnapshotFile(buffer, size); | 138 WriteSnapshotFile(buffer, size); |
| 140 Dart_ExitScope(); | 139 Dart_ExitScope(); |
| 141 return data; | 140 return data; |
| 142 } | 141 } |
| 143 | 142 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // and writes out a snapshot. | 176 // and writes out a snapshot. |
| 178 Dart_Isolate isolate = Dart_CreateIsolate(NULL, script_name); | 177 Dart_Isolate isolate = Dart_CreateIsolate(NULL, script_name); |
| 179 if (isolate == NULL) { | 178 if (isolate == NULL) { |
| 180 return 255; | 179 return 255; |
| 181 } | 180 } |
| 182 | 181 |
| 183 // Shutdown the isolate. | 182 // Shutdown the isolate. |
| 184 Dart_ShutdownIsolate(); | 183 Dart_ShutdownIsolate(); |
| 185 return 0; | 184 return 0; |
| 186 } | 185 } |
| OLD | NEW |