[llvm-commits] CVS: llvm/lib/Linker/LinkArchives.cpp LinkItems.cpp Linker.cpp

Chris Lattner sabre at nondot.org
Sat May 5 23:02:30 PDT 2007



Changes in directory llvm/lib/Linker:

LinkArchives.cpp updated: 1.57 -> 1.58
LinkItems.cpp updated: 1.14 -> 1.15
Linker.cpp updated: 1.14 -> 1.15
---
Log message:

add bitcode support


---
Diffs of the changes:  (+23 -4)

 LinkArchives.cpp |    1 -
 LinkItems.cpp    |    2 ++
 Linker.cpp       |   24 +++++++++++++++++++++---
 3 files changed, 23 insertions(+), 4 deletions(-)


Index: llvm/lib/Linker/LinkArchives.cpp
diff -u llvm/lib/Linker/LinkArchives.cpp:1.57 llvm/lib/Linker/LinkArchives.cpp:1.58
--- llvm/lib/Linker/LinkArchives.cpp:1.57	Sun Apr 29 19:29:39 2007
+++ llvm/lib/Linker/LinkArchives.cpp	Sun May  6 01:02:13 2007
@@ -16,7 +16,6 @@
 #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>


Index: llvm/lib/Linker/LinkItems.cpp
diff -u llvm/lib/Linker/LinkItems.cpp:1.14 llvm/lib/Linker/LinkItems.cpp:1.15
--- llvm/lib/Linker/LinkItems.cpp:1.14	Sun Apr 29 19:29:39 2007
+++ llvm/lib/Linker/LinkItems.cpp	Sun May  6 01:02:13 2007
@@ -83,6 +83,7 @@
       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))
@@ -175,6 +176,7 @@
         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() + "'");


Index: llvm/lib/Linker/Linker.cpp
diff -u llvm/lib/Linker/Linker.cpp:1.14 llvm/lib/Linker/Linker.cpp:1.15
--- llvm/lib/Linker/Linker.cpp:1.14	Wed Feb  7 15:41:02 2007
+++ llvm/lib/Linker/Linker.cpp	Sun May  6 01:02:13 2007
@@ -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 @@
 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 @@
     return FullPath;
   if (FullPath.isBytecodeFile())    // .so file containing bytecode?
     return FullPath;
+  if (FullPath.isBitcodeFile())    // .so file containing bitcode?
+    return FullPath;
 
   // Not found .. fall through
 






More information about the llvm-commits mailing list