From 545a2beb44e10e02f590f50053129935db54b9bf Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sun, 16 Oct 2011 08:06:54 +0000 Subject: Update tutorial to reflect the current APIs. Also correct a small omission in LangImpl6.html (it needed to defined the 'binary :' operator). PR9052 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142123 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/tutorial/LangImpl4.html | 64 ++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 23 deletions(-) (limited to 'docs/tutorial/LangImpl4.html') diff --git a/docs/tutorial/LangImpl4.html b/docs/tutorial/LangImpl4.html index fe54fb5..77c9dbe 100644 --- a/docs/tutorial/LangImpl4.html +++ b/docs/tutorial/LangImpl4.html @@ -343,9 +343,10 @@ code that is statically linked into your application.

 ready> 4+5;
-define double @""() {
+Read top-level expression:
+define double @0() {
 entry:
-        ret double 9.000000e+00
+  ret double 9.000000e+00
 }
 
 Evaluated to 9.000000
@@ -363,16 +364,17 @@ ready> def testfunc(x y) x + y*2; 
 Read function definition:
 define double @testfunc(double %x, double %y) {
 entry:
-        %multmp = fmul double %y, 2.000000e+00
-        %addtmp = fadd double %multmp, %x
-        ret double %addtmp
+  %multmp = fmul double %y, 2.000000e+00
+  %addtmp = fadd double %multmp, %x
+  ret double %addtmp
 }
 
 ready> testfunc(4, 10);
-define double @""() {
+Read top-level expression:
+define double @1() {
 entry:
-        %calltmp = call double @testfunc(double 4.000000e+00, double 1.000000e+01)
-        ret double %calltmp
+  %calltmp = call double @testfunc(double 4.000000e+00, double 1.000000e+01)
+  ret double %calltmp
 }
 
 Evaluated to 24.000000
@@ -404,21 +406,34 @@ Read extern:
 declare double @cos(double)
 
 ready> sin(1.0);
+Read top-level expression:
+define double @2() {
+entry:
+  ret double 0x3FEAED548F090CEE
+}
+
 Evaluated to 0.841471
 
 ready> def foo(x) sin(x)*sin(x) + cos(x)*cos(x);
 Read function definition:
 define double @foo(double %x) {
 entry:
-        %calltmp = call double @sin(double %x)
-        %multmp = fmul double %calltmp, %calltmp
-        %calltmp2 = call double @cos(double %x)
-        %multmp4 = fmul double %calltmp2, %calltmp2
-        %addtmp = fadd double %multmp, %multmp4
-        ret double %addtmp
+  %calltmp = call double @sin(double %x)
+  %multmp = fmul double %calltmp, %calltmp
+  %calltmp2 = call double @cos(double %x)
+  %multmp4 = fmul double %calltmp2, %calltmp2
+  %addtmp = fadd double %multmp, %multmp4
+  ret double %addtmp
 }
 
 ready> foo(4.0);
+Read top-level expression:
+define double @3() {
+entry:
+  %calltmp = call double @foo(double 4.000000e+00)
+  ret double %calltmp
+}
+
 Evaluated to 1.000000
 
@@ -484,10 +499,10 @@ LLVM JIT and optimizer. 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
 
@@ -509,9 +524,9 @@ at runtime.

#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> @@ -905,13 +920,13 @@ Value *CallExprAST::Codegen() { if (ArgsV.back() == 0) return 0; } - return Builder.CreateCall(CalleeF, ArgsV.begin(), ArgsV.end(), "calltmp"); + return Builder.CreateCall(CalleeF, ArgsV, "calltmp"); } 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); @@ -1013,6 +1028,9 @@ static void HandleTopLevelExpression() { // Evaluate a top-level expression into an anonymous function. if (FunctionAST *F = ParseTopLevelExpr()) { if (Function *LF = F->Codegen()) { + fprintf(stderr, "Read top-level expression:"); + LF->dump(); + // JIT the function, returning a function pointer. void *FPtr = TheExecutionEngine->getPointerToFunction(LF); @@ -1076,7 +1094,7 @@ int main() { // Create the JIT. This takes ownership of the module. std::string ErrStr; -TheExecutionEngine = EngineBuilder(TheModule).setErrorStr(&ErrStr).create(); + TheExecutionEngine = EngineBuilder(TheModule).setErrorStr(&ErrStr).create(); if (!TheExecutionEngine) { fprintf(stderr, "Could not create ExecutionEngine: %s\n", ErrStr.c_str()); exit(1); -- cgit v1.1