push bytecode decompressor out through APIs. Now the bytecode reader
authorChris Lattner <sabre@nondot.org>
Wed, 7 Feb 2007 21:41:02 +0000 (21:41 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 7 Feb 2007 21:41:02 +0000 (21:41 +0000)
api's look like this:

ModuleProvider *getBytecodeModuleProvider(
  const std::string &Filename,  ///< Name of file to be read
  BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
  std::string* ErrMsg = 0,      ///< Optional error message holder
  BytecodeHandler* H = 0        ///< Optional handler for reader events
);

This is ugly, but allows a client to say:

  getBytecodeModuleProvider("foo", 0);

If they do this, there is no dependency on the compression libraries, saving
codesize.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34012 91177308-0d34-0410-b5e6-96231b3b80d8

25 files changed:
include/llvm/Bytecode/Analyzer.h
include/llvm/Bytecode/Archive.h
include/llvm/Bytecode/Reader.h
lib/Archive/Archive.cpp
lib/Archive/ArchiveReader.cpp
lib/Archive/ArchiveWriter.cpp
lib/Bytecode/Archive/Archive.cpp
lib/Bytecode/Archive/ArchiveReader.cpp
lib/Bytecode/Archive/ArchiveWriter.cpp
lib/Bytecode/Reader/Reader.cpp
lib/Bytecode/Reader/Reader.h
lib/Bytecode/Reader/ReaderWrappers.cpp
lib/Linker/Linker.cpp
tools/bugpoint/BugDriver.cpp
tools/llc/llc.cpp
tools/lli/lli.cpp
tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
tools/llvm-dis/llvm-dis.cpp
tools/llvm-extract/llvm-extract.cpp
tools/llvm-link/llvm-link.cpp
tools/llvm-nm/llvm-nm.cpp
tools/llvm-prof/llvm-prof.cpp
tools/llvm2cpp/llvm2cpp.cpp
tools/llvmc/CompilerDriver.cpp
tools/opt/opt.cpp

index b6a0eed220a5d856a4ed0d91e42d5cdc0cb8a959..7d02f68eeeb6a365c8b6f30cde63bf2f212d5a59 100644 (file)
 #define LLVM_BYTECODE_ANALYZER_H
 
 #include "llvm/Bytecode/Format.h"
+#include "llvm/Bytecode/Reader.h"
 #include <string>
 #include <map>
-#include <ostream>
+#include <iosfwd>
 
 namespace llvm {
 
@@ -102,23 +103,11 @@ struct BytecodeAnalysis {
 Module* AnalyzeBytecodeFile(
       const std::string& Filename, ///< The name of the bytecode file to read
       BytecodeAnalysis& Results,   ///< The results of the analysis
+      BCDecompressor_t *BCDC = 0,     ///< Optional decompressor to use.
       std::string* ErrorStr = 0,   ///< Errors, if any.
       std::ostream* output = 0     ///< Stream for dump output, if wanted
     );
 
-/// This function is an alternate entry point into the bytecode analysis
-/// library. It allows you to provide an arbitrary memory buffer which is
-/// assumed to contain a complete bytecode file. The \p Buffer is analyzed and
-/// the \p Results are filled in.
-/// @brief Analyze contents of a bytecode buffer.
-Module* AnalyzeBytecodeBuffer(
-       const unsigned char* Buffer, ///< Pointer to start of bytecode buffer
-       unsigned BufferSize,         ///< Size of the bytecode buffer
-       const std::string& ModuleID, ///< Identifier for the module
-       BytecodeAnalysis& Results,   ///< The results of the analysis
-       std::string* ErrorStr = 0,   ///< Errors, if any.
-       std::ostream* output = 0     ///< Stream for dump output, if wanted
-     );
 
 /// This function prints the contents of rhe BytecodeAnalysis structure in
 /// a human legible form.
index 59d825a7224125ffca1cb93590aa3a5fed1ba010..d0a72561e416f3bc62be04cc36611eae9b30ceb1 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/ADT/ilist"
 #include "llvm/System/Path.h"
 #include "llvm/System/MappedFile.h"
+#include "llvm/Support/Compressor.h"
 #include <map>
 #include <set>
 #include <fstream>
@@ -32,6 +33,9 @@ class Module;              // From VMCore
 class Archive;             // Declared below
 class ArchiveMemberHeader; // Internal implementation class
 
+typedef size_t BCDecompressor_t(const char *, size_t, char*&, std::string*);
+
+
 /// 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
 /// stored by the Archive's ilist, the Archive's main abstraction. Because of
@@ -223,7 +227,7 @@ class ArchiveMember {
 /// applications and the linkers. Consequently, the implementation of the class
 /// is optimized for reading.
 class Archive {
-
+  
   /// @name Types
   /// @{
   public:
@@ -468,7 +472,8 @@ class Archive {
   protected:
     /// @brief Construct an Archive for \p filename and optionally  map it
     /// into memory.
-    Archive(const sys::Path& filename);
+    Archive(const sys::Path& filename, BCDecompressor_t *BCDC = 
+            Compressor::decompressToNewBuffer);
 
     /// @param error Set to address of a std::string to get error messages
     /// @returns false on error
@@ -547,7 +552,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.
-
+    BCDecompressor_t *Decompressor;  ///< Optional decompressor
   /// @}
   /// @name Hidden
   /// @{
index 362718613598e23edd4563406e58a5076a35453a..f1757455edb0c093c537c39216048d0fd2e860cd 100644 (file)
 #ifndef LLVM_BYTECODE_READER_H
 #define LLVM_BYTECODE_READER_H
 
-#include "llvm/System/Path.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/Module.h"
-#include <string>
+#include "llvm/Support/Compressor.h"
+#include "llvm/System/Path.h"
 
 namespace llvm {
 
 // Forward declare the handler class
 class BytecodeHandler;
 
+typedef size_t BCDecompressor_t(const char *, size_t, char*&, std::string*);
+
 /// This function returns a ModuleProvider that can be used to do lazy 
 /// function-at-a-time loading from a bytecode file.
 /// @returns NULL on error
@@ -36,6 +38,7 @@ class BytecodeHandler;
 /// @brief Get a ModuleProvide for a bytecode file.
 ModuleProvider *getBytecodeModuleProvider(
   const std::string &Filename,  ///< Name of file to be read
+  BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
   std::string* ErrMsg = 0,      ///< Optional error message holder 
   BytecodeHandler* H = 0        ///< Optional handler for reader events
 );
@@ -49,6 +52,7 @@ ModuleProvider *getBytecodeBufferModuleProvider(
   const unsigned char *Buffer,    ///< Start of buffer to parse
   unsigned BufferSize,            ///< Size of the buffer
   const std::string &ModuleID,    ///< Name to give the module
+  BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
   std::string* ErrMsg = 0,        ///< Optional place to return an error message
   BytecodeHandler* H = 0          ///< Optional handler for reader events
 );
@@ -61,6 +65,7 @@ ModuleProvider *getBytecodeBufferModuleProvider(
 /// @brief Parse the given bytecode file
 Module* ParseBytecodeFile(
   const std::string &Filename,    ///< Name of file to parse
+  BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
   std::string *ErrMsg = 0         ///< Optional place to return an error message
 );
 
@@ -72,6 +77,7 @@ Module* ParseBytecodeBuffer(
   const unsigned char *Buffer,    ///< Start of buffer to parse
   unsigned BufferSize,            ///< Size of the buffer
   const std::string &ModuleID="", ///< Name to give the module
+  BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
   std::string *ErrMsg = 0         ///< Optional place to return an error message
 );
 
@@ -84,6 +90,7 @@ Module* ParseBytecodeBuffer(
 bool GetBytecodeDependentLibraries(
   const std::string &fileName,       ///< File name to read bytecode from
   Module::LibraryListType& deplibs,  ///< List of dependent libraries extracted
+  BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
   std::string* ErrMsg = 0            ///< Optional error message holder
 );
 
@@ -96,6 +103,7 @@ bool GetBytecodeDependentLibraries(
 bool GetBytecodeSymbols(
   const sys::Path& fileName,       ///< Filename to read bytecode from
   std::vector<std::string>& syms,  ///< Vector to return symbols in
+  BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
   std::string* ErrMsg = 0          ///< Optional error message holder
 );
 
@@ -111,6 +119,7 @@ ModuleProvider* GetBytecodeSymbols(
   unsigned Length,                   ///< The length of \p Buffer
   const std::string& ModuleID,       ///< An identifier for the module
   std::vector<std::string>& symbols, ///< The symbols defined in the module
+  BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
   std::string* ErrMsg = 0            ///< Optional error message holder
 );
 
index 3bbc49dbe2a84a905e9ace3f05ddc3eb701357e7..d299694383a0eb3d444b8919da921ff638d1cf4e 100644 (file)
@@ -138,10 +138,10 @@ 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, BCDecompressor_t *BCDC)
   : archPath(filename), members(), mapfile(0), base(0), symTab(), strtab(),
-    symTabSize(0), firstFileOffset(0), modules(), foreignST(0)
-{
+    symTabSize(0), firstFileOffset(0), modules(), foreignST(0)
+    Decompressor(BCDC) {
 }
 
 bool
index 82ff9edc8ae427b9688ab2409b24578e46a230bf..67b6549e15ee0a9cfd50ee61325c8e281d009db3 100644 (file)
@@ -13,8 +13,8 @@
 
 #include "ArchiveInternals.h"
 #include "llvm/Bytecode/Reader.h"
+#include "llvm/Support/Compressor.h"
 #include <memory>
-
 using namespace llvm;
 
 /// Read a variable-bit-rate encoded unsigned integer
@@ -351,7 +351,9 @@ Archive::getAllModules(std::vector<Module*>& Modules, std::string* ErrMessage) {
       std::string FullMemberName = archPath.toString() +
         "(" + I->getPath().toString() + ")";
       Module* M = ParseBytecodeBuffer((const unsigned char*)I->getData(),
-          I->getSize(), FullMemberName, ErrMessage);
+                                      I->getSize(), FullMemberName,
+                                      Compressor::decompressToNewBuffer,
+                                      ErrMessage);
       if (!M)
         return true;
 
@@ -486,7 +488,7 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
     mbr->getPath().toString() + ")";
   ModuleProvider* mp = getBytecodeBufferModuleProvider(
       (const unsigned char*) mbr->getData(), mbr->getSize(),
-      FullMemberName, ErrMsg, 0);
+      FullMemberName, Decompressor, ErrMsg, 0);
   if (!mp)
     return 0;
 
@@ -500,8 +502,7 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
 bool
 Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
                                     std::set<ModuleProvider*>& result,
-                                    std::string* error)
-{
+                                    std::string* error) {
   if (!mapfile || !base) {
     if (error)
       *error = "Empty archive invalid for finding modules defining symbols";
@@ -533,8 +534,10 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
         std::vector<std::string> symbols;
         std::string FullMemberName = archPath.toString() + "(" +
           mbr->getPath().toString() + ")";
-        ModuleProvider* MP = GetBytecodeSymbols((const unsigned char*)At,
-            mbr->getSize(), FullMemberName, symbols, error);
+        ModuleProvider* MP = 
+          GetBytecodeSymbols((const unsigned char*)At, mbr->getSize(),
+                             FullMemberName, symbols, 
+                             Compressor::decompressToNewBuffer, error);
 
         if (MP) {
           // Insert the module's symbols into the symbol table
index 9f4e797998c74c2c769a77614069905d21ab8578..ff8c5f0348c1983a13dd33f3435a2c8e4575735d 100644 (file)
@@ -225,8 +225,10 @@ Archive::writeMember(
     std::string FullMemberName = archPath.toString() + "(" +
       member.getPath().toString()
       + ")";
-    ModuleProvider* MP = GetBytecodeSymbols(
-      (const unsigned char*)data,fSize,FullMemberName, symbols, ErrMsg);
+    ModuleProvider* MP = 
+      GetBytecodeSymbols((const unsigned char*)data,fSize,
+                         FullMemberName, symbols,
+                         Compressor::decompressToNewBuffer, ErrMsg);
 
     // If the bytecode parsed successfully
     if ( MP ) {
index 3bbc49dbe2a84a905e9ace3f05ddc3eb701357e7..d299694383a0eb3d444b8919da921ff638d1cf4e 100644 (file)
@@ -138,10 +138,10 @@ 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, BCDecompressor_t *BCDC)
   : archPath(filename), members(), mapfile(0), base(0), symTab(), strtab(),
-    symTabSize(0), firstFileOffset(0), modules(), foreignST(0)
-{
+    symTabSize(0), firstFileOffset(0), modules(), foreignST(0)
+    Decompressor(BCDC) {
 }
 
 bool
index 82ff9edc8ae427b9688ab2409b24578e46a230bf..67b6549e15ee0a9cfd50ee61325c8e281d009db3 100644 (file)
@@ -13,8 +13,8 @@
 
 #include "ArchiveInternals.h"
 #include "llvm/Bytecode/Reader.h"
+#include "llvm/Support/Compressor.h"
 #include <memory>
-
 using namespace llvm;
 
 /// Read a variable-bit-rate encoded unsigned integer
@@ -351,7 +351,9 @@ Archive::getAllModules(std::vector<Module*>& Modules, std::string* ErrMessage) {
       std::string FullMemberName = archPath.toString() +
         "(" + I->getPath().toString() + ")";
       Module* M = ParseBytecodeBuffer((const unsigned char*)I->getData(),
-          I->getSize(), FullMemberName, ErrMessage);
+                                      I->getSize(), FullMemberName,
+                                      Compressor::decompressToNewBuffer,
+                                      ErrMessage);
       if (!M)
         return true;
 
@@ -486,7 +488,7 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
     mbr->getPath().toString() + ")";
   ModuleProvider* mp = getBytecodeBufferModuleProvider(
       (const unsigned char*) mbr->getData(), mbr->getSize(),
-      FullMemberName, ErrMsg, 0);
+      FullMemberName, Decompressor, ErrMsg, 0);
   if (!mp)
     return 0;
 
@@ -500,8 +502,7 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
 bool
 Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
                                     std::set<ModuleProvider*>& result,
-                                    std::string* error)
-{
+                                    std::string* error) {
   if (!mapfile || !base) {
     if (error)
       *error = "Empty archive invalid for finding modules defining symbols";
@@ -533,8 +534,10 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
         std::vector<std::string> symbols;
         std::string FullMemberName = archPath.toString() + "(" +
           mbr->getPath().toString() + ")";
-        ModuleProvider* MP = GetBytecodeSymbols((const unsigned char*)At,
-            mbr->getSize(), FullMemberName, symbols, error);
+        ModuleProvider* MP = 
+          GetBytecodeSymbols((const unsigned char*)At, mbr->getSize(),
+                             FullMemberName, symbols, 
+                             Compressor::decompressToNewBuffer, error);
 
         if (MP) {
           // Insert the module's symbols into the symbol table
index 9f4e797998c74c2c769a77614069905d21ab8578..ff8c5f0348c1983a13dd33f3435a2c8e4575735d 100644 (file)
@@ -225,8 +225,10 @@ Archive::writeMember(
     std::string FullMemberName = archPath.toString() + "(" +
       member.getPath().toString()
       + ")";
-    ModuleProvider* MP = GetBytecodeSymbols(
-      (const unsigned char*)data,fSize,FullMemberName, symbols, ErrMsg);
+    ModuleProvider* MP = 
+      GetBytecodeSymbols((const unsigned char*)data,fSize,
+                         FullMemberName, symbols,
+                         Compressor::decompressToNewBuffer, ErrMsg);
 
     // If the bytecode parsed successfully
     if ( MP ) {
index 1ba79915e72e42470adb90a290d02fd25c7184fd..0f0cf5e6cdfd70cf05405b86e14fcfc54940cf46 100644 (file)
@@ -1981,7 +1981,7 @@ void BytecodeReader::ParseModule() {
 /// and \p Length parameters.
 bool BytecodeReader::ParseBytecode(volatile BufPtr Buf, unsigned Length,
                                    const std::string &ModuleID,
-                                   Decompressor_t *Decompressor, 
+                                   BCDecompressor_t *Decompressor, 
                                    std::string* ErrMsg) {
 
   /// We handle errors by
@@ -2016,6 +2016,9 @@ bool BytecodeReader::ParseBytecode(volatile BufPtr Buf, unsigned Length,
 
   // If this is a compressed file
   if (Sig == ('l' | ('l' << 8) | ('v' << 16) | ('c' << 24))) {
+    if (!Decompressor) {
+      error("Compressed bytecode found, but not decompressor available");
+    }
 
     // Invoke the decompression of the bytecode. Note that we have to skip the
     // file's magic number which is not part of the compressed block. Hence,
index 4593e2acc4b586d0688e8a750a34fb8869e74f3d..516a116f8b539d9f4298e4afec5939c1ae7e71dd 100644 (file)
@@ -140,16 +140,15 @@ public:
 /// @name Methods
 /// @{
 public:
-    
-  typedef size_t Decompressor_t(const char *, size_t, char*&, std::string*);
-  
+  typedef size_t BCDecompressor_t(const char *, size_t, char*&, std::string*);
+
   /// @returns true if an error occurred
   /// @brief Main interface to parsing a bytecode buffer.
   bool ParseBytecode(
      volatile BufPtr Buf,         ///< Beginning of the bytecode buffer
      unsigned Length,             ///< Length of the bytecode buffer
      const std::string &ModuleID, ///< An identifier for the module constructed.
-     Decompressor_t *Decompressor = 0, ///< Optional decompressor.
+     BCDecompressor_t *Decompressor = 0, ///< Optional decompressor.
      std::string* ErrMsg = 0      ///< Optional place for error message 
   );
 
index 4542b46d988e87f1138c780850c9d8e6b45ac994..84fa836508decf4f43119ae1008fa4b432e8cd67 100644 (file)
@@ -18,7 +18,6 @@
 #include "llvm/Module.h"
 #include "llvm/Instructions.h"
 #include "llvm/ADT/StringExtras.h"
-#include "llvm/Support/Compressor.h"
 #include "llvm/System/MappedFile.h"
 #include "llvm/System/Program.h"
 #include <cerrno>
@@ -35,13 +34,15 @@ namespace {
   class BytecodeFileReader : public BytecodeReader {
   private:
     std::string fileName;
+    BCDecompressor_t *Decompressor;
     sys::MappedFile mapFile;
 
     BytecodeFileReader(const BytecodeFileReader&); // Do not implement
     void operator=(const BytecodeFileReader &BFR); // Do not implement
 
   public:
-    BytecodeFileReader(const std::string &Filename, llvm::BytecodeHandler* H=0);
+    BytecodeFileReader(const std::string &Filename, BCDecompressor_t *BCDC,
+                       llvm::BytecodeHandler* H=0);
     bool read(std::string* ErrMsg);
     
     void freeState() {
@@ -52,8 +53,9 @@ namespace {
 }
 
 BytecodeFileReader::BytecodeFileReader(const std::string &Filename,
+                                       BCDecompressor_t *BCDC,
                                        llvm::BytecodeHandler* H)
-  : BytecodeReader(H), fileName(Filename) {
+  : BytecodeReader(H), fileName(Filename), Decompressor(BCDC) {
 }
 
 bool BytecodeFileReader::read(std::string* ErrMsg) {
@@ -65,7 +67,7 @@ bool BytecodeFileReader::read(std::string* ErrMsg) {
   }
   unsigned char* buffer = reinterpret_cast<unsigned char*>(mapFile.base());
   return ParseBytecode(buffer, mapFile.size(), fileName,
-                       Compressor::decompressToNewBuffer, ErrMsg);
+                       Decompressor, ErrMsg);
 }
 
 //===----------------------------------------------------------------------===//
@@ -81,6 +83,7 @@ namespace {
     const unsigned char *Buf;
     unsigned Length;
     std::string ModuleID;
+    BCDecompressor_t *Decompressor;
     bool MustDelete;
 
     BytecodeBufferReader(const BytecodeBufferReader&); // Do not implement
@@ -88,7 +91,7 @@ namespace {
 
   public:
     BytecodeBufferReader(const unsigned char *Buf, unsigned Length,
-                         const std::string &ModuleID,
+                         const std::string &ModuleID, BCDecompressor_t *BCDC,
                          llvm::BytecodeHandler* Handler = 0);
     ~BytecodeBufferReader();
 
@@ -100,9 +103,10 @@ namespace {
 BytecodeBufferReader::BytecodeBufferReader(const unsigned char *buf,
                                            unsigned len,
                                            const std::string &modID,
+                                           BCDecompressor_t *BCDC,
                                            llvm::BytecodeHandler *H)
   : BytecodeReader(H), Buffer(0), Buf(buf), Length(len), ModuleID(modID)
-  , MustDelete(false) {
+  , Decompressor(BCDC), MustDelete(false) {
 }
 
 BytecodeBufferReader::~BytecodeBufferReader() {
@@ -124,8 +128,7 @@ BytecodeBufferReader::read(std::string* ErrMsg) {
     ParseBegin = Buffer = Buf;
     MustDelete = false;
   }
-  if (ParseBytecode(ParseBegin, Length, ModuleID,
-                    Compressor::decompressToNewBuffer, ErrMsg)) {
+  if (ParseBytecode(ParseBegin, Length, ModuleID, Decompressor, ErrMsg)) {
     if (MustDelete) delete [] Buffer;
     return true;
   }
@@ -142,25 +145,24 @@ namespace {
   class BytecodeStdinReader : public BytecodeReader {
   private:
     std::vector<unsigned char> FileData;
+    BCDecompressor_t *Decompressor;
     unsigned char *FileBuf;
 
     BytecodeStdinReader(const BytecodeStdinReader&); // Do not implement
     void operator=(const BytecodeStdinReader &BFR);  // Do not implement
 
   public:
-    BytecodeStdinReader( llvm::BytecodeHandler* H = 0 );
+    BytecodeStdinReader(BCDecompressor_t *BCDC, llvm::BytecodeHandler* H = 0);
     bool read(std::string* ErrMsg);
   };
 }
 
-BytecodeStdinReader::BytecodeStdinReader( BytecodeHandler* H )
-  : BytecodeReader(H)
-{
+BytecodeStdinReader::BytecodeStdinReader(BCDecompressor_t *BCDC,
+                                         BytecodeHandler* H)
+  : BytecodeReader(H), Decompressor(BCDC) {
 }
 
-bool
-BytecodeStdinReader::read(std::string* ErrMsg)
-{
+bool BytecodeStdinReader::read(std::string* ErrMsg) {
   sys::Program::ChangeStdinToBinary();
   char Buffer[4096*4];
 
@@ -180,8 +182,7 @@ BytecodeStdinReader::read(std::string* ErrMsg)
   }
 
   FileBuf = &FileData[0];
-  if (ParseBytecode(FileBuf, FileData.size(), "<stdin>", 
-                    Compressor::decompressToNewBuffer, ErrMsg))
+  if (ParseBytecode(FileBuf, FileData.size(), "<stdin>", Decompressor, ErrMsg))
     return true;
   return false;
 }
@@ -196,10 +197,11 @@ ModuleProvider*
 llvm::getBytecodeBufferModuleProvider(const unsigned char *Buffer,
                                       unsigned Length,
                                       const std::string &ModuleID,
+                                      BCDecompressor_t *BCDC,
                                       std::string *ErrMsg, 
                                       BytecodeHandler *H) {
   BytecodeBufferReader *rdr = 
-    new BytecodeBufferReader(Buffer, Length, ModuleID, H);
+    new BytecodeBufferReader(Buffer, Length, ModuleID, BCDC, H);
   if (rdr->read(ErrMsg))
     return 0;
   return rdr;
@@ -209,9 +211,10 @@ llvm::getBytecodeBufferModuleProvider(const unsigned char *Buffer,
 ///
 Module *llvm::ParseBytecodeBuffer(const unsigned char *Buffer, unsigned Length,
                                   const std::string &ModuleID,
+                                  BCDecompressor_t *BCDC,
                                   std::string *ErrMsg) {
   ModuleProvider *MP = 
-    getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, ErrMsg, 0);
+    getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, BCDC, ErrMsg, 0);
   if (!MP) return 0;
   Module *M = MP->releaseModule(ErrMsg);
   delete MP;
@@ -222,18 +225,19 @@ Module *llvm::ParseBytecodeBuffer(const unsigned char *Buffer, unsigned Length,
 ///
 ModuleProvider *
 llvm::getBytecodeModuleProvider(const std::string &Filename,
+                                BCDecompressor_t *BCDC,
                                 std::string* ErrMsg,
                                 BytecodeHandler* H) {
   // Read from a file
   if (Filename != std::string("-")) {
-    BytecodeFileReader *rdr = new BytecodeFileReader(Filename, H);
+    BytecodeFileReader *rdr = new BytecodeFileReader(Filename, BCDC, H);
     if (rdr->read(ErrMsg))
       return 0;
     return rdr;
   }
 
   // Read from stdin
-  BytecodeStdinReader *rdr = new BytecodeStdinReader(H);
+  BytecodeStdinReader *rdr = new BytecodeStdinReader(BCDC, H);
   if (rdr->read(ErrMsg))
     return 0;
   return rdr;
@@ -242,8 +246,9 @@ llvm::getBytecodeModuleProvider(const std::string &Filename,
 /// ParseBytecodeFile - Parse the given bytecode file
 ///
 Module *llvm::ParseBytecodeFile(const std::string &Filename,
+                                BCDecompressor_t *BCDC,
                                 std::string *ErrMsg) {
-  ModuleProvider* MP = getBytecodeModuleProvider(Filename, ErrMsg);
+  ModuleProvider* MP = getBytecodeModuleProvider(Filename, BCDC, ErrMsg);
   if (!MP) return 0;
   Module *M = MP->releaseModule(ErrMsg);
   delete MP;
@@ -254,30 +259,12 @@ Module *llvm::ParseBytecodeFile(const std::string &Filename,
 Module* llvm::AnalyzeBytecodeFile(
   const std::string &Filename,  ///< File to analyze
   BytecodeAnalysis& bca,        ///< Statistical output
+  BCDecompressor_t *BCDC,
   std::string *ErrMsg,          ///< Error output
   std::ostream* output          ///< Dump output
 ) {
   BytecodeHandler* AH = createBytecodeAnalyzerHandler(bca,output);
-  ModuleProvider* MP = getBytecodeModuleProvider(Filename, ErrMsg, AH);
-  if (!MP) return 0;
-  Module *M = MP->releaseModule(ErrMsg);
-  delete MP;
-  return M;
-}
-
-// AnalyzeBytecodeBuffer - analyze a buffer
-Module* llvm::AnalyzeBytecodeBuffer(
-  const unsigned char* Buffer, ///< Pointer to start of bytecode buffer
-  unsigned Length,             ///< Size of the bytecode buffer
-  const std::string& ModuleID, ///< Identifier for the module
-  BytecodeAnalysis& bca,       ///< The results of the analysis
-  std::string* ErrMsg,         ///< Errors, if any.
-  std::ostream* output         ///< Dump output, if any
-)
-{
-  BytecodeHandler* hdlr = createBytecodeAnalyzerHandler(bca, output);
-  ModuleProvider* MP = 
-    getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, ErrMsg, hdlr);
+  ModuleProvider* MP = getBytecodeModuleProvider(Filename, BCDC, ErrMsg, AH);
   if (!MP) return 0;
   Module *M = MP->releaseModule(ErrMsg);
   delete MP;
@@ -286,8 +273,9 @@ Module* llvm::AnalyzeBytecodeBuffer(
 
 bool llvm::GetBytecodeDependentLibraries(const std::string &fname,
                                          Module::LibraryListType& deplibs,
+                                         BCDecompressor_t *BCDC,
                                          std::string* ErrMsg) {
-  ModuleProvider* MP = getBytecodeModuleProvider(fname, ErrMsg);
+  ModuleProvider* MP = getBytecodeModuleProvider(fname, BCDC, ErrMsg);
   if (!MP) {
     deplibs.clear();
     return true;
@@ -316,8 +304,9 @@ static void getSymbols(Module*M, std::vector<std::string>& symbols) {
 // Get just the externally visible defined symbols from the bytecode
 bool llvm::GetBytecodeSymbols(const sys::Path& fName,
                               std::vector<std::string>& symbols,
+                               BCDecompressor_t *BCDC,
                               std::string* ErrMsg) {
-  ModuleProvider *MP = getBytecodeModuleProvider(fName.toString(), ErrMsg);
+  ModuleProvider *MP = getBytecodeModuleProvider(fName.toString(), BCDC,ErrMsg);
   if (!MP)
     return true;
 
@@ -340,10 +329,11 @@ ModuleProvider*
 llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
                          const std::string& ModuleID,
                          std::vector<std::string>& symbols,
+                          BCDecompressor_t *BCDC,
                          std::string* ErrMsg) {
   // Get the module provider
   ModuleProvider* MP = 
-    getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, ErrMsg, 0);
+    getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, BCDC, ErrMsg, 0);
   if (!MP)
     return 0;
 
index 71905109eab353ae0cba3bc62375dc70ef9c7ec0..d7959b41e7de942478488a5773684333a1fe15bd 100644 (file)
@@ -16,6 +16,7 @@
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/Streams.h"
+#include "llvm/Support/Compressor.h"
 using namespace llvm;
 
 Linker::Linker(const std::string& progname, const std::string& modname, unsigned flags)
@@ -99,7 +100,9 @@ Linker::releaseModule() {
 std::auto_ptr<Module>
 Linker::LoadObject(const sys::Path &FN) {
   std::string ParseErrorMessage;
-  Module *Result = ParseBytecodeFile(FN.toString(), &ParseErrorMessage);
+  Module *Result = ParseBytecodeFile(FN.toString(), 
+                                     Compressor::decompressToNewBuffer,
+                                     &ParseErrorMessage);
   if (Result)
     return std::auto_ptr<Module>(Result);
   Error = "Bytecode file '" + FN.toString() + "' could not be loaded";
index 236e8a3cac193ea7ca5210701e95ea1be4cdcb69..2b4d35d142e819867bbbcdbefd5279562b028bd1 100644 (file)
@@ -21,6 +21,7 @@
 #include "llvm/Assembly/Parser.h"
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Compressor.h"
 #include "llvm/Support/FileUtilities.h"
 #include <iostream>
 #include <memory>
@@ -74,7 +75,8 @@ BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs,
 ///
 Module *llvm::ParseInputFile(const std::string &InputFilename) {
   ParseError Err;
-  Module *Result = ParseBytecodeFile(InputFilename);
+  Module *Result = ParseBytecodeFile(InputFilename,
+                                     Compressor::decompressToNewBuffer);
   if (!Result && !(Result = ParseAssemblyFile(InputFilename,&Err))) {
     std::cerr << "bugpoint: " << Err.getMessage() << "\n"; 
     Result = 0;
index 200b1475a3b531fdd10c64256219d39e70cedf17..d8b596db8d776f10944070d2e96853d8e0491839 100644 (file)
@@ -24,6 +24,7 @@
 #include "llvm/PassManager.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Compressor.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/PluginLoader.h"
 #include "llvm/Support/FileUtilities.h"
@@ -175,7 +176,8 @@ int main(int argc, char **argv) {
     sys::PrintStackTraceOnErrorSignal();
 
     // Load the module to be compiled...
-    std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename));
+    std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename, 
+                                            Compressor::decompressToNewBuffer));
     if (M.get() == 0) {
       std::cerr << argv[0] << ": bytecode didn't read correctly.\n";
       return 1;
index c7b0765d52baa1cc703585bc277c465afeebd3b3..0f96a4a2b15b3742024409ae7fbb4179fd337414 100644 (file)
@@ -22,6 +22,7 @@
 #include "llvm/ExecutionEngine/Interpreter.h"
 #include "llvm/ExecutionEngine/GenericValue.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Compressor.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/PluginLoader.h"
 #include "llvm/System/Process.h"
@@ -70,7 +71,9 @@ int main(int argc, char **argv, char * const *envp) {
     // Load the bytecode...
     std::string ErrorMsg;
     ModuleProvider *MP = 0;
-    MP = getBytecodeModuleProvider(InputFile, &ErrorMsg);
+    MP = getBytecodeModuleProvider(InputFile, 
+                                   Compressor::decompressToNewBuffer,
+                                   &ErrorMsg);
     if (!MP) {
       std::cerr << "Error loading program '" << InputFile << "': "
                 << ErrorMsg << "\n";
index bba9c7163a8d54d8b7ccbe00fbc3d41bd93fda46..cbb51521121911a796355b11fa12c9bc27feaa89 100644 (file)
@@ -32,6 +32,7 @@
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/Bytecode/Analyzer.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Compressor.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/System/Signals.h"
 #include <fstream>
@@ -66,7 +67,9 @@ int main(int argc, char **argv) {
     bca.progressiveVerify = Verify;
 
     /// Analyze the bytecode file
-    Module* M = AnalyzeBytecodeFile(InputFilename, bca, &ErrorMessage, (Dump?Out:0));
+    Module* M = AnalyzeBytecodeFile(InputFilename, bca, 
+                                    Compressor::decompressToNewBuffer,
+                                    &ErrorMessage, (Dump?Out:0));
 
     // All that bcanalyzer does is write the gathered statistics to the output
     PrintBytecodeAnalysis(bca,*Out);
index e4ed2b32ca94edb5e7bbedb42ea8f5ec580e9a36..38b863c20c8276fe5d073696a2d8b468b7ae0f3b 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/PassManager.h"
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Assembly/PrintModulePass.h"
+#include "llvm/Support/Compressor.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Streams.h"
@@ -51,7 +52,9 @@ int main(int argc, char **argv) {
     std::ostream *Out = &std::cout;  // Default to printing to stdout.
     std::string ErrorMessage;
 
-    std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename, &ErrorMessage));
+    std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename, 
+                                              Compressor::decompressToNewBuffer,
+                                              &ErrorMessage));
     if (M.get() == 0) {
       cerr << argv[0] << ": ";
       if (ErrorMessage.size())
index b26fd9c5b02e79657481ecaa442b0a2b3b0dd8ed..60a0134ef7b9afcac0889e9f66f6f71f88f4739d 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/Transforms/IPO.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Compressor.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/System/Signals.h"
@@ -57,7 +58,8 @@ int main(int argc, char **argv) {
     cl::ParseCommandLineOptions(argc, argv, " llvm extractor\n");
     sys::PrintStackTraceOnErrorSignal();
 
-    std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename));
+    std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename,
+                                            Compressor::decompressToNewBuffer));
     if (M.get() == 0) {
       cerr << argv[0] << ": bytecode didn't read correctly.\n";
       return 1;
index 343b36cefcd0a3f14e66ef7a2bdd60b7700ecf77..223475eed81f2139f2b86c93d12cbb5250703a6c 100644 (file)
@@ -59,7 +59,9 @@ static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
   std::string ErrorMessage;
   if (Filename.exists()) {
     if (Verbose) cerr << "Loading '" << Filename.c_str() << "'\n";
-    Module* Result = ParseBytecodeFile(Filename.toString(), &ErrorMessage);
+    Module* Result = ParseBytecodeFile(Filename.toString(), 
+                                       Compressor::decompressToNewBuffer,
+                                       &ErrorMessage);
     if (Result) return std::auto_ptr<Module>(Result);   // Load successful!
 
     if (Verbose) {
index 2d80f531edd7130e247783051e2253c36a727267..49f662d7453c46ab2bc93f362340f95c36f3f5d6 100644 (file)
@@ -127,7 +127,9 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
   }
   // Note: Currently we do not support reading an archive from stdin.
   if (Filename == "-" || aPath.isBytecodeFile()) {
-    Module *Result = ParseBytecodeFile(Filename, &ErrorMessage);
+    Module *Result = ParseBytecodeFile(Filename,
+                                       Compressor::decompressToNewBuffer,
+                                       &ErrorMessage);
     if (Result) {
       DumpSymbolNamesFromModule (Result);
     } else {
index 44bc6c5d864fdfd58532c10b760c6db8193783bb..b0767e6fdf3066b85fa36f8d99a7b925825ef3ad 100644 (file)
@@ -115,7 +115,9 @@ int main(int argc, char **argv) {
 
     // Read in the bytecode file...
     std::string ErrorMessage;
-    Module *M = ParseBytecodeFile(BytecodeFile, &ErrorMessage);
+    Module *M = ParseBytecodeFile(BytecodeFile, 
+                                  Compressor::decompressToNewBuffer, 
+                                  &ErrorMessage);
     if (M == 0) {
       std::cerr << argv[0] << ": " << BytecodeFile << ": " 
         << ErrorMessage << "\n";
index 01c8fbd0a51dbab9239f684a86ab848478bd29ae..fe9504e5673757a92e44051e9af2b4eb7a3dd54f 100644 (file)
@@ -49,7 +49,9 @@ int main(int argc, char **argv) {
   int exitCode = 0;
   std::ostream *Out = 0;
   std::string ErrorMessage;
-  std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename, &ErrorMessage));
+  std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename, 
+                                            Compressor::decompressToNewBuffer, 
+                                            &ErrorMessage));
   if (M.get() == 0) {
     std::cerr << argv[0] << ": ";
     if (ErrorMessage.size())
index 18aab21604b553d27145a48b014b060af963229f..055a4f4a32337906e505e509eb77a544c336ebae 100644 (file)
@@ -569,7 +569,9 @@ private:
     if (fullpath.isBytecodeFile()) {
       // Process the dependent libraries recursively
       Module::LibraryListType modlibs;
-      if (GetBytecodeDependentLibraries(fullpath.toString(),modlibs,&err)) {
+      if (GetBytecodeDependentLibraries(fullpath.toString(),modlibs,
+                                        Compressor::decompressToNewBuffer,
+                                        &err)) {
         // Traverse the dependent libraries list
         Module::lib_iterator LI = modlibs.begin();
         Module::lib_iterator LE = modlibs.end();
index 5294cac76b2aef60d73a33cf2d4d055e71cf94a9..24dab745c50dbba12b33faa6208a7609c4c6bfbf 100644 (file)
@@ -254,7 +254,8 @@ int main(int argc, char **argv) {
     std::string ErrorMessage;
 
     // Load the input module...
-    std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename, &ErrorMessage));
+    std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename, 
+                            Compressor::decompressToNewBuffer, &ErrorMessage));
     if (M.get() == 0) {
       cerr << argv[0] << ": ";
       if (ErrorMessage.size())