summaryrefslogtreecommitdiff
path: root/lib/Archive
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-05-06 09:28:33 +0000
committerChris Lattner <sabre@nondot.org>2007-05-06 09:28:33 +0000
commitc1d5624d71f7534cfc1bd51b76ead9cea99d3e8d (patch)
tree25dfd54464e8e2231589e55b4edf5d416a947f03 /lib/Archive
parent4cbc5485e0ce158a81930fdf44b119ce7e129e13 (diff)
Switch this over to bitcode instead of bytecode.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36866 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Archive')
-rw-r--r--lib/Archive/Archive.cpp28
-rw-r--r--lib/Archive/ArchiveInternals.h5
-rw-r--r--lib/Archive/ArchiveReader.cpp61
-rw-r--r--lib/Archive/ArchiveWriter.cpp6
4 files changed, 40 insertions, 60 deletions
diff --git a/lib/Archive/Archive.cpp b/lib/Archive/Archive.cpp
index d594a8715f7..6fabc5c862f 100644
--- a/lib/Archive/Archive.cpp
+++ b/lib/Archive/Archive.cpp
@@ -13,9 +13,10 @@
//===----------------------------------------------------------------------===//
#include "ArchiveInternals.h"
+#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/ModuleProvider.h"
#include "llvm/Module.h"
-#include "llvm/Bytecode/Reader.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/System/Process.h"
using namespace llvm;
@@ -142,10 +143,9 @@ 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, BCDecompressor_t *BCDC)
+Archive::Archive(const sys::Path& filename)
: archPath(filename), members(), mapfile(0), base(0), symTab(), strtab(),
- symTabSize(0), firstFileOffset(0), modules(), foreignST(0),
- Decompressor(BCDC) {
+ symTabSize(0), firstFileOffset(0), modules(), foreignST(0) {
}
bool
@@ -213,9 +213,16 @@ 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(), BCDC,ErrMsg);
+ std::auto_ptr<MemoryBuffer> Buffer(
+ MemoryBuffer::getFileOrSTDIN(&fName.toString()[0],
+ fName.toString().size()));
+ if (!Buffer.get()) {
+ if (ErrMsg) *ErrMsg = "Could not open file '" + fName.toString() + "'";
+ return true;
+ }
+
+ ModuleProvider *MP = getBitcodeModuleProvider(Buffer.get(), ErrMsg);
if (!MP)
return true;
@@ -235,14 +242,15 @@ bool llvm::GetBytecodeSymbols(const sys::Path& fName,
}
ModuleProvider*
-llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
+llvm::GetBytecodeSymbols(const unsigned char *BufPtr, 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, BCDC, ErrMsg, 0);
+ MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(Length, ModuleID.c_str());
+ memcpy((char*)Buffer->getBufferStart(), BufPtr, Length);
+
+ ModuleProvider *MP = getBitcodeModuleProvider(Buffer, ErrMsg);
if (!MP)
return 0;
diff --git a/lib/Archive/ArchiveInternals.h b/lib/Archive/ArchiveInternals.h
index 7a918a96535..4642f7a30ab 100644
--- a/lib/Archive/ArchiveInternals.h
+++ b/lib/Archive/ArchiveInternals.h
@@ -14,7 +14,7 @@
#ifndef LIB_BYTECODE_ARCHIVEINTERNALS_H
#define LIB_BYTECODE_ARCHIVEINTERNALS_H
-#include "llvm/Bytecode/Archive.h"
+#include "llvm/Bitcode/Archive.h"
#include "llvm/System/TimeValue.h"
#include "llvm/ADT/StringExtras.h"
@@ -70,12 +70,11 @@ namespace llvm {
// Get just the externally visible defined symbols from the bytecode
bool GetBytecodeSymbols(const sys::Path& fName,
std::vector<std::string>& symbols,
- BCDecompressor_t *BCDC, std::string* ErrMsg);
+ std::string* ErrMsg);
ModuleProvider* GetBytecodeSymbols(const unsigned char*Buffer,unsigned Length,
const std::string& ModuleID,
std::vector<std::string>& symbols,
- BCDecompressor_t *BCDC,
std::string* ErrMsg);
}
diff --git a/lib/Archive/ArchiveReader.cpp b/lib/Archive/ArchiveReader.cpp
index 209db77ee00..c38389e2d7c 100644
--- a/lib/Archive/ArchiveReader.cpp
+++ b/lib/Archive/ArchiveReader.cpp
@@ -12,15 +12,12 @@
//===----------------------------------------------------------------------===//
#include "ArchiveInternals.h"
-#include "llvm/Bytecode/Reader.h"
#include "llvm/Bitcode/ReaderWriter.h"
-#include "llvm/Support/Compressor.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Module.h"
#include <memory>
using namespace llvm;
-static bool Bitcode = false;
-
/// Read a variable-bit-rate encoded unsigned integer
inline unsigned readInteger(const char*&At, const char*End){
unsigned Shift = 0;
@@ -355,21 +352,12 @@ Archive::getAllModules(std::vector<Module*>& Modules, std::string* ErrMessage) {
if (I->isBytecode() || I->isCompressedBytecode()) {
std::string FullMemberName = archPath.toString() +
"(" + I->getPath().toString() + ")";
- Module *M;
+ MemoryBuffer *Buffer =
+ MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
+ memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize());
- if (Bitcode) {
- MemoryBuffer *Buffer =
- MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
- memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize());
-
- M = ParseBitcodeFile(Buffer, ErrMessage);
- delete Buffer;
- } else {
- M = ParseBytecodeBuffer((const unsigned char*)I->getData(),
- I->getSize(), FullMemberName,
- Compressor::decompressToNewBuffer,
- ErrMessage);
- }
+ Module *M = ParseBitcodeFile(Buffer, ErrMessage);
+ delete Buffer;
if (!M)
return true;
@@ -502,17 +490,11 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
// Now, load the bytecode module to get the ModuleProvider
std::string FullMemberName = archPath.toString() + "(" +
mbr->getPath().toString() + ")";
- ModuleProvider* mp;
- if (Bitcode) {
- MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(mbr->getSize(),
- FullMemberName.c_str());
- memcpy((char*)Buffer->getBufferStart(), mbr->getData(), mbr->getSize());
-
- mp = getBitcodeModuleProvider(Buffer, ErrMsg);
- } else
- mp = getBytecodeBufferModuleProvider(
- (const unsigned char*) mbr->getData(), mbr->getSize(),
- FullMemberName, Decompressor, ErrMsg, 0);
+ MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(mbr->getSize(),
+ FullMemberName.c_str());
+ memcpy((char*)Buffer->getBufferStart(), mbr->getData(), mbr->getSize());
+
+ ModuleProvider *mp = getBitcodeModuleProvider(Buffer, ErrMsg);
if (!mp)
return 0;
@@ -560,8 +542,7 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
mbr->getPath().toString() + ")";
ModuleProvider* MP =
GetBytecodeSymbols((const unsigned char*)At, mbr->getSize(),
- FullMemberName, symbols,
- Compressor::decompressToNewBuffer, error);
+ FullMemberName, symbols, error);
if (MP) {
// Insert the module's symbols into the symbol table
@@ -636,18 +617,12 @@ bool Archive::isBytecodeArchive() {
std::string FullMemberName =
archPath.toString() + "(" + I->getPath().toString() + ")";
- Module *M;
-
- if (Bitcode) {
- MemoryBuffer *Buffer =
- MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
- memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize());
- M = ParseBitcodeFile(Buffer);
- delete Buffer;
- } else {
- M = ParseBytecodeBuffer((const unsigned char*)I->getData(),
- I->getSize(), FullMemberName);
- }
+
+ MemoryBuffer *Buffer =
+ MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
+ memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize());
+ Module *M = ParseBitcodeFile(Buffer);
+ delete Buffer;
if (!M)
return false; // Couldn't parse bytecode, not a bytecode archive.
delete M;
diff --git a/lib/Archive/ArchiveWriter.cpp b/lib/Archive/ArchiveWriter.cpp
index f08526ce824..051d31fce95 100644
--- a/lib/Archive/ArchiveWriter.cpp
+++ b/lib/Archive/ArchiveWriter.cpp
@@ -12,11 +12,10 @@
//===----------------------------------------------------------------------===//
#include "ArchiveInternals.h"
-#include "llvm/Bytecode/Reader.h"
#include "llvm/Bitcode/ReaderWriter.h"
-#include "llvm/Support/Compressor.h"
#include "llvm/System/Signals.h"
#include "llvm/System/Process.h"
+#include "llvm/ModuleProvider.h"
#include <fstream>
#include <ostream>
#include <iomanip>
@@ -232,8 +231,7 @@ Archive::writeMember(
+ ")";
ModuleProvider* MP =
GetBytecodeSymbols((const unsigned char*)data,fSize,
- FullMemberName, symbols,
- Compressor::decompressToNewBuffer, ErrMsg);
+ FullMemberName, symbols, ErrMsg);
// If the bytecode parsed successfully
if ( MP ) {