OLD | NEW |
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 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "include/dart_debugger_api.h" | 10 #include "include/dart_debugger_api.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace dart { | 28 namespace dart { |
29 namespace bin { | 29 namespace bin { |
30 | 30 |
31 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise | 31 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise |
32 // it is initialized to NULL. | 32 // it is initialized to NULL. |
33 extern const uint8_t* snapshot_buffer; | 33 extern const uint8_t* snapshot_buffer; |
34 | 34 |
35 // Global state that stores a pointer to the application script snapshot. | 35 // Global state that stores a pointer to the application script snapshot. |
36 static bool generate_script_snapshot = false; | 36 static bool generate_script_snapshot = false; |
37 static File* snapshot_file = NULL; | 37 static const char* snapshot_filename = NULL; |
38 | 38 |
39 | 39 |
40 // Global state that indicates whether there is a debug breakpoint. | 40 // Global state that indicates whether there is a debug breakpoint. |
41 // This pointer points into an argv buffer and does not need to be | 41 // This pointer points into an argv buffer and does not need to be |
42 // free'd. | 42 // free'd. |
43 static const char* breakpoint_at = NULL; | 43 static const char* breakpoint_at = NULL; |
44 | 44 |
45 | 45 |
46 // Global state that indicates whether we should open a connection | 46 // Global state that indicates whether we should open a connection |
47 // and listen for a debugger to connect. | 47 // and listen for a debugger to connect. |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 267 |
268 static bool ProcessGenScriptSnapshotOption(const char* filename, | 268 static bool ProcessGenScriptSnapshotOption(const char* filename, |
269 CommandLineOptions* vm_options) { | 269 CommandLineOptions* vm_options) { |
270 if (filename != NULL && strlen(filename) != 0) { | 270 if (filename != NULL && strlen(filename) != 0) { |
271 // Ensure that are already running using a full snapshot. | 271 // Ensure that are already running using a full snapshot. |
272 if (snapshot_buffer == NULL) { | 272 if (snapshot_buffer == NULL) { |
273 Log::PrintErr("Script snapshots cannot be generated in this version of" | 273 Log::PrintErr("Script snapshots cannot be generated in this version of" |
274 " dart\n"); | 274 " dart\n"); |
275 return false; | 275 return false; |
276 } | 276 } |
277 snapshot_file = File::Open(filename, File::kWriteTruncate); | 277 snapshot_filename = filename; |
278 if (snapshot_file == NULL) { | |
279 Log::PrintErr("Unable to open file %s for writing the snapshot\n", | |
280 filename); | |
281 return false; | |
282 } | |
283 generate_script_snapshot = true; | 278 generate_script_snapshot = true; |
284 return true; | 279 return true; |
285 } | 280 } |
286 return false; | 281 return false; |
287 } | 282 } |
288 | 283 |
289 | 284 |
290 static bool ProcessEnableVmServiceOption(const char* option_value, | 285 static bool ProcessEnableVmServiceOption(const char* option_value, |
291 CommandLineOptions* vm_options) { | 286 CommandLineOptions* vm_options) { |
292 ASSERT(option_value != NULL); | 287 ASSERT(option_value != NULL); |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 Dart_EnterScope(); | 1061 Dart_EnterScope(); |
1067 | 1062 |
1068 if (generate_script_snapshot) { | 1063 if (generate_script_snapshot) { |
1069 // First create a snapshot. | 1064 // First create a snapshot. |
1070 Dart_Handle result; | 1065 Dart_Handle result; |
1071 uint8_t* buffer = NULL; | 1066 uint8_t* buffer = NULL; |
1072 intptr_t size = 0; | 1067 intptr_t size = 0; |
1073 result = Dart_CreateScriptSnapshot(&buffer, &size); | 1068 result = Dart_CreateScriptSnapshot(&buffer, &size); |
1074 DartExitOnError(result); | 1069 DartExitOnError(result); |
1075 | 1070 |
| 1071 // Open the snapshot file. |
| 1072 File* snapshot_file = File::Open(snapshot_filename, File::kWriteTruncate); |
| 1073 if (snapshot_file == NULL) { |
| 1074 ErrorExit(kErrorExitCode, |
| 1075 "Unable to open file %s for writing the snapshot\n", |
| 1076 snapshot_filename); |
| 1077 } |
| 1078 |
1076 // Write the magic number to indicate file is a script snapshot. | 1079 // Write the magic number to indicate file is a script snapshot. |
1077 DartUtils::WriteMagicNumber(snapshot_file); | 1080 DartUtils::WriteMagicNumber(snapshot_file); |
1078 | 1081 |
1079 // Now write the snapshot out to specified file. | 1082 // Now write the snapshot out to specified file. |
1080 bool bytes_written = snapshot_file->WriteFully(buffer, size); | 1083 bool bytes_written = snapshot_file->WriteFully(buffer, size); |
1081 ASSERT(bytes_written); | 1084 ASSERT(bytes_written); |
1082 delete snapshot_file; | 1085 delete snapshot_file; |
| 1086 snapshot_file = NULL; |
1083 } else { | 1087 } else { |
1084 // Lookup the library of the root script. | 1088 // Lookup the library of the root script. |
1085 Dart_Handle root_lib = Dart_RootLibrary(); | 1089 Dart_Handle root_lib = Dart_RootLibrary(); |
1086 // Import the root library into the builtin library so that we can easily | 1090 // Import the root library into the builtin library so that we can easily |
1087 // lookup the main entry point exported from the root library. | 1091 // lookup the main entry point exported from the root library. |
1088 Dart_Handle builtin_lib = | 1092 Dart_Handle builtin_lib = |
1089 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 1093 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
1090 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); | 1094 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); |
1091 | 1095 |
1092 if (has_compile_all) { | 1096 if (has_compile_all) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 exit(Process::GlobalExitCode()); | 1173 exit(Process::GlobalExitCode()); |
1170 } | 1174 } |
1171 | 1175 |
1172 } // namespace bin | 1176 } // namespace bin |
1173 } // namespace dart | 1177 } // namespace dart |
1174 | 1178 |
1175 int main(int argc, char** argv) { | 1179 int main(int argc, char** argv) { |
1176 dart::bin::main(argc, argv); | 1180 dart::bin::main(argc, argv); |
1177 UNREACHABLE(); | 1181 UNREACHABLE(); |
1178 } | 1182 } |
OLD | NEW |