projects
/
oota-llvm.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Minor reorg.
[oota-llvm.git]
/
lib
/
Archive
/
ArchiveReader.cpp
diff --git
a/lib/Archive/ArchiveReader.cpp
b/lib/Archive/ArchiveReader.cpp
index c38389e2d7c08ef8753546051aaf8e8af72653df..b07e884b654796f0e01c72104eabaf917193d15d 100644
(file)
--- a/
lib/Archive/ArchiveReader.cpp
+++ b/
lib/Archive/ArchiveReader.cpp
@@
-2,12
+2,12
@@
//
// The LLVM Compiler Infrastructure
//
//
// The LLVM Compiler Infrastructure
//
-// This file
was developed by Reid Spencer and is distributed under th
e
-//
University of Illinois Open Source
License. See LICENSE.TXT for details.
+// This file
is distributed under the University of Illinois Open Sourc
e
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//
//
-// Builds up standard unix archive files (.a) containing LLVM b
yte
code.
+// Builds up standard unix archive files (.a) containing LLVM b
it
code.
//
//===----------------------------------------------------------------------===//
//
//===----------------------------------------------------------------------===//
@@
-15,11
+15,12
@@
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Module.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Module.h"
+#include <cstdlib>
#include <memory>
using namespace llvm;
/// Read a variable-bit-rate encoded unsigned integer
#include <memory>
using namespace llvm;
/// Read a variable-bit-rate encoded unsigned integer
-
inline unsigned readInteger(const char*&At, const char*End)
{
+
static inline unsigned readInteger(const char*&At, const char*End)
{
unsigned Shift = 0;
unsigned Result = 0;
unsigned Shift = 0;
unsigned Result = 0;
@@
-109,7
+110,7
@@
Archive::parseMemberHeader(const char*& At, const char* End, std::string* error)
// it will accept them. If the name starts with #1/ and the remainder is
// digits, then those digits specify the length of the name that is
// stored immediately following the header. The special name
// it will accept them. If the name starts with #1/ and the remainder is
// digits, then those digits specify the length of the name that is
// stored immediately following the header. The special name
- // __LLVM_SYM_TAB__ identifies the symbol table for LLVM b
yte
code.
+ // __LLVM_SYM_TAB__ identifies the symbol table for LLVM b
it
code.
// Anything else is a regular, short filename that is terminated with
// a '/' and blanks.
// Anything else is a regular, short filename that is terminated with
// a '/' and blanks.
@@
-204,19
+205,13
@@
Archive::parseMemberHeader(const char*& At, const char* End, std::string* error)
break;
}
break;
}
- // Determine if this is a b
yte
code file
+ // Determine if this is a b
it
code file
switch (sys::IdentifyFileType(At, 4)) {
case sys::Bitcode_FileType:
switch (sys::IdentifyFileType(At, 4)) {
case sys::Bitcode_FileType:
- case sys::Bytecode_FileType:
- flags |= ArchiveMember::BytecodeFlag;
- break;
- case sys::CompressedBytecode_FileType:
- flags |= ArchiveMember::CompressedBytecodeFlag;
- flags &= ~ArchiveMember::CompressedFlag;
+ flags |= ArchiveMember::BitcodeFlag;
break;
default:
break;
default:
- flags &= ~(ArchiveMember::BytecodeFlag|
- ArchiveMember::CompressedBytecodeFlag);
+ flags &= ~ArchiveMember::BitcodeFlag;
break;
}
break;
}
@@
-224,8
+219,6
@@
Archive::parseMemberHeader(const char*& At, const char* End, std::string* error)
ArchiveMember* member = new ArchiveMember(this);
// Fill in fields of the ArchiveMember
ArchiveMember* member = new ArchiveMember(this);
// Fill in fields of the ArchiveMember
- member->next = 0;
- member->prev = 0;
member->parent = this;
member->path.set(pathname);
member->info.fileSize = MemberSize;
member->parent = this;
member->path.set(pathname);
member->info.fileSize = MemberSize;
@@
-244,7
+237,7
@@
Archive::parseMemberHeader(const char*& At, const char* End, std::string* error)
bool
Archive::checkSignature(std::string* error) {
// Check the magic string at file's header
bool
Archive::checkSignature(std::string* error) {
// Check the magic string at file's header
- if (mapfile->
s
ize() < 8 || memcmp(base, ARFILE_MAGIC, 8)) {
+ if (mapfile->
getBufferS
ize() < 8 || memcmp(base, ARFILE_MAGIC, 8)) {
if (error)
*error = "invalid signature for an archive file";
return false;
if (error)
*error = "invalid signature for an archive file";
return false;
@@
-262,7
+255,7
@@
Archive::loadArchive(std::string* error) {
members.clear();
symTab.clear();
const char *At = base;
members.clear();
symTab.clear();
const char *At = base;
- const char *End =
base + mapfile->size
();
+ const char *End =
mapfile->getBufferEnd
();
if (!checkSignature(error))
return false;
if (!checkSignature(error))
return false;
@@
-344,12
+337,12
@@
Archive::OpenAndLoad(const sys::Path& file, std::string* ErrorMessage)
return result.release();
}
return result.release();
}
-// Get all the b
yte
code modules from the archive
+// Get all the b
it
code modules from the archive
bool
Archive::getAllModules(std::vector<Module*>& Modules, std::string* ErrMessage) {
for (iterator I=begin(), E=end(); I != E; ++I) {
bool
Archive::getAllModules(std::vector<Module*>& Modules, std::string* ErrMessage) {
for (iterator I=begin(), E=end(); I != E; ++I) {
- if (I->isB
ytecode() || I->isCompressedByte
code()) {
+ if (I->isB
it
code()) {
std::string FullMemberName = archPath.toString() +
"(" + I->getPath().toString() + ")";
MemoryBuffer *Buffer =
std::string FullMemberName = archPath.toString() +
"(" + I->getPath().toString() + ")";
MemoryBuffer *Buffer =
@@
-375,7
+368,7
@@
Archive::loadSymbolTable(std::string* ErrorMsg) {
members.clear();
symTab.clear();
const char *At = base;
members.clear();
symTab.clear();
const char *At = base;
- const char *End =
base + mapfile->size
();
+ const char *End =
mapfile->getBufferEnd
();
// Make sure we're dealing with an archive
if (!checkSignature(ErrorMsg))
// Make sure we're dealing with an archive
if (!checkSignature(ErrorMsg))
@@
-483,11
+476,12
@@
Archive::findModuleDefiningSymbol(const std::string& symbol,
// Module hasn't been loaded yet, we need to load it
const char* modptr = base + fileOffset;
// Module hasn't been loaded yet, we need to load it
const char* modptr = base + fileOffset;
- ArchiveMember* mbr = parseMemberHeader(modptr, base + mapfile->size(),ErrMsg);
+ ArchiveMember* mbr = parseMemberHeader(modptr, mapfile->getBufferEnd(),
+ ErrMsg);
if (!mbr)
return 0;
if (!mbr)
return 0;
- // Now, load the b
yte
code module to get the ModuleProvider
+ // Now, load the b
it
code module to get the ModuleProvider
std::string FullMemberName = archPath.toString() + "(" +
mbr->getPath().toString() + ")";
MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(mbr->getSize(),
std::string FullMemberName = archPath.toString() + "(" +
mbr->getPath().toString() + ")";
MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(mbr->getSize(),
@@
-522,8
+516,8
@@
Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
// below.
// Get a pointer to the first file
// below.
// Get a pointer to the first file
- const char* At =
((const char*)base)
+ firstFileOffset;
- const char* End =
((const char*)base) + mapfile->size
();
+ const char* At =
base
+ firstFileOffset;
+ const char* End =
mapfile->getBufferEnd
();
while ( At < End) {
// Compute the offset to be put in the symbol table
while ( At < End) {
// Compute the offset to be put in the symbol table
@@
-535,14
+529,14
@@
Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
return false;
// If it contains symbols
return false;
// If it contains symbols
- if (mbr->isB
ytecode() || mbr->isCompressedByte
code()) {
+ if (mbr->isB
it
code()) {
// Get the symbols
std::vector<std::string> symbols;
std::string FullMemberName = archPath.toString() + "(" +
mbr->getPath().toString() + ")";
ModuleProvider* MP =
// Get the symbols
std::vector<std::string> symbols;
std::string FullMemberName = archPath.toString() + "(" +
mbr->getPath().toString() + ")";
ModuleProvider* MP =
- GetB
yte
codeSymbols((const unsigned char*)At, mbr->getSize(),
-
FullMemberName, symbols, error);
+ GetB
it
codeSymbols((const unsigned char*)At, mbr->getSize(),
+ FullMemberName, symbols, error);
if (MP) {
// Insert the module's symbols into the symbol table
if (MP) {
// Insert the module's symbols into the symbol table
@@
-555,7
+549,7
@@
Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
modules.insert(std::make_pair(offset, std::make_pair(MP, mbr)));
} else {
if (error)
modules.insert(std::make_pair(offset, std::make_pair(MP, mbr)));
} else {
if (error)
- *error = "Can't parse b
yte
code member: " +
+ *error = "Can't parse b
it
code member: " +
mbr->getPath().toString() + ": " + *error;
delete mbr;
return false;
mbr->getPath().toString() + ": " + *error;
delete mbr;
return false;
@@
-591,10
+585,10
@@
Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
return true;
}
return true;
}
-bool Archive::isB
yte
codeArchive() {
+bool Archive::isB
it
codeArchive() {
// Make sure the symTab has been loaded. In most cases this should have been
// done when the archive was constructed, but still, this is just in case.
// Make sure the symTab has been loaded. In most cases this should have been
// done when the archive was constructed, but still, this is just in case.
- if (
!symTab.size
())
+ if (
symTab.empty
())
if (!loadSymbolTable(0))
return false;
if (!loadSymbolTable(0))
return false;
@@
-602,17
+596,17
@@
bool Archive::isBytecodeArchive() {
// if it has a size
if (symTab.size()) return true;
// if it has a size
if (symTab.size()) return true;
- //
We still can't be sure it isn't a byte
code archive
+ //
We still can't be sure it isn't a bit
code archive
if (!loadArchive(0))
return false;
std::vector<Module *> Modules;
std::string ErrorMessage;
if (!loadArchive(0))
return false;
std::vector<Module *> Modules;
std::string ErrorMessage;
- // Scan the archive, trying to load a b
yte
code member. We only load one to
+ // Scan the archive, trying to load a b
it
code member. We only load one to
// see if this works.
for (iterator I = begin(), E = end(); I != E; ++I) {
// see if this works.
for (iterator I = begin(), E = end(); I != E; ++I) {
- if (!I->isB
ytecode() && !I->isCompressedByte
code())
+ if (!I->isB
it
code())
continue;
std::string FullMemberName =
continue;
std::string FullMemberName =
@@
-624,7
+618,7
@@
bool Archive::isBytecodeArchive() {
Module *M = ParseBitcodeFile(Buffer);
delete Buffer;
if (!M)
Module *M = ParseBitcodeFile(Buffer);
delete Buffer;
if (!M)
- return false; // Couldn't parse b
ytecode, not a byte
code archive.
+ return false; // Couldn't parse b
itcode, not a bit
code archive.
delete M;
return true;
}
delete M;
return true;
}