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 12 matching lines...) Expand all Loading... |
23 | 23 |
24 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise | 24 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise |
25 // it is initialized to NULL. | 25 // it is initialized to NULL. |
26 extern const uint8_t* snapshot_buffer; | 26 extern const uint8_t* snapshot_buffer; |
27 | 27 |
28 | 28 |
29 // Global state that stores the original working directory.. | 29 // Global state that stores the original working directory.. |
30 static const char* original_working_directory = NULL; | 30 static const char* original_working_directory = NULL; |
31 | 31 |
32 | 32 |
33 // Global state that stores the import URL map specified on the | |
34 // command line. | |
35 static CommandLineOptions* import_map_options = NULL; | |
36 | |
37 | |
38 // Global state that indicates whether perf_events symbol information | 33 // Global state that indicates whether perf_events symbol information |
39 // is to be generated or not. | 34 // is to be generated or not. |
40 static File* perf_events_symbols_file = NULL; | 35 static File* perf_events_symbols_file = NULL; |
41 | 36 |
42 | 37 |
43 // Global state that indicates whether pprof symbol information is | 38 // Global state that indicates whether pprof symbol information is |
44 // to be generated or not. | 39 // to be generated or not. |
45 static const char* generate_pprof_symbols_filename = NULL; | 40 static const char* generate_pprof_symbols_filename = NULL; |
46 | 41 |
47 | 42 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 153 } |
159 | 154 |
160 | 155 |
161 static void ProcessFlowGraphOption(const char* flowgraph_option) { | 156 static void ProcessFlowGraphOption(const char* flowgraph_option) { |
162 ASSERT(flowgraph_option != NULL); | 157 ASSERT(flowgraph_option != NULL); |
163 flow_graph_file = File::Open("flowgraph.cfg", File::kWriteTruncate); | 158 flow_graph_file = File::Open("flowgraph.cfg", File::kWriteTruncate); |
164 ASSERT(flow_graph_file != NULL); | 159 ASSERT(flow_graph_file != NULL); |
165 } | 160 } |
166 | 161 |
167 | 162 |
168 static void ProcessImportMapOption(const char* map) { | |
169 ASSERT(map != NULL); | |
170 import_map_options->AddArgument(map); | |
171 } | |
172 | |
173 | |
174 static struct { | 163 static struct { |
175 const char* option_name; | 164 const char* option_name; |
176 void (*process)(const char* option); | 165 void (*process)(const char* option); |
177 } main_options[] = { | 166 } main_options[] = { |
178 { "--break_at=", ProcessBreakpointOption }, | 167 { "--break_at=", ProcessBreakpointOption }, |
179 { "--compile_all", ProcessCompileAllOption }, | 168 { "--compile_all", ProcessCompileAllOption }, |
180 { "--debug", ProcessDebugOption }, | 169 { "--debug", ProcessDebugOption }, |
181 { "--generate_perf_events_symbols", ProcessPerfEventsOption }, | 170 { "--generate_perf_events_symbols", ProcessPerfEventsOption }, |
182 { "--generate_pprof_symbols=", ProcessPprofOption }, | 171 { "--generate_pprof_symbols=", ProcessPprofOption }, |
183 { "--import_map=", ProcessImportMapOption }, | |
184 { "--package-root=", ProcessPackageRootOption }, | 172 { "--package-root=", ProcessPackageRootOption }, |
185 { "--generate_flow_graph", ProcessFlowGraphOption }, | 173 { "--generate_flow_graph", ProcessFlowGraphOption }, |
186 { NULL, NULL } | 174 { NULL, NULL } |
187 }; | 175 }; |
188 | 176 |
189 | 177 |
190 static bool ProcessMainOptions(const char* option) { | 178 static bool ProcessMainOptions(const char* option) { |
191 int i = 0; | 179 int i = 0; |
192 const char* name = main_options[0].option_name; | 180 const char* name = main_options[0].option_name; |
193 while (name != NULL) { | 181 while (name != NULL) { |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 resolved_script_uri = Dart_NewString(script_uri); | 488 resolved_script_uri = Dart_NewString(script_uri); |
501 } | 489 } |
502 Dart_Handle source = ReadSource(resolved_script_uri, builtin_lib); | 490 Dart_Handle source = ReadSource(resolved_script_uri, builtin_lib); |
503 if (Dart_IsError(source)) { | 491 if (Dart_IsError(source)) { |
504 return source; | 492 return source; |
505 } | 493 } |
506 return Dart_LoadScript(resolved_script_uri, source); | 494 return Dart_LoadScript(resolved_script_uri, source); |
507 } | 495 } |
508 | 496 |
509 | 497 |
510 static Dart_Handle CreateImportMap(CommandLineOptions* map) { | |
511 intptr_t length = (map == NULL) ? 0 : map->count(); | |
512 Dart_Handle import_map = Dart_NewList(length * 2); | |
513 for (intptr_t i = 0; i < length; i++) { | |
514 ASSERT(map->GetArgument(i) != NULL); | |
515 char* name = strdup(map->GetArgument(i)); | |
516 ASSERT(name != NULL); | |
517 char* map_name = strchr(name, ','); | |
518 intptr_t index = i * 2; | |
519 if (map_name != NULL) { | |
520 *map_name = '\0'; | |
521 map_name += 1; | |
522 Dart_ListSetAt(import_map, index, Dart_NewString(name)); | |
523 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name)); | |
524 } else { | |
525 Dart_ListSetAt(import_map, index, Dart_NewString(name)); | |
526 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); | |
527 } | |
528 free(name); | |
529 } | |
530 return import_map; | |
531 } | |
532 | |
533 | |
534 // Returns true on success, false on failure. | 498 // Returns true on success, false on failure. |
535 static bool CreateIsolateAndSetupHelper(const char* script_uri, | 499 static bool CreateIsolateAndSetupHelper(const char* script_uri, |
536 const char* main, | 500 const char* main, |
537 bool resolve_script, | 501 bool resolve_script, |
538 void* data, | 502 void* data, |
539 char** error) { | 503 char** error) { |
540 Dart_Isolate isolate = | 504 Dart_Isolate isolate = |
541 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); | 505 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); |
542 if (isolate == NULL) { | 506 if (isolate == NULL) { |
543 return false; | 507 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
555 | 519 |
556 // Set up the library tag handler for this isolate. | 520 // Set up the library tag handler for this isolate. |
557 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); | 521 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); |
558 if (Dart_IsError(result)) { | 522 if (Dart_IsError(result)) { |
559 *error = strdup(Dart_GetError(result)); | 523 *error = strdup(Dart_GetError(result)); |
560 Dart_ExitScope(); | 524 Dart_ExitScope(); |
561 Dart_ShutdownIsolate(); | 525 Dart_ShutdownIsolate(); |
562 return false; | 526 return false; |
563 } | 527 } |
564 | 528 |
565 // Set up the import map for this isolate. | |
566 result = Dart_SetImportMap(CreateImportMap(import_map_options)); | |
567 if (Dart_IsError(result)) { | |
568 *error = strdup(Dart_GetError(result)); | |
569 Dart_ExitScope(); | |
570 Dart_ShutdownIsolate(); | |
571 return false; | |
572 } | |
573 | |
574 // Prepare builtin and its dependent libraries for use to resolve URIs. | 529 // Prepare builtin and its dependent libraries for use to resolve URIs. |
575 Dart_Handle uri_lib = Builtin::LoadLibrary(Builtin::kUriLibrary); | 530 Dart_Handle uri_lib = Builtin::LoadLibrary(Builtin::kUriLibrary); |
576 if (Dart_IsError(uri_lib)) { | 531 if (Dart_IsError(uri_lib)) { |
577 *error = strdup(Dart_GetError(uri_lib)); | 532 *error = strdup(Dart_GetError(uri_lib)); |
578 Dart_ExitScope(); | 533 Dart_ExitScope(); |
579 Dart_ShutdownIsolate(); | 534 Dart_ShutdownIsolate(); |
580 return false; | 535 return false; |
581 } | 536 } |
582 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); | 537 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); |
583 if (Dart_IsError(builtin_lib)) { | 538 if (Dart_IsError(builtin_lib)) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 if (handler != NULL) handler->Shutdown(); | 692 if (handler != NULL) handler->Shutdown(); |
738 delete isolate_data; | 693 delete isolate_data; |
739 } | 694 } |
740 | 695 |
741 | 696 |
742 int main(int argc, char** argv) { | 697 int main(int argc, char** argv) { |
743 char* executable_name; | 698 char* executable_name; |
744 char* script_name; | 699 char* script_name; |
745 CommandLineOptions vm_options(argc); | 700 CommandLineOptions vm_options(argc); |
746 CommandLineOptions dart_options(argc); | 701 CommandLineOptions dart_options(argc); |
747 CommandLineOptions import_map(argc); | |
748 import_map_options = &import_map; | |
749 bool print_flags_seen = false; | 702 bool print_flags_seen = false; |
750 | 703 |
751 // Perform platform specific initialization. | 704 // Perform platform specific initialization. |
752 if (!Platform::Initialize()) { | 705 if (!Platform::Initialize()) { |
753 fprintf(stderr, "Initialization failed\n"); | 706 fprintf(stderr, "Initialization failed\n"); |
754 } | 707 } |
755 | 708 |
756 // Parse command line arguments. | 709 // Parse command line arguments. |
757 if (ParseArguments(argc, | 710 if (ParseArguments(argc, |
758 argv, | 711 argv, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 DumpPprofSymbolInfo(); | 808 DumpPprofSymbolInfo(); |
856 // Shutdown the isolate. | 809 // Shutdown the isolate. |
857 Dart_ShutdownIsolate(); | 810 Dart_ShutdownIsolate(); |
858 // Terminate process exit-code handler. | 811 // Terminate process exit-code handler. |
859 Process::TerminateExitCodeHandler(); | 812 Process::TerminateExitCodeHandler(); |
860 | 813 |
861 free(const_cast<char*>(original_working_directory)); | 814 free(const_cast<char*>(original_working_directory)); |
862 | 815 |
863 return 0; | 816 return 0; |
864 } | 817 } |
OLD | NEW |