From 1d8f626f66392b1577ce0e16ecfa7068823d2e61 Mon Sep 17 00:00:00 2001 From: Jim Laskey Date: Thu, 25 Aug 2005 22:52:43 +0000 Subject: Documentation updated to include upcoming support for bit vector support (flags.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23063 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/CommandLine.html | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'docs/CommandLine.html') diff --git a/docs/CommandLine.html b/docs/CommandLine.html index 83db04d..9bd2b60 100644 --- a/docs/CommandLine.html +++ b/docs/CommandLine.html @@ -23,6 +23,7 @@ set of possibilities
  • Named alternatives
  • Parsing a list of options
  • +
  • Collecting options as a set of flags
  • Adding freeform text to help output
  • @@ -61,6 +62,7 @@ cl::ParseEnvironmentOptions function
  • The cl::opt class
  • The cl::list class
  • +
  • The cl::bits class
  • The cl::alias class
  • The cl::extrahelp class
  • @@ -693,6 +695,65 @@ checking we have to do.

    + Collecting options as a set of flags +
    + +
    + +

    Instead of collecting sets of options in a list, it is also possible to +gather information for enum values in a bit vector. The represention used by +the cl::bits class is an unsigned long +integer. An enum value is represented by a 0/1 in the enum's ordinal value bit +position. 1 indicating that the enum was specified, 0 otherwise. As each +specified value is parsed, the resulting enum's bit is set in the option's bit +vector:

    + +
    +  bits |= 1 << (unsigned)enum;
    +
    + +

    An option specified more than once is redundant as far as the result is +concerned. The argument position information is however updated.

    + +

    Reworking the above list example, we could replace +cl::list with cl::bits:

    + +
    +cl::bits<Opts> OptimizationBits(cl::desc("Available Optimizations:"),
    +  cl::values(
    +    clEnumVal(dce               , "Dead Code Elimination"),
    +    clEnumVal(constprop         , "Constant Propagation"),
    +   clEnumValN(inlining, "inline", "Procedure Integration"),
    +    clEnumVal(strip             , "Strip Symbols"),
    +  clEnumValEnd));
    +
    + +

    To test to see if constprop was specified, we can use the +cl:bits::isSet function:

    + +
    +  if (OptimizationBits.isSet(constprop)) {
    +    ...
    +  }
    +
    + +

    It's also possible to get the raw bit vector using the +cl::bits::getBits function:

    + +
    +  unsigned long bits = OptimizationBits.getBits();
    +
    + +

    Finally, if external storage is used, then the location specified must be of +type unsigned long. In all other ways a cl::bits option is morally equivalent to a cl::list option

    + +
    + + + +
    Adding freeform text to help output
    @@ -1508,6 +1569,31 @@ be used.

    + The cl::bits class +
    + +
    + +

    The cl::bits class is the class used to represent a list of command +line options in the form of a bit vector. It is also a templated class which +can take up to three arguments:

    + +
    +namespace cl {
    +  template <class DataType, class Storage = bool,
    +            class ParserClass = parser<DataType> >
    +  class bits;
    +}
    +
    + +

    This class works the exact same as the cl::lists class, except that the second argument +must be of type unsigned long if external storage is used.

    + +
    + + +
    The cl::alias class
    -- cgit v1.1