Mercurial > hg > CbC > CbC_llvm
comparison docs/CommandLine.rst @ 120:1172e4bd9c6f
update 4.0.0
author | mir3636 |
---|---|
date | Fri, 25 Nov 2016 19:14:25 +0900 |
parents | afa8332a0e37 |
children | 803732b1fca8 |
comparison
equal
deleted
inserted
replaced
101:34baf5011add | 120:1172e4bd9c6f |
---|---|
353 cl::opt<OptLevel> OptimizationLevel(cl::desc("Choose optimization level:"), | 353 cl::opt<OptLevel> OptimizationLevel(cl::desc("Choose optimization level:"), |
354 cl::values( | 354 cl::values( |
355 clEnumVal(g , "No optimizations, enable debugging"), | 355 clEnumVal(g , "No optimizations, enable debugging"), |
356 clEnumVal(O1, "Enable trivial optimizations"), | 356 clEnumVal(O1, "Enable trivial optimizations"), |
357 clEnumVal(O2, "Enable default optimizations"), | 357 clEnumVal(O2, "Enable default optimizations"), |
358 clEnumVal(O3, "Enable expensive optimizations"), | 358 clEnumVal(O3, "Enable expensive optimizations"))); |
359 clEnumValEnd)); | |
360 | 359 |
361 ... | 360 ... |
362 if (OptimizationLevel >= O2) doPartialRedundancyElimination(...); | 361 if (OptimizationLevel >= O2) doPartialRedundancyElimination(...); |
363 ... | 362 ... |
364 | 363 |
365 This declaration defines a variable "``OptimizationLevel``" of the | 364 This declaration defines a variable "``OptimizationLevel``" of the |
366 "``OptLevel``" enum type. This variable can be assigned any of the values that | 365 "``OptLevel``" enum type. This variable can be assigned any of the values that |
367 are listed in the declaration (Note that the declaration list must be terminated | 366 are listed in the declaration. The CommandLine library enforces that |
368 with the "``clEnumValEnd``" argument!). The CommandLine library enforces that | |
369 the user can only specify one of the options, and it ensure that only valid enum | 367 the user can only specify one of the options, and it ensure that only valid enum |
370 values can be specified. The "``clEnumVal``" macros ensure that the command | 368 values can be specified. The "``clEnumVal``" macros ensure that the command |
371 line arguments matched the enum values. With this option added, our help output | 369 line arguments matched the enum values. With this option added, our help output |
372 now is: | 370 now is: |
373 | 371 |
399 cl::opt<OptLevel> OptimizationLevel(cl::desc("Choose optimization level:"), | 397 cl::opt<OptLevel> OptimizationLevel(cl::desc("Choose optimization level:"), |
400 cl::values( | 398 cl::values( |
401 clEnumValN(Debug, "g", "No optimizations, enable debugging"), | 399 clEnumValN(Debug, "g", "No optimizations, enable debugging"), |
402 clEnumVal(O1 , "Enable trivial optimizations"), | 400 clEnumVal(O1 , "Enable trivial optimizations"), |
403 clEnumVal(O2 , "Enable default optimizations"), | 401 clEnumVal(O2 , "Enable default optimizations"), |
404 clEnumVal(O3 , "Enable expensive optimizations"), | 402 clEnumVal(O3 , "Enable expensive optimizations"))); |
405 clEnumValEnd)); | |
406 | 403 |
407 ... | 404 ... |
408 if (OptimizationLevel == Debug) outputDebugInfo(...); | 405 if (OptimizationLevel == Debug) outputDebugInfo(...); |
409 ... | 406 ... |
410 | 407 |
434 // Enable Debug Options to be specified on the command line | 431 // Enable Debug Options to be specified on the command line |
435 cl::opt<DebugLev> DebugLevel("debug_level", cl::desc("Set the debugging level:"), | 432 cl::opt<DebugLev> DebugLevel("debug_level", cl::desc("Set the debugging level:"), |
436 cl::values( | 433 cl::values( |
437 clEnumValN(nodebuginfo, "none", "disable debug information"), | 434 clEnumValN(nodebuginfo, "none", "disable debug information"), |
438 clEnumVal(quick, "enable quick debug information"), | 435 clEnumVal(quick, "enable quick debug information"), |
439 clEnumVal(detailed, "enable detailed debug information"), | 436 clEnumVal(detailed, "enable detailed debug information"))); |
440 clEnumValEnd)); | |
441 | 437 |
442 This definition defines an enumerated command line variable of type "``enum | 438 This definition defines an enumerated command line variable of type "``enum |
443 DebugLev``", which works exactly the same way as before. The difference here is | 439 DebugLev``", which works exactly the same way as before. The difference here is |
444 just the interface exposed to the user of your program and the help output by | 440 just the interface exposed to the user of your program and the help output by |
445 the "``-help``" option: | 441 the "``-help``" option: |
496 cl::list<Opts> OptimizationList(cl::desc("Available Optimizations:"), | 492 cl::list<Opts> OptimizationList(cl::desc("Available Optimizations:"), |
497 cl::values( | 493 cl::values( |
498 clEnumVal(dce , "Dead Code Elimination"), | 494 clEnumVal(dce , "Dead Code Elimination"), |
499 clEnumVal(constprop , "Constant Propagation"), | 495 clEnumVal(constprop , "Constant Propagation"), |
500 clEnumValN(inlining, "inline", "Procedure Integration"), | 496 clEnumValN(inlining, "inline", "Procedure Integration"), |
501 clEnumVal(strip , "Strip Symbols"), | 497 clEnumVal(strip , "Strip Symbols"))); |
502 clEnumValEnd)); | |
503 | 498 |
504 This defines a variable that is conceptually of the type | 499 This defines a variable that is conceptually of the type |
505 "``std::vector<enum Opts>``". Thus, you can access it with standard vector | 500 "``std::vector<enum Opts>``". Thus, you can access it with standard vector |
506 methods: | 501 methods: |
507 | 502 |
556 cl::bits<Opts> OptimizationBits(cl::desc("Available Optimizations:"), | 551 cl::bits<Opts> OptimizationBits(cl::desc("Available Optimizations:"), |
557 cl::values( | 552 cl::values( |
558 clEnumVal(dce , "Dead Code Elimination"), | 553 clEnumVal(dce , "Dead Code Elimination"), |
559 clEnumVal(constprop , "Constant Propagation"), | 554 clEnumVal(constprop , "Constant Propagation"), |
560 clEnumValN(inlining, "inline", "Procedure Integration"), | 555 clEnumValN(inlining, "inline", "Procedure Integration"), |
561 clEnumVal(strip , "Strip Symbols"), | 556 clEnumVal(strip , "Strip Symbols"))); |
562 clEnumValEnd)); | |
563 | 557 |
564 To test to see if ``constprop`` was specified, we can use the ``cl:bits::isSet`` | 558 To test to see if ``constprop`` was specified, we can use the ``cl:bits::isSet`` |
565 function: | 559 function: |
566 | 560 |
567 .. code-block:: c++ | 561 .. code-block:: c++ |
965 an alias for. | 959 an alias for. |
966 | 960 |
967 .. _cl::values: | 961 .. _cl::values: |
968 | 962 |
969 * The **cl::values** attribute specifies the string-to-value mapping to be used | 963 * The **cl::values** attribute specifies the string-to-value mapping to be used |
970 by the generic parser. It takes a **clEnumValEnd terminated** list of | 964 by the generic parser. It takes a list of (option, value, description) |
971 (option, value, description) triplets that specify the option name, the value | 965 triplets that specify the option name, the value mapped to, and the |
972 mapped to, and the description shown in the ``-help`` for the tool. Because | 966 description shown in the ``-help`` for the tool. Because the generic parser |
973 the generic parser is used most frequently with enum values, two macros are | 967 is used most frequently with enum values, two macros are often useful: |
974 often useful: | |
975 | 968 |
976 #. The **clEnumVal** macro is used as a nice simple way to specify a triplet | 969 #. The **clEnumVal** macro is used as a nice simple way to specify a triplet |
977 for an enum. This macro automatically makes the option name be the same as | 970 for an enum. This macro automatically makes the option name be the same as |
978 the enum name. The first option to the macro is the enum, the second is | 971 the enum name. The first option to the macro is the enum, the second is |
979 the description for the command line option. | 972 the description for the command line option. |
1294 | 1287 |
1295 using namespace llvm; | 1288 using namespace llvm; |
1296 int main(int argc, char **argv) { | 1289 int main(int argc, char **argv) { |
1297 cl::OptionCategory AnotherCategory("Some options"); | 1290 cl::OptionCategory AnotherCategory("Some options"); |
1298 | 1291 |
1299 StringMap<cl::Option*> Map; | 1292 StringMap<cl::Option*> &Map = cl::getRegisteredOptions(); |
1300 cl::getRegisteredOptions(Map); | |
1301 | 1293 |
1302 //Unhide useful option and put it in a different category | 1294 //Unhide useful option and put it in a different category |
1303 assert(Map.count("print-all-options") > 0); | 1295 assert(Map.count("print-all-options") > 0); |
1304 Map["print-all-options"]->setHiddenFlag(cl::NotHidden); | 1296 Map["print-all-options"]->setHiddenFlag(cl::NotHidden); |
1305 Map["print-all-options"]->setCategory(AnotherCategory); | 1297 Map["print-all-options"]->setCategory(AnotherCategory); |