[PATCH] D85821: [MachOYAML] Simplify the section data emitting function. NFC.

Xing GUO via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 02:15:35 PDT 2020


Higuoxing created this revision.
Higuoxing added reviewers: jhenderson, grimar, MaskRay.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
Higuoxing requested review of this revision.

This patch helps simplify some codes in writeSectionData() function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85821

Files:
  llvm/lib/ObjectYAML/MachOEmitter.cpp


Index: llvm/lib/ObjectYAML/MachOEmitter.cpp
===================================================================
--- llvm/lib/ObjectYAML/MachOEmitter.cpp
+++ llvm/lib/ObjectYAML/MachOEmitter.cpp
@@ -286,31 +286,12 @@
               errc::invalid_argument,
               "wrote too much data somewhere, section offsets don't line up");
         if (0 == strncmp(&Sec.segname[0], "__DWARF", 16)) {
-          Error Err = Error::success();
-          cantFail(std::move(Err));
-
-          if (0 == strncmp(&Sec.sectname[0], "__debug_str", 16))
-            Err = DWARFYAML::emitDebugStr(OS, Obj.DWARF);
-          else if (0 == strncmp(&Sec.sectname[0], "__debug_abbrev", 16))
-            Err = DWARFYAML::emitDebugAbbrev(OS, Obj.DWARF);
-          else if (0 == strncmp(&Sec.sectname[0], "__debug_aranges", 16)) {
-            if (Obj.DWARF.DebugAranges)
-              Err = DWARFYAML::emitDebugAranges(OS, Obj.DWARF);
-          } else if (0 == strncmp(&Sec.sectname[0], "__debug_ranges", 16))
-            Err = DWARFYAML::emitDebugRanges(OS, Obj.DWARF);
-          else if (0 == strncmp(&Sec.sectname[0], "__debug_pubnames", 16)) {
-            if (Obj.DWARF.PubNames)
-              Err = DWARFYAML::emitDebugPubnames(OS, Obj.DWARF);
-          } else if (0 == strncmp(&Sec.sectname[0], "__debug_pubtypes", 16)) {
-            if (Obj.DWARF.PubTypes)
-              Err = DWARFYAML::emitDebugPubtypes(OS, Obj.DWARF);
-          } else if (0 == strncmp(&Sec.sectname[0], "__debug_info", 16))
-            Err = DWARFYAML::emitDebugInfo(OS, Obj.DWARF);
-          else if (0 == strncmp(&Sec.sectname[0], "__debug_line", 16))
-            Err = DWARFYAML::emitDebugLine(OS, Obj.DWARF);
-
-          if (Err)
-            return Err;
+          StringRef SectName(Sec.sectname, strnlen(Sec.sectname, 16));
+          auto EmitFunc = DWARFYAML::getDWARFEmitterByName(SectName.substr(2));
+          if (Obj.DWARF.getNonEmptySectionNames().count(SectName.substr(2))) {
+            if (Error Err = EmitFunc(OS, Obj.DWARF))
+              return Err;
+          }
 
           continue;
         }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85821.285015.patch
Type: text/x-patch
Size: 2096 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200812/bd4ccfef/attachment.bin>


More information about the llvm-commits mailing list