Add reverseColor to raw_ostream.
[oota-llvm.git] / docs / TableGenFundamentals.html
index f5b7e4ab5770c18bae862e44e8cfb55497304c2c..b401c7a49f0967c4ac32d984e5cfc04db2d72ae0 100644 (file)
@@ -2,6 +2,7 @@
                       "http://www.w3.org/TR/html4/strict.dtd">
 <html>
 <head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <title>TableGen Fundamentals</title>
   <link rel="stylesheet" href="llvm.css" type="text/css">
 </head>
@@ -36,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>
@@ -207,6 +209,14 @@ file, to factor out the common features that instructions of its class share.  A
 key feature of TableGen is that it allows the end-user to define the
 abstractions they prefer to use when describing their information.</p>
 
+<p>Each def record has a special entry called "NAME."  This is the
+name of the def ("ADD32rr" above).  In the general case def names can
+be formed from various kinds of string processing expressions and NAME
+resolves to the final value obtained after resolving all of those
+expressions.  The user may refer to NAME anywhere she desires to use
+the ultimate name of the def.  NAME should not be defined anywhere
+else in user code to avoid conflict problems.</p>
+
 </div>
 
 <!-- ======================================================================= -->
@@ -392,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
@@ -399,6 +417,10 @@ which case the user must specify it explicitly.</dd>
 <dt><tt>!strconcat(a, b)</tt></dt>
   <dd>A string value that is the result of concatenating the 'a' and 'b'
   strings.</dd>
+<dt><tt>str1#str2</tt></dt>
+  <dd>"#" (paste) is a shorthand for !strconcat.  It may concatenate
+  things that are not quoted strings, in which case an implicit
+  !cast&lt;string&gt; is done on the operand of the paste.</dd>
 <dt><tt>!cast&lt;type&gt;(a)</tt></dt>
   <dd>A symbol of type <em>type</em> obtained by looking up the string 'a' in
 the symbol table.  If the type of 'a' does not match <em>type</em>, TableGen
@@ -769,65 +791,6 @@ before them.
 </pre>
 </div>
 
-<p>
-A special "multidef" may be used inside a multiclass to generate
-several defs given a list of values.
-</p>
-
-<div class="doc_code">
-<pre>
-<b>class</b> Base&lt;int i&gt; {
-  int value = i;
-}
-
-<b>multiclass</b> Multi&lt;list&lt;int&gt; values&gt; {
-  <b>def</b> ONE : Base&lt;values[0]&gt;;
-  <b>def</b> TWO : Base&lt;values[1]&gt;;
-
-  <b>multidef</b> COUNT&lt;values, int v, 2&gt; : Base&lt;v&gt;;
-}
-
-<b>defm</b> List : Multi&lt;[1, 2, 3, 4, 5, 6]&lt;;
-...
-
-<i>// Results</i>
-<b>def</b> ListCOUNT {
-  int v = ?;
-  int value = v;
-  list<int> Multi::values = [1, 2, 3, 4, 5, 6];
-}
-<b>def</b> ListONE {
-  int value = 1;
-}
-<b>def</b> ListTWO {
-  int value = 2;
-}
-<b>def</b> MD2.ListCOUNT {
-  int value = 3;
-}
-<b>def</b> MD3.ListCOUNT {
-  int value = 4;
-}
-<b>def</b> MD4.ListCOUNT {
-  int value = 5;
-}
-<b>def</b> MD5.ListCOUNT {
-  int value = 6;
-}
-</pre>
-</div>
-
-<p>
-A multidef takes three "arguments" in the &lt;&gt; notation after the multidef 
-name.  The first is a list of items to process.  The second is a declaration.  
-This declaration creates a temporary name used as an iterator.  It picks up the 
-value of each processed list item as TableGen generates defs from the multidef.  
-This temporary may be named and passed into the multidef body as shown in the 
-example above.  This provides a powerful way to generate defs with various 
-values from a single multidef.  The final "argument" is an integer value 
-indicating where in the list to begin processing.  In the above example we 
-chose to begin list processing with the third item (index 2).
-</p>
 </div>
 
 </div>
@@ -926,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>