Bugfixes for smallvector when the element size is small and N is small.
[oota-llvm.git] / docs / Stacker.html
index 033ba30c0e5e134e93da84e5d9d7e33ec65c41a9..7656dc10c08c174a5b781fad3b6625d848705c48 100644 (file)
@@ -4,10 +4,6 @@
 <head>
   <title>Stacker: An Example Of Using LLVM</title>
   <link rel="stylesheet" href="llvm.css" type="text/css">
-  <style>
-    table, tr, td { border: 2px solid gray }
-    table { border-collapse: collapse; margin-bottom: 2em }
-  </style>
 </head>
 <body>
 
@@ -33,7 +29,7 @@
       <li><a href="#comments">Comments</a></li>
       <li><a href="#literals">Literals</a></li>
       <li><a href="#words">Words</a></li>
-      <li><a href="style">Standard Style</a></li>
+      <li><a href="#style">Standard Style</a></li>
       <li><a href="#builtins">Built-Ins</a></li>
     </ol></li>
   <li><a href="#example">Prime: A Complete Example</a></li>
@@ -51,8 +47,8 @@
     </ol></li>
 </ol>
 
-<div class="doc_text">
-<p><b>Written by <a href="mailto:rspencer@x10sys.com">Reid Spencer</a></b></p>
+<div class="doc_author">
+  <p>Written by <a href="mailto:rspencer@x10sys.com">Reid Spencer</a></p>
 </div>
 
 <!-- ======================================================================= -->
@@ -131,31 +127,28 @@ I noted that most of the important LLVM IR (Intermediate Representation) C++
 classes were derived from the Value class. The full power of that simple
 design only became fully understood once I started constructing executable
 expressions for Stacker.</p>
+
 <p>This really makes your programming go faster. Think about compiling code
 for the following C/C++ expression: <code>(a|b)*((x+1)/(y+1))</code>. Assuming
 the values are on the stack in the order a, b, x, y, this could be
 expressed in stacker as: <code>1 + SWAP 1 + / ROT2 OR *</code>.
-You could write a function using LLVM that computes this expression like this: </p>
-<pre><code>
+You could write a function using LLVM that computes this expression like 
+this: </p>
+
+<div class="doc_code"><pre>
 Value* 
 expression(BasicBlock* bb, Value* a, Value* b, Value* x, Value* y )
 {
-    Instruction* tail = bb->getTerminator();
-    ConstantSInt* one = ConstantSInt::get( Type::IntTy, 1);
-    BinaryOperator* or1 = 
-       BinaryOperator::create( Instruction::Or, a, b, "", tail );
-    BinaryOperator* add1 = 
-       BinaryOperator::create( Instruction::Add, x, one, "", tail );
-    BinaryOperator* add2 =
-       BinaryOperator::create( Instruction::Add, y, one, "", tail );
-    BinaryOperator* div1 = 
-       BinaryOperator::create( Instruction::Div, add1, add2, "", tail);
-    BinaryOperator* mult1 = 
-       BinaryOperator::create( Instruction::Mul, or1, div1, "", tail );
-
+    ConstantSInt* one = ConstantSInt::get(Type::IntTy, 1);
+    BinaryOperator* or1 = BinaryOperator::createOr(a, b, "", bb);
+    BinaryOperator* add1 = BinaryOperator::createAdd(x, one, "", bb);
+    BinaryOperator* add2 = BinaryOperator::createAdd(y, one, "", bb);
+    BinaryOperator* div1 = BinaryOperator::createDiv(add1, add2, "", bb);
+    BinaryOperator* mult1 = BinaryOperator::createMul(or1, div1, "", bb);
     return mult1;
 }
-</code></pre>
+</pre></div>
+
 <p>"Okay, big deal," you say?  It is a big deal. Here's why. Note that I didn't
 have to tell this function which kinds of Values are being passed in. They could be
 <code>Instruction</code>s, <code>Constant</code>s, <code>GlobalVariable</code>s, or
@@ -470,6 +463,11 @@ unit. Anything declared with <code>FORWARD</code> is an external symbol for
 linking.</p>
 </div>
 <!-- ======================================================================= -->
+<div class="doc_subsection"><a name="style"></a>Standard Style</div>
+<div class="doc_text">
+<p>TODO</p>
+</div>
+<!-- ======================================================================= -->
 <div class="doc_subsection"><a name="builtins"></a>Built In Words</div>
 <div class="doc_text">
 <p>The built-in words of the Stacker language are put in several groups 
@@ -513,16 +511,16 @@ using the following construction:</p>
 </ol>
 </div>
 <div class="doc_text" >
-    <table class="doc_table">
-<tr class="doc_table"><td colspan="4">Definition Of Operation Of Built In Words</td></tr>
-<tr class="doc_table"><td colspan="4"><b>LOGICAL OPERATIONS</b></td></tr>
-<tr class="doc_table">
+    <table>
+<tr><th colspan="4">Definition Of Operation Of Built In Words</th></tr>
+<tr><th colspan="4"><b>LOGICAL OPERATIONS</b></th></tr>
+<tr>
     <td>Word</td>
     <td>Name</td>
     <td>Operation</td>
     <td>Description</td>
 </tr>
-<tr class="doc_table">
+<tr>
     <td>&lt;</td>
     <td>LT</td>
     <td>w1 w2 -- b</td>
@@ -579,7 +577,7 @@ using the following construction:</p>
     <td> -- b</td>
     <td>The boolean value TRUE (-1) is pushed on to the stack.</td>
 </tr>
-<tr><td colspan="4"><b>BITWISE OPERATORS</b></td></tr>
+<tr><th colspan="4"><b>BITWISE OPERATORS</b></th></tr>
 <tr>
     <td>Word</td>
     <td>Name</td>
@@ -621,7 +619,7 @@ using the following construction:</p>
     are bitwise exclusive OR'd together and pushed back on the stack. 
     For example, The sequence 1 3 XOR yields 2.</td>
 </tr>
-<tr><td colspan="4"><b>ARITHMETIC OPERATORS</b></td></tr>
+<tr><th colspan="4"><b>ARITHMETIC OPERATORS</b></th></tr>
 <tr>
     <td>Word</td>
     <td>Name</td>
@@ -702,7 +700,7 @@ using the following construction:</p>
     <td>Two values are popped off the stack. The larger value is pushed back
        on to the stack.</td>
 </tr>
-<tr><td colspan="4"><b>STACK MANIPULATION OPERATORS</b></td></tr>
+<tr><th colspan="4"><b>STACK MANIPULATION OPERATORS</b></th></tr>
 <tr>
     <td>Word</td>
     <td>Name</td>
@@ -789,7 +787,7 @@ using the following construction:</p>
 </tr>
 <tr><td>RROT</td>
     <td>RROT</td>
-    <td>w1 w2 w3 -- w2 w3 w1</td>
+    <td>w1 w2 w3 -- w3 w1 w2</td>
     <td>Reverse rotation. Like ROT, but it rotates the other way around.
        Essentially, the third element on the stack is moved to the top
        of the stack.</td>
@@ -847,7 +845,7 @@ using the following construction:</p>
     how much to rotate. That is, ROLL with n=1 is the same as ROT and 
     ROLL with n=2 is the same as ROT2.</td>
 </tr>
-<tr><td colspan="4"><b>MEMORY OPERATORS</b></td></tr>
+<tr><th colspan="4"><b>MEMORY OPERATORS</b></th></tr>
 <tr>
     <td>Word</td>
     <td>Name</td>
@@ -900,7 +898,7 @@ using the following construction:</p>
        pushed back on the stack so this doesn't count as a "use ptr"
        in the FREE idiom.</td>
 </tr>
-<tr><td colspan="4"><b>CONTROL FLOW OPERATORS</b></td></tr>
+<tr><th colspan="4"><b>CONTROL FLOW OPERATORS</b></th></tr>
 <tr>
     <td>Word</td>
     <td>Name</td>
@@ -948,26 +946,30 @@ using the following construction:</p>
        executed. In either case, after the (words....) have executed, execution continues
         immediately following the ENDIF. </td>
 </tr>
-<tr><td>WHILE (words...) END</td>
-    <td>WHILE (words...) END</td>
+<tr><td>WHILE word END</td>
+    <td>WHILE word END</td>
     <td>b -- b </td>
-    <td>The boolean value on the top of the stack is examined. If it is non-zero then the 
-       "words..." between WHILE and END are executed. Execution then begins again at the WHILE where another
-       boolean is popped off the stack. To prevent this operation from eating up the entire
-       stack, you should push on to the stack (just before the END) a boolean value that indicates
-       whether to terminate. Note that since booleans and integers can be coerced you can
-       use the following "for loop" idiom:<br/>
-       <code>(push count) WHILE (words...) -- END</code><br/>
+    <td>The boolean value on the top of the stack is examined (not popped). If 
+      it is non-zero then the "word" between WHILE and END is executed. 
+      Execution then begins again at the WHILE where the boolean on the top of 
+      the stack is examined again. The stack is not modified by the WHILE...END 
+      loop, only examined. It is imperative that the "word" in the body of the
+      loop ensure that the top of the stack contains the next boolean to examine
+      when it completes.  Note that since booleans and integers can be coerced 
+      you can use the following "for loop" idiom:<br/>
+       <code>(push count) WHILE word -- END</code><br/>
        For example:<br/>
-       <code>10 WHILE DUP &gt;d -- END</code><br/>
-       This will print the numbers from 10 down to 1. 10 is pushed on the stack. Since that is
-       non-zero, the while loop is entered. The top of the stack (10) is duplicated and then
-       printed out with &gt;d. The top of the stack is decremented, yielding 9 and control is
-       transfered back to the WHILE keyword. The process starts all over again and repeats until
-       the top of stack is decremented to 0 at which the WHILE test fails and control is
-       transfered to the word after the END.</td>
-</tr>
-<tr><td colspan="4"><b>INPUT &amp; OUTPUT OPERATORS</b></td></tr>
+       <code>10 WHILE &gt;d -- END</code><br/>
+        This will print the numbers from 10 down to 1. 10 is pushed on the 
+        stack. Since that is non-zero, the while loop is entered. The top of 
+        the stack (10) is printed out with &gt;d. The top of the stack is 
+        decremented, yielding 9 and control is transfered back to the WHILE 
+        keyword. The process starts all over again and repeats until
+        the top of stack is decremented to 0 at which point the WHILE test 
+        fails and control is transfered to the word after the END.
+      </td>
+</tr>
+<tr><th colspan="4"><b>INPUT &amp; OUTPUT OPERATORS</b></th></tr>
 <tr>
     <td>Word</td>
     <td>Name</td>
@@ -1377,8 +1379,6 @@ interested, here are some things that could be implemented better:</p>
     <li>Write an LLVM pass to optimize the use of the global stack. The code
     emitted currently is somewhat wasteful. It gets cleaned up a lot by existing
     passes but more could be done.</li>
-    <li>Add -O -O1 -O2 and -O3 optimization switches to the compiler driver to
-    allow LLVM optimization without using "opt."</li>
     <li>Make the compiler driver use the LLVM linking facilities (with IPO)
     before depending on GCC to do the final link.</li>
     <li>Clean up parsing. It doesn't handle errors very well.</li>
@@ -1404,7 +1404,7 @@ interested, here are some things that could be implemented better:</p>
   src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
 
   <a href="mailto:rspencer@x10sys.com">Reid Spencer</a><br>
-  <a href="http://llvm.cs.uiuc.edu">LLVM Compiler Infrastructure</a><br>
+  <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
   Last modified: $Date$
 </address>