diff options
Diffstat (limited to 'docs/tutorial/LangImpl4.html')
-rw-r--r-- | docs/tutorial/LangImpl4.html | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/docs/tutorial/LangImpl4.html b/docs/tutorial/LangImpl4.html index 5b8990e4..e910cc1 100644 --- a/docs/tutorial/LangImpl4.html +++ b/docs/tutorial/LangImpl4.html @@ -343,9 +343,10 @@ code that is statically linked into your application.</p> <div class="doc_code"> <pre> ready> <b>4+5;</b> -define double @""() { +Read top-level expression: +define double @0() { entry: - ret double 9.000000e+00 + ret double 9.000000e+00 } <em>Evaluated to 9.000000</em> @@ -363,16 +364,17 @@ ready> <b>def testfunc(x y) x + y*2; </b> 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> <b>testfunc(4, 10);</b> -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 } <em>Evaluated to 24.000000</em> @@ -404,21 +406,34 @@ Read extern: declare double @cos(double) ready> <b>sin(1.0);</b> +Read top-level expression: +define double @2() { +entry: + ret double 0x3FEAED548F090CEE +} + <em>Evaluated to 0.841471</em> ready> <b>def foo(x) sin(x)*sin(x) + cos(x)*cos(x);</b> 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> <b>foo(4.0);</b> +Read top-level expression: +define double @3() { +entry: + %calltmp = call double @foo(double 4.000000e+00) + ret double %calltmp +} + <em>Evaluated to 1.000000</em> </pre> </div> @@ -484,10 +499,10 @@ LLVM JIT and optimizer. To build this example, use: <div class="doc_code"> <pre> - # 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 </pre> </div> @@ -509,9 +524,9 @@ at runtime.</p> #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); @@ -1129,7 +1147,7 @@ TheExecutionEngine = EngineBuilder(TheModule).setErrorStr(&ErrStr).create(); <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - 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) $ </address> </body> </html> |