From 7b3392326c40c3c20697816acae597ba7b3144eb Mon Sep 17 00:00:00 2001 From: dim Date: Thu, 20 Oct 2011 21:10:27 +0000 Subject: Vendor import of llvm release_30 branch r142614: http://llvm.org/svn/llvm-project/llvm/branches/release_30@142614 --- docs/tutorial/LangImpl6.html | 68 ++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 28 deletions(-) (limited to 'docs/tutorial/LangImpl6.html') diff --git a/docs/tutorial/LangImpl6.html b/docs/tutorial/LangImpl6.html index 31d7ff4..8876e83 100644 --- a/docs/tutorial/LangImpl6.html +++ b/docs/tutorial/LangImpl6.html @@ -293,8 +293,8 @@ Value *BinaryExprAST::Codegen() { Function *F = TheModule->getFunction(std::string("binary")+Op); assert(F && "binary operator not found!"); - Value *Ops[] = { L, R }; - return Builder.CreateCall(F, Ops, Ops+2, "binop"); + Value *Ops[2] = { L, R }; + return Builder.CreateCall(F, Ops, "binop"); } @@ -505,7 +505,9 @@ defined to print out the specified value and a newline):

 ready> extern printd(x);
-Read extern: declare double @printd(double)
+Read extern:
+declare double @printd(double)
+
 ready> def binary : 1 (x y) 0;  # Low-precedence operator that ignores operands.
 ..
 ready> printd(123) : printd(456) : printd(789);
@@ -555,6 +557,9 @@ def binary& 6 (LHS RHS)
 def binary = 9 (LHS RHS)
   !(LHS < RHS | LHS > RHS);
 
+# Define ':' for sequencing: as a low-precedence operator that ignores operands
+# and just returns the RHS.
+def binary : 1 (x y) y;
 
@@ -579,9 +584,10 @@ def printdensity(d) else putchard(42); # '*' ... -ready> printdensity(1): printdensity(2): printdensity(3) : - printdensity(4): printdensity(5): printdensity(9): putchard(10); -*++.. +ready> printdensity(1): printdensity(2): printdensity(3): + printdensity(4): printdensity(5): printdensity(9): + putchard(10); +**++. Evaluated to 0.000000 @@ -593,7 +599,7 @@ converge:

-# determine whether the specific location diverges.
+# Determine whether the specific location diverges.
 # Solve for z = z^2 + c in the complex plane.
 def mandleconverger(real imag iters creal cimag)
   if iters > 255 | (real*real + imag*imag > 4) then
@@ -603,25 +609,25 @@ def mandleconverger(real imag iters creal cimag)
                     2*real*imag + cimag,
                     iters+1, creal, cimag);
 
-# return the number of iterations required for the iteration to escape
+# Return the number of iterations required for the iteration to escape
 def mandleconverge(real imag)
   mandleconverger(real, imag, 0, real, imag);
 
-

This "z = z2 + c" function is a beautiful little creature that is the basis -for computation of the Mandelbrot Set. Our -mandelconverge function returns the number of iterations that it takes -for a complex orbit to escape, saturating to 255. This is not a very useful -function by itself, but if you plot its value over a two-dimensional plane, -you can see the Mandelbrot set. Given that we are limited to using putchard -here, our amazing graphical output is limited, but we can whip together +

This "z = z2 + c" function is a beautiful little +creature that is the basis for computation of +the Mandelbrot Set. +Our mandelconverge function returns the number of iterations that it +takes for a complex orbit to escape, saturating to 255. This is not a very +useful function by itself, but if you plot its value over a two-dimensional +plane, you can see the Mandelbrot set. Given that we are limited to using +putchard here, our amazing graphical output is limited, but we can whip together something using the density plotter above:

-# compute and plot the mandlebrot set with the specified 2 dimensional range
+# Compute and plot the mandlebrot set with the specified 2 dimensional range
 # info.
 def mandelhelp(xmin xmax xstep   ymin ymax ystep)
   for y = ymin, y < ymax, ystep in (
@@ -808,13 +814,19 @@ if/then/else and for expressions..  To build this example, use:
 
 
-   # Compile
-   g++ -g toy.cpp `llvm-config --cppflags --ldflags --libs core jit native` -O3 -o toy
-   # Run
-   ./toy
+# Compile
+clang++ -g toy.cpp `llvm-config --cppflags --ldflags --libs core jit native` -O3 -o toy
+# Run
+./toy
 
+

On some platforms, you will need to specify -rdynamic or -Wl,--export-dynamic +when linking. This ensures that symbols defined in the main executable are +exported to the dynamic linker and so are available for symbol resolution at +run time. This is not needed if you compile your support code into a shared +library, although doing that will cause problems on Windows.

+

Here is the code:

@@ -828,9 +840,9 @@ if/then/else and for expressions.. To build this example, use: #include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/Passes.h" #include "llvm/Target/TargetData.h" -#include "llvm/Target/TargetSelect.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Support/IRBuilder.h" +#include "llvm/Support/TargetSelect.h" #include <cstdio> #include <string> #include <map> @@ -1409,8 +1421,8 @@ Value *BinaryExprAST::Codegen() { Function *F = TheModule->getFunction(std::string("binary")+Op); assert(F && "binary operator not found!"); - Value *Ops[] = { L, R }; - return Builder.CreateCall(F, Ops, Ops+2, "binop"); + Value *Ops[2] = { L, R }; + return Builder.CreateCall(F, Ops, "binop"); } Value *CallExprAST::Codegen() { @@ -1429,7 +1441,7 @@ Value *CallExprAST::Codegen() { if (ArgsV.back() == 0) return 0; } - return Builder.CreateCall(CalleeF, ArgsV.begin(), ArgsV.end(), "calltmp"); + return Builder.CreateCall(CalleeF, ArgsV, "calltmp"); } Value *IfExprAST::Codegen() { @@ -1578,8 +1590,8 @@ Value *ForExprAST::Codegen() { Function *PrototypeAST::Codegen() { // Make the function type: double(double,double) etc. - std::vector<const Type*> Doubles(Args.size(), - Type::getDoubleTy(getGlobalContext())); + std::vector<Type*> Doubles(Args.size(), + Type::getDoubleTy(getGlobalContext())); FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false); @@ -1811,7 +1823,7 @@ int main() { Chris Lattner
The LLVM Compiler Infrastructure
- Last modified: $Date: 2011-04-23 02:30:22 +0200 (Sat, 23 Apr 2011) $ + Last modified: $Date: 2011-10-16 10:07:38 +0200 (Sun, 16 Oct 2011) $ -- cgit v1.1