[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
Thu Jul 23 07:56:45 PDT 2020


Higuoxing updated this revision to Diff 280120.
Higuoxing marked 2 inline comments as done.
Higuoxing added a comment.

Thanks for reviewing!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84383/new/

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,31 @@
   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 @@
   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.280120.patch
Type: text/x-patch
Size: 2932 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200723/2fd9054c/attachment.bin>


More information about the llvm-commits mailing list