add bitcode support
authorChris Lattner <sabre@nondot.org>
Sun, 6 May 2007 06:02:13 +0000 (06:02 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 6 May 2007 06:02:13 +0000 (06:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36855 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Linker/LinkArchives.cpp
lib/Linker/LinkItems.cpp
lib/Linker/Linker.cpp

index 95ac1ab1fd9d6de45cb033f6f8ba53cc524ba60a..e6a3b8a52309673fe3b0821f38e20bd9d9630f9b 100644 (file)
@@ -16,7 +16,6 @@
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/ADT/SetOperations.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/ADT/SetOperations.h"
-#include "llvm/Bytecode/Reader.h"
 #include "llvm/Bytecode/Archive.h"
 #include "llvm/Config/config.h"
 #include <memory>
 #include "llvm/Bytecode/Archive.h"
 #include "llvm/Config/config.h"
 #include <memory>
index ad7ae65209c8e7876b55bace967f1054e5985e23..50efe46bd1cc6ba069544430fee1b786f345ad7f 100644 (file)
@@ -83,6 +83,7 @@ bool Linker::LinkInLibrary(const std::string& Lib, bool& is_native) {
       return warning("Supposed library '" + Lib + "' isn't a library.");
 
     case sys::Bytecode_FileType:
       return warning("Supposed library '" + Lib + "' isn't a library.");
 
     case sys::Bytecode_FileType:
+    case sys::Bitcode_FileType:
     case sys::CompressedBytecode_FileType:
       // LLVM ".so" file.
       if (LinkInFile(Pathname, is_native))
     case sys::CompressedBytecode_FileType:
       // LLVM ".so" file.
       if (LinkInFile(Pathname, is_native))
@@ -175,6 +176,7 @@ bool Linker::LinkInFile(const sys::Path &File, bool &is_native) {
         return error("Cannot link archive '" + File.toString() + "'");
       break;
 
         return error("Cannot link archive '" + File.toString() + "'");
       break;
 
+    case sys::Bitcode_FileType:
     case sys::Bytecode_FileType:
     case sys::CompressedBytecode_FileType: {
       verbose("Linking bytecode file '" + File.toString() + "'");
     case sys::Bytecode_FileType:
     case sys::CompressedBytecode_FileType: {
       verbose("Linking bytecode file '" + File.toString() + "'");
index d7959b41e7de942478488a5773684333a1fe15bd..bfa30044dcf61b060ddc4f2e25181d70c98f99c2 100644 (file)
 #include "llvm/Linker.h"
 #include "llvm/Module.h"
 #include "llvm/Bytecode/Reader.h"
 #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/Config/config.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/Support/Compressor.h"
 using namespace llvm;
 
 #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()
 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;
 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";
   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;
     return FullPath;
   if (FullPath.isBytecodeFile())    // .so file containing bytecode?
     return FullPath;
+  if (FullPath.isBitcodeFile())    // .so file containing bitcode?
+    return FullPath;
 
   // Not found .. fall through
 
 
   // Not found .. fall through