[llvm] a997e6e - [DWARFYAML] Pull out common helper functions for rnglist and loclist tables. NFC.
Xing GUO via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 23 07:58:01 PDT 2020
Author: Xing GUO
Date: 2020-07-23T22:57:30+08:00
New Revision: a997e6edb9619dcc02696ee45131e892626f0e60
URL: https://github.com/llvm/llvm-project/commit/a997e6edb9619dcc02696ee45131e892626f0e60
DIFF: https://github.com/llvm/llvm-project/commit/a997e6edb9619dcc02696ee45131e892626f0e60.diff
LOG: [DWARFYAML] Pull out common helper functions for rnglist and loclist tables. NFC.
This patch helps pull out some common helper functions for range list
and location list tables. NFC.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D84383
Added:
Modified:
llvm/lib/ObjectYAML/DWARFEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index 2caa63f41940..3012813ced39 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -442,6 +442,31 @@ Error DWARFYAML::emitDebugStrOffsets(raw_ostream &OS, const Data &DI) {
return Error::success();
}
+static Error checkListEntryOperands(StringRef EncodingString,
+ ArrayRef<yaml::Hex64> Values,
+ uint64_t ExpectedOperands) {
+ if (Values.size() != ExpectedOperands)
+ return createStringError(
+ errc::invalid_argument,
+ "invalid number (%zu) of operands for the operator: %s, %" PRIu64
+ " expected",
+ Values.size(), EncodingString.str().c_str(), ExpectedOperands);
+
+ return Error::success();
+}
+
+static Error writeListEntryAddress(StringRef EncodingName, raw_ostream &OS,
+ uint64_t Addr, uint8_t AddrSize,
+ bool IsLittleEndian) {
+ if (Error Err = writeVariableSizedInteger(Addr, AddrSize, OS, IsLittleEndian))
+ return createStringError(errc::invalid_argument,
+ "unable to write address for the operator %s: %s",
+ EncodingName.str().c_str(),
+ toString(std::move(Err)).c_str());
+
+ return Error::success();
+}
+
static Expected<uint64_t> writeListEntry(raw_ostream &OS,
const DWARFYAML::RnglistEntry &Entry,
uint8_t AddrSize,
@@ -449,29 +474,15 @@ static Expected<uint64_t> writeListEntry(raw_ostream &OS,
uint64_t BeginOffset = OS.tell();
writeInteger((uint8_t)Entry.Operator, OS, IsLittleEndian);
- auto CheckOperands = [&](uint64_t ExpectedOperands) -> Error {
- if (Entry.Values.size() != ExpectedOperands) {
- return createStringError(
- errc::invalid_argument,
- "invalid number (%zu) of operands for the operator: %s, %" PRIu64
- " expected",
- Entry.Values.size(),
- dwarf::RangeListEncodingString(Entry.Operator).str().c_str(),
- ExpectedOperands);
- }
+ StringRef EncodingName = dwarf::RangeListEncodingString(Entry.Operator);
- return Error::success();
+ auto CheckOperands = [&](uint64_t ExpectedOperands) -> Error {
+ return checkListEntryOperands(EncodingName, Entry.Values, ExpectedOperands);
};
auto WriteAddress = [&](uint64_t Addr) -> Error {
- if (Error Err =
- writeVariableSizedInteger(Addr, AddrSize, OS, IsLittleEndian))
- return createStringError(
- errc::not_supported,
- "unable to write address for the operator %s: %s",
- dwarf::RangeListEncodingString(Entry.Operator).str().c_str(),
- toString(std::move(Err)).c_str());
- return Error::success();
+ return writeListEntryAddress(EncodingName, OS, Addr, AddrSize,
+ IsLittleEndian);
};
switch (Entry.Operator) {
More information about the llvm-commits
mailing list