[PATCH] D84383: [DWARFYAML] Pull out common helper functions for rnglist and loclist tables. NFC.
Xing GUO via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 22 21:13:16 PDT 2020
Higuoxing created this revision.
Higuoxing added reviewers: jhenderson, grimar, MaskRay, labath.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
This patch helps pull out some common helper functions for range list
and location list tables. NFC.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84383
Files:
llvm/lib/ObjectYAML/DWARFEmitter.cpp
Index: llvm/lib/ObjectYAML/DWARFEmitter.cpp
===================================================================
--- llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -442,6 +442,32 @@
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 +475,15 @@
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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84383.280023.patch
Type: text/x-patch
Size: 2939 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200723/8773ed4c/attachment.bin>
More information about the llvm-commits
mailing list