Push LLVMContexts through the IntegerType APIs.
[oota-llvm.git] / examples / BrainF / BrainFDriver.cpp
index 3f3b6c339280d25dca3f7344f1b59d9e4ca16d7e..f4f1e79b822398959e522df1b884b28c64da9724 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Sterling Stein and is distributed under the
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===--------------------------------------------------------------------===//
 //
@@ -34,9 +34,9 @@
 #include "llvm/ExecutionEngine/JIT.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
+#include "llvm/Target/TargetSelect.h"
 #include <fstream>
 #include <iostream>
-
 using namespace llvm;
 
 //Command line options
@@ -58,9 +58,10 @@ JIT("jit", cl::desc("Run program Just-In-Time"));
 void addMainFunction(Module *mod) {
   //define i32 @main(i32 %argc, i8 **%argv)
   Function *main_func = cast<Function>(mod->
-    getOrInsertFunction("main", IntegerType::Int32Ty, IntegerType::Int32Ty,
+    getOrInsertFunction("main", IntegerType::getInt32Ty(mod->getContext()),
+                        IntegerType::getInt32Ty(mod->getContext()),
                         PointerType::getUnqual(PointerType::getUnqual(
-                          IntegerType::Int8Ty)), NULL));
+                          IntegerType::getInt8Ty(mod->getContext()))), NULL));
   {
     Function::arg_iterator args = main_func->arg_begin();
     Value *arg_0 = args++;
@@ -70,25 +71,28 @@ void addMainFunction(Module *mod) {
   }
 
   //main.0:
-  BasicBlock *bb = new BasicBlock("main.0", main_func);
+  BasicBlock *bb = BasicBlock::Create(mod->getContext(), "main.0", main_func);
 
   //call void @brainf()
   {
-    CallInst *brainf_call = new CallInst(mod->getFunction("brainf"),
-                                         "", bb);
+    CallInst *brainf_call = CallInst::Create(mod->getFunction("brainf"),
+                                             "", bb);
     brainf_call->setTailCall(false);
   }
 
   //ret i32 0
-  new ReturnInst(ConstantInt::get(APInt(32, 0)), bb);
+  ReturnInst::Create(mod->getContext(),
+                     ConstantInt::get(mod->getContext(), APInt(32, 0)), bb);
 }
 
 int main(int argc, char **argv) {
   cl::ParseCommandLineOptions(argc, argv, " BrainF compiler\n");
 
+  LLVMContext &Context = getGlobalContext();
+
   if (InputFilename == "") {
-    cerr<<"Error: You must specify the filename of the program to "
-          "be compiled.  Use --help to see the options.\n";
+    std::cerr<<"Error: You must specify the filename of the program to "
+    "be compiled.  Use --help to see the options.\n";
     abort();
   }
 
@@ -124,21 +128,22 @@ int main(int argc, char **argv) {
 
   //Read the BrainF program
   BrainF bf;
-  Module *mod = bf.parse(in, 65536, cf); //64 KiB
+  Module *mod = bf.parse(in, 65536, cf, Context); //64 KiB
   if (in != &std::cin) {delete in;}
   addMainFunction(mod);
 
   //Verify generated code
   if (verifyModule(*mod)) {
-    cerr<<"Error: module failed verification.  This shouldn't happen.\n";
+    std::cerr<<"Error: module failed verification.  This shouldn't happen.\n";
     abort();
   }
 
   //Write it out
   if (JIT) {
-    cout<<"------- Running JIT -------\n";
-    ExistingModuleProvider *mp = new ExistingModuleProvider(mod);
-    ExecutionEngine *ee = ExecutionEngine::create(mp, false);
+    InitializeNativeTarget();
+
+    std::cout << "------- Running JIT -------\n";
+    ExecutionEngine *ee = EngineBuilder(mod).create();
     std::vector<GenericValue> args;
     Function *brainf_func = mod->getFunction("brainf");
     GenericValue gv = ee->runFunction(brainf_func, args);