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
#ifndef BRAINF_H
#define BRAINF_H
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Support/IRBuilder.h"
/// 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
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 "[]".
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";
//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);
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Constants.h"
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);
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
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".
#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"
int main() {
InitializeNativeTarget();
+ LLVMContext Context;
// Install standard binary operators.
// 1 is lowest precedence.
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);
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Constants.h"
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);
// 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"
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 );
/* Builds a module from the bitcode in the specified memory buffer, returning a
reference to the module via the OutModule parameter. Returns 0 on success.
Optionally returns a human-readable error message via OutMessage. */
-int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
+int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, LLVMContextRef ContextRef,
LLVMModuleRef *OutModule, char **OutMessage);
/* Reads a module from the specified path, returning via the OutMP parameter
a module provider which performs lazy deserialization. Returns 0 on success.
Optionally returns a human-readable error message via OutMessage. */
int LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf,
+ LLVMContextRef ContextRef,
LLVMModuleProviderRef *OutMP,
char **OutMessage);
/* Opaque types. */
+/**
+ * The top-level container for all LLVM global data. See the LLVMContext class.
+ */
+typedef struct LLVMCtxt *LLVMContextRef;
+
/**
* The top-level container for all other LLVM Intermediate Representation (IR)
* objects. See the llvm::Module class.
/*===-- Modules -----------------------------------------------------------===*/
+/* Create and destroy contexts. */
+LLVMContextRef LLVMContextCreate();
+void LLVMContextDispose(LLVMContextRef C);
+
/* Create and destroy modules. */
/** See llvm::Module::Module. */
LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
+ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
#undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
class Module;
class ParseError;
class raw_ostream;
+class LLVMContext;
/// This function is the main interface to the LLVM Assembly Parser. It parses
/// an ASCII file that (presumably) contains LLVM Assembly code. It returns a
/// @brief Parse LLVM Assembly from a file
Module *ParseAssemblyFile(
const std::string &Filename, ///< The name of the file to parse
- ParseError &Error ///< If not null, an object to return errors in.
+ ParseError &Error, ///< If not null, an object to return errors in.
+ LLVMContext* Context ///< Context in which to allocate globals info.
);
/// The function is a secondary interface to the LLVM Assembly Parser. It parses
Module *ParseAssemblyString(
const char *AsmString, ///< The string containing assembly
Module *M, ///< A module to add the assembly too.
- ParseError &Error ///< If not null, an object to return errors in.
+ ParseError &Error, ///< If not null, an object to return errors in.
+ LLVMContext* Context
);
//===------------------------------------------------------------------------===
class Module; // From VMCore
class Archive; // Declared below
class ArchiveMemberHeader; // Internal implementation class
+class LLVMContext; // Global data
/// This class is the main class manipulated by users of the Archive class. It
/// holds information about one member of the Archive. It is also the element
/// @returns An Archive* that represents the new archive file.
/// @brief Create an empty Archive.
static Archive* CreateEmpty(
- const sys::Path& Filename ///< Name of the archive to (eventually) create.
+ const sys::Path& Filename,///< Name of the archive to (eventually) create.
+ LLVMContext* C ///< Context to use for global information
);
/// Open an existing archive and load its contents in preparation for
/// @brief Open and load an archive file
static Archive* OpenAndLoad(
const sys::Path& filePath, ///< The file path to open and load
+ LLVMContext* C, ///< The context to use for global information
std::string* ErrorMessage ///< An optional error string
);
/// @brief Open an existing archive and load its symbols.
static Archive* OpenAndLoadSymbols(
const sys::Path& Filename, ///< Name of the archive file to open
+ LLVMContext* C, ///< The context to use for global info
std::string* ErrorMessage=0 ///< An optional error string
);
protected:
/// @brief Construct an Archive for \p filename and optionally map it
/// into memory.
- explicit Archive(const sys::Path& filename);
+ explicit Archive(const sys::Path& filename, LLVMContext* C);
/// @param data The symbol table data to be parsed
/// @param len The length of the symbol table data
unsigned firstFileOffset; ///< Offset to first normal file.
ModuleMap modules; ///< The modules loaded via symbol lookup.
ArchiveMember* foreignST; ///< This holds the foreign symbol table.
+ LLVMContext* Context; ///< This holds global data.
/// @}
/// @name Hidden
/// @{
class MemoryBuffer;
class ModulePass;
class BitstreamWriter;
+ class LLVMContext;
class raw_ostream;
/// getBitcodeModuleProvider - Read the header of the specified bitcode buffer
/// error, this returns null, *does not* take ownership of Buffer, and fills
/// in *ErrMsg with an error description if ErrMsg is non-null.
ModuleProvider *getBitcodeModuleProvider(MemoryBuffer *Buffer,
+ LLVMContext* Context,
std::string *ErrMsg = 0);
/// ParseBitcodeFile - Read the specified bitcode file, returning the module.
/// If an error occurs, this returns null and fills in *ErrMsg if it is
/// non-null. This method *never* takes ownership of Buffer.
- Module *ParseBitcodeFile(MemoryBuffer *Buffer, std::string *ErrMsg = 0);
+ Module *ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext* Context,
+ std::string *ErrMsg = 0);
/// WriteBitcodeToFile - Write the specified module to the specified output
/// stream.
namespace llvm {
class Module;
class InferiorProcess;
+ class LLVMContext;
/// Debugger class - This class implements the LLVM source-level debugger.
/// This allows clients to handle the user IO processing without having to
/// the PATH for the specified program, loading it when found. If the
/// specified program cannot be found, an exception is thrown to indicate
/// the error.
- void loadProgram(const std::string &Path);
+ void loadProgram(const std::string &Path, LLVMContext* Context);
/// unloadProgram - If a program is running, kill it, then unload all traces
/// of the current program. If no program is loaded, this method silently
// to know that getenv() never returns -1, this will do the job.
if (std::getenv("bar") != (char*) -1)
return;
- llvm::Module* M = new llvm::Module("");
+ llvm::Module* M = new llvm::Module("", 0);
(void)new llvm::UnreachableInst();
(void) llvm::createVerifierPass();
(void) new llvm::Mangler(*M,"");
namespace llvm {
class Module;
+class LLVMContext;
/// This class provides the core functionality of linking in LLVM. It retains a
/// Module object which is the composite of the modules and libraries linked
Linker(
const std::string& progname, ///< name of tool running linker
const std::string& modulename, ///< name of linker's end-result module
+ LLVMContext* C, ///< Context for global info
unsigned Flags = 0 ///< ControlFlags (one or more |'d together)
);
/// @name Data
/// @{
private:
+ LLVMContext* Context; ///< The context for global information
Module* Composite; ///< The composite module linked together
std::vector<sys::Path> LibPaths; ///< The library search paths
unsigned Flags; ///< Flags to control optional behavior.
class GlobalValueRefMap; // Used by ConstantVals.cpp
class FunctionType;
+class LLVMContext;
template<> struct ilist_traits<Function>
: public SymbolTableListTraits<Function, Module> {
/// @name Member Variables
/// @{
private:
+ LLVMContext* Context; ///< The LLVMContext from which types and
+ ///< constants are allocated.
GlobalListType GlobalList; ///< The Global Variables in the module
FunctionListType FunctionList; ///< The Functions in the module
AliasListType AliasList; ///< The Aliases in the module
public:
/// The Module constructor. Note that there is no default constructor. You
/// must provide a name for the module upon construction.
- explicit Module(const std::string &ModuleID);
+ explicit Module(const std::string &ModuleID, LLVMContext* C);
/// The module destructor. This will dropAllReferences.
~Module();
/// @returns PointerSize - an enumeration for the size of the target's pointer
PointerSize getPointerSize() const;
+ /// Get the global data context.
+ /// @returns LLVMContext - a container for LLVM's global information
+ LLVMContext* getContext() const { return Context; }
+
/// Get any module-scope inline assembly blocks.
/// @returns a string containing the module-scope inline assembly blocks.
const std::string &getModuleInlineAsm() const { return GlobalScopeAsm; }
class CallGraph;
class TargetData;
class LoopInfo;
+class LLVMContext;
template<class N> class LoopBase;
typedef LoopBase<BasicBlock> Loop;
// Archive constructor - this is the only constructor that gets used for the
// Archive class. Everything else (default,copy) is deprecated. This just
// initializes and maps the file into memory, if requested.
-Archive::Archive(const sys::Path& filename)
+Archive::Archive(const sys::Path& filename, LLVMContext* C)
: archPath(filename), members(), mapfile(0), base(0), symTab(), strtab(),
- symTabSize(0), firstFileOffset(0), modules(), foreignST(0) {
+ symTabSize(0), firstFileOffset(0), modules(), foreignST(0), Context(C) {
}
bool
// Get just the externally visible defined symbols from the bitcode
bool llvm::GetBitcodeSymbols(const sys::Path& fName,
+ LLVMContext* Context,
std::vector<std::string>& symbols,
std::string* ErrMsg) {
std::auto_ptr<MemoryBuffer> Buffer(
return true;
}
- ModuleProvider *MP = getBitcodeModuleProvider(Buffer.get(), ErrMsg);
+ ModuleProvider *MP = getBitcodeModuleProvider(Buffer.get(), Context, ErrMsg);
if (!MP)
return true;
ModuleProvider*
llvm::GetBitcodeSymbols(const unsigned char *BufPtr, unsigned Length,
const std::string& ModuleID,
+ LLVMContext* Context,
std::vector<std::string>& symbols,
std::string* ErrMsg) {
// Get the module provider
MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(Length, ModuleID.c_str());
memcpy((char*)Buffer->getBufferStart(), BufPtr, Length);
- ModuleProvider *MP = getBitcodeModuleProvider(Buffer, ErrMsg);
+ ModuleProvider *MP = getBitcodeModuleProvider(Buffer, Context, ErrMsg);
if (!MP)
return 0;
namespace llvm {
+ class LLVMContext;
+
/// The ArchiveMemberHeader structure is used internally for bitcode
/// archives.
/// The header precedes each file member in the archive. This structure is
// Get just the externally visible defined symbols from the bitcode
bool GetBitcodeSymbols(const sys::Path& fName,
+ LLVMContext* Context,
std::vector<std::string>& symbols,
std::string* ErrMsg);
ModuleProvider* GetBitcodeSymbols(const unsigned char*Buffer,unsigned Length,
const std::string& ModuleID,
+ LLVMContext* Context,
std::vector<std::string>& symbols,
std::string* ErrMsg);
}
// Open and completely load the archive file.
Archive*
-Archive::OpenAndLoad(const sys::Path& file, std::string* ErrorMessage)
-{
- std::auto_ptr<Archive> result ( new Archive(file));
+Archive::OpenAndLoad(const sys::Path& file, LLVMContext* C,
+ std::string* ErrorMessage) {
+ std::auto_ptr<Archive> result ( new Archive(file, C));
if (result->mapToMemory(ErrorMessage))
return 0;
if (!result->loadArchive(ErrorMessage))
// Get all the bitcode modules from the archive
bool
-Archive::getAllModules(std::vector<Module*>& Modules, std::string* ErrMessage) {
+Archive::getAllModules(std::vector<Module*>& Modules,
+ std::string* ErrMessage) {
for (iterator I=begin(), E=end(); I != E; ++I) {
if (I->isBitcode()) {
MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize());
- Module *M = ParseBitcodeFile(Buffer, ErrMessage);
+ Module *M = ParseBitcodeFile(Buffer, Context, ErrMessage);
delete Buffer;
if (!M)
return true;
}
// Open the archive and load just the symbol tables
-Archive*
-Archive::OpenAndLoadSymbols(const sys::Path& file, std::string* ErrorMessage) {
- std::auto_ptr<Archive> result ( new Archive(file) );
+Archive* Archive::OpenAndLoadSymbols(const sys::Path& file, LLVMContext* C,
+ std::string* ErrorMessage) {
+ std::auto_ptr<Archive> result ( new Archive(file, C) );
if (result->mapToMemory(ErrorMessage))
return 0;
if (!result->loadSymbolTable(ErrorMessage))
FullMemberName.c_str());
memcpy((char*)Buffer->getBufferStart(), mbr->getData(), mbr->getSize());
- ModuleProvider *mp = getBitcodeModuleProvider(Buffer, ErrMsg);
+ ModuleProvider *mp = getBitcodeModuleProvider(Buffer, Context, ErrMsg);
if (!mp)
return 0;
mbr->getPath().toString() + ")";
ModuleProvider* MP =
GetBitcodeSymbols((const unsigned char*)At, mbr->getSize(),
- FullMemberName, symbols, error);
+ FullMemberName, Context, symbols, error);
if (MP) {
// Insert the module's symbols into the symbol table
MemoryBuffer *Buffer =
MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize());
- Module *M = ParseBitcodeFile(Buffer);
+ Module *M = ParseBitcodeFile(Buffer, Context);
delete Buffer;
if (!M)
return false; // Couldn't parse bitcode, not a bitcode archive.
}
// Create an empty archive.
-Archive*
-Archive::CreateEmpty(const sys::Path& FilePath ) {
- Archive* result = new Archive(FilePath);
+Archive* Archive::CreateEmpty(const sys::Path& FilePath, LLVMContext* C) {
+ Archive* result = new Archive(FilePath, C);
return result;
}
+ ")";
ModuleProvider* MP =
GetBitcodeSymbols((const unsigned char*)data,fSize,
- FullMemberName, symbols, ErrMsg);
+ FullMemberName, Context, symbols, ErrMsg);
// If the bitcode parsed successfully
if ( MP ) {
#include <cstring>
using namespace llvm;
-Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err) {
+Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err,
+ LLVMContext* Context) {
Err.setFilename(Filename);
std::string ErrorStr;
return 0;
}
- OwningPtr<Module> M(new Module(Filename));
+ OwningPtr<Module> M(new Module(Filename, Context));
if (LLParser(F.get(), Err, M.get()).Run())
return 0;
return M.take();
}
Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
- ParseError &Err) {
+ ParseError &Err, LLVMContext* Context) {
Err.setFilename("<string>");
OwningPtr<MemoryBuffer>
return LLParser(F.get(), Err, M).Run() ? 0 : M;
// Otherwise create a new module.
- OwningPtr<Module> M2(new Module("<string>"));
+ OwningPtr<Module> M2(new Module("<string>", Context));
if (LLParser(F.get(), Err, M2.get()).Run())
return 0;
return M2.take();
/* Builds a module from the bitcode in the specified memory buffer, returning a
reference to the module via the OutModule parameter. Returns 0 on success.
Optionally returns a human-readable error message via OutMessage. */
-int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
+int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, LLVMContextRef ContextRef,
LLVMModuleRef *OutModule, char **OutMessage) {
std::string Message;
- *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), &Message));
+ *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), unwrap(ContextRef),
+ &Message));
if (!*OutModule) {
if (OutMessage)
*OutMessage = strdup(Message.c_str());
a module provider which performs lazy deserialization. Returns 0 on success.
Optionally returns a human-readable error message via OutMessage. */
int LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf,
+ LLVMContextRef ContextRef,
LLVMModuleProviderRef *OutMP,
char **OutMessage) {
std::string Message;
- *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), &Message));
+ *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), unwrap(ContextRef),
+ &Message));
if (!*OutMP) {
if (OutMessage)
*OutMessage = strdup(Message.c_str());
return Error("Malformed block record");
// Otherwise, create the module.
- TheModule = new Module(ModuleID);
+ TheModule = new Module(ModuleID, Context);
SmallVector<uint64_t, 64> Record;
std::vector<std::string> SectionTable;
/// getBitcodeModuleProvider - lazy function-at-a-time loading from a file.
///
ModuleProvider *llvm::getBitcodeModuleProvider(MemoryBuffer *Buffer,
+ LLVMContext* Context,
std::string *ErrMsg) {
- BitcodeReader *R = new BitcodeReader(Buffer);
+ BitcodeReader *R = new BitcodeReader(Buffer, Context);
if (R->ParseBitcode()) {
if (ErrMsg)
*ErrMsg = R->getErrorString();
/// ParseBitcodeFile - Read the specified bitcode file, returning the module.
/// If an error occurs, return null and fill in *ErrMsg if non-null.
-Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, std::string *ErrMsg){
+Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext* Context,
+ std::string *ErrMsg){
BitcodeReader *R;
- R = static_cast<BitcodeReader*>(getBitcodeModuleProvider(Buffer, ErrMsg));
+ R = static_cast<BitcodeReader*>(getBitcodeModuleProvider(Buffer, Context,
+ ErrMsg));
if (!R) return 0;
// Read in the entire module.
namespace llvm {
class MemoryBuffer;
+ class LLVMContext;
//===----------------------------------------------------------------------===//
// BitcodeReaderValueList Class
};
class BitcodeReader : public ModuleProvider {
+ LLVMContext* Context;
MemoryBuffer *Buffer;
BitstreamReader StreamFile;
BitstreamCursor Stream;
/// stream) and what linkage the original function had.
DenseMap<Function*, std::pair<uint64_t, unsigned> > DeferredFunctionInfo;
public:
- explicit BitcodeReader(MemoryBuffer *buffer)
- : Buffer(buffer), ErrorString(0) {
+ explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext* C)
+ : Context(C), Buffer(buffer), ErrorString(0) {
HasReversedFunctionsWithBodies = false;
}
~BitcodeReader() {
}
static Module *
-getMaterializedModuleProvider(const std::string &Filename) {
+getMaterializedModuleProvider(const std::string &Filename, LLVMContext* C) {
std::auto_ptr<MemoryBuffer> Buffer;
Buffer.reset(MemoryBuffer::getFileOrSTDIN(Filename.c_str()));
if (Buffer.get())
- return ParseBitcodeFile(Buffer.get());
+ return ParseBitcodeFile(Buffer.get(), C);
return 0;
}
/// the PATH for the specified program, loading it when found. If the
/// specified program cannot be found, an exception is thrown to indicate the
/// error.
-void Debugger::loadProgram(const std::string &Filename) {
- if ((Program = getMaterializedModuleProvider(Filename)) ||
- (Program = getMaterializedModuleProvider(Filename+".bc")))
+void Debugger::loadProgram(const std::string &Filename, LLVMContext* C) {
+ if ((Program = getMaterializedModuleProvider(Filename, C)) ||
+ (Program = getMaterializedModuleProvider(Filename+".bc", C)))
return; // Successfully loaded the program.
// Search the program path for the file...
std::string Directory = getToken(Path, ":");
while (!Directory.empty()) {
- if ((Program = getMaterializedModuleProvider(Directory +"/"+ Filename)) ||
- (Program = getMaterializedModuleProvider(Directory +"/"+ Filename
- + ".bc")))
+ if ((Program = getMaterializedModuleProvider(Directory +"/"+ Filename, C))
+ || (Program = getMaterializedModuleProvider(Directory +"/"+ Filename
+ + ".bc", C)))
return; // Successfully loaded the program.
Directory = getToken(Path, ":");
std::string ErrMsg;
std::auto_ptr<Archive> AutoArch (
- Archive::OpenAndLoadSymbols(Filename,&ErrMsg));
+ Archive::OpenAndLoadSymbols(Filename, Context, &ErrMsg));
Archive* arch = AutoArch.get();
if (File.toString() == "-") {
std::auto_ptr<Module> M;
if (MemoryBuffer *Buffer = MemoryBuffer::getSTDIN()) {
- M.reset(ParseBitcodeFile(Buffer, &Error));
+ M.reset(ParseBitcodeFile(Buffer, Context, &Error));
delete Buffer;
if (M.get())
if (!LinkInModule(M.get(), &Error))
using namespace llvm;
Linker::Linker(const std::string& progname, const std::string& modname,
- unsigned flags)
- : Composite(0)
- , LibPaths()
- , Flags(flags)
- , Error()
- , ProgramName(progname)
-{
- Composite = new Module(modname);
-}
-
-Linker::Linker(const std::string& progname, Module* aModule, unsigned flags)
- : Composite(aModule)
- , LibPaths()
- , Flags(flags)
- , Error()
- , ProgramName(progname)
-{
-}
+ LLVMContext* C, unsigned flags):
+ Context(C),
+ Composite(new Module(modname, C)),
+ LibPaths(),
+ Flags(flags),
+ Error(),
+ ProgramName(progname) { }
+
+Linker::Linker(const std::string& progname, Module* aModule, unsigned flags) :
+ Context(aModule->getContext()),
+ Composite(aModule),
+ LibPaths(),
+ Flags(flags),
+ Error(),
+ ProgramName(progname) { }
Linker::~Linker() {
delete Composite;
const std::string &FNS = FN.toString();
std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(FNS.c_str()));
if (Buffer.get())
- Result = ParseBitcodeFile(Buffer.get(), &ParseErrorMessage);
+ Result = ParseBitcodeFile(Buffer.get(), Context, &ParseErrorMessage);
else
ParseErrorMessage = "Error reading file '" + FNS + "'";
Module *llvm::CloneModule(const Module *M,
DenseMap<const Value*, Value*> &ValueMap) {
// First off, we need to create the new module...
- Module *New = new Module(M->getModuleIdentifier());
+ Module *New = new Module(M->getModuleIdentifier(), M->getContext());
New->setDataLayout(M->getDataLayout());
New->setTargetTriple(M->getTargetTriple());
New->setModuleInlineAsm(M->getModuleInlineAsm());
#include "llvm/DerivedTypes.h"
#include "llvm/GlobalVariable.h"
#include "llvm/GlobalAlias.h"
+#include "llvm/LLVMContext.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/ModuleProvider.h"
#include "llvm/InlineAsm.h"
}
+/*===-- Operations on contexts --------------------------------------------===*/
+
+LLVMContextRef LLVMContextCreate() {
+ return wrap(new LLVMContext());
+}
+
+void LLVMContextDispose(LLVMContextRef C) {
+ delete unwrap(C);
+}
+
+
/*===-- Operations on modules ---------------------------------------------===*/
-LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) {
- return wrap(new Module(ModuleID));
+LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID, LLVMContextRef C) {
+ return wrap(new Module(ModuleID, unwrap(C)));
}
void LLVMDisposeModule(LLVMModuleRef M) {
#include "llvm/InstrTypes.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/LeakDetector.h"
// Primitive Module methods.
//
-Module::Module(const std::string &MID)
- : ModuleID(MID), DataLayout("") {
+Module::Module(const std::string &MID, LLVMContext* C)
+ : Context(C), ModuleID(MID), DataLayout("") {
ValSymTab = new ValueSymbolTable();
TypeSymTab = new TypeSymbolTable();
}
}
BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs,
- unsigned timeout, unsigned memlimit)
- : ToolName(toolname), ReferenceOutputFile(OutputFile),
+ unsigned timeout, unsigned memlimit, LLVMContext* ctxt)
+ : Context(ctxt), ToolName(toolname), ReferenceOutputFile(OutputFile),
Program(0), Interpreter(0), SafeInterpreter(0), gcc(0),
- run_as_child(as_child),
- run_find_bugs(find_bugs), Timeout(timeout), MemoryLimit(memlimit) {}
+ run_as_child(as_child), run_find_bugs(find_bugs), Timeout(timeout),
+ MemoryLimit(memlimit) {}
/// ParseInputFile - Given a bitcode or assembly input filename, parse and
/// return it, or return null if not possible.
///
-Module *llvm::ParseInputFile(const std::string &Filename) {
+Module *llvm::ParseInputFile(const std::string &Filename, LLVMContext* Ctxt) {
std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(Filename));
Module *Result = 0;
if (Buffer.get())
- Result = ParseBitcodeFile(Buffer.get());
+ Result = ParseBitcodeFile(Buffer.get(), Ctxt);
ParseError Err;
- if (!Result && !(Result = ParseAssemblyFile(Filename, Err))) {
+ if (!Result && !(Result = ParseAssemblyFile(Filename, Err, Ctxt))) {
Err.PrintError("bugpoint", errs());
Result = 0;
}
try {
// Load the first input file.
- Program = ParseInputFile(Filenames[0]);
+ Program = ParseInputFile(Filenames[0], Context);
if (Program == 0) return true;
if (!run_as_child)
std::cout << "Read input file : '" << Filenames[0] << "'\n";
for (unsigned i = 1, e = Filenames.size(); i != e; ++i) {
- std::auto_ptr<Module> M(ParseInputFile(Filenames[i]));
+ std::auto_ptr<Module> M(ParseInputFile(Filenames[i], Context));
if (M.get() == 0) return true;
if (!run_as_child)
class BasicBlock;
class AbstractInterpreter;
class Instruction;
+class LLVMContext;
class DebugCrashes;
extern bool BugpointIsInterrupted;
class BugDriver {
+ LLVMContext* Context;
const std::string ToolName; // Name of bugpoint
std::string ReferenceOutputFile; // Name of `good' output file
Module *Program; // The raw program, linked together
public:
BugDriver(const char *toolname, bool as_child, bool find_bugs,
- unsigned timeout, unsigned memlimit);
+ unsigned timeout, unsigned memlimit, LLVMContext* ctxt);
const std::string &getToolName() const { return ToolName; }
+ LLVMContext* getContext() { return Context; }
+
// Set up methods... these methods are used to copy information about the
// command line arguments into instance variables of BugDriver.
//
/// ParseInputFile - Given a bitcode or assembly input filename, parse and
/// return it, or return null if not possible.
///
-Module *ParseInputFile(const std::string &InputFilename);
+Module *ParseInputFile(const std::string &InputFilename, LLVMContext* ctxt);
/// getPassesString - Turn a list of passes into a string which indicates the
PrefixOutput.set(PfxOutput);
OrigProgram = BD.Program;
- BD.Program = ParseInputFile(PrefixOutput.toString());
+ BD.Program = ParseInputFile(PrefixOutput.toString(), BD.getContext());
if (BD.Program == 0) {
std::cerr << BD.getToolName() << ": Error reading bitcode file '"
<< PrefixOutput << "'!\n";
// Ok, so now we know that the prefix passes work, try running the suffix
// passes on the result of the prefix passes.
//
- Module *PrefixOutput = ParseInputFile(BitcodeResult);
+ Module *PrefixOutput = ParseInputFile(BitcodeResult, BD.getContext());
if (PrefixOutput == 0) {
std::cerr << BD.getToolName() << ": Error reading bitcode file '"
<< BitcodeResult << "'!\n";
// Restore the current program.
swapProgramIn(OldProgram);
- Module *Ret = ParseInputFile(BitcodeResult);
+ Module *Ret = ParseInputFile(BitcodeResult, Context);
if (Ret == 0) {
cerr << getToolName() << ": Error reading bitcode file '"
<< BitcodeResult << "'!\n";
#include "BugDriver.h"
#include "ToolRunner.h"
#include "llvm/LinkAllPasses.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Support/PassNameParser.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
"llvm.org/cmds/bugpoint.html"
" for more information.\n");
sys::SetInterruptFunction(BugpointInterruptFunction);
-
- BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit);
+
+ LLVMContext Context;
+ BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit, &Context);
if (D.addSources(InputFilenames)) return 1;
D.addPasses(PassList.begin(), PassList.end());
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetMachineRegistry.h"
#include "llvm/Transforms/Scalar.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
#include "llvm/PassManager.h"
int main(int argc, char **argv) {
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
+ LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv, "llvm system compiler\n");
std::auto_ptr<MemoryBuffer> Buffer(
MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage));
if (Buffer.get())
- M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage));
+ M.reset(ParseBitcodeFile(Buffer.get(), &Context, &ErrorMessage));
if (M.get() == 0) {
std::cerr << argv[0] << ": bitcode didn't read correctly.\n";
std::cerr << "Reason: " << ErrorMessage << "\n";
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
#include "llvm/Type.h"
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
+ LLVMContext Context;
atexit(do_shutdown); // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv,
"llvm interpreter & dynamic compiler\n");
// Load the bitcode...
std::string ErrorMsg;
ModuleProvider *MP = NULL;
- if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFile,&ErrorMsg)) {
- MP = getBitcodeModuleProvider(Buffer, &ErrorMsg);
+ if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFile,&ErrorMsg)){
+ MP = getBitcodeModuleProvider(Buffer, &Context, &ErrorMsg);
if (!MP) delete Buffer;
}
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Bitcode/Archive.h"
#include "llvm/Support/CommandLine.h"
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
+ LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
// Have the command line options parsed and handle things
// Produce a warning if we should and we're creating the archive
if (!Create)
std::cerr << argv[0] << ": creating " << ArchivePath.toString() << "\n";
- TheArchive = Archive::CreateEmpty(ArchivePath);
+ TheArchive = Archive::CreateEmpty(ArchivePath, &Context);
TheArchive->writeToDisk();
} else {
std::string Error;
- TheArchive = Archive::OpenAndLoad(ArchivePath, &Error);
+ TheArchive = Archive::OpenAndLoad(ArchivePath, &Context, &Error);
if (TheArchive == 0) {
std::cerr << argv[0] << ": error loading '" << ArchivePath << "': "
<< Error << "!\n";
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Assembly/Parser.h"
#include "llvm/Analysis/Verifier.h"
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
+ LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
try {
// Parse the file now...
ParseError Err;
- std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err));
+ std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err, &Context));
if (M.get() == 0) {
Err.PrintError(argv[0], errs());
return 1;
/// CLIDebugger constructor - This initializes the debugger to its default
/// state, and initializes the command table.
///
-CLIDebugger::CLIDebugger()
- : TheProgramInfo(0), TheRuntimeInfo(0), Prompt("(llvm-db) "), ListSize(10) {
+CLIDebugger::CLIDebugger(LLVMContext* ctxt)
+ : Context(ctxt), TheProgramInfo(0), TheRuntimeInfo(0),
+ Prompt("(llvm-db) "), ListSize(10) {
// Initialize instance variables
CurrentFile = 0;
LineListedStart = 1;
class SourceLanguage;
class ProgramInfo;
class RuntimeInfo;
+ class LLVMContext;
/// CLIDebugger - This class implements the command line interface for the
/// LLVM debugger.
class CLIDebugger {
+ LLVMContext* Context;
+
/// Dbg - The low-level LLVM debugger object that we use to do our dirty
/// work.
Debugger Dbg;
const SourceLanguage *CurrentLanguage;
public:
- CLIDebugger();
+ CLIDebugger(LLVMContext* ctxt);
/// getDebugger - Return the current LLVM debugger implementation being
/// used.
TheProgramInfo = 0;
CurrentFile = 0;
- Dbg.loadProgram(Program.toString());
+ Dbg.loadProgram(Program.toString(), Context);
TheProgramInfo = new ProgramInfo(Dbg.getProgram());
}
std::cout << "Unloaded program.\n";
} else {
std::cout << "Loading program... " << std::flush;
- Dbg.loadProgram(Prog);
+ Dbg.loadProgram(Prog, Context);
assert(Dbg.isProgramLoaded() &&
"loadProgram succeeded, but not program loaded!");
TheProgramInfo = new ProgramInfo(Dbg.getProgram());
//===----------------------------------------------------------------------===//
#include "CLIDebugger.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h"
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
+ LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
std::cout << "NOTE: llvm-db is known useless right now.\n";
try {
InputArgs.push_back(InputFile);
// Create the CLI debugger...
- CLIDebugger D;
+ CLIDebugger D(&Context);
// Initialize the debugger with the command line options we read...
Debugger &Dbg = D.getDebugger();
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/PassManager.h"
#include "llvm/Bitcode/ReaderWriter.h"
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
+ LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
try {
cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
if (MemoryBuffer *Buffer
= MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
- M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
+ M.reset(ParseBitcodeFile(Buffer, &Context, &ErrorMessage));
delete Buffer;
}
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/PassManager.h"
#include "llvm/Bitcode/ReaderWriter.h"
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
-
+
+ LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");
cerr << argv[0] << ": Error reading file '" + InputFilename + "'\n";
return 1;
} else {
- M.reset(ParseBitcodeFile(Buffer));
+ M.reset(ParseBitcodeFile(Buffer, &Context));
}
delete Buffer;
#include "llvm/LinkAllVMCore.h"
#include "llvm/Linker.h"
+#include "llvm/LLVMContext.h"
#include "llvm/System/Program.h"
#include "llvm/Module.h"
#include "llvm/PassManager.h"
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
-
+
+ LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
try {
// Initial global variable above for convenience printing of program name.
cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
// Construct a Linker (now that Verbose is set)
- Linker TheLinker(progname, OutputFilename, Verbose);
+ Linker TheLinker(progname, OutputFilename, &Context, Verbose);
// Keep track of the native link items (versus the bitcode items)
Linker::ItemList NativeLinkItems;
//===----------------------------------------------------------------------===//
#include "llvm/Linker.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Bitcode/ReaderWriter.h"
// LoadFile - Read the specified bitcode file in and return it. This routine
// searches the link path for the specified file to try to find it...
//
-static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
+static inline std::auto_ptr<Module> LoadFile(const std::string &FN,
+ LLVMContext* Context) {
sys::Path Filename;
if (!Filename.set(FN)) {
cerr << "Invalid file name: '" << FN << "'\n";
const std::string &FNStr = Filename.toString();
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(FNStr,
&ErrorMessage)) {
- Result = ParseBitcodeFile(Buffer, &ErrorMessage);
+ Result = ParseBitcodeFile(Buffer, Context, &ErrorMessage);
delete Buffer;
}
if (Result) return std::auto_ptr<Module>(Result); // Load successful!
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
+ LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
unsigned BaseArg = 0;
std::string ErrorMessage;
- std::auto_ptr<Module> Composite(LoadFile(InputFilenames[BaseArg]));
+ std::auto_ptr<Module> Composite(LoadFile(InputFilenames[BaseArg], &Context));
if (Composite.get() == 0) {
cerr << argv[0] << ": error loading file '"
<< InputFilenames[BaseArg] << "'\n";
}
for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) {
- std::auto_ptr<Module> M(LoadFile(InputFilenames[i]));
+ std::auto_ptr<Module> M(LoadFile(InputFilenames[i], &Context));
if (M.get() == 0) {
cerr << argv[0] << ": error loading file '" <<InputFilenames[i]<< "'\n";
return 1;
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Bitcode/Archive.h"
}
static void DumpSymbolNamesFromFile(std::string &Filename) {
+ LLVMContext Context;
std::string ErrorMessage;
sys::Path aPath(Filename);
// Note: Currently we do not support reading an archive from stdin.
MemoryBuffer::getFileOrSTDIN(Filename, &ErrorMessage));
Module *Result = 0;
if (Buffer.get())
- Result = ParseBitcodeFile(Buffer.get(), &ErrorMessage);
+ Result = ParseBitcodeFile(Buffer.get(), &Context, &ErrorMessage);
if (Result)
DumpSymbolNamesFromModule(Result);
} else if (aPath.isArchive()) {
std::string ErrMsg;
- Archive* archive = Archive::OpenAndLoad(sys::Path(Filename), &ErrorMessage);
+ Archive* archive = Archive::OpenAndLoad(sys::Path(Filename), &Context,
+ &ErrorMessage);
if (!archive)
std::cerr << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
std::vector<Module *> Modules;
//===----------------------------------------------------------------------===//
#include "llvm/InstrTypes.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Assembly/AsmAnnotationWriter.h"
#include "llvm/Analysis/ProfileInfoLoader.h"
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
-
+
+ LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
try {
cl::ParseCommandLineOptions(argc, argv, "llvm profile dump decoder\n");
Module *M = 0;
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BitcodeFile,
&ErrorMessage)) {
- M = ParseBitcodeFile(Buffer, &ErrorMessage);
+ M = ParseBitcodeFile(Buffer, &Context, &ErrorMessage);
delete Buffer;
}
if (M == 0) {
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Bitcode/Archive.h"
#include "llvm/Support/CommandLine.h"
// Print a stack trace if we signal out.
llvm::sys::PrintStackTraceOnErrorSignal();
llvm::PrettyStackTraceProgram X(argc, argv);
-
+
+ LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
// Have the command line options parsed and handle things
std::string err_msg;
std::auto_ptr<Archive>
- AutoArchive(Archive::OpenAndLoad(ArchivePath,&err_msg));
+ AutoArchive(Archive::OpenAndLoad(ArchivePath, &Context, &err_msg));
Archive* TheArchive = AutoArchive.get();
if (!TheArchive)
throw err_msg;
LTOCodeGenerator::LTOCodeGenerator()
- : _linker("LinkTimeOptimizer", "ld-temp.o"), _target(NULL),
+ : _context(new LLVMContext()),
+ _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL),
_emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
_codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
_nativeObjectFile(NULL), _gccPath(NULL), _assemblerPath(NULL)
#define LTO_CODE_GENERATOR_H
#include "llvm/Linker.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/SmallVector.h"
typedef llvm::StringMap<uint8_t> StringSet;
+ llvm::LLVMContext* _context;
llvm::Linker _linker;
llvm::TargetMachine* _target;
bool _emitDwarfDebugInfo;
#include "LTOModule.h"
#include "llvm/Constants.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
#include "llvm/ADT/OwningPtr.h"
// takes ownership of buffer
bool LTOModule::isTargetMatch(MemoryBuffer* buffer, const char* triplePrefix)
{
- OwningPtr<ModuleProvider> mp(getBitcodeModuleProvider(buffer));
+ OwningPtr<ModuleProvider> mp(getBitcodeModuleProvider(buffer,
+ new LLVMContext()));
// on success, mp owns buffer and both are deleted at end of this method
if ( !mp ) {
delete buffer;
{
}
-LTOModule* LTOModule::makeLTOModule(const char* path, std::string& errMsg)
+LTOModule* LTOModule::makeLTOModule(const char* path, LLVMContext* Context,
+ std::string& errMsg)
{
OwningPtr<MemoryBuffer> buffer(MemoryBuffer::getFile(path, &errMsg));
if ( !buffer )
return NULL;
- return makeLTOModule(buffer.get(), errMsg);
+ return makeLTOModule(buffer.get(), Context, errMsg);
}
/// makeBuffer - create a MemoryBuffer from a memory range.
LTOModule* LTOModule::makeLTOModule(const void* mem, size_t length,
+ LLVMContext* Context,
std::string& errMsg)
{
OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length));
if ( !buffer )
return NULL;
- return makeLTOModule(buffer.get(), errMsg);
+ return makeLTOModule(buffer.get(), Context, errMsg);
}
/// getFeatureString - Return a string listing the features associated with the
return Features.getString();
}
-LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer, std::string& errMsg)
+LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer, LLVMContext* Context,
+ std::string& errMsg)
{
// parse bitcode buffer
- OwningPtr<Module> m(ParseBitcodeFile(buffer, &errMsg));
+ OwningPtr<Module> m(ParseBitcodeFile(buffer, Context, &errMsg));
if ( !m )
return NULL;
// find machine architecture for this module
class GlobalValue;
class Value;
class Function;
+ class LLVMContext;
}
static bool isBitcodeFileForTarget(const char* path,
const char* triplePrefix);
- static LTOModule* makeLTOModule(const char* path, std::string& errMsg);
+ static LTOModule* makeLTOModule(const char* path,
+ llvm::LLVMContext* Context,
+ std::string& errMsg);
static LTOModule* makeLTOModule(const void* mem, size_t length,
- std::string& errMsg);
+ llvm::LLVMContext* Context,
+ std::string& errMsg);
const char* getTargetTriple();
uint32_t getSymbolCount();
bool objcClassNameFromExpression(llvm::Constant* c,
std::string& name);
- static bool isTargetMatch(llvm::MemoryBuffer* memBuffer,
+ static bool isTargetMatch(llvm::MemoryBuffer* memBuffer,
const char* triplePrefix);
- static LTOModule* makeLTOModule(llvm::MemoryBuffer* buffer,
+ static LTOModule* makeLTOModule(llvm::MemoryBuffer* buffer,
+ llvm::LLVMContext* Context,
std::string& errMsg);
static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t length);
//===----------------------------------------------------------------------===//
#include "llvm-c/lto.h"
+#include "llvm-c/Core.h"
#include "LTOModule.h"
#include "LTOCodeGenerator.h"
// loads an object file from disk
// returns NULL on error (check lto_get_error_message() for details)
//
-lto_module_t lto_module_create(const char* path)
+lto_module_t lto_module_create(const char* path, LLVMContextRef Ctxt)
{
- return LTOModule::makeLTOModule(path, sLastErrorString);
+ return LTOModule::makeLTOModule(path, llvm::unwrap(Ctxt),
+ sLastErrorString);
}
// loads an object file from memory
// returns NULL on error (check lto_get_error_message() for details)
//
-lto_module_t lto_module_create_from_memory(const void* mem, size_t length)
+lto_module_t lto_module_create_from_memory(const void* mem, size_t length,
+ LLVMContextRef Ctxt)
{
- return LTOModule::makeLTOModule(mem, length, sLastErrorString);
+ return LTOModule::makeLTOModule(mem, length, llvm::unwrap(Ctxt),
+ sLastErrorString);
}
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
#include "llvm/PassManager.h"
//
int main(int argc, char **argv) {
llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
+ LLVMContext Context;
try {
cl::ParseCommandLineOptions(argc, argv,
"llvm .bc -> .bc modular optimizer and analysis printer\n");
std::auto_ptr<Module> M;
if (MemoryBuffer *Buffer
= MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
- M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
+ M.reset(ParseBitcodeFile(Buffer, &Context, &ErrorMessage));
delete Buffer;
}