diff options
author | Chris Lattner <sabre@nondot.org> | 2007-05-06 06:02:13 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-05-06 06:02:13 +0000 |
commit | 1a019e5ffd0d8643ddffc7ed5736eb78065c5f88 (patch) | |
tree | d69f7bb65c5a27607d7018c9734eedd13c12e0f3 /lib/Linker/Linker.cpp | |
parent | 5e3c9f96d7526743e9ed02aa03bc684ea0b7f12c (diff) |
add bitcode support
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36855 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Linker/Linker.cpp')
-rw-r--r-- | lib/Linker/Linker.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/Linker/Linker.cpp b/lib/Linker/Linker.cpp index d7959b41e7..bfa30044dc 100644 --- a/lib/Linker/Linker.cpp +++ b/lib/Linker/Linker.cpp @@ -14,11 +14,15 @@ #include "llvm/Linker.h" #include "llvm/Module.h" #include "llvm/Bytecode/Reader.h" +#include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Config/config.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Streams.h" #include "llvm/Support/Compressor.h" using namespace llvm; +static const bool Bitcode = false; + Linker::Linker(const std::string& progname, const std::string& modname, unsigned flags) : Composite(0) , LibPaths() @@ -100,9 +104,21 @@ Linker::releaseModule() { std::auto_ptr<Module> Linker::LoadObject(const sys::Path &FN) { std::string ParseErrorMessage; - Module *Result = ParseBytecodeFile(FN.toString(), - Compressor::decompressToNewBuffer, - &ParseErrorMessage); + Module *Result = 0; + + const std::string &FNS = FN.toString(); + if (Bitcode) { + std::auto_ptr<MemoryBuffer> Buffer( + MemoryBuffer::getFileOrSTDIN(&FNS[0], FNS.size())); + if (Buffer.get()) + Result = ParseBitcodeFile(Buffer.get(), &ParseErrorMessage); + else + ParseErrorMessage = "Error reading file '" + FNS + "'"; + + } else { + Result = ParseBytecodeFile(FNS, Compressor::decompressToNewBuffer, + &ParseErrorMessage); + } if (Result) return std::auto_ptr<Module>(Result); Error = "Bytecode file '" + FN.toString() + "' could not be loaded"; @@ -137,6 +153,8 @@ static inline sys::Path IsLibrary(const std::string& Name, return FullPath; if (FullPath.isBytecodeFile()) // .so file containing bytecode? return FullPath; + if (FullPath.isBitcodeFile()) // .so file containing bitcode? + return FullPath; // Not found .. fall through |