[llvm] r270503 - llvm-dwp: Split out processing of input sections to improve readability

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon May 23 15:21:11 PDT 2016


Author: dblaikie
Date: Mon May 23 17:21:10 2016
New Revision: 270503

URL: http://llvm.org/viewvc/llvm-project?rev=270503&view=rev
Log:
llvm-dwp: Split out processing of input sections to improve readability

Modified:
    llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp

Modified: llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp?rev=270503&r1=270502&r2=270503&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Mon May 23 17:21:10 2016
@@ -378,14 +378,89 @@ static Error handleCompressedSection(
   Contents = UncompressedSections.back();
   return Error();
 }
-Error buildDuplicateError(const std::pair<uint64_t, UnitIndexEntry> &PrevE,
-                          const CompileUnitIdentifiers &ID, StringRef DWPName) {
+
+static Error handleSection(
+    const StringMap<std::pair<MCSection *, DWARFSectionKind>> &KnownSections,
+    const MCSection *StrSection, const MCSection *StrOffsetSection,
+    const MCSection *TypesSection, const MCSection *CUIndexSection,
+    const MCSection *TUIndexSection, const SectionRef &Section, MCStreamer &Out,
+    SmallVector<SmallString<32>, 4> &UncompressedSections,
+    uint32_t (&ContributionOffsets)[8], UnitIndexEntry &CurEntry,
+    StringRef &CurStrSection, StringRef &CurStrOffsetSection,
+    std::vector<StringRef> &CurTypesSection, StringRef &InfoSection,
+    StringRef &AbbrevSection, StringRef &CurCUIndexSection,
+    StringRef &CurTUIndexSection) {
+  if (Section.isBSS())
+    return Error();
+
+  if (Section.isVirtual())
+    return Error();
+
+  StringRef Name;
+  if (std::error_code Err = Section.getName(Name))
+    return errorCodeToError(Err);
+
+  Name = Name.substr(Name.find_first_not_of("._"));
+
+  StringRef Contents;
+  if (auto Err = Section.getContents(Contents))
+    return errorCodeToError(Err);
+
+  if (auto Err = handleCompressedSection(UncompressedSections, Name, Contents))
+    return Err;
+
+  auto SectionPair = KnownSections.find(Name);
+  if (SectionPair == KnownSections.end())
+    return Error();
+
+  if (DWARFSectionKind Kind = SectionPair->second.second) {
+    auto Index = Kind - DW_SECT_INFO;
+    if (Kind != DW_SECT_TYPES) {
+      CurEntry.Contributions[Index].Offset = ContributionOffsets[Index];
+      ContributionOffsets[Index] +=
+          (CurEntry.Contributions[Index].Length = Contents.size());
+    }
+
+    switch (Kind) {
+    case DW_SECT_INFO:
+      InfoSection = Contents;
+      break;
+    case DW_SECT_ABBREV:
+      AbbrevSection = Contents;
+      break;
+    default:
+      break;
+    }
+  }
+
+  MCSection *OutSection = SectionPair->second.first;
+  if (OutSection == StrOffsetSection)
+    CurStrOffsetSection = Contents;
+  else if (OutSection == StrSection)
+    CurStrSection = Contents;
+  else if (OutSection == TypesSection)
+    CurTypesSection.push_back(Contents);
+  else if (OutSection == CUIndexSection)
+    CurCUIndexSection = Contents;
+  else if (OutSection == TUIndexSection)
+    CurTUIndexSection = Contents;
+  else {
+    Out.SwitchSection(OutSection);
+    Out.EmitBytes(Contents);
+  }
+  return Error();
+}
+
+static Error
+buildDuplicateError(const std::pair<uint64_t, UnitIndexEntry> &PrevE,
+                    const CompileUnitIdentifiers &ID, StringRef DWPName) {
   return make_error<DWPError>(
       std::string("Duplicate DWO ID (") + utohexstr(PrevE.first) + ") in " +
       buildDWODescription(PrevE.second.Name, PrevE.second.DWPName,
                           PrevE.second.DWOName) +
       " and " + buildDWODescription(ID.Name, DWPName, ID.DWOName));
 }
+
 static Error write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
   const auto &MCOFI = *Out.getContext().getObjectFileInfo();
   MCSection *const StrSection = MCOFI.getDwarfStrDWOSection();
@@ -434,67 +509,15 @@ static Error write(MCStreamer &Out, Arra
     StringRef CurCUIndexSection;
     StringRef CurTUIndexSection;
 
-    for (const auto &Section : Obj.sections()) {
-      if (Section.isBSS())
-        continue;
-      if (Section.isVirtual())
-        continue;
-
-      StringRef Name;
-      if (std::error_code Err = Section.getName(Name))
-        return errorCodeToError(Err);
-
-      Name = Name.substr(Name.find_first_not_of("._"));
-
-      StringRef Contents;
-      if (auto Err = Section.getContents(Contents))
-        return errorCodeToError(Err);
-
-      if (auto Err =
-              handleCompressedSection(UncompressedSections, Name, Contents))
+    for (const auto &Section : Obj.sections())
+      if (auto Err = handleSection(
+              KnownSections, StrSection, StrOffsetSection, TypesSection,
+              CUIndexSection, TUIndexSection, Section, Out,
+              UncompressedSections, ContributionOffsets, CurEntry,
+              CurStrSection, CurStrOffsetSection, CurTypesSection, InfoSection,
+              AbbrevSection, CurCUIndexSection, CurTUIndexSection))
         return Err;
 
-      auto SectionPair = KnownSections.find(Name);
-      if (SectionPair == KnownSections.end())
-        continue;
-
-      if (DWARFSectionKind Kind = SectionPair->second.second) {
-        auto Index = Kind - DW_SECT_INFO;
-        if (Kind != DW_SECT_TYPES) {
-          CurEntry.Contributions[Index].Offset = ContributionOffsets[Index];
-          ContributionOffsets[Index] +=
-              (CurEntry.Contributions[Index].Length = Contents.size());
-        }
-
-        switch (Kind) {
-        case DW_SECT_INFO:
-          InfoSection = Contents;
-          break;
-        case DW_SECT_ABBREV:
-          AbbrevSection = Contents;
-          break;
-        default:
-          break;
-        }
-      }
-
-      MCSection *OutSection = SectionPair->second.first;
-      if (OutSection == StrOffsetSection)
-        CurStrOffsetSection = Contents;
-      else if (OutSection == StrSection)
-        CurStrSection = Contents;
-      else if (OutSection == TypesSection)
-        CurTypesSection.push_back(Contents);
-      else if (OutSection == CUIndexSection)
-        CurCUIndexSection = Contents;
-      else if (OutSection == TUIndexSection)
-        CurTUIndexSection = Contents;
-      else {
-        Out.SwitchSection(OutSection);
-        Out.EmitBytes(Contents);
-      }
-    }
-
     if (InfoSection.empty())
       continue;
 




More information about the llvm-commits mailing list