mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
Reformat.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190064 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
67990fa3ba
commit
5b9544b526
@ -26,25 +26,30 @@ using namespace llvm;
|
||||
|
||||
const char *DwarfAccelTable::Atom::AtomTypeString(enum AtomType AT) {
|
||||
switch (AT) {
|
||||
case eAtomTypeNULL: return "eAtomTypeNULL";
|
||||
case eAtomTypeDIEOffset: return "eAtomTypeDIEOffset";
|
||||
case eAtomTypeCUOffset: return "eAtomTypeCUOffset";
|
||||
case eAtomTypeTag: return "eAtomTypeTag";
|
||||
case eAtomTypeNameFlags: return "eAtomTypeNameFlags";
|
||||
case eAtomTypeTypeFlags: return "eAtomTypeTypeFlags";
|
||||
case eAtomTypeNULL:
|
||||
return "eAtomTypeNULL";
|
||||
case eAtomTypeDIEOffset:
|
||||
return "eAtomTypeDIEOffset";
|
||||
case eAtomTypeCUOffset:
|
||||
return "eAtomTypeCUOffset";
|
||||
case eAtomTypeTag:
|
||||
return "eAtomTypeTag";
|
||||
case eAtomTypeNameFlags:
|
||||
return "eAtomTypeNameFlags";
|
||||
case eAtomTypeTypeFlags:
|
||||
return "eAtomTypeTypeFlags";
|
||||
}
|
||||
llvm_unreachable("invalid AtomType!");
|
||||
}
|
||||
|
||||
// The length of the header data is always going to be 4 + 4 + 4*NumAtoms.
|
||||
DwarfAccelTable::DwarfAccelTable(ArrayRef<DwarfAccelTable::Atom> atomList) :
|
||||
Header(8 + (atomList.size() * 4)),
|
||||
HeaderData(atomList),
|
||||
Entries(Allocator) { }
|
||||
DwarfAccelTable::DwarfAccelTable(ArrayRef<DwarfAccelTable::Atom> atomList)
|
||||
: Header(8 + (atomList.size() * 4)), HeaderData(atomList),
|
||||
Entries(Allocator) {}
|
||||
|
||||
DwarfAccelTable::~DwarfAccelTable() { }
|
||||
DwarfAccelTable::~DwarfAccelTable() {}
|
||||
|
||||
void DwarfAccelTable::AddName(StringRef Name, DIE* die, char Flags) {
|
||||
void DwarfAccelTable::AddName(StringRef Name, DIE *die, char Flags) {
|
||||
assert(Data.empty() && "Already finalized!");
|
||||
// If the string is in the list already then add this die to the list
|
||||
// otherwise add a new one.
|
||||
@ -59,13 +64,16 @@ void DwarfAccelTable::ComputeBucketCount(void) {
|
||||
uniques[i] = Data[i]->HashValue;
|
||||
array_pod_sort(uniques.begin(), uniques.end());
|
||||
std::vector<uint32_t>::iterator p =
|
||||
std::unique(uniques.begin(), uniques.end());
|
||||
std::unique(uniques.begin(), uniques.end());
|
||||
uint32_t num = std::distance(uniques.begin(), p);
|
||||
|
||||
// Then compute the bucket size, minimum of 1 bucket.
|
||||
if (num > 1024) Header.bucket_count = num/4;
|
||||
if (num > 16) Header.bucket_count = num/2;
|
||||
else Header.bucket_count = num > 0 ? num : 1;
|
||||
if (num > 1024)
|
||||
Header.bucket_count = num / 4;
|
||||
if (num > 16)
|
||||
Header.bucket_count = num / 2;
|
||||
else
|
||||
Header.bucket_count = num > 0 ? num : 1;
|
||||
|
||||
Header.hashes_count = num;
|
||||
}
|
||||
@ -78,13 +86,13 @@ static bool compareDIEs(const DwarfAccelTable::HashDataContents *A,
|
||||
|
||||
void DwarfAccelTable::FinalizeTable(AsmPrinter *Asm, StringRef Prefix) {
|
||||
// Create the individual hash data outputs.
|
||||
for (StringMap<DataArray>::iterator
|
||||
EI = Entries.begin(), EE = Entries.end(); EI != EE; ++EI) {
|
||||
for (StringMap<DataArray>::iterator EI = Entries.begin(), EE = Entries.end();
|
||||
EI != EE; ++EI) {
|
||||
|
||||
// Unique the entries.
|
||||
std::stable_sort(EI->second.begin(), EI->second.end(), compareDIEs);
|
||||
EI->second.erase(std::unique(EI->second.begin(), EI->second.end()),
|
||||
EI->second.end());
|
||||
EI->second.end());
|
||||
|
||||
HashData *Entry = new (Allocator) HashData(EI->getKey(), EI->second);
|
||||
Data.push_back(Entry);
|
||||
@ -152,7 +160,8 @@ void DwarfAccelTable::EmitBuckets(AsmPrinter *Asm) {
|
||||
void DwarfAccelTable::EmitHashes(AsmPrinter *Asm) {
|
||||
for (size_t i = 0, e = Buckets.size(); i < e; ++i) {
|
||||
for (HashList::const_iterator HI = Buckets[i].begin(),
|
||||
HE = Buckets[i].end(); HI != HE; ++HI) {
|
||||
HE = Buckets[i].end();
|
||||
HI != HE; ++HI) {
|
||||
Asm->OutStreamer.AddComment("Hash in Bucket " + Twine(i));
|
||||
Asm->EmitInt32((*HI)->HashValue);
|
||||
}
|
||||
@ -166,13 +175,13 @@ void DwarfAccelTable::EmitHashes(AsmPrinter *Asm) {
|
||||
void DwarfAccelTable::EmitOffsets(AsmPrinter *Asm, MCSymbol *SecBegin) {
|
||||
for (size_t i = 0, e = Buckets.size(); i < e; ++i) {
|
||||
for (HashList::const_iterator HI = Buckets[i].begin(),
|
||||
HE = Buckets[i].end(); HI != HE; ++HI) {
|
||||
HE = Buckets[i].end();
|
||||
HI != HE; ++HI) {
|
||||
Asm->OutStreamer.AddComment("Offset in Bucket " + Twine(i));
|
||||
MCContext &Context = Asm->OutStreamer.getContext();
|
||||
const MCExpr *Sub =
|
||||
MCBinaryExpr::CreateSub(MCSymbolRefExpr::Create((*HI)->Sym, Context),
|
||||
MCSymbolRefExpr::Create(SecBegin, Context),
|
||||
Context);
|
||||
const MCExpr *Sub = MCBinaryExpr::CreateSub(
|
||||
MCSymbolRefExpr::Create((*HI)->Sym, Context),
|
||||
MCSymbolRefExpr::Create(SecBegin, Context), Context);
|
||||
Asm->OutStreamer.EmitValue(Sub, sizeof(uint32_t));
|
||||
}
|
||||
}
|
||||
@ -185,7 +194,8 @@ void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfUnits *D) {
|
||||
uint64_t PrevHash = UINT64_MAX;
|
||||
for (size_t i = 0, e = Buckets.size(); i < e; ++i) {
|
||||
for (HashList::const_iterator HI = Buckets[i].begin(),
|
||||
HE = Buckets[i].end(); HI != HE; ++HI) {
|
||||
HE = Buckets[i].end();
|
||||
HI != HE; ++HI) {
|
||||
// Remember to emit the label for our offset.
|
||||
Asm->OutStreamer.EmitLabel((*HI)->Sym);
|
||||
Asm->OutStreamer.AddComment((*HI)->Str);
|
||||
@ -193,8 +203,9 @@ void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfUnits *D) {
|
||||
D->getStringPoolSym());
|
||||
Asm->OutStreamer.AddComment("Num DIEs");
|
||||
Asm->EmitInt32((*HI)->Data.size());
|
||||
for (ArrayRef<HashDataContents*>::const_iterator
|
||||
DI = (*HI)->Data.begin(), DE = (*HI)->Data.end();
|
||||
for (ArrayRef<HashDataContents *>::const_iterator
|
||||
DI = (*HI)->Data.begin(),
|
||||
DE = (*HI)->Data.end();
|
||||
DI != DE; ++DI) {
|
||||
// Emit the DIE offset
|
||||
Asm->EmitInt32((*DI)->Die->getOffset());
|
||||
@ -214,8 +225,7 @@ void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfUnits *D) {
|
||||
}
|
||||
|
||||
// Emit the entire data structure to the output file.
|
||||
void DwarfAccelTable::Emit(AsmPrinter *Asm, MCSymbol *SecBegin,
|
||||
DwarfUnits *D) {
|
||||
void DwarfAccelTable::Emit(AsmPrinter *Asm, MCSymbol *SecBegin, DwarfUnits *D) {
|
||||
// Emit the header.
|
||||
EmitHeader(Asm);
|
||||
|
||||
@ -239,11 +249,12 @@ void DwarfAccelTable::print(raw_ostream &O) {
|
||||
HeaderData.print(O);
|
||||
|
||||
O << "Entries: \n";
|
||||
for (StringMap<DataArray>::const_iterator
|
||||
EI = Entries.begin(), EE = Entries.end(); EI != EE; ++EI) {
|
||||
for (StringMap<DataArray>::const_iterator EI = Entries.begin(),
|
||||
EE = Entries.end();
|
||||
EI != EE; ++EI) {
|
||||
O << "Name: " << EI->getKeyData() << "\n";
|
||||
for (DataArray::const_iterator DI = EI->second.begin(),
|
||||
DE = EI->second.end();
|
||||
DE = EI->second.end();
|
||||
DI != DE; ++DI)
|
||||
(*DI)->print(O);
|
||||
}
|
||||
@ -251,14 +262,14 @@ void DwarfAccelTable::print(raw_ostream &O) {
|
||||
O << "Buckets and Hashes: \n";
|
||||
for (size_t i = 0, e = Buckets.size(); i < e; ++i)
|
||||
for (HashList::const_iterator HI = Buckets[i].begin(),
|
||||
HE = Buckets[i].end(); HI != HE; ++HI)
|
||||
HE = Buckets[i].end();
|
||||
HI != HE; ++HI)
|
||||
(*HI)->print(O);
|
||||
|
||||
O << "Data: \n";
|
||||
for (std::vector<HashData*>::const_iterator
|
||||
DI = Data.begin(), DE = Data.end(); DI != DE; ++DI)
|
||||
(*DI)->print(O);
|
||||
|
||||
|
||||
for (std::vector<HashData *>::const_iterator DI = Data.begin(),
|
||||
DE = Data.end();
|
||||
DI != DE; ++DI)
|
||||
(*DI)->print(O);
|
||||
}
|
||||
#endif
|
||||
|
@ -71,7 +71,7 @@ class DwarfAccelTable {
|
||||
eHashFunctionDJB = 0u
|
||||
};
|
||||
|
||||
static uint32_t HashDJB (StringRef Str) {
|
||||
static uint32_t HashDJB(StringRef Str) {
|
||||
uint32_t h = 5381;
|
||||
for (unsigned i = 0, e = Str.size(); i != e; ++i)
|
||||
h = ((h << 5) + h) + Str[i];
|
||||
@ -80,25 +80,24 @@ class DwarfAccelTable {
|
||||
|
||||
// Helper function to compute the number of buckets needed based on
|
||||
// the number of unique hashes.
|
||||
void ComputeBucketCount (void);
|
||||
void ComputeBucketCount(void);
|
||||
|
||||
struct TableHeader {
|
||||
uint32_t magic; // 'HASH' magic value to allow endian detection
|
||||
uint16_t version; // Version number.
|
||||
uint16_t hash_function; // The hash function enumeration that was used.
|
||||
uint32_t bucket_count; // The number of buckets in this hash table.
|
||||
uint32_t hashes_count; // The total number of unique hash values
|
||||
// and hash data offsets in this table.
|
||||
uint32_t header_data_len; // The bytes to skip to get to the hash
|
||||
// indexes (buckets) for correct alignment.
|
||||
uint32_t magic; // 'HASH' magic value to allow endian detection
|
||||
uint16_t version; // Version number.
|
||||
uint16_t hash_function; // The hash function enumeration that was used.
|
||||
uint32_t bucket_count; // The number of buckets in this hash table.
|
||||
uint32_t hashes_count; // The total number of unique hash values
|
||||
// and hash data offsets in this table.
|
||||
uint32_t header_data_len; // The bytes to skip to get to the hash
|
||||
// indexes (buckets) for correct alignment.
|
||||
// Also written to disk is the implementation specific header data.
|
||||
|
||||
static const uint32_t MagicHash = 0x48415348;
|
||||
|
||||
TableHeader (uint32_t data_len) :
|
||||
magic (MagicHash), version (1), hash_function (eHashFunctionDJB),
|
||||
bucket_count (0), hashes_count (0), header_data_len (data_len)
|
||||
{}
|
||||
TableHeader(uint32_t data_len)
|
||||
: magic(MagicHash), version(1), hash_function(eHashFunctionDJB),
|
||||
bucket_count(0), hashes_count(0), header_data_len(data_len) {}
|
||||
|
||||
#ifndef NDEBUG
|
||||
void print(raw_ostream &O) {
|
||||
@ -125,15 +124,15 @@ public:
|
||||
// uint32_t atom_count
|
||||
// atom_count Atoms
|
||||
enum AtomType {
|
||||
eAtomTypeNULL = 0u,
|
||||
eAtomTypeDIEOffset = 1u, // DIE offset, check form for encoding
|
||||
eAtomTypeCUOffset = 2u, // DIE offset of the compiler unit header that
|
||||
// contains the item in question
|
||||
eAtomTypeTag = 3u, // DW_TAG_xxx value, should be encoded as
|
||||
// DW_FORM_data1 (if no tags exceed 255) or
|
||||
// DW_FORM_data2.
|
||||
eAtomTypeNameFlags = 4u, // Flags from enum NameFlags
|
||||
eAtomTypeTypeFlags = 5u // Flags from enum TypeFlags
|
||||
eAtomTypeNULL = 0u,
|
||||
eAtomTypeDIEOffset = 1u, // DIE offset, check form for encoding
|
||||
eAtomTypeCUOffset = 2u, // DIE offset of the compiler unit header that
|
||||
// contains the item in question
|
||||
eAtomTypeTag = 3u, // DW_TAG_xxx value, should be encoded as
|
||||
// DW_FORM_data1 (if no tags exceed 255) or
|
||||
// DW_FORM_data2.
|
||||
eAtomTypeNameFlags = 4u, // Flags from enum NameFlags
|
||||
eAtomTypeTypeFlags = 5u // Flags from enum TypeFlags
|
||||
};
|
||||
|
||||
enum TypeFlags {
|
||||
@ -141,7 +140,7 @@ public:
|
||||
|
||||
// Always set for C++, only set for ObjC if this is the
|
||||
// @implementation for a class.
|
||||
eTypeFlagClassIsImplementation = ( 1u << 1 )
|
||||
eTypeFlagClassIsImplementation = (1u << 1)
|
||||
};
|
||||
|
||||
// Make these public so that they can be used as a general interface to
|
||||
@ -151,35 +150,31 @@ public:
|
||||
uint16_t form; // DWARF DW_FORM_ defines
|
||||
|
||||
Atom(AtomType type, uint16_t form) : type(type), form(form) {}
|
||||
static const char * AtomTypeString(enum AtomType);
|
||||
static const char *AtomTypeString(enum AtomType);
|
||||
#ifndef NDEBUG
|
||||
void print(raw_ostream &O) {
|
||||
O << "Type: " << AtomTypeString(type) << "\n"
|
||||
<< "Form: " << dwarf::FormEncodingString(form) << "\n";
|
||||
}
|
||||
void dump() {
|
||||
print(dbgs());
|
||||
}
|
||||
void dump() { print(dbgs()); }
|
||||
#endif
|
||||
};
|
||||
|
||||
private:
|
||||
private:
|
||||
struct TableHeaderData {
|
||||
uint32_t die_offset_base;
|
||||
SmallVector<Atom, 1> Atoms;
|
||||
|
||||
TableHeaderData(ArrayRef<Atom> AtomList, uint32_t offset = 0)
|
||||
: die_offset_base(offset), Atoms(AtomList.begin(), AtomList.end()) { }
|
||||
: die_offset_base(offset), Atoms(AtomList.begin(), AtomList.end()) {}
|
||||
|
||||
#ifndef NDEBUG
|
||||
void print (raw_ostream &O) {
|
||||
void print(raw_ostream &O) {
|
||||
O << "die_offset_base: " << die_offset_base << "\n";
|
||||
for (size_t i = 0; i < Atoms.size(); i++)
|
||||
Atoms[i].print(O);
|
||||
}
|
||||
void dump() {
|
||||
print(dbgs());
|
||||
}
|
||||
void dump() { print(dbgs()); }
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -193,37 +188,38 @@ public:
|
||||
// HashData[hash_data_count]
|
||||
public:
|
||||
struct HashDataContents {
|
||||
DIE *Die; // Offsets
|
||||
DIE *Die; // Offsets
|
||||
char Flags; // Specific flags to output
|
||||
|
||||
HashDataContents(DIE *D, char Flags) :
|
||||
Die(D),
|
||||
Flags(Flags) { }
|
||||
#ifndef NDEBUG
|
||||
HashDataContents(DIE *D, char Flags) : Die(D), Flags(Flags) {}
|
||||
#ifndef NDEBUG
|
||||
void print(raw_ostream &O) const {
|
||||
O << " Offset: " << Die->getOffset() << "\n";
|
||||
O << " Tag: " << dwarf::TagString(Die->getTag()) << "\n";
|
||||
O << " Flags: " << Flags << "\n";
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
private:
|
||||
struct HashData {
|
||||
StringRef Str;
|
||||
uint32_t HashValue;
|
||||
MCSymbol *Sym;
|
||||
ArrayRef<HashDataContents*> Data; // offsets
|
||||
HashData(StringRef S, ArrayRef<HashDataContents*> Data)
|
||||
: Str(S), Data(Data) {
|
||||
ArrayRef<HashDataContents *> Data; // offsets
|
||||
HashData(StringRef S, ArrayRef<HashDataContents *> Data)
|
||||
: Str(S), Data(Data) {
|
||||
HashValue = DwarfAccelTable::HashDJB(S);
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
#ifndef NDEBUG
|
||||
void print(raw_ostream &O) {
|
||||
O << "Name: " << Str << "\n";
|
||||
O << " Hash Value: " << format("0x%x", HashValue) << "\n";
|
||||
O << " Symbol: " ;
|
||||
if (Sym) Sym->print(O);
|
||||
else O << "<none>";
|
||||
O << " Symbol: ";
|
||||
if (Sym)
|
||||
Sym->print(O);
|
||||
else
|
||||
O << "<none>";
|
||||
O << "\n";
|
||||
for (size_t i = 0; i < Data.size(); i++) {
|
||||
O << " Offset: " << Data[i]->Die->getOffset() << "\n";
|
||||
@ -231,14 +227,12 @@ private:
|
||||
O << " Flags: " << Data[i]->Flags << "\n";
|
||||
}
|
||||
}
|
||||
void dump() {
|
||||
print(dbgs());
|
||||
}
|
||||
#endif
|
||||
void dump() { print(dbgs()); }
|
||||
#endif
|
||||
};
|
||||
|
||||
DwarfAccelTable(const DwarfAccelTable&) LLVM_DELETED_FUNCTION;
|
||||
void operator=(const DwarfAccelTable&) LLVM_DELETED_FUNCTION;
|
||||
DwarfAccelTable(const DwarfAccelTable &) LLVM_DELETED_FUNCTION;
|
||||
void operator=(const DwarfAccelTable &) LLVM_DELETED_FUNCTION;
|
||||
|
||||
// Internal Functions
|
||||
void EmitHeader(AsmPrinter *);
|
||||
@ -253,24 +247,24 @@ private:
|
||||
// Output Variables
|
||||
TableHeader Header;
|
||||
TableHeaderData HeaderData;
|
||||
std::vector<HashData*> Data;
|
||||
std::vector<HashData *> Data;
|
||||
|
||||
// String Data
|
||||
typedef std::vector<HashDataContents*> DataArray;
|
||||
typedef StringMap<DataArray, BumpPtrAllocator&> StringEntries;
|
||||
typedef std::vector<HashDataContents *> DataArray;
|
||||
typedef StringMap<DataArray, BumpPtrAllocator &> StringEntries;
|
||||
StringEntries Entries;
|
||||
|
||||
// Buckets/Hashes/Offsets
|
||||
typedef std::vector<HashData*> HashList;
|
||||
typedef std::vector<HashData *> HashList;
|
||||
typedef std::vector<HashList> BucketList;
|
||||
BucketList Buckets;
|
||||
HashList Hashes;
|
||||
|
||||
// Public Implementation
|
||||
public:
|
||||
public:
|
||||
DwarfAccelTable(ArrayRef<DwarfAccelTable::Atom>);
|
||||
~DwarfAccelTable();
|
||||
void AddName(StringRef, DIE*, char = 0);
|
||||
void AddName(StringRef, DIE *, char = 0);
|
||||
void FinalizeTable(AsmPrinter *, StringRef);
|
||||
void Emit(AsmPrinter *, MCSymbol *, DwarfUnits *);
|
||||
#ifndef NDEBUG
|
||||
@ -278,6 +272,5 @@ private:
|
||||
void dump() { print(dbgs()); }
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user