aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-07-01 16:58:40 +0000
committerOwen Anderson <resistor@mac.com>2009-07-01 16:58:40 +0000
commit8b477ed579794ba6d76915d56b3f448a7dd20120 (patch)
tree70d3be97f6ecf1ab7962e6cfafd113f2f7ce2579 /examples
parent4fb75e542539153acaf31d9221845a7d0feccbf6 (diff)
downloadexternal_llvm-8b477ed579794ba6d76915d56b3f448a7dd20120.zip
external_llvm-8b477ed579794ba6d76915d56b3f448a7dd20120.tar.gz
external_llvm-8b477ed579794ba6d76915d56b3f448a7dd20120.tar.bz2
Add a pointer to the owning LLVMContext to Module. This requires threading LLVMContext through a lot
of the bitcode reader and ASM parser APIs, as well as supporting it in all of the tools. Patches for Clang and LLVM-GCC to follow. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74614 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'examples')
-rw-r--r--examples/BrainF/BrainF.cpp9
-rw-r--r--examples/BrainF/BrainF.h5
-rw-r--r--examples/BrainF/BrainFDriver.cpp4
-rw-r--r--examples/Fibonacci/fibonacci.cpp5
-rw-r--r--examples/HowToUseJIT/HowToUseJIT.cpp5
-rw-r--r--examples/Kaleidoscope/toy.cpp4
-rw-r--r--examples/ModuleMaker/ModuleMaker.cpp5
-rw-r--r--examples/ParallelJIT/ParallelJIT.cpp4
8 files changed, 29 insertions, 12 deletions
diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp
index 32a14c4..0caff13 100644
--- a/examples/BrainF/BrainF.cpp
+++ b/examples/BrainF/BrainF.cpp
@@ -36,19 +36,20 @@ const char *BrainF::headreg = "head";
const char *BrainF::label = "brainf";
const char *BrainF::testreg = "test";
-Module *BrainF::parse(std::istream *in1, int mem, CompileFlags cf) {
+Module *BrainF::parse(std::istream *in1, int mem, CompileFlags cf,
+ LLVMContext* Context) {
in = in1;
memtotal = mem;
comflag = cf;
- header();
+ header(Context);
readloop(0, 0, 0);
delete builder;
return module;
}
-void BrainF::header() {
- module = new Module("BrainF");
+void BrainF::header(LLVMContext* C) {
+ module = new Module("BrainF", C);
//Function prototypes
diff --git a/examples/BrainF/BrainF.h b/examples/BrainF/BrainF.h
index 06c00ae..d0fb1b1 100644
--- a/examples/BrainF/BrainF.h
+++ b/examples/BrainF/BrainF.h
@@ -15,6 +15,7 @@
#ifndef BRAINF_H
#define BRAINF_H
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Support/IRBuilder.h"
@@ -38,7 +39,7 @@ class BrainF {
/// containing the resulting code.
/// On error, it calls abort.
/// The caller must delete the returned module.
- Module *parse(std::istream *in1, int mem, CompileFlags cf);
+ Module *parse(std::istream *in1, int mem, CompileFlags cf, LLVMContext* C);
protected:
/// The different symbols in the BrainF language
@@ -64,7 +65,7 @@ class BrainF {
static const char *testreg;
/// Put the brainf function preamble and other fixed pieces of code
- void header();
+ void header(LLVMContext* C);
/// The main loop for parsing. It calls itself recursively
/// to handle the depth of nesting of "[]".
diff --git a/examples/BrainF/BrainFDriver.cpp b/examples/BrainF/BrainFDriver.cpp
index 06e77d2..0868d73 100644
--- a/examples/BrainF/BrainFDriver.cpp
+++ b/examples/BrainF/BrainFDriver.cpp
@@ -86,6 +86,8 @@ void addMainFunction(Module *mod) {
int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv, " BrainF compiler\n");
+ LLVMContext Context;
+
if (InputFilename == "") {
std::cerr<<"Error: You must specify the filename of the program to "
"be compiled. Use --help to see the options.\n";
@@ -124,7 +126,7 @@ 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);
diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp
index 09f2203..58c0dcd 100644
--- a/examples/Fibonacci/fibonacci.cpp
+++ b/examples/Fibonacci/fibonacci.cpp
@@ -23,6 +23,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Constants.h"
@@ -90,8 +91,10 @@ static Function *CreateFibFunction(Module *M) {
int main(int argc, char **argv) {
int n = argc > 1 ? atol(argv[1]) : 24;
+ LLVMContext Context;
+
// Create some module to put our function into it.
- Module *M = new Module("test");
+ Module *M = new Module("test", &Context);
// We are about to create the "fib" function:
Function *FibF = CreateFibFunction(M);
diff --git a/examples/HowToUseJIT/HowToUseJIT.cpp b/examples/HowToUseJIT/HowToUseJIT.cpp
index a9f1000..f11c3e2 100644
--- a/examples/HowToUseJIT/HowToUseJIT.cpp
+++ b/examples/HowToUseJIT/HowToUseJIT.cpp
@@ -34,6 +34,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
@@ -50,9 +51,11 @@ using namespace llvm;
int main() {
InitializeNativeTarget();
+
+ LLVMContext Context;
// Create some module to put our function into it.
- Module *M = new Module("test");
+ Module *M = new Module("test", &Context);
// Create the add1 function entry and insert this entry into module M. The
// function will have a return type of "int" and take an argument of "int".
diff --git a/examples/Kaleidoscope/toy.cpp b/examples/Kaleidoscope/toy.cpp
index c75014a..9ca6035 100644
--- a/examples/Kaleidoscope/toy.cpp
+++ b/examples/Kaleidoscope/toy.cpp
@@ -1,5 +1,6 @@
#include "llvm/DerivedTypes.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
#include "llvm/PassManager.h"
@@ -1083,6 +1084,7 @@ double printd(double X) {
int main() {
InitializeNativeTarget();
+ LLVMContext Context;
// Install standard binary operators.
// 1 is lowest precedence.
@@ -1097,7 +1099,7 @@ int main() {
getNextToken();
// Make the module, which holds all the code.
- TheModule = new Module("my cool jit");
+ TheModule = new Module("my cool jit", &Context);
// Create the JIT.
TheExecutionEngine = ExecutionEngine::create(TheModule);
diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp
index e2584e7..322835e 100644
--- a/examples/ModuleMaker/ModuleMaker.cpp
+++ b/examples/ModuleMaker/ModuleMaker.cpp
@@ -13,6 +13,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Constants.h"
@@ -22,9 +23,11 @@
using namespace llvm;
int main() {
+ LLVMContext Context;
+
// Create the "module" or "program" or "translation unit" to hold the
// function
- Module *M = new Module("test");
+ Module *M = new Module("test", &Context);
// Create the main function: first create the type 'int ()'
FunctionType *FT = FunctionType::get(Type::Int32Ty, /*not vararg*/false);
diff --git a/examples/ParallelJIT/ParallelJIT.cpp b/examples/ParallelJIT/ParallelJIT.cpp
index a6d7dcf..858cd52 100644
--- a/examples/ParallelJIT/ParallelJIT.cpp
+++ b/examples/ParallelJIT/ParallelJIT.cpp
@@ -18,6 +18,7 @@
// same time). This test had assertion errors until I got the locking right.
#include <pthread.h>
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
@@ -232,9 +233,10 @@ void* callFunc( void* param )
int main() {
InitializeNativeTarget();
+ LLVMContext Context;
// Create some module to put our function into it.
- Module *M = new Module("test");
+ Module *M = new Module("test", &Context);
Function* add1F = createAdd1( M );
Function* fibF = CreateFibFunction( M );