Update the tutorial to match changes to examples/Kaleidoscope.

One change I'm not folding in is the removal of two unused variables that
caused warnings, because those were there for expository purposes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81721 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky
2009-09-13 21:38:54 +00:00
parent f845c74c62
commit 422094c38d
5 changed files with 77 additions and 29 deletions
+14 -5
View File
@@ -901,12 +901,15 @@ if/then/else and for expressions.. To build this example, use:
<pre>
#include "llvm/DerivedTypes.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/Interpreter.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
#include "llvm/PassManager.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetSelect.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Support/IRBuilder.h"
#include &lt;cstdio&gt;
@@ -1381,7 +1384,8 @@ Value *BinaryExprAST::Codegen() {
case '&lt;':
L = Builder.CreateFCmpULT(L, R, "cmptmp");
// Convert bool 0/1 to double 0.0 or 1.0
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp");
return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
"booltmp");
default: return ErrorV("invalid binary operator");
}
}
@@ -1448,7 +1452,8 @@ Value *IfExprAST::Codegen() {
// Emit merge block.
TheFunction-&gt;getBasicBlockList().push_back(MergeBB);
Builder.SetInsertPoint(MergeBB);
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), "iftmp");
PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
"iftmp");
PN-&gt;addIncoming(ThenV, ThenBB);
PN-&gt;addIncoming(ElseV, ElseBB);
@@ -1550,8 +1555,10 @@ Value *ForExprAST::Codegen() {
Function *PrototypeAST::Codegen() {
// Make the function type: double(double,double) etc.
std::vector&lt;const Type*&gt; Doubles(Args.size(), Type::getDoubleTy(getGlobalContext()));
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
std::vector&lt;const Type*&gt; Doubles(Args.size(),
Type::getDoubleTy(getGlobalContext()));
FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
Doubles, false);
Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
@@ -1656,7 +1663,7 @@ static void HandleTopLevelExpression() {
// Cast it to the right type (takes no arguments, returns a double) so we
// can call it as a native function.
double (*FP)() = (double (*)())FPtr;
double (*FP)() = (double (*)())(intptr_t)FPtr;
fprintf(stderr, "Evaluated to %f\n", FP());
}
} else {
@@ -1731,6 +1738,8 @@ int main() {
// Simplify the control flow graph (deleting unreachable blocks, etc).
OurFPM.add(createCFGSimplificationPass());
OurFPM.doInitialization();
// Set the global so the code gen can use this.
TheFPM = &amp;OurFPM;