Mercurial > hg > CbC > CbC_llvm
comparison docs/CommandLine.rst @ 148:63bd29f05246
merged
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 19:46:37 +0900 |
parents | c2174574ed3a |
children |
comparison
equal
deleted
inserted
replaced
146:3fc4d5c3e21e | 148:63bd29f05246 |
---|---|
126 :: | 126 :: |
127 | 127 |
128 USAGE: compiler [options] | 128 USAGE: compiler [options] |
129 | 129 |
130 OPTIONS: | 130 OPTIONS: |
131 -h - Alias for -help | |
131 -help - display available options (-help-hidden for more) | 132 -help - display available options (-help-hidden for more) |
132 -o <filename> - Specify output filename | 133 -o <filename> - Specify output filename |
133 | 134 |
134 Because we specified that the command line option should parse using the | 135 Because we specified that the command line option should parse using the |
135 ``string`` data type, the variable declared is automatically usable as a real | 136 ``string`` data type, the variable declared is automatically usable as a real |
192 :: | 193 :: |
193 | 194 |
194 USAGE: compiler [options] <input file> | 195 USAGE: compiler [options] <input file> |
195 | 196 |
196 OPTIONS: | 197 OPTIONS: |
198 -h - Alias for -help | |
197 -help - display available options (-help-hidden for more) | 199 -help - display available options (-help-hidden for more) |
198 -o <filename> - Specify output filename | 200 -o <filename> - Specify output filename |
199 | 201 |
200 ... indicating that an input filename is expected. | 202 ... indicating that an input filename is expected. |
201 | 203 |
884 // DEBUG macro - This macro should be used by code to emit debug information. | 886 // DEBUG macro - This macro should be used by code to emit debug information. |
885 // In the '-debug' option is specified on the command line, and if this is a | 887 // In the '-debug' option is specified on the command line, and if this is a |
886 // debug build, then the code specified as the option to the macro will be | 888 // debug build, then the code specified as the option to the macro will be |
887 // executed. Otherwise it will not be. | 889 // executed. Otherwise it will not be. |
888 #ifdef NDEBUG | 890 #ifdef NDEBUG |
889 #define DEBUG(X) | 891 #define LLVM_DEBUG(X) |
890 #else | 892 #else |
891 #define DEBUG(X) do { if (DebugFlag) { X; } } while (0) | 893 #define LLVM_DEBUG(X) do { if (DebugFlag) { X; } } while (0) |
892 #endif | 894 #endif |
893 | 895 |
894 This allows clients to blissfully use the ``DEBUG()`` macro, or the | 896 This allows clients to blissfully use the ``LLVM_DEBUG()`` macro, or the |
895 ``DebugFlag`` explicitly if they want to. Now we just need to be able to set | 897 ``DebugFlag`` explicitly if they want to. Now we just need to be able to set |
896 the ``DebugFlag`` boolean when the option is set. To do this, we pass an | 898 the ``DebugFlag`` boolean when the option is set. To do this, we pass an |
897 additional argument to our command line argument processor, and we specify where | 899 additional argument to our command line argument processor, and we specify where |
898 to fill in with the `cl::location`_ attribute: | 900 to fill in with the `cl::location`_ attribute: |
899 | 901 |
1166 specified. | 1168 specified. |
1167 | 1169 |
1168 .. _grouping: | 1170 .. _grouping: |
1169 .. _cl::Grouping: | 1171 .. _cl::Grouping: |
1170 | 1172 |
1171 * The **cl::Grouping** modifier is used to implement Unix-style tools (like | 1173 Controlling options grouping |
1172 ``ls``) that have lots of single letter arguments, but only require a single | 1174 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
1173 dash. For example, the '``ls -labF``' command actually enables four different | 1175 |
1174 options, all of which are single letters. Note that **cl::Grouping** options | 1176 The **cl::Grouping** modifier can be combined with any formatting types except |
1175 cannot have values. | 1177 for `cl::Positional`_. It is used to implement Unix-style tools (like ``ls``) |
1178 that have lots of single letter arguments, but only require a single dash. | |
1179 For example, the '``ls -labF``' command actually enables four different options, | |
1180 all of which are single letters. | |
1181 | |
1182 Note that **cl::Grouping** options can have values only if they are used | |
1183 separately or at the end of the groups. For `cl::ValueRequired`_, it is | |
1184 a runtime error if such an option is used elsewhere in the group. | |
1176 | 1185 |
1177 The CommandLine library does not restrict how you use the **cl::Prefix** or | 1186 The CommandLine library does not restrict how you use the **cl::Prefix** or |
1178 **cl::Grouping** modifiers, but it is possible to specify ambiguous argument | 1187 **cl::Grouping** modifiers, but it is possible to specify ambiguous argument |
1179 settings. Thus, it is possible to have multiple letter options that are prefix | 1188 settings. Thus, it is possible to have multiple letter options that are prefix |
1180 or grouping options, and they will still work as designed. | 1189 or grouping options, and they will still work as designed. |
1185 | 1194 |
1186 :: | 1195 :: |
1187 | 1196 |
1188 parse(string OrigInput) { | 1197 parse(string OrigInput) { |
1189 | 1198 |
1190 1. string input = OrigInput; | 1199 1. string Input = OrigInput; |
1191 2. if (isOption(input)) return getOption(input).parse(); // Normal option | 1200 2. if (isOption(Input)) return getOption(Input).parse(); // Normal option |
1192 3. while (!isOption(input) && !input.empty()) input.pop_back(); // Remove the last letter | 1201 3. while (!Input.empty() && !isOption(Input)) Input.pop_back(); // Remove the last letter |
1193 4. if (input.empty()) return error(); // No matching option | 1202 4. while (!Input.empty()) { |
1194 5. if (getOption(input).isPrefix()) | 1203 string MaybeValue = OrigInput.substr(Input.length()) |
1195 return getOption(input).parse(input); | 1204 if (getOption(Input).isPrefix()) |
1196 6. while (!input.empty()) { // Must be grouping options | 1205 return getOption(Input).parse(MaybeValue) |
1197 getOption(input).parse(); | 1206 if (!MaybeValue.empty() && MaybeValue[0] == '=') |
1198 OrigInput.erase(OrigInput.begin(), OrigInput.begin()+input.length()); | 1207 return getOption(Input).parse(MaybeValue.substr(1)) |
1199 input = OrigInput; | 1208 if (!getOption(Input).isGrouping()) |
1200 while (!isOption(input) && !input.empty()) input.pop_back(); | 1209 return error() |
1210 getOption(Input).parse() | |
1211 Input = OrigInput = MaybeValue | |
1212 while (!Input.empty() && !isOption(Input)) Input.pop_back(); | |
1213 if (!Input.empty() && !getOption(Input).isGrouping()) | |
1214 return error() | |
1201 } | 1215 } |
1202 7. if (!OrigInput.empty()) error(); | 1216 5. if (!OrigInput.empty()) error(); |
1203 | 1217 |
1204 } | 1218 } |
1205 | 1219 |
1206 Miscellaneous option modifiers | 1220 Miscellaneous option modifiers |
1207 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 1221 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
1217 the option. For example, these two options are equivalent when | 1231 the option. For example, these two options are equivalent when |
1218 ``cl::CommaSeparated`` is specified: "``-foo=a -foo=b -foo=c``" and | 1232 ``cl::CommaSeparated`` is specified: "``-foo=a -foo=b -foo=c``" and |
1219 "``-foo=a,b,c``". This option only makes sense to be used in a case where the | 1233 "``-foo=a,b,c``". This option only makes sense to be used in a case where the |
1220 option is allowed to accept one or more values (i.e. it is a `cl::list`_ | 1234 option is allowed to accept one or more values (i.e. it is a `cl::list`_ |
1221 option). | 1235 option). |
1236 | |
1237 .. _cl::DefaultOption: | |
1238 | |
1239 * The **cl::DefaultOption** modifier is used to specify that the option is a | |
1240 default that can be overridden by application specific parsers. For example, | |
1241 the ``-help`` alias, ``-h``, is registered this way, so it can be overridden | |
1242 by applications that need to use the ``-h`` option for another purpose, | |
1243 either as a regular option or an alias for another option. | |
1222 | 1244 |
1223 .. _cl::PositionalEatsArgs: | 1245 .. _cl::PositionalEatsArgs: |
1224 | 1246 |
1225 * The **cl::PositionalEatsArgs** modifier (which only applies to positional | 1247 * The **cl::PositionalEatsArgs** modifier (which only applies to positional |
1226 arguments, and only makes sense for lists) indicates that positional argument | 1248 arguments, and only makes sense for lists) indicates that positional argument |
1237 least one option with ``cl::Sink`` modifier specified, the parser passes | 1259 least one option with ``cl::Sink`` modifier specified, the parser passes |
1238 unrecognized option strings to it as values instead of signaling an error. As | 1260 unrecognized option strings to it as values instead of signaling an error. As |
1239 with ``cl::CommaSeparated``, this modifier only makes sense with a `cl::list`_ | 1261 with ``cl::CommaSeparated``, this modifier only makes sense with a `cl::list`_ |
1240 option. | 1262 option. |
1241 | 1263 |
1242 So far, these are the only three miscellaneous option modifiers. | |
1243 | |
1244 .. _response files: | 1264 .. _response files: |
1245 | 1265 |
1246 Response files | 1266 Response files |
1247 ^^^^^^^^^^^^^^ | 1267 ^^^^^^^^^^^^^^ |
1248 | 1268 |
1272 Note this method should not be called during any static initialisation because | 1292 Note this method should not be called during any static initialisation because |
1273 it cannot be guaranteed that all options will have been initialised. Hence it | 1293 it cannot be guaranteed that all options will have been initialised. Hence it |
1274 should be called from ``main``. | 1294 should be called from ``main``. |
1275 | 1295 |
1276 This function can be used to gain access to options declared in libraries that | 1296 This function can be used to gain access to options declared in libraries that |
1277 the tool writter may not have direct access to. | 1297 the tool writer may not have direct access to. |
1278 | 1298 |
1279 The function retrieves a :ref:`StringMap <dss_stringmap>` that maps the option | 1299 The function retrieves a :ref:`StringMap <dss_stringmap>` that maps the option |
1280 string (e.g. ``-help``) to an ``Option*``. | 1300 string (e.g. ``-help``) to an ``Option*``. |
1281 | 1301 |
1282 Here is an example of how the function could be used: | 1302 Here is an example of how the function could be used: |
1714 a feature. However, sometimes it is necessary to know the value of the command | 1734 a feature. However, sometimes it is necessary to know the value of the command |
1715 line option outside of the library. In these cases the library does or should | 1735 line option outside of the library. In these cases the library does or should |
1716 provide an external storage location that is accessible to users of the | 1736 provide an external storage location that is accessible to users of the |
1717 library. Examples of this include the ``llvm::DebugFlag`` exported by the | 1737 library. Examples of this include the ``llvm::DebugFlag`` exported by the |
1718 ``lib/Support/Debug.cpp`` file and the ``llvm::TimePassesIsEnabled`` flag | 1738 ``lib/Support/Debug.cpp`` file and the ``llvm::TimePassesIsEnabled`` flag |
1719 exported by the ``lib/VMCore/PassManager.cpp`` file. | 1739 exported by the ``lib/IR/PassManager.cpp`` file. |
1720 | 1740 |
1721 .. todo:: | 1741 .. todo:: |
1722 | 1742 |
1723 TODO: complete this section | 1743 TODO: complete this section |
1724 | 1744 |