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

@@ -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