mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-10-30 16:17:05 +00:00
DWARFAbbreviationDeclaration: remove dead code, refactor parsing code and make it more robust. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193770 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -14,37 +14,51 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace dwarf;
|
using namespace dwarf;
|
||||||
|
|
||||||
bool
|
void DWARFAbbreviationDeclaration::clear() {
|
||||||
DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr){
|
Code = 0;
|
||||||
return extract(data, offset_ptr, data.getULEB128(offset_ptr));
|
Tag = 0;
|
||||||
|
HasChildren = false;
|
||||||
|
Attributes.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() {
|
||||||
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr,
|
DWARFAbbreviationDeclaration::extract(DataExtractor Data, uint32_t* OffsetPtr) {
|
||||||
uint32_t code) {
|
clear();
|
||||||
Code = code;
|
Code = Data.getULEB128(OffsetPtr);
|
||||||
Attribute.clear();
|
if (Code == 0) {
|
||||||
if (Code) {
|
return false;
|
||||||
Tag = data.getULEB128(offset_ptr);
|
}
|
||||||
HasChildren = data.getU8(offset_ptr);
|
Tag = Data.getULEB128(OffsetPtr);
|
||||||
|
uint8_t ChildrenByte = Data.getU8(OffsetPtr);
|
||||||
|
HasChildren = (ChildrenByte == DW_CHILDREN_yes);
|
||||||
|
|
||||||
while (data.isValidOffset(*offset_ptr)) {
|
while (true) {
|
||||||
uint16_t attr = data.getULEB128(offset_ptr);
|
uint32_t CurOffset = *OffsetPtr;
|
||||||
uint16_t form = data.getULEB128(offset_ptr);
|
uint16_t Attr = Data.getULEB128(OffsetPtr);
|
||||||
|
if (CurOffset == *OffsetPtr) {
|
||||||
if (attr && form)
|
clear();
|
||||||
Attribute.push_back(DWARFAttribute(attr, form));
|
return false;
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
CurOffset = *OffsetPtr;
|
||||||
return Tag != 0;
|
uint16_t Form = Data.getULEB128(OffsetPtr);
|
||||||
} else {
|
if (CurOffset == *OffsetPtr) {
|
||||||
Tag = 0;
|
clear();
|
||||||
HasChildren = false;
|
return false;
|
||||||
|
}
|
||||||
|
if (Attr == 0 && Form == 0)
|
||||||
|
break;
|
||||||
|
Attributes.push_back(AttributeSpec(Attr, Form));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
if (Tag == 0) {
|
||||||
|
clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
|
void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
|
||||||
@@ -55,19 +69,19 @@ void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
|
|||||||
else
|
else
|
||||||
OS << format("DW_TAG_Unknown_%x", getTag());
|
OS << format("DW_TAG_Unknown_%x", getTag());
|
||||||
OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n';
|
OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n';
|
||||||
for (unsigned i = 0, e = Attribute.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Attributes.size(); i != e; ++i) {
|
||||||
OS << '\t';
|
OS << '\t';
|
||||||
const char *attrString = AttributeString(Attribute[i].getAttribute());
|
const char *attrString = AttributeString(Attributes[i].Attr);
|
||||||
if (attrString)
|
if (attrString)
|
||||||
OS << attrString;
|
OS << attrString;
|
||||||
else
|
else
|
||||||
OS << format("DW_AT_Unknown_%x", Attribute[i].getAttribute());
|
OS << format("DW_AT_Unknown_%x", Attributes[i].Attr);
|
||||||
OS << '\t';
|
OS << '\t';
|
||||||
const char *formString = FormEncodingString(Attribute[i].getForm());
|
const char *formString = FormEncodingString(Attributes[i].Form);
|
||||||
if (formString)
|
if (formString)
|
||||||
OS << formString;
|
OS << formString;
|
||||||
else
|
else
|
||||||
OS << format("DW_FORM_Unknown_%x", Attribute[i].getForm());
|
OS << format("DW_FORM_Unknown_%x", Attributes[i].Form);
|
||||||
OS << '\n';
|
OS << '\n';
|
||||||
}
|
}
|
||||||
OS << '\n';
|
OS << '\n';
|
||||||
@@ -75,8 +89,8 @@ void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
|
|||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const {
|
DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const {
|
||||||
for (uint32_t i = 0, e = Attribute.size(); i != e; ++i) {
|
for (uint32_t i = 0, e = Attributes.size(); i != e; ++i) {
|
||||||
if (Attribute[i].getAttribute() == attr)
|
if (Attributes[i].Attr == attr)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return -1U;
|
return -1U;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
#ifndef LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
|
#ifndef LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
|
||||||
#define LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
|
#define LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
|
||||||
|
|
||||||
#include "DWARFAttribute.h"
|
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/Support/DataExtractor.h"
|
#include "llvm/Support/DataExtractor.h"
|
||||||
|
|
||||||
@@ -22,31 +21,33 @@ class DWARFAbbreviationDeclaration {
|
|||||||
uint32_t Code;
|
uint32_t Code;
|
||||||
uint32_t Tag;
|
uint32_t Tag;
|
||||||
bool HasChildren;
|
bool HasChildren;
|
||||||
SmallVector<DWARFAttribute, 8> Attribute;
|
|
||||||
|
struct AttributeSpec {
|
||||||
|
AttributeSpec(uint16_t Attr, uint16_t Form) : Attr(Attr), Form(Form) {}
|
||||||
|
uint16_t Attr;
|
||||||
|
uint16_t Form;
|
||||||
|
};
|
||||||
|
SmallVector<AttributeSpec, 8> Attributes;
|
||||||
public:
|
public:
|
||||||
enum { InvalidCode = 0 };
|
DWARFAbbreviationDeclaration();
|
||||||
DWARFAbbreviationDeclaration()
|
|
||||||
: Code(InvalidCode), Tag(0), HasChildren(0) {}
|
|
||||||
|
|
||||||
uint32_t getCode() const { return Code; }
|
uint32_t getCode() const { return Code; }
|
||||||
uint32_t getTag() const { return Tag; }
|
uint32_t getTag() const { return Tag; }
|
||||||
bool hasChildren() const { return HasChildren; }
|
bool hasChildren() const { return HasChildren; }
|
||||||
uint32_t getNumAttributes() const { return Attribute.size(); }
|
uint32_t getNumAttributes() const { return Attributes.size(); }
|
||||||
uint16_t getAttrByIndex(uint32_t idx) const {
|
uint16_t getAttrByIndex(uint32_t idx) const {
|
||||||
return Attribute.size() > idx ? Attribute[idx].getAttribute() : 0;
|
return idx < Attributes.size() ? Attributes[idx].Attr : 0;
|
||||||
}
|
}
|
||||||
uint16_t getFormByIndex(uint32_t idx) const {
|
uint16_t getFormByIndex(uint32_t idx) const {
|
||||||
return Attribute.size() > idx ? Attribute[idx].getForm() : 0;
|
return idx < Attributes.size() ? Attributes[idx].Form : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t findAttributeIndex(uint16_t attr) const;
|
uint32_t findAttributeIndex(uint16_t attr) const;
|
||||||
bool extract(DataExtractor data, uint32_t* offset_ptr);
|
bool extract(DataExtractor Data, uint32_t* OffsetPtr);
|
||||||
bool extract(DataExtractor data, uint32_t* offset_ptr, uint32_t code);
|
|
||||||
bool isValid() const { return Code != 0 && Tag != 0; }
|
|
||||||
void dump(raw_ostream &OS) const;
|
void dump(raw_ostream &OS) const;
|
||||||
const SmallVectorImpl<DWARFAttribute> &getAttributes() const {
|
|
||||||
return Attribute;
|
private:
|
||||||
}
|
void clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
//===-- DWARFAttribute.h ----------------------------------------*- C++ -*-===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#ifndef LLVM_DEBUGINFO_DWARFATTRIBUTE_H
|
|
||||||
#define LLVM_DEBUGINFO_DWARFATTRIBUTE_H
|
|
||||||
|
|
||||||
#include "llvm/Support/DataTypes.h"
|
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
|
|
||||||
class DWARFAttribute {
|
|
||||||
uint16_t Attribute;
|
|
||||||
uint16_t Form;
|
|
||||||
public:
|
|
||||||
DWARFAttribute(uint16_t attr, uint16_t form)
|
|
||||||
: Attribute(attr), Form(form) {}
|
|
||||||
|
|
||||||
uint16_t getAttribute() const { return Attribute; }
|
|
||||||
uint16_t getForm() const { return Form; }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user