| 1 | // Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file | 
|---|
| 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. | 
|---|
| 4 |  | 
|---|
| 5 | #ifndef RUNTIME_BIN_MAIN_OPTIONS_H_ | 
|---|
| 6 | #define RUNTIME_BIN_MAIN_OPTIONS_H_ | 
|---|
| 7 |  | 
|---|
| 8 | #include "bin/dartutils.h" | 
|---|
| 9 | #include "bin/dfe.h" | 
|---|
| 10 | #include "platform/globals.h" | 
|---|
| 11 | #include "platform/growable_array.h" | 
|---|
| 12 | #include "platform/hashmap.h" | 
|---|
| 13 |  | 
|---|
| 14 | namespace dart { | 
|---|
| 15 | namespace bin { | 
|---|
| 16 |  | 
|---|
| 17 | // A list of options taking string arguments. Organized as: | 
|---|
| 18 | //   V(flag_name, field_name) | 
|---|
| 19 | // The value of the flag can then be accessed with Options::field_name(). | 
|---|
| 20 | #define STRING_OPTIONS_LIST(V)                                                 \ | 
|---|
| 21 | V(packages, packages_file)                                                   \ | 
|---|
| 22 | V(snapshot, snapshot_filename)                                               \ | 
|---|
| 23 | V(snapshot_depfile, snapshot_deps_filename)                                  \ | 
|---|
| 24 | V(depfile, depfile)                                                          \ | 
|---|
| 25 | V(depfile_output_filename, depfile_output_filename)                          \ | 
|---|
| 26 | V(save_compilation_trace, save_compilation_trace_filename)                   \ | 
|---|
| 27 | V(load_compilation_trace, load_compilation_trace_filename)                   \ | 
|---|
| 28 | V(save_type_feedback, save_type_feedback_filename)                           \ | 
|---|
| 29 | V(load_type_feedback, load_type_feedback_filename)                           \ | 
|---|
| 30 | V(root_certs_file, root_certs_file)                                          \ | 
|---|
| 31 | V(root_certs_cache, root_certs_cache)                                        \ | 
|---|
| 32 | V(namespace, namespc)                                                        \ | 
|---|
| 33 | V(write_service_info, vm_write_service_info_filename) | 
|---|
| 34 |  | 
|---|
| 35 | // As STRING_OPTIONS_LIST but for boolean valued options. The default value is | 
|---|
| 36 | // always false, and the presence of the flag switches the value to true. | 
|---|
| 37 | #define BOOL_OPTIONS_LIST(V)                                                   \ | 
|---|
| 38 | V(version, version_option)                                                   \ | 
|---|
| 39 | V(compile_all, compile_all)                                                  \ | 
|---|
| 40 | V(disable_service_origin_check, vm_service_dev_mode)                         \ | 
|---|
| 41 | V(disable_service_auth_codes, vm_service_auth_disabled)                      \ | 
|---|
| 42 | V(deterministic, deterministic)                                              \ | 
|---|
| 43 | V(trace_loading, trace_loading)                                              \ | 
|---|
| 44 | V(short_socket_read, short_socket_read)                                      \ | 
|---|
| 45 | V(short_socket_write, short_socket_write)                                    \ | 
|---|
| 46 | V(disable_exit, exit_disabled)                                               \ | 
|---|
| 47 | V(preview_dart_2, nop_option)                                                \ | 
|---|
| 48 | V(suppress_core_dump, suppress_core_dump)                                    \ | 
|---|
| 49 | V(enable_service_port_fallback, enable_service_port_fallback)                \ | 
|---|
| 50 | V(disable_dart_dev, disable_dart_dev) | 
|---|
| 51 |  | 
|---|
| 52 | // Boolean flags that have a short form. | 
|---|
| 53 | #define SHORT_BOOL_OPTIONS_LIST(V)                                             \ | 
|---|
| 54 | V(h, help, help_option)                                                      \ | 
|---|
| 55 | V(v, verbose, verbose_option) | 
|---|
| 56 |  | 
|---|
| 57 | #define DEBUG_BOOL_OPTIONS_LIST(V)                                             \ | 
|---|
| 58 | V(force_load_elf_from_memory, force_load_elf_from_memory) | 
|---|
| 59 |  | 
|---|
| 60 | // A list of flags taking arguments from an enum. Organized as: | 
|---|
| 61 | //   V(flag_name, enum_type, field_name) | 
|---|
| 62 | // In main_options.cc there must be a list of strings that matches the enum | 
|---|
| 63 | // called k{enum_type}Names. The field is not automatically declared in | 
|---|
| 64 | // main_options.cc. It must be explicitly declared. | 
|---|
| 65 | #define ENUM_OPTIONS_LIST(V) V(snapshot_kind, SnapshotKind, gen_snapshot_kind) | 
|---|
| 66 |  | 
|---|
| 67 | // Callbacks passed to DEFINE_CB_OPTION(). | 
|---|
| 68 | #define CB_OPTIONS_LIST(V)                                                     \ | 
|---|
| 69 | V(ProcessEnvironmentOption)                                                  \ | 
|---|
| 70 | V(ProcessEnableVmServiceOption)                                              \ | 
|---|
| 71 | V(ProcessObserveOption)                                                      \ | 
|---|
| 72 | V(ProcessEnableExperimentOption)                                             \ | 
|---|
| 73 | V(ProcessVMDebuggingOptions) | 
|---|
| 74 |  | 
|---|
| 75 | // This enum must match the strings in kSnapshotKindNames in main_options.cc. | 
|---|
| 76 | enum SnapshotKind { | 
|---|
| 77 | kNone, | 
|---|
| 78 | kKernel, | 
|---|
| 79 | kAppJIT, | 
|---|
| 80 | }; | 
|---|
| 81 |  | 
|---|
| 82 | class Options { | 
|---|
| 83 | public: | 
|---|
| 84 | static int ParseArguments(int argc, | 
|---|
| 85 | char** argv, | 
|---|
| 86 | bool vm_run_app_shapshot, | 
|---|
| 87 | CommandLineOptions* vm_options, | 
|---|
| 88 | char** script_name, | 
|---|
| 89 | CommandLineOptions* dart_options, | 
|---|
| 90 | bool* print_flags_seen, | 
|---|
| 91 | bool* verbose_debug_seen); | 
|---|
| 92 |  | 
|---|
| 93 | #define STRING_OPTION_GETTER(flag, variable)                                   \ | 
|---|
| 94 | static const char* variable() { return variable##_; } | 
|---|
| 95 | STRING_OPTIONS_LIST(STRING_OPTION_GETTER) | 
|---|
| 96 | #undef STRING_OPTION_GETTER | 
|---|
| 97 |  | 
|---|
| 98 | #define BOOL_OPTION_GETTER(flag, variable)                                     \ | 
|---|
| 99 | static bool variable() { return variable##_; } | 
|---|
| 100 | BOOL_OPTIONS_LIST(BOOL_OPTION_GETTER) | 
|---|
| 101 | #if defined(DEBUG) | 
|---|
| 102 | DEBUG_BOOL_OPTIONS_LIST(BOOL_OPTION_GETTER) | 
|---|
| 103 | #endif | 
|---|
| 104 | #undef BOOL_OPTION_GETTER | 
|---|
| 105 |  | 
|---|
| 106 | #define SHORT_BOOL_OPTION_GETTER(short_name, long_name, variable)              \ | 
|---|
| 107 | static bool variable() { return variable##_; } | 
|---|
| 108 | SHORT_BOOL_OPTIONS_LIST(SHORT_BOOL_OPTION_GETTER) | 
|---|
| 109 | #undef SHORT_BOOL_OPTION_GETTER | 
|---|
| 110 |  | 
|---|
| 111 | #define ENUM_OPTIONS_GETTER(flag, type, variable)                              \ | 
|---|
| 112 | static type variable() { return variable##_; } | 
|---|
| 113 | ENUM_OPTIONS_LIST(ENUM_OPTIONS_GETTER) | 
|---|
| 114 | #undef ENUM_OPTIONS_GETTER | 
|---|
| 115 |  | 
|---|
| 116 | // Callbacks have to be public. | 
|---|
| 117 | #define CB_OPTIONS_DECL(callback)                                              \ | 
|---|
| 118 | static bool callback(const char* arg, CommandLineOptions* vm_options); | 
|---|
| 119 | CB_OPTIONS_LIST(CB_OPTIONS_DECL) | 
|---|
| 120 | #undef CB_OPTIONS_DECL | 
|---|
| 121 |  | 
|---|
| 122 | static bool preview_dart_2() { return true; } | 
|---|
| 123 |  | 
|---|
| 124 | static dart::SimpleHashMap* environment() { return environment_; } | 
|---|
| 125 |  | 
|---|
| 126 | static const char* vm_service_server_ip() { return vm_service_server_ip_; } | 
|---|
| 127 | static int vm_service_server_port() { return vm_service_server_port_; } | 
|---|
| 128 |  | 
|---|
| 129 | #if !defined(DART_PRECOMPILED_RUNTIME) | 
|---|
| 130 | static DFE* dfe() { return dfe_; } | 
|---|
| 131 | static void set_dfe(DFE* dfe) { dfe_ = dfe; } | 
|---|
| 132 | #endif  // !defined(DART_PRECOMPILED_RUNTIME) | 
|---|
| 133 |  | 
|---|
| 134 | static void PrintUsage(); | 
|---|
| 135 | static void PrintVersion(); | 
|---|
| 136 |  | 
|---|
| 137 | static void DestroyEnvironment(); | 
|---|
| 138 |  | 
|---|
| 139 | private: | 
|---|
| 140 | #define STRING_OPTION_DECL(flag, variable) static const char* variable##_; | 
|---|
| 141 | STRING_OPTIONS_LIST(STRING_OPTION_DECL) | 
|---|
| 142 | #undef STRING_OPTION_DECL | 
|---|
| 143 |  | 
|---|
| 144 | #define BOOL_OPTION_DECL(flag, variable) static bool variable##_; | 
|---|
| 145 | BOOL_OPTIONS_LIST(BOOL_OPTION_DECL) | 
|---|
| 146 | #if defined(DEBUG) | 
|---|
| 147 | DEBUG_BOOL_OPTIONS_LIST(BOOL_OPTION_DECL) | 
|---|
| 148 | #endif | 
|---|
| 149 | #undef BOOL_OPTION_DECL | 
|---|
| 150 |  | 
|---|
| 151 | #define SHORT_BOOL_OPTION_DECL(short_name, long_name, variable)                \ | 
|---|
| 152 | static bool variable##_; | 
|---|
| 153 | SHORT_BOOL_OPTIONS_LIST(SHORT_BOOL_OPTION_DECL) | 
|---|
| 154 | #undef SHORT_BOOL_OPTION_DECL | 
|---|
| 155 |  | 
|---|
| 156 | #define ENUM_OPTION_DECL(flag, type, variable) static type variable##_; | 
|---|
| 157 | ENUM_OPTIONS_LIST(ENUM_OPTION_DECL) | 
|---|
| 158 | #undef ENUM_OPTION_DECL | 
|---|
| 159 |  | 
|---|
| 160 | static dart::SimpleHashMap* environment_; | 
|---|
| 161 |  | 
|---|
| 162 | // Frontend argument processing. | 
|---|
| 163 | #if !defined(DART_PRECOMPILED_RUNTIME) | 
|---|
| 164 | static DFE* dfe_; | 
|---|
| 165 | #endif  // !defined(DART_PRECOMPILED_RUNTIME) | 
|---|
| 166 |  | 
|---|
| 167 | // VM Service argument processing. | 
|---|
| 168 | static const char* vm_service_server_ip_; | 
|---|
| 169 | static bool enable_vm_service_; | 
|---|
| 170 | static int vm_service_server_port_; | 
|---|
| 171 | static bool ExtractPortAndAddress(const char* option_value, | 
|---|
| 172 | int* out_port, | 
|---|
| 173 | const char** out_ip, | 
|---|
| 174 | int default_port, | 
|---|
| 175 | const char* default_ip); | 
|---|
| 176 |  | 
|---|
| 177 | static MallocGrowableArray<const char*> enabled_experiments_; | 
|---|
| 178 |  | 
|---|
| 179 | #define OPTION_FRIEND(flag, variable) friend class OptionProcessor_##flag; | 
|---|
| 180 | STRING_OPTIONS_LIST(OPTION_FRIEND) | 
|---|
| 181 | BOOL_OPTIONS_LIST(OPTION_FRIEND) | 
|---|
| 182 | #if defined(DEBUG) | 
|---|
| 183 | DEBUG_BOOL_OPTIONS_LIST(OPTION_FRIEND) | 
|---|
| 184 | #endif | 
|---|
| 185 | #undef OPTION_FRIEND | 
|---|
| 186 |  | 
|---|
| 187 | #define SHORT_BOOL_OPTION_FRIEND(short_name, long_name, variable)              \ | 
|---|
| 188 | friend class OptionProcessor_##long_name; | 
|---|
| 189 | SHORT_BOOL_OPTIONS_LIST(SHORT_BOOL_OPTION_FRIEND) | 
|---|
| 190 | #undef SHORT_BOOL_OPTION_FRIEND | 
|---|
| 191 |  | 
|---|
| 192 | #define ENUM_OPTION_FRIEND(flag, type, variable)                               \ | 
|---|
| 193 | friend class OptionProcessor_##flag; | 
|---|
| 194 | ENUM_OPTIONS_LIST(ENUM_OPTION_FRIEND) | 
|---|
| 195 | #undef ENUM_OPTION_FRIEND | 
|---|
| 196 |  | 
|---|
| 197 | DISALLOW_ALLOCATION(); | 
|---|
| 198 | DISALLOW_IMPLICIT_CONSTRUCTORS(Options); | 
|---|
| 199 | }; | 
|---|
| 200 |  | 
|---|
| 201 | }  // namespace bin | 
|---|
| 202 | }  // namespace dart | 
|---|
| 203 |  | 
|---|
| 204 | #endif  // RUNTIME_BIN_MAIN_OPTIONS_H_ | 
|---|
| 205 |  | 
|---|