mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-11 11:34:02 +00:00
[DWARF parser] Cleanup code in DWARFDebugAbbrev.
No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207274 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d761cc1dfa
commit
bfd66f57da
@ -218,7 +218,7 @@ const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {
|
|||||||
DataExtractor abbrData(getAbbrevSection(), isLittleEndian(), 0);
|
DataExtractor abbrData(getAbbrevSection(), isLittleEndian(), 0);
|
||||||
|
|
||||||
Abbrev.reset(new DWARFDebugAbbrev());
|
Abbrev.reset(new DWARFDebugAbbrev());
|
||||||
Abbrev->parse(abbrData);
|
Abbrev->extract(abbrData);
|
||||||
return Abbrev.get();
|
return Abbrev.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ const DWARFDebugAbbrev *DWARFContext::getDebugAbbrevDWO() {
|
|||||||
|
|
||||||
DataExtractor abbrData(getAbbrevDWOSection(), isLittleEndian(), 0);
|
DataExtractor abbrData(getAbbrevDWOSection(), isLittleEndian(), 0);
|
||||||
AbbrevDWO.reset(new DWARFDebugAbbrev());
|
AbbrevDWO.reset(new DWARFDebugAbbrev());
|
||||||
AbbrevDWO->parse(abbrData);
|
AbbrevDWO->extract(abbrData);
|
||||||
return AbbrevDWO.get();
|
return AbbrevDWO.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,24 +12,36 @@
|
|||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
bool DWARFAbbreviationDeclarationSet::extract(DataExtractor data,
|
DWARFAbbreviationDeclarationSet::DWARFAbbreviationDeclarationSet() {
|
||||||
uint32_t* offset_ptr) {
|
|
||||||
const uint32_t beginOffset = *offset_ptr;
|
|
||||||
Offset = beginOffset;
|
|
||||||
clear();
|
clear();
|
||||||
DWARFAbbreviationDeclaration abbrevDeclaration;
|
}
|
||||||
uint32_t prevAbbrAode = 0;
|
|
||||||
while (abbrevDeclaration.extract(data, offset_ptr)) {
|
void DWARFAbbreviationDeclarationSet::clear() {
|
||||||
Decls.push_back(abbrevDeclaration);
|
Offset = 0;
|
||||||
if (IdxOffset == 0) {
|
FirstAbbrCode = 0;
|
||||||
IdxOffset = abbrevDeclaration.getCode();
|
Decls.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DWARFAbbreviationDeclarationSet::extract(DataExtractor Data,
|
||||||
|
uint32_t *OffsetPtr) {
|
||||||
|
clear();
|
||||||
|
const uint32_t BeginOffset = *OffsetPtr;
|
||||||
|
Offset = BeginOffset;
|
||||||
|
DWARFAbbreviationDeclaration AbbrDecl;
|
||||||
|
uint32_t PrevAbbrCode = 0;
|
||||||
|
while (AbbrDecl.extract(Data, OffsetPtr)) {
|
||||||
|
Decls.push_back(AbbrDecl);
|
||||||
|
if (FirstAbbrCode == 0) {
|
||||||
|
FirstAbbrCode = AbbrDecl.getCode();
|
||||||
} else {
|
} else {
|
||||||
if (prevAbbrAode + 1 != abbrevDeclaration.getCode())
|
if (PrevAbbrCode + 1 != AbbrDecl.getCode()) {
|
||||||
IdxOffset = UINT32_MAX;// Out of order indexes, we can't do O(1) lookups
|
// Codes are not consecutive, can't do O(1) lookups.
|
||||||
|
FirstAbbrCode = UINT32_MAX;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
prevAbbrAode = abbrevDeclaration.getCode();
|
PrevAbbrCode = AbbrDecl.getCode();
|
||||||
}
|
}
|
||||||
return beginOffset != *offset_ptr;
|
return BeginOffset != *OffsetPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DWARFAbbreviationDeclarationSet::dump(raw_ostream &OS) const {
|
void DWARFAbbreviationDeclarationSet::dump(raw_ostream &OS) const {
|
||||||
@ -37,49 +49,50 @@ void DWARFAbbreviationDeclarationSet::dump(raw_ostream &OS) const {
|
|||||||
Decl.dump(OS);
|
Decl.dump(OS);
|
||||||
}
|
}
|
||||||
|
|
||||||
const DWARFAbbreviationDeclaration*
|
const DWARFAbbreviationDeclaration *
|
||||||
DWARFAbbreviationDeclarationSet::getAbbreviationDeclaration(uint32_t abbrCode)
|
DWARFAbbreviationDeclarationSet::getAbbreviationDeclaration(
|
||||||
const {
|
uint32_t AbbrCode) const {
|
||||||
if (IdxOffset == UINT32_MAX) {
|
if (FirstAbbrCode == UINT32_MAX) {
|
||||||
for (const auto &Decl : Decls) {
|
for (const auto &Decl : Decls) {
|
||||||
if (Decl.getCode() == abbrCode)
|
if (Decl.getCode() == AbbrCode)
|
||||||
return &Decl;
|
return &Decl;
|
||||||
}
|
}
|
||||||
} else {
|
return nullptr;
|
||||||
uint32_t idx = abbrCode - IdxOffset;
|
|
||||||
if (idx < Decls.size())
|
|
||||||
return &Decls[idx];
|
|
||||||
}
|
}
|
||||||
return nullptr;
|
if (AbbrCode < FirstAbbrCode || AbbrCode >= FirstAbbrCode + Decls.size())
|
||||||
|
return nullptr;
|
||||||
|
return &Decls[AbbrCode - FirstAbbrCode];
|
||||||
}
|
}
|
||||||
|
|
||||||
DWARFDebugAbbrev::DWARFDebugAbbrev() :
|
DWARFDebugAbbrev::DWARFDebugAbbrev() {
|
||||||
AbbrevCollMap(),
|
clear();
|
||||||
PrevAbbrOffsetPos(AbbrevCollMap.end()) {}
|
}
|
||||||
|
|
||||||
|
void DWARFDebugAbbrev::clear() {
|
||||||
|
AbbrDeclSets.clear();
|
||||||
|
PrevAbbrOffsetPos = AbbrDeclSets.end();
|
||||||
|
}
|
||||||
|
|
||||||
void DWARFDebugAbbrev::parse(DataExtractor data) {
|
void DWARFDebugAbbrev::extract(DataExtractor Data) {
|
||||||
uint32_t offset = 0;
|
clear();
|
||||||
|
|
||||||
while (data.isValidOffset(offset)) {
|
uint32_t Offset = 0;
|
||||||
uint32_t initial_cu_offset = offset;
|
DWARFAbbreviationDeclarationSet AbbrDecls;
|
||||||
DWARFAbbreviationDeclarationSet abbrevDeclSet;
|
while (Data.isValidOffset(Offset)) {
|
||||||
|
uint32_t CUAbbrOffset = Offset;
|
||||||
if (abbrevDeclSet.extract(data, &offset))
|
if (!AbbrDecls.extract(Data, &Offset))
|
||||||
AbbrevCollMap[initial_cu_offset] = abbrevDeclSet;
|
|
||||||
else
|
|
||||||
break;
|
break;
|
||||||
|
AbbrDeclSets[CUAbbrOffset] = AbbrDecls;
|
||||||
}
|
}
|
||||||
PrevAbbrOffsetPos = AbbrevCollMap.end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DWARFDebugAbbrev::dump(raw_ostream &OS) const {
|
void DWARFDebugAbbrev::dump(raw_ostream &OS) const {
|
||||||
if (AbbrevCollMap.empty()) {
|
if (AbbrDeclSets.empty()) {
|
||||||
OS << "< EMPTY >\n";
|
OS << "< EMPTY >\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &I : AbbrevCollMap) {
|
for (const auto &I : AbbrDeclSets) {
|
||||||
OS << format("Abbrev table for offset: 0x%8.8" PRIx64 "\n", I.first);
|
OS << format("Abbrev table for offset: 0x%8.8" PRIx64 "\n", I.first);
|
||||||
I.second.dump(OS);
|
I.second.dump(OS);
|
||||||
}
|
}
|
||||||
@ -87,13 +100,12 @@ void DWARFDebugAbbrev::dump(raw_ostream &OS) const {
|
|||||||
|
|
||||||
const DWARFAbbreviationDeclarationSet*
|
const DWARFAbbreviationDeclarationSet*
|
||||||
DWARFDebugAbbrev::getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const {
|
DWARFDebugAbbrev::getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const {
|
||||||
DWARFAbbreviationDeclarationCollMapConstIter End = AbbrevCollMap.end();
|
const auto End = AbbrDeclSets.end();
|
||||||
if (PrevAbbrOffsetPos != End && PrevAbbrOffsetPos->first == CUAbbrOffset) {
|
if (PrevAbbrOffsetPos != End && PrevAbbrOffsetPos->first == CUAbbrOffset) {
|
||||||
return &(PrevAbbrOffsetPos->second);
|
return &(PrevAbbrOffsetPos->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
DWARFAbbreviationDeclarationCollMapConstIter Pos =
|
const auto Pos = AbbrDeclSets.find(CUAbbrOffset);
|
||||||
AbbrevCollMap.find(CUAbbrOffset);
|
|
||||||
if (Pos != End) {
|
if (Pos != End) {
|
||||||
PrevAbbrOffsetPos = Pos;
|
PrevAbbrOffsetPos = Pos;
|
||||||
return &(Pos->second);
|
return &(Pos->second);
|
||||||
|
@ -17,48 +17,33 @@
|
|||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
typedef std::vector<DWARFAbbreviationDeclaration>
|
|
||||||
DWARFAbbreviationDeclarationColl;
|
|
||||||
typedef DWARFAbbreviationDeclarationColl::iterator
|
|
||||||
DWARFAbbreviationDeclarationCollIter;
|
|
||||||
typedef DWARFAbbreviationDeclarationColl::const_iterator
|
|
||||||
DWARFAbbreviationDeclarationCollConstIter;
|
|
||||||
|
|
||||||
class DWARFAbbreviationDeclarationSet {
|
class DWARFAbbreviationDeclarationSet {
|
||||||
uint32_t Offset;
|
uint32_t Offset;
|
||||||
uint32_t IdxOffset;
|
/// Code of the first abbreviation, if all abbreviations in the set have
|
||||||
|
/// consecutive codes. UINT32_MAX otherwise.
|
||||||
|
uint32_t FirstAbbrCode;
|
||||||
std::vector<DWARFAbbreviationDeclaration> Decls;
|
std::vector<DWARFAbbreviationDeclaration> Decls;
|
||||||
public:
|
|
||||||
DWARFAbbreviationDeclarationSet()
|
|
||||||
: Offset(0), IdxOffset(0) {}
|
|
||||||
|
|
||||||
DWARFAbbreviationDeclarationSet(uint32_t offset, uint32_t idxOffset)
|
public:
|
||||||
: Offset(offset), IdxOffset(idxOffset) {}
|
DWARFAbbreviationDeclarationSet();
|
||||||
|
|
||||||
void clear() {
|
|
||||||
IdxOffset = 0;
|
|
||||||
Decls.clear();
|
|
||||||
}
|
|
||||||
uint32_t getOffset() const { return Offset; }
|
uint32_t getOffset() const { return Offset; }
|
||||||
void dump(raw_ostream &OS) const;
|
void dump(raw_ostream &OS) const;
|
||||||
bool extract(DataExtractor data, uint32_t* offset_ptr);
|
bool extract(DataExtractor Data, uint32_t *OffsetPtr);
|
||||||
|
|
||||||
const DWARFAbbreviationDeclaration *
|
const DWARFAbbreviationDeclaration *
|
||||||
getAbbreviationDeclaration(uint32_t abbrCode) const;
|
getAbbreviationDeclaration(uint32_t AbbrCode) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
class DWARFDebugAbbrev {
|
class DWARFDebugAbbrev {
|
||||||
public:
|
|
||||||
typedef std::map<uint64_t, DWARFAbbreviationDeclarationSet>
|
typedef std::map<uint64_t, DWARFAbbreviationDeclarationSet>
|
||||||
DWARFAbbreviationDeclarationCollMap;
|
DWARFAbbreviationDeclarationSetMap;
|
||||||
typedef DWARFAbbreviationDeclarationCollMap::iterator
|
|
||||||
DWARFAbbreviationDeclarationCollMapIter;
|
|
||||||
typedef DWARFAbbreviationDeclarationCollMap::const_iterator
|
|
||||||
DWARFAbbreviationDeclarationCollMapConstIter;
|
|
||||||
|
|
||||||
private:
|
DWARFAbbreviationDeclarationSetMap AbbrDeclSets;
|
||||||
DWARFAbbreviationDeclarationCollMap AbbrevCollMap;
|
mutable DWARFAbbreviationDeclarationSetMap::const_iterator PrevAbbrOffsetPos;
|
||||||
mutable DWARFAbbreviationDeclarationCollMapConstIter PrevAbbrOffsetPos;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DWARFDebugAbbrev();
|
DWARFDebugAbbrev();
|
||||||
@ -67,7 +52,10 @@ public:
|
|||||||
getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const;
|
getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const;
|
||||||
|
|
||||||
void dump(raw_ostream &OS) const;
|
void dump(raw_ostream &OS) const;
|
||||||
void parse(DataExtractor data);
|
void extract(DataExtractor Data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user