[llvm] 386d5af - [MachOYAML] Simplify the section data emitting function. NFC.

Xing GUO via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 06:47:04 PDT 2020


Author: Xing GUO
Date: 2020-08-12T21:46:43+08:00
New Revision: 386d5af04b65aca7c81eed1468e53462a6b54550

URL: https://github.com/llvm/llvm-project/commit/386d5af04b65aca7c81eed1468e53462a6b54550
DIFF: https://github.com/llvm/llvm-project/commit/386d5af04b65aca7c81eed1468e53462a6b54550.diff

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

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

Reviewed By: jhenderson, grimar

Differential Revision: https://reviews.llvm.org/D85821

Added: 
    

Modified: 
    llvm/lib/ObjectYAML/MachOEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp
index 3b1421440cb99..f9e518259c568 100644
--- a/llvm/lib/ObjectYAML/MachOEmitter.cpp
+++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp
@@ -285,32 +285,14 @@ Error MachOWriter::writeSectionData(raw_ostream &OS) {
           return createStringError(
               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;
+        if (0 == strncmp(&Sec.segname[0], "__DWARF", sizeof(Sec.segname))) {
+          StringRef SectName(Sec.sectname,
+                             strnlen(Sec.sectname, sizeof(Sec.sectname)));
+          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;
         }


        


More information about the llvm-commits mailing list