mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-03 13:31:05 +00:00
Move some code out of line. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185901 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
842b1bdd94
commit
5263d0aa6a
@ -14,11 +14,8 @@
|
|||||||
#ifndef LLVM_OBJECT_ARCHIVE_H
|
#ifndef LLVM_OBJECT_ARCHIVE_H
|
||||||
#define LLVM_OBJECT_ARCHIVE_H
|
#define LLVM_OBJECT_ARCHIVE_H
|
||||||
|
|
||||||
#include "llvm/ADT/SmallString.h"
|
|
||||||
#include "llvm/ADT/StringRef.h"
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include "llvm/ADT/Twine.h"
|
|
||||||
#include "llvm/Object/Binary.h"
|
#include "llvm/Object/Binary.h"
|
||||||
#include "llvm/Support/DataTypes.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
|
|
||||||
@ -33,28 +30,10 @@ struct ArchiveMemberHeader {
|
|||||||
char Size[10]; ///< Size of data, not including header or padding.
|
char Size[10]; ///< Size of data, not including header or padding.
|
||||||
char Terminator[2];
|
char Terminator[2];
|
||||||
|
|
||||||
///! Get the name without looking up long names.
|
/// Get the name without looking up long names.
|
||||||
llvm::StringRef getName() const {
|
llvm::StringRef getName() const;
|
||||||
char EndCond;
|
|
||||||
if (Name[0] == '/' || Name[0] == '#')
|
|
||||||
EndCond = ' ';
|
|
||||||
else
|
|
||||||
EndCond = '/';
|
|
||||||
llvm::StringRef::size_type end =
|
|
||||||
llvm::StringRef(Name, sizeof(Name)).find(EndCond);
|
|
||||||
if (end == llvm::StringRef::npos)
|
|
||||||
end = sizeof(Name);
|
|
||||||
assert(end <= sizeof(Name) && end > 0);
|
|
||||||
// Don't include the EndCond if there is one.
|
|
||||||
return llvm::StringRef(Name, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t getSize() const {
|
uint64_t getSize() const;
|
||||||
uint64_t ret;
|
|
||||||
if (llvm::StringRef(Size, sizeof(Size)).rtrim(" ").getAsInteger(10, ret))
|
|
||||||
llvm_unreachable("Size is not an integer.");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const ArchiveMemberHeader *ToHeader(const char *base) {
|
static const ArchiveMemberHeader *ToHeader(const char *base) {
|
||||||
@ -72,20 +51,7 @@ public:
|
|||||||
uint16_t StartOfFile;
|
uint16_t StartOfFile;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Child(const Archive *p, StringRef d) : Parent(p), Data(d) {
|
Child(const Archive *p, StringRef d);
|
||||||
if (!p || d.empty())
|
|
||||||
return;
|
|
||||||
// Setup StartOfFile and PaddingBytes.
|
|
||||||
StartOfFile = sizeof(ArchiveMemberHeader);
|
|
||||||
// Don't include attached name.
|
|
||||||
StringRef Name = ToHeader(Data.data())->getName();
|
|
||||||
if (Name.startswith("#1/")) {
|
|
||||||
uint64_t NameSize;
|
|
||||||
if (Name.substr(3).rtrim(" ").getAsInteger(10, NameSize))
|
|
||||||
llvm_unreachable("Long name length is not an integer");
|
|
||||||
StartOfFile += NameSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator ==(const Child &other) const {
|
bool operator ==(const Child &other) const {
|
||||||
return (Parent == other.Parent) && (Data.begin() == other.Data.begin());
|
return (Parent == other.Parent) && (Data.begin() == other.Data.begin());
|
||||||
@ -95,23 +61,7 @@ public:
|
|||||||
return Data.begin() < other.Data.begin();
|
return Data.begin() < other.Data.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
Child getNext() const {
|
Child getNext() const;
|
||||||
size_t SpaceToSkip = Data.size();
|
|
||||||
// If it's odd, add 1 to make it even.
|
|
||||||
if (SpaceToSkip & 1)
|
|
||||||
++SpaceToSkip;
|
|
||||||
|
|
||||||
const char *NextLoc = Data.data() + SpaceToSkip;
|
|
||||||
|
|
||||||
// Check to see if this is past the end of the archive.
|
|
||||||
if (NextLoc >= Parent->Data->getBufferEnd())
|
|
||||||
return Child(Parent, StringRef(0, 0));
|
|
||||||
|
|
||||||
size_t NextSize =
|
|
||||||
sizeof(ArchiveMemberHeader) + ToHeader(NextLoc)->getSize();
|
|
||||||
|
|
||||||
return Child(Parent, StringRef(NextLoc, NextSize));
|
|
||||||
}
|
|
||||||
|
|
||||||
error_code getName(StringRef &Result) const;
|
error_code getName(StringRef &Result) const;
|
||||||
StringRef getRawName() const { return ToHeader(Data.data())->getName(); }
|
StringRef getRawName() const { return ToHeader(Data.data())->getName(); }
|
||||||
@ -127,16 +77,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
error_code getMemoryBuffer(OwningPtr<MemoryBuffer> &Result,
|
error_code getMemoryBuffer(OwningPtr<MemoryBuffer> &Result,
|
||||||
bool FullPath = false) const {
|
bool FullPath = false) const;
|
||||||
StringRef Name;
|
|
||||||
if (error_code ec = getName(Name))
|
|
||||||
return ec;
|
|
||||||
SmallString<128> Path;
|
|
||||||
Result.reset(MemoryBuffer::getMemBuffer(
|
|
||||||
getBuffer(), FullPath ? (Twine(Parent->getFileName()) + "(" + Name +
|
|
||||||
")").toStringRef(Path) : Name, false));
|
|
||||||
return error_code::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
error_code getAsBinary(OwningPtr<Binary> &Result) const;
|
error_code getAsBinary(OwningPtr<Binary> &Result) const;
|
||||||
};
|
};
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
#include "llvm/Object/Archive.h"
|
#include "llvm/Object/Archive.h"
|
||||||
#include "llvm/ADT/APInt.h"
|
#include "llvm/ADT/APInt.h"
|
||||||
|
#include "llvm/ADT/SmallString.h"
|
||||||
|
#include "llvm/ADT/Twine.h"
|
||||||
#include "llvm/Support/Endian.h"
|
#include "llvm/Support/Endian.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
|
|
||||||
@ -37,6 +39,60 @@ static bool isInternalMember(const ArchiveMemberHeader &amh) {
|
|||||||
|
|
||||||
void Archive::anchor() { }
|
void Archive::anchor() { }
|
||||||
|
|
||||||
|
StringRef ArchiveMemberHeader::getName() const {
|
||||||
|
char EndCond;
|
||||||
|
if (Name[0] == '/' || Name[0] == '#')
|
||||||
|
EndCond = ' ';
|
||||||
|
else
|
||||||
|
EndCond = '/';
|
||||||
|
llvm::StringRef::size_type end =
|
||||||
|
llvm::StringRef(Name, sizeof(Name)).find(EndCond);
|
||||||
|
if (end == llvm::StringRef::npos)
|
||||||
|
end = sizeof(Name);
|
||||||
|
assert(end <= sizeof(Name) && end > 0);
|
||||||
|
// Don't include the EndCond if there is one.
|
||||||
|
return llvm::StringRef(Name, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t ArchiveMemberHeader::getSize() const {
|
||||||
|
uint64_t ret;
|
||||||
|
if (llvm::StringRef(Size, sizeof(Size)).rtrim(" ").getAsInteger(10, ret))
|
||||||
|
llvm_unreachable("Size is not an integer.");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
Archive::Child::Child(const Archive *p, StringRef d) : Parent(p), Data(d) {
|
||||||
|
if (!p || d.empty())
|
||||||
|
return;
|
||||||
|
// Setup StartOfFile and PaddingBytes.
|
||||||
|
StartOfFile = sizeof(ArchiveMemberHeader);
|
||||||
|
// Don't include attached name.
|
||||||
|
StringRef Name = ToHeader(Data.data())->getName();
|
||||||
|
if (Name.startswith("#1/")) {
|
||||||
|
uint64_t NameSize;
|
||||||
|
if (Name.substr(3).rtrim(" ").getAsInteger(10, NameSize))
|
||||||
|
llvm_unreachable("Long name length is not an integer");
|
||||||
|
StartOfFile += NameSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Archive::Child Archive::Child::getNext() const {
|
||||||
|
size_t SpaceToSkip = Data.size();
|
||||||
|
// If it's odd, add 1 to make it even.
|
||||||
|
if (SpaceToSkip & 1)
|
||||||
|
++SpaceToSkip;
|
||||||
|
|
||||||
|
const char *NextLoc = Data.data() + SpaceToSkip;
|
||||||
|
|
||||||
|
// Check to see if this is past the end of the archive.
|
||||||
|
if (NextLoc >= Parent->Data->getBufferEnd())
|
||||||
|
return Child(Parent, StringRef(0, 0));
|
||||||
|
|
||||||
|
size_t NextSize = sizeof(ArchiveMemberHeader) + ToHeader(NextLoc)->getSize();
|
||||||
|
|
||||||
|
return Child(Parent, StringRef(NextLoc, NextSize));
|
||||||
|
}
|
||||||
|
|
||||||
error_code Archive::Child::getName(StringRef &Result) const {
|
error_code Archive::Child::getName(StringRef &Result) const {
|
||||||
StringRef name = getRawName();
|
StringRef name = getRawName();
|
||||||
// Check if it's a special name.
|
// Check if it's a special name.
|
||||||
@ -89,6 +145,20 @@ error_code Archive::Child::getName(StringRef &Result) const {
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_code Archive::Child::getMemoryBuffer(OwningPtr<MemoryBuffer> &Result,
|
||||||
|
bool FullPath) const {
|
||||||
|
StringRef Name;
|
||||||
|
if (error_code ec = getName(Name))
|
||||||
|
return ec;
|
||||||
|
SmallString<128> Path;
|
||||||
|
Result.reset(MemoryBuffer::getMemBuffer(
|
||||||
|
getBuffer(), FullPath ? (Twine(Parent->getFileName()) + "(" + Name + ")")
|
||||||
|
.toStringRef(Path)
|
||||||
|
: Name,
|
||||||
|
false));
|
||||||
|
return error_code::success();
|
||||||
|
}
|
||||||
|
|
||||||
error_code Archive::Child::getAsBinary(OwningPtr<Binary> &Result) const {
|
error_code Archive::Child::getAsBinary(OwningPtr<Binary> &Result) const {
|
||||||
OwningPtr<Binary> ret;
|
OwningPtr<Binary> ret;
|
||||||
OwningPtr<MemoryBuffer> Buff;
|
OwningPtr<MemoryBuffer> Buff;
|
||||||
|
Loading…
Reference in New Issue
Block a user