mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-26 23:32:58 +00:00
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
This commit is contained in:
parent
4fb75e5425
commit
8b477ed579
@ -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
|
||||
|
||||
|
@ -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 "[]".
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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".
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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 );
|
||||
|
@ -29,13 +29,14 @@ extern "C" {
|
||||
/* 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);
|
||||
|
||||
|
@ -46,6 +46,11 @@ extern "C" {
|
||||
|
||||
/* 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.
|
||||
@ -188,6 +193,10 @@ void LLVMDisposeMessage(char *Message);
|
||||
|
||||
/*===-- Modules -----------------------------------------------------------===*/
|
||||
|
||||
/* Create and destroy contexts. */
|
||||
LLVMContextRef LLVMContextCreate();
|
||||
void LLVMContextDispose(LLVMContextRef C);
|
||||
|
||||
/* Create and destroy modules. */
|
||||
/** See llvm::Module::Module. */
|
||||
LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
|
||||
@ -815,6 +824,7 @@ namespace llvm {
|
||||
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
|
||||
|
@ -21,6 +21,7 @@ namespace llvm {
|
||||
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
|
||||
@ -30,7 +31,8 @@ class raw_ostream;
|
||||
/// @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
|
||||
@ -42,7 +44,8 @@ Module *ParseAssemblyFile(
|
||||
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
|
||||
);
|
||||
|
||||
//===------------------------------------------------------------------------===
|
||||
|
@ -32,6 +32,7 @@ class ModuleProvider; // From VMCore
|
||||
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
|
||||
@ -278,7 +279,8 @@ class Archive {
|
||||
/// @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
|
||||
@ -289,6 +291,7 @@ class Archive {
|
||||
/// @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
|
||||
);
|
||||
|
||||
@ -310,6 +313,7 @@ class Archive {
|
||||
/// @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
|
||||
);
|
||||
|
||||
@ -449,7 +453,7 @@ class Archive {
|
||||
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
|
||||
@ -530,6 +534,7 @@ class Archive {
|
||||
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
|
||||
/// @{
|
||||
|
@ -23,6 +23,7 @@ namespace llvm {
|
||||
class MemoryBuffer;
|
||||
class ModulePass;
|
||||
class BitstreamWriter;
|
||||
class LLVMContext;
|
||||
class raw_ostream;
|
||||
|
||||
/// getBitcodeModuleProvider - Read the header of the specified bitcode buffer
|
||||
@ -31,12 +32,14 @@ namespace llvm {
|
||||
/// 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.
|
||||
|
@ -20,6 +20,7 @@
|
||||
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
|
||||
@ -95,7 +96,7 @@ namespace llvm {
|
||||
/// 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
|
||||
|
@ -44,7 +44,7 @@ namespace {
|
||||
// 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,"");
|
||||
|
@ -21,6 +21,7 @@
|
||||
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
|
||||
@ -66,6 +67,7 @@ class Linker {
|
||||
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)
|
||||
);
|
||||
|
||||
@ -283,6 +285,7 @@ class Linker {
|
||||
/// @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.
|
||||
|
@ -25,6 +25,7 @@ namespace llvm {
|
||||
|
||||
class GlobalValueRefMap; // Used by ConstantVals.cpp
|
||||
class FunctionType;
|
||||
class LLVMContext;
|
||||
|
||||
template<> struct ilist_traits<Function>
|
||||
: public SymbolTableListTraits<Function, Module> {
|
||||
@ -109,6 +110,8 @@ public:
|
||||
/// @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
|
||||
@ -128,7 +131,7 @@ private:
|
||||
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();
|
||||
|
||||
@ -157,6 +160,10 @@ public:
|
||||
/// @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; }
|
||||
|
@ -37,6 +37,7 @@ class Trace;
|
||||
class CallGraph;
|
||||
class TargetData;
|
||||
class LoopInfo;
|
||||
class LLVMContext;
|
||||
template<class N> class LoopBase;
|
||||
typedef LoopBase<BasicBlock> Loop;
|
||||
|
||||
|
@ -138,9 +138,9 @@ bool ArchiveMember::replaceWith(const sys::Path& newFile, std::string* ErrMsg) {
|
||||
// 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
|
||||
@ -208,6 +208,7 @@ static void getSymbols(Module*M, std::vector<std::string>& symbols) {
|
||||
|
||||
// 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(
|
||||
@ -217,7 +218,7 @@ bool llvm::GetBitcodeSymbols(const sys::Path& fName,
|
||||
return true;
|
||||
}
|
||||
|
||||
ModuleProvider *MP = getBitcodeModuleProvider(Buffer.get(), ErrMsg);
|
||||
ModuleProvider *MP = getBitcodeModuleProvider(Buffer.get(), Context, ErrMsg);
|
||||
if (!MP)
|
||||
return true;
|
||||
|
||||
@ -239,13 +240,14 @@ bool llvm::GetBitcodeSymbols(const sys::Path& fName,
|
||||
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;
|
||||
|
||||
|
@ -31,6 +31,8 @@
|
||||
|
||||
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
|
||||
@ -71,11 +73,13 @@ namespace llvm {
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
@ -327,9 +327,9 @@ Archive::loadArchive(std::string* error) {
|
||||
|
||||
// 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))
|
||||
@ -339,7 +339,8 @@ Archive::OpenAndLoad(const sys::Path& file, std::string* 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()) {
|
||||
@ -349,7 +350,7 @@ Archive::getAllModules(std::vector<Module*>& Modules, std::string* ErrMessage) {
|
||||
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;
|
||||
@ -440,9 +441,9 @@ Archive::loadSymbolTable(std::string* ErrorMsg) {
|
||||
}
|
||||
|
||||
// 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))
|
||||
@ -488,7 +489,7 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
|
||||
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;
|
||||
|
||||
@ -536,7 +537,7 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
|
||||
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
|
||||
@ -615,7 +616,7 @@ bool Archive::isBitcodeArchive() {
|
||||
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.
|
||||
|
@ -64,9 +64,8 @@ static inline unsigned numVbrBytes(unsigned num) {
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@ -229,7 +228,7 @@ Archive::writeMember(
|
||||
+ ")";
|
||||
ModuleProvider* MP =
|
||||
GetBitcodeSymbols((const unsigned char*)data,fSize,
|
||||
FullMemberName, symbols, ErrMsg);
|
||||
FullMemberName, Context, symbols, ErrMsg);
|
||||
|
||||
// If the bitcode parsed successfully
|
||||
if ( MP ) {
|
||||
|
@ -20,7 +20,8 @@
|
||||
#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;
|
||||
@ -31,14 +32,14 @@ Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err) {
|
||||
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>
|
||||
@ -50,7 +51,7 @@ Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
|
||||
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();
|
||||
|
@ -18,11 +18,12 @@ using namespace llvm;
|
||||
/* 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());
|
||||
@ -36,11 +37,13 @@ int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
|
||||
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());
|
||||
|
@ -1087,7 +1087,7 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) {
|
||||
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;
|
||||
@ -2090,8 +2090,9 @@ Module *BitcodeReader::releaseModule(std::string *ErrInfo) {
|
||||
/// 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();
|
||||
@ -2106,9 +2107,11 @@ ModuleProvider *llvm::getBitcodeModuleProvider(MemoryBuffer *Buffer,
|
||||
|
||||
/// 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.
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
namespace llvm {
|
||||
class MemoryBuffer;
|
||||
class LLVMContext;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// BitcodeReaderValueList Class
|
||||
@ -85,6 +86,7 @@ public:
|
||||
};
|
||||
|
||||
class BitcodeReader : public ModuleProvider {
|
||||
LLVMContext* Context;
|
||||
MemoryBuffer *Buffer;
|
||||
BitstreamReader StreamFile;
|
||||
BitstreamCursor Stream;
|
||||
@ -123,8 +125,8 @@ class BitcodeReader : public ModuleProvider {
|
||||
/// 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() {
|
||||
|
@ -46,11 +46,11 @@ std::string Debugger::getProgramPath() const {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -58,9 +58,9 @@ getMaterializedModuleProvider(const std::string &Filename) {
|
||||
/// 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...
|
||||
@ -69,9 +69,9 @@ void Debugger::loadProgram(const std::string &Filename) {
|
||||
|
||||
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, ":");
|
||||
|
@ -115,7 +115,7 @@ Linker::LinkInArchive(const sys::Path &Filename, bool &is_native) {
|
||||
|
||||
std::string ErrMsg;
|
||||
std::auto_ptr<Archive> AutoArch (
|
||||
Archive::OpenAndLoadSymbols(Filename,&ErrMsg));
|
||||
Archive::OpenAndLoadSymbols(Filename, Context, &ErrMsg));
|
||||
|
||||
Archive* arch = AutoArch.get();
|
||||
|
||||
|
@ -160,7 +160,7 @@ bool Linker::LinkInFile(const sys::Path &File, bool &is_native) {
|
||||
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))
|
||||
|
@ -20,24 +20,21 @@
|
||||
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);
|
||||
}
|
||||
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)
|
||||
: Composite(aModule)
|
||||
, 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;
|
||||
@ -106,7 +103,7 @@ Linker::LoadObject(const sys::Path &FN) {
|
||||
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 + "'";
|
||||
|
||||
|
@ -35,7 +35,7 @@ Module *llvm::CloneModule(const Module *M) {
|
||||
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());
|
||||
|
@ -18,6 +18,7 @@
|
||||
#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"
|
||||
@ -38,10 +39,21 @@ void LLVMDisposeMessage(char *Message) {
|
||||
}
|
||||
|
||||
|
||||
/*===-- 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) {
|
||||
|
@ -15,6 +15,7 @@
|
||||
#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"
|
||||
@ -54,8 +55,8 @@ template class SymbolTableListTraits<GlobalAlias, Module>;
|
||||
// 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();
|
||||
}
|
||||
|
@ -64,24 +64,24 @@ std::string llvm::getPassesString(const std::vector<const PassInfo*> &Passes) {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@ -100,14 +100,14 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) {
|
||||
|
||||
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)
|
||||
|
@ -30,6 +30,7 @@ class Function;
|
||||
class BasicBlock;
|
||||
class AbstractInterpreter;
|
||||
class Instruction;
|
||||
class LLVMContext;
|
||||
|
||||
class DebugCrashes;
|
||||
|
||||
@ -42,6 +43,7 @@ extern bool DisableSimplifyCFG;
|
||||
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
|
||||
@ -60,10 +62,12 @@ class BugDriver {
|
||||
|
||||
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.
|
||||
//
|
||||
@ -290,7 +294,7 @@ private:
|
||||
/// 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
|
||||
|
@ -73,7 +73,7 @@ ReducePassList::doTest(std::vector<const PassInfo*> &Prefix,
|
||||
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";
|
||||
|
@ -112,7 +112,7 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
|
||||
// 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";
|
||||
|
@ -255,7 +255,7 @@ Module *BugDriver::runPassesOn(Module *M,
|
||||
// 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";
|
||||
|
@ -16,6 +16,7 @@
|
||||
#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"
|
||||
@ -73,8 +74,9 @@ int main(int argc, char **argv) {
|
||||
"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());
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#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"
|
||||
@ -212,6 +213,7 @@ static raw_ostream *GetOutputStream(const char *ProgName) {
|
||||
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");
|
||||
|
||||
@ -225,7 +227,7 @@ int main(int argc, char **argv) {
|
||||
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";
|
||||
|
@ -13,6 +13,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/ModuleProvider.h"
|
||||
#include "llvm/Type.h"
|
||||
@ -93,6 +94,7 @@ int main(int argc, char **argv, char * const *envp) {
|
||||
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");
|
||||
@ -104,8 +106,8 @@ int main(int argc, char **argv, char * const *envp) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Bitcode/Archive.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
@ -690,6 +691,7 @@ int main(int argc, char **argv) {
|
||||
// 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
|
||||
@ -717,11 +719,11 @@ int main(int argc, char **argv) {
|
||||
// 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";
|
||||
|
@ -15,6 +15,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Assembly/Parser.h"
|
||||
#include "llvm/Analysis/Verifier.h"
|
||||
@ -55,6 +56,7 @@ int main(int argc, char **argv) {
|
||||
// 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");
|
||||
|
||||
@ -63,7 +65,7 @@ int main(int argc, char **argv) {
|
||||
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;
|
||||
|
@ -22,8 +22,9 @@ using namespace llvm;
|
||||
/// 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;
|
||||
|
@ -24,10 +24,13 @@ namespace llvm {
|
||||
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;
|
||||
@ -79,7 +82,7 @@ namespace llvm {
|
||||
const SourceLanguage *CurrentLanguage;
|
||||
|
||||
public:
|
||||
CLIDebugger();
|
||||
CLIDebugger(LLVMContext* ctxt);
|
||||
|
||||
/// getDebugger - Return the current LLVM debugger implementation being
|
||||
/// used.
|
||||
|
@ -64,7 +64,7 @@ void CLIDebugger::startProgramRunning() {
|
||||
TheProgramInfo = 0;
|
||||
CurrentFile = 0;
|
||||
|
||||
Dbg.loadProgram(Program.toString());
|
||||
Dbg.loadProgram(Program.toString(), Context);
|
||||
TheProgramInfo = new ProgramInfo(Dbg.getProgram());
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ void CLIDebugger::fileCommand(std::string &Options) {
|
||||
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());
|
||||
|
@ -13,6 +13,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "CLIDebugger.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
#include "llvm/Support/PrettyStackTrace.h"
|
||||
@ -54,6 +55,7 @@ int main(int argc, char **argv, char * const *envp) {
|
||||
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 {
|
||||
@ -68,7 +70,7 @@ int main(int argc, char **argv, char * const *envp) {
|
||||
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();
|
||||
|
@ -16,6 +16,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/PassManager.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
@ -50,6 +51,7 @@ int main(int argc, char **argv) {
|
||||
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");
|
||||
@ -61,7 +63,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
if (MemoryBuffer *Buffer
|
||||
= MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
|
||||
M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
|
||||
M.reset(ParseBitcodeFile(Buffer, &Context, &ErrorMessage));
|
||||
delete Buffer;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/PassManager.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
@ -60,7 +61,8 @@ int main(int argc, char **argv) {
|
||||
// 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");
|
||||
|
||||
@ -71,7 +73,7 @@ int main(int argc, char **argv) {
|
||||
cerr << argv[0] << ": Error reading file '" + InputFilename + "'\n";
|
||||
return 1;
|
||||
} else {
|
||||
M.reset(ParseBitcodeFile(Buffer));
|
||||
M.reset(ParseBitcodeFile(Buffer, &Context));
|
||||
}
|
||||
delete Buffer;
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#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"
|
||||
@ -505,7 +506,8 @@ int main(int argc, char **argv, char **envp) {
|
||||
// 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.
|
||||
@ -515,7 +517,7 @@ int main(int argc, char **argv, char **envp) {
|
||||
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;
|
||||
|
@ -13,6 +13,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Linker.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Analysis/Verifier.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
@ -47,7 +48,8 @@ DumpAsm("d", cl::desc("Print assembly as linked"), cl::Hidden);
|
||||
// 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";
|
||||
@ -62,7 +64,7 @@ static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
|
||||
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!
|
||||
@ -84,13 +86,14 @@ 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 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";
|
||||
@ -98,7 +101,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -16,6 +16,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
#include "llvm/Bitcode/Archive.h"
|
||||
@ -132,6 +133,7 @@ static void DumpSymbolNamesFromModule(Module *M) {
|
||||
}
|
||||
|
||||
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.
|
||||
@ -140,7 +142,7 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
|
||||
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);
|
||||
@ -151,7 +153,8 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
|
||||
|
||||
} 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;
|
||||
|
@ -14,6 +14,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/InstrTypes.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Assembly/AsmAnnotationWriter.h"
|
||||
#include "llvm/Analysis/ProfileInfoLoader.h"
|
||||
@ -115,7 +116,8 @@ int main(int argc, char **argv) {
|
||||
// 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");
|
||||
@ -125,7 +127,7 @@ int main(int argc, char **argv) {
|
||||
Module *M = 0;
|
||||
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BitcodeFile,
|
||||
&ErrorMessage)) {
|
||||
M = ParseBitcodeFile(Buffer, &ErrorMessage);
|
||||
M = ParseBitcodeFile(Buffer, &Context, &ErrorMessage);
|
||||
delete Buffer;
|
||||
}
|
||||
if (M == 0) {
|
||||
|
@ -11,6 +11,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Bitcode/Archive.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
@ -46,7 +47,8 @@ int main(int argc, char **argv) {
|
||||
// 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
|
||||
@ -73,7 +75,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
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;
|
||||
|
@ -70,7 +70,8 @@ const char* LTOCodeGenerator::getVersionString()
|
||||
|
||||
|
||||
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)
|
||||
|
@ -16,6 +16,7 @@
|
||||
#define LTO_CODE_GENERATOR_H
|
||||
|
||||
#include "llvm/Linker.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
|
||||
@ -53,6 +54,7 @@ private:
|
||||
|
||||
typedef llvm::StringMap<uint8_t> StringSet;
|
||||
|
||||
llvm::LLVMContext* _context;
|
||||
llvm::Linker _linker;
|
||||
llvm::TargetMachine* _target;
|
||||
bool _emitDwarfDebugInfo;
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "LTOModule.h"
|
||||
|
||||
#include "llvm/Constants.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/ModuleProvider.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
@ -67,7 +68,8 @@ bool LTOModule::isBitcodeFileForTarget(const char* path,
|
||||
// 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;
|
||||
@ -84,12 +86,13 @@ LTOModule::LTOModule(Module* m, TargetMachine* t)
|
||||
{
|
||||
}
|
||||
|
||||
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.
|
||||
@ -109,12 +112,13 @@ MemoryBuffer* LTOModule::makeBuffer(const void* mem, size_t length)
|
||||
|
||||
|
||||
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
|
||||
@ -136,10 +140,11 @@ std::string getFeatureString(const char *TargetTriple) {
|
||||
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
|
||||
|
@ -32,6 +32,7 @@ namespace llvm {
|
||||
class GlobalValue;
|
||||
class Value;
|
||||
class Function;
|
||||
class LLVMContext;
|
||||
}
|
||||
|
||||
|
||||
@ -50,9 +51,12 @@ public:
|
||||
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();
|
||||
@ -83,10 +87,11 @@ private:
|
||||
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);
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm-c/lto.h"
|
||||
#include "llvm-c/Core.h"
|
||||
|
||||
#include "LTOModule.h"
|
||||
#include "LTOCodeGenerator.h"
|
||||
@ -85,9 +86,10 @@ bool lto_module_is_object_file_in_memory_for_target(const void* mem,
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
@ -95,9 +97,11 @@ lto_module_t lto_module_create(const char* path)
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/ModuleProvider.h"
|
||||
#include "llvm/PassManager.h"
|
||||
@ -310,6 +311,7 @@ void AddStandardCompilePasses(PassManager &PM) {
|
||||
//
|
||||
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");
|
||||
@ -325,7 +327,7 @@ int main(int argc, char **argv) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user