</ol></li>
</ol>
-<div class="doc_text">
- <p><b>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a></b></p>
+<div class="doc_author">
+ <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a></p>
</div>
<!-- *********************************************************************** -->
to specify where to put the output. With the CommandLine library, this is
represented like this:</p>
-<p><tt>
-<a name="value_desc_example">
-<a href="#cl::opt">cl::opt</a><string> OutputFilename("<i>o</i>", <a href="#cl::desc">cl::desc</a>("<i>Specify output filename</i>"), <a href="#cl::value_desc">cl::value_desc</a>("<i>filename</i>"));</a>
-</tt></p>
+<a name="value_desc_example"></a>
+<pre>
+<a href="#cl::opt">cl::opt</a><string> OutputFilename("<i>o</i>", <a href="#cl::desc">cl::desc</a>("<i>Specify output filename</i>"), <a href="#cl::value_desc">cl::value_desc</a>("<i>filename</i>"));
+</pre>
<p>This declares a global variable "<tt>OutputFilename</tt>" that is used to
capture the result of the "<tt>o</tt>" argument (first parameter). We specify
clEnumVal(O1, "<i>Enable trivial optimizations</i>"),
clEnumVal(O2, "<i>Enable default optimizations</i>"),
clEnumVal(O3, "<i>Enable expensive optimizations</i>"),
- 0));
+ clEnumValEnd));
...
if (OptimizationLevel >= O2) doPartialRedundancyElimination(...);
<p>This declaration defines a variable "<tt>OptimizationLevel</tt>" of the
"<tt>OptLevel</tt>" enum type. This variable can be assigned any of the values
that are listed in the declaration (Note that the declaration list must be
-terminated with the "<tt>0</tt>" argument!). The CommandLine library enforces
+terminated with the "<tt>clEnumValEnd</tt>" argument!). The CommandLine
+library enforces
that the user can only specify one of the options, and it ensure that only valid
enum values can be specified. The "<tt>clEnumVal</tt>" macros ensure that the
command line arguments matched the enum values. With this option added, our
clEnumVal(O1 , "<i>Enable trivial optimizations</i>"),
clEnumVal(O2 , "<i>Enable default optimizations</i>"),
clEnumVal(O3 , "<i>Enable expensive optimizations</i>"),
- 0));
+ clEnumValEnd));
...
if (OptimizationLevel == Debug) outputDebugInfo(...);
clEnumValN(nodebuginfo, "none", "<i>disable debug information</i>"),
clEnumVal(quick, "<i>enable quick debug information</i>"),
clEnumVal(detailed, "<i>enable detailed debug information</i>"),
- 0));
+ clEnumValEnd));
</pre>
<p>This definition defines an enumerated command line variable of type "<tt>enum
clEnumVal(constprop , "<i>Constant Propagation</i>"),
clEnumValN(inlining, "<i>inline</i>", "<i>Procedure Integration</i>"),
clEnumVal(strip , "<i>Strip Symbols</i>"),
- 0));
+ clEnumValEnd));
</pre>
<p>This defines a variable that is conceptually of the type
<p>There are several limitations to when <tt>cl::ConsumeAfter</tt> options can
be specified. For example, only one <tt>cl::ConsumeAfter</tt> can be specified
per program, there must be at least one <a href="#positional">positional
-argument</a> specified, and the <tt>cl::ConsumeAfter</tt> option should be a <a
+argument</a> specified, there must not be any <a href="#cl::list">cl::list</a>
+positional arguments, and the <tt>cl::ConsumeAfter</tt> option should be a <a
href="#cl::list">cl::list</a> option.</p>
</div>
<!-- ======================================================================= -->
-<div class="subsection">
+<div class="doc_subsection">
<a name="storage">Internal vs External Storage</a>
</div>
<pre>
bool DebugFlag; <i>// the actual value</i>
static <a href="#cl::opt">cl::opt</a><bool, true> <i>// The parser</i>
-Debug("<i>debug</i>", <a href="#cl::desc">cl::desc</a>("<i>Enable debug output</i>")</a>, <a href="#cl::Hidden">cl::Hidden</a>,
+Debug("<i>debug</i>", <a href="#cl::desc">cl::desc</a>("<i>Enable debug output</i>"), <a href="#cl::Hidden">cl::Hidden</a>,
<a href="#cl::location">cl::location</a>(DebugFlag));
</pre>
<li><a name="cl::values">The <b><tt>cl::values</tt></b></a> attribute specifies
the string-to-value mapping to be used by the generic parser. It takes a
-<b>null terminated</b> list of (option, value, description) triplets that
+<b>clEnumValEnd terminated</b> list of (option, value, description) triplets
+that
specify the option name, the value mapped to, and the description shown in the
<tt>--help</tt> for the tool. Because the generic parser is used most
frequently with enum values, two macros are often useful:
strategy basically looks like this:</p>
<p><tt>parse(string OrigInput) {</tt>
+
<ol>
<li><tt>string input = OrigInput;</tt>
<li><tt>if (isOption(input)) return getOption(input).parse();</tt> <i>// Normal option</i>
input = OrigInput;<br>
while (!isOption(input) && !input.empty()) input.pop_back();<br>
}</tt>
-<li><tt>if (!OrigInput.empty()) error();</tt>
-</tt>
+<li><tt>if (!OrigInput.empty()) error();</tt></li>
</ol>
-<tt>}</tt></p>
+
+<p><tt>}</tt></p>
</div>
makes sense to be used in a case where the option is allowed to accept one or
more values (i.e. it is a <a href="#cl::list">cl::list</a> option).</li>
+<li><a name="cl::PositionalEatsArgs">The
+<b><tt>cl::PositionalEatsArgs</tt></b></a> modifier (which only applies to
+positional arguments, and only makes sense for lists) indicates that positional
+argument should consume any strings after it (including strings that start with
+a "-") up until another recognized positional argument. For example, if you
+have two "eating" positional arguments "<tt>pos1</tt>" and "<tt>pos2</tt>" the
+string "<tt>-pos1 -foo -bar baz -pos2 -bork</tt>" would cause the "<tt>-foo -bar
+-baz</tt>" strings to be applied to the "<tt>-pos1</tt>" option and the
+"<tt>-bork</tt>" string to be applied to the "<tt>-pos2</tt>" option.</li>
+
</ul>
-<p>So far, the only miscellaneous option modifier is the
-<tt>cl::CommaSeparated</tt> modifier.</p>
+<p>So far, these are the only two miscellaneous option modifiers.</p>
</div>
<!-- *********************************************************************** -->
<hr>
-<div class="doc_footer">
- <address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
- <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a>
- <br>
+<address>
+ <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
+ src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
+ <a href="http://validator.w3.org/check/referer"><img
+ src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
+
+ <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
+ <a href="http://llvm.cs.uiuc.edu">LLVM Compiler Infrastructure</a><br>
Last modified: $Date$
-</div>
+</address>
</body>
</html>