Thumb2 does not allow the use of "pc" register as part of the load / store address.
[oota-llvm.git] / examples / Kaleidoscope / toy.cpp
index 134742516d3d69965d3f1e5c37854331703ce877..1aa9965fa4a8e005309f4d45412f5cf323a46209 100644 (file)
@@ -1,5 +1,7 @@
 #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"
@@ -621,7 +623,7 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
 
 
 Value *NumberExprAST::Codegen() {
-  return ConstantFP::get(APFloat(Val));
+  return getGlobalContext().getConstantFP(APFloat(Val));
 }
 
 Value *VariableExprAST::Codegen() {
@@ -714,7 +716,7 @@ Value *IfExprAST::Codegen() {
   
   // Convert condition to a bool by comparing equal to 0.0.
   CondV = Builder.CreateFCmpONE(CondV, 
-                                ConstantFP::get(APFloat(0.0)),
+                                getGlobalContext().getConstantFP(APFloat(0.0)),
                                 "ifcond");
   
   Function *TheFunction = Builder.GetInsertBlock()->getParent();
@@ -819,7 +821,7 @@ Value *ForExprAST::Codegen() {
     if (StepVal == 0) return 0;
   } else {
     // If not specified, use 1.0.
-    StepVal = ConstantFP::get(APFloat(1.0));
+    StepVal = getGlobalContext().getConstantFP(APFloat(1.0));
   }
   
   // Compute the end condition.
@@ -834,7 +836,7 @@ Value *ForExprAST::Codegen() {
   
   // Convert condition to a bool by comparing equal to 0.0.
   EndCond = Builder.CreateFCmpONE(EndCond, 
-                                  ConstantFP::get(APFloat(0.0)),
+                                getGlobalContext().getConstantFP(APFloat(0.0)),
                                   "loopcond");
   
   // Create the "after loop" block and insert it.
@@ -854,7 +856,7 @@ Value *ForExprAST::Codegen() {
 
   
   // for expr always returns 0.0.
-  return TheFunction->getContext()->getNullValue(Type::DoubleTy);
+  return TheFunction->getContext().getNullValue(Type::DoubleTy);
 }
 
 Value *VarExprAST::Codegen() {
@@ -877,7 +879,7 @@ Value *VarExprAST::Codegen() {
       InitVal = Init->Codegen();
       if (InitVal == 0) return 0;
     } else { // If not specified, use 0.0.
-      InitVal = ConstantFP::get(APFloat(0.0));
+      InitVal = getGlobalContext().getConstantFP(APFloat(0.0));
     }
     
     AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
@@ -907,7 +909,8 @@ Value *VarExprAST::Codegen() {
 Function *PrototypeAST::Codegen() {
   // Make the function type:  double(double,double) etc.
   std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy);
-  FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
+  FunctionType *FT =
+    getGlobalContext().getFunctionType(Type::DoubleTy, Doubles, false);
   
   Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
   
@@ -1084,7 +1087,7 @@ double printd(double X) {
 
 int main() {
   InitializeNativeTarget();
-  LLVMContext Context;
+  LLVMContext &Context = getGlobalContext();
   
   // Install standard binary operators.
   // 1 is lowest precedence.
@@ -1102,7 +1105,7 @@ int main() {
   TheModule = new Module("my cool jit", Context);
   
   // Create the JIT.
-  TheExecutionEngine = ExecutionEngine::create(TheModule);
+  TheExecutionEngine = EngineBuilder(TheModule).create();
 
   {
     ExistingModuleProvider OurModuleProvider(TheModule);
@@ -1122,6 +1125,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 = &OurFPM;
 
@@ -1137,4 +1142,3 @@ int main() {
   
   return 0;
 }
-