push bytecode decompressor out through APIs. Now the bytecode reader

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
This commit is contained in:
Chris Lattner
2007-02-07 21:41:02 +00:00
parent 403e4a4725
commit f2e292ce58
25 changed files with 140 additions and 106 deletions

View File

@@ -20,9 +20,10 @@
#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.

View 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
/// @{

View File

@@ -19,16 +19,18 @@
#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
);