[llvm] bbb057c - [DWARFYAML] Replace 'Format', 'Version', etc with 'FormParams'. NFC.
Xing GUO via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 24 01:55:13 PDT 2020
Author: Xing GUO
Date: 2020-07-24T16:54:51+08:00
New Revision: bbb057c49a12ad4bc6f5c50980c7c58f69fa6bc0
URL: https://github.com/llvm/llvm-project/commit/bbb057c49a12ad4bc6f5c50980c7c58f69fa6bc0
DIFF: https://github.com/llvm/llvm-project/commit/bbb057c49a12ad4bc6f5c50980c7c58f69fa6bc0.diff
LOG: [DWARFYAML] Replace 'Format', 'Version', etc with 'FormParams'. NFC.
This patch replaces 'Format', 'Version' fields, etc with 'FormParams' to
simplify codes.
Reviewed By: labath
Differential Revision: https://reviews.llvm.org/D84496
Added:
Modified:
llvm/include/llvm/ObjectYAML/DWARFYAML.h
llvm/lib/ObjectYAML/DWARFEmitter.cpp
llvm/lib/ObjectYAML/DWARFYAML.cpp
llvm/tools/obj2yaml/dwarf2yaml.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ObjectYAML/DWARFYAML.h b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
index 1427332fafe0..7b18ceebdb1c 100644
--- a/llvm/include/llvm/ObjectYAML/DWARFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
@@ -119,12 +119,10 @@ struct DWARFContext {
};
struct Unit {
- dwarf::DwarfFormat Format;
+ dwarf::FormParams FormParams;
Optional<yaml::Hex64> Length;
- uint16_t Version;
llvm::dwarf::UnitType Type; // Added in DWARF 5
yaml::Hex64 AbbrOffset;
- uint8_t AddrSize;
std::vector<Entry> Entries;
};
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index 54cbe3807661..f61191022fb9 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -207,16 +207,6 @@ Error DWARFYAML::emitPubSection(raw_ostream &OS,
return Error::success();
}
-static unsigned getOffsetSize(const DWARFYAML::Unit &Unit) {
- return Unit.Format == dwarf::DWARF64 ? 8 : 4;
-}
-
-static unsigned getRefSize(const DWARFYAML::Unit &Unit) {
- if (Unit.Version == 2)
- return Unit.AddrSize;
- return getOffsetSize(Unit);
-}
-
static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
const DWARFYAML::Unit &Unit,
const DWARFYAML::Entry &Entry,
@@ -244,14 +234,15 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
switch (Form) {
case dwarf::DW_FORM_addr:
// TODO: Test this error.
- if (Error Err = writeVariableSizedInteger(FormVal->Value, Unit.AddrSize,
- OS, IsLittleEndian))
+ if (Error Err = writeVariableSizedInteger(
+ FormVal->Value, Unit.FormParams.AddrSize, OS, IsLittleEndian))
return std::move(Err);
break;
case dwarf::DW_FORM_ref_addr:
// TODO: Test this error.
if (Error Err = writeVariableSizedInteger(
- FormVal->Value, getRefSize(Unit), OS, IsLittleEndian))
+ FormVal->Value, Unit.FormParams.getRefAddrByteSize(), OS,
+ IsLittleEndian))
return std::move(Err);
break;
case dwarf::DW_FORM_exprloc:
@@ -333,10 +324,9 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
case dwarf::DW_FORM_GNU_strp_alt:
case dwarf::DW_FORM_line_strp:
case dwarf::DW_FORM_strp_sup:
- // TODO: Test this error.
- if (Error Err = writeVariableSizedInteger(
- FormVal->Value, getOffsetSize(Unit), OS, IsLittleEndian))
- return std::move(Err);
+ cantFail(writeVariableSizedInteger(
+ FormVal->Value, Unit.FormParams.getDwarfOffsetByteSize(), OS,
+ IsLittleEndian));
break;
default:
break;
@@ -350,9 +340,9 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
for (const DWARFYAML::Unit &Unit : DI.CompileUnits) {
uint64_t Length = 3; // sizeof(version) + sizeof(address_size)
- Length += Unit.Version >= 5 ? 1 : 0; // sizeof(unit_type)
+ Length += Unit.FormParams.Version >= 5 ? 1 : 0; // sizeof(unit_type)
Length +=
- Unit.Format == dwarf::DWARF64 ? 8 : 4; // sizeof(debug_abbrev_offset)
+ Unit.FormParams.getDwarfOffsetByteSize(); // sizeof(debug_abbrev_offset)
// Since the length of the current compilation unit is undetermined yet, we
// firstly write the content of the compilation unit to a buffer to
@@ -374,15 +364,17 @@ Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
if (Unit.Length)
Length = *Unit.Length;
- writeInitialLength(Unit.Format, Length, OS, DI.IsLittleEndian);
- writeInteger((uint16_t)Unit.Version, OS, DI.IsLittleEndian);
- if (Unit.Version >= 5) {
+ writeInitialLength(Unit.FormParams.Format, Length, OS, DI.IsLittleEndian);
+ writeInteger((uint16_t)Unit.FormParams.Version, OS, DI.IsLittleEndian);
+ if (Unit.FormParams.Version >= 5) {
writeInteger((uint8_t)Unit.Type, OS, DI.IsLittleEndian);
- writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian);
- writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian);
+ writeInteger((uint8_t)Unit.FormParams.AddrSize, OS, DI.IsLittleEndian);
+ writeDWARFOffset(Unit.AbbrOffset, Unit.FormParams.Format, OS,
+ DI.IsLittleEndian);
} else {
- writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian);
- writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian);
+ writeDWARFOffset(Unit.AbbrOffset, Unit.FormParams.Format, OS,
+ DI.IsLittleEndian);
+ writeInteger((uint8_t)Unit.FormParams.AddrSize, OS, DI.IsLittleEndian);
}
OS.write(EntryBuffer.data(), EntryBuffer.size());
@@ -438,7 +430,8 @@ Error DWARFYAML::emitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) {
case dwarf::DW_LNE_set_discriminator:
// TODO: Test this error.
if (Error Err = writeVariableSizedInteger(
- Op.Data, DI.CompileUnits[0].AddrSize, OS, DI.IsLittleEndian))
+ Op.Data, DI.CompileUnits[0].FormParams.AddrSize, OS,
+ DI.IsLittleEndian))
return Err;
break;
case dwarf::DW_LNE_define_file:
diff --git a/llvm/lib/ObjectYAML/DWARFYAML.cpp b/llvm/lib/ObjectYAML/DWARFYAML.cpp
index 6a3afb28d801..186ec8ac4bdc 100644
--- a/llvm/lib/ObjectYAML/DWARFYAML.cpp
+++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp
@@ -142,13 +142,13 @@ void MappingTraits<DWARFYAML::PubSection>::mapping(
}
void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) {
- IO.mapOptional("Format", Unit.Format, dwarf::DWARF32);
+ IO.mapOptional("Format", Unit.FormParams.Format, dwarf::DWARF32);
IO.mapOptional("Length", Unit.Length);
- IO.mapRequired("Version", Unit.Version);
- if (Unit.Version >= 5)
+ IO.mapRequired("Version", Unit.FormParams.Version);
+ if (Unit.FormParams.Version >= 5)
IO.mapRequired("UnitType", Unit.Type);
IO.mapRequired("AbbrOffset", Unit.AbbrOffset);
- IO.mapRequired("AddrSize", Unit.AddrSize);
+ IO.mapRequired("AddrSize", Unit.FormParams.AddrSize);
IO.mapOptional("Entries", Unit.Entries);
}
diff --git a/llvm/tools/obj2yaml/dwarf2yaml.cpp b/llvm/tools/obj2yaml/dwarf2yaml.cpp
index a318a547e32c..66264a46068a 100644
--- a/llvm/tools/obj2yaml/dwarf2yaml.cpp
+++ b/llvm/tools/obj2yaml/dwarf2yaml.cpp
@@ -165,13 +165,13 @@ void dumpDebugPubSections(DWARFContext &DCtx, DWARFYAML::Data &Y) {
void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {
for (const auto &CU : DCtx.compile_units()) {
DWARFYAML::Unit NewUnit;
- NewUnit.Format = CU->getFormat();
+ NewUnit.FormParams.Format = CU->getFormat();
NewUnit.Length = CU->getLength();
- NewUnit.Version = CU->getVersion();
- if(NewUnit.Version >= 5)
+ NewUnit.FormParams.Version = CU->getVersion();
+ if (NewUnit.FormParams.Version >= 5)
NewUnit.Type = (dwarf::UnitType)CU->getUnitType();
NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset();
- NewUnit.AddrSize = CU->getAddressByteSize();
+ NewUnit.FormParams.AddrSize = CU->getAddressByteSize();
for (auto DIE : CU->dies()) {
DWARFYAML::Entry NewEntry;
DataExtractor EntryData = CU->getDebugInfoExtractor();
More information about the llvm-commits
mailing list