summaryrefslogtreecommitdiffstats
path: root/llvm/docs/TableGenFundamentals.html
diff options
context:
space:
mode:
authorDavid Greene <greened@obbligato.org>2012-02-22 16:09:41 +0000
committerDavid Greene <greened@obbligato.org>2012-02-22 16:09:41 +0000
commitfb927af24f4966ba6c488d38180a6cb9487f00fc (patch)
tree0e79928c3a6e7c5e4b9eb9326c67b6e9ee63af9b /llvm/docs/TableGenFundamentals.html
parent8bde4c078b1bed60dadf0bd83bc3d2db44a199bb (diff)
downloadbcm5719-llvm-fb927af24f4966ba6c488d38180a6cb9487f00fc.tar.gz
bcm5719-llvm-fb927af24f4966ba6c488d38180a6cb9487f00fc.zip
Add Foreach Loop
Add some data structures to represent for loops. These will be referenced during object processing to do any needed iteration and instantiation. Add foreach keyword support to the lexer. Add a mode to indicate that we're parsing a foreach loop. This allows the value parser to early-out when processing the foreach value list. Add a routine to parse foreach iteration declarations. This is separate from ParseDeclaration because the type of the named value (the iterator) doesn't match the type of the initializer value (the value list). It also needs to add two values to the foreach record: the iterator and the value list. Add parsing support for foreach. Add the code to process foreach loops and create defs based on iterator values. Allow foreach loops to be matched at the top level. When parsing an IDValue check if it is a foreach loop iterator for one of the active loops. If so, return a VarInit for it. Add Emacs keyword support for foreach. Add VIM keyword support for foreach. Add tests to check foreach operation. Add TableGen documentation for foreach. Support foreach with multiple objects. Support non-braced foreach body with one object. Do not require types for the foreach declaration. Assume the iterator type from the iteration list element type. llvm-svn: 151164
Diffstat (limited to 'llvm/docs/TableGenFundamentals.html')
-rw-r--r--llvm/docs/TableGenFundamentals.html42
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/docs/TableGenFundamentals.html b/llvm/docs/TableGenFundamentals.html
index 6db1827b3be..45baf198454 100644
--- a/llvm/docs/TableGenFundamentals.html
+++ b/llvm/docs/TableGenFundamentals.html
@@ -37,6 +37,7 @@
<ol>
<li><a href="#include">File inclusion</a></li>
<li><a href="#globallet">'let' expressions</a></li>
+ <li><a href="#foreach">'foreach' blocks</a></li>
</ol></li>
</ol></li>
<li><a href="#backends">TableGen backends</a>
@@ -401,6 +402,14 @@ which case the user must specify it explicitly.</dd>
<dt><tt>list[4-7,17,2-3]</tt></dt>
<dd>A slice of the 'list' list, including elements 4,5,6,7,17,2, and 3 from
it. Elements may be included multiple times.</dd>
+<dt><tt>foreach &lt;var&gt; = &lt;list&gt; in { &lt;body&gt; }</tt></dt>
+<dt><tt>foreach &lt;var&gt; = &lt;list&gt; in &lt;def&gt;</tt></dt>
+ <dd> Replicate &lt;body&gt; or &lt;def&gt;, replacing instances of
+ &lt;var&gt; with each value in &lt;list&gt;. &lt;var&gt; is scoped at the
+ level of the <tt>foreach</tt> loop and must not conflict with any other object
+ introduced in &lt;body&gt; or &lt;def&gt;. Currently only <tt>def</tt>s are
+ expanded within &lt;body&gt;.
+ </dd>
<dt><tt>(DEF a, b)</tt></dt>
<dd>a dag value. The first element is required to be a record definition, the
remaining elements in the list may be arbitrary other values, including nested
@@ -880,6 +889,39 @@ several levels of multiclass instanciations. This also avoids the need of using
</pre>
</div>
+<!-- -------------------------------------------------------------------------->
+<h4>
+ <a name="foreach">Looping</a>
+</h4>
+
+<div>
+<p>TableGen supports the '<tt>foreach</tt>' block, which textually replicates
+the loop body, substituting iterator values for iterator references in the
+body. Example:</p>
+
+<div class="doc_code">
+<pre>
+<b>foreach</b> i = [0, 1, 2, 3] in {
+ <b>def</b> R#i : Register&lt;...&gt;;
+ <b>def</b> F#i : Register&lt;...&gt;;
+}
+</pre>
+</div>
+
+<p>This will create objects <tt>R0</tt>, <tt>R1</tt>, <tt>R2</tt> and
+<tt>R3</tt>. <tt>foreach</tt> blocks may be nested. If there is only
+one item in the body the braces may be elided:</p>
+
+<div class="doc_code">
+<pre>
+<b>foreach</b> i = [0, 1, 2, 3] in
+ <b>def</b> R#i : Register&lt;...&gt;;
+
+</pre>
+</div>
+
+</div>
+
</div>
</div>
OpenPOWER on IntegriCloud