[llvm] 78bfcc5 - [MC] Export MCDXContainerObjectWriter

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 1 23:03:30 PDT 2024


Author: Fangrui Song
Date: 2024-11-01T23:03:25-07:00
New Revision: 78bfcc5932fd0a39b61fe812ebed9d2f3957070b

URL: https://github.com/llvm/llvm-project/commit/78bfcc5932fd0a39b61fe812ebed9d2f3957070b
DIFF: https://github.com/llvm/llvm-project/commit/78bfcc5932fd0a39b61fe812ebed9d2f3957070b.diff

LOG: [MC] Export MCDXContainerObjectWriter

Similar to other ObjectWriter classes.

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCDXContainerWriter.h
    llvm/lib/MC/MCAsmBackend.cpp
    llvm/lib/MC/MCDXContainerWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCDXContainerWriter.h b/llvm/include/llvm/MC/MCDXContainerWriter.h
index 8e78b1f48e1675..b3ca3d73a09b78 100644
--- a/llvm/include/llvm/MC/MCDXContainerWriter.h
+++ b/llvm/include/llvm/MC/MCDXContainerWriter.h
@@ -10,6 +10,8 @@
 #define LLVM_MC_MCDXCONTAINERWRITER_H
 
 #include "llvm/MC/MCObjectWriter.h"
+#include "llvm/MC/MCValue.h"
+#include "llvm/Support/EndianStream.h"
 #include "llvm/TargetParser/Triple.h"
 
 namespace llvm {
@@ -31,15 +33,21 @@ class MCDXContainerTargetWriter : public MCObjectTargetWriter {
   }
 };
 
-/// Construct a new DXContainer writer instance.
-///
-/// \param MOTW - The target specific DXContainer writer subclass.
-/// \param OS - The stream to write to.
-/// \returns The constructed object writer.
-std::unique_ptr<MCObjectWriter>
-createDXContainerObjectWriter(std::unique_ptr<MCDXContainerTargetWriter> MOTW,
-                              raw_pwrite_stream &OS);
+class DXContainerObjectWriter final : public MCObjectWriter {
+  support::endian::Writer W;
+  std::unique_ptr<MCDXContainerTargetWriter> TargetObjectWriter;
 
+public:
+  DXContainerObjectWriter(std::unique_ptr<MCDXContainerTargetWriter> MOTW,
+                          raw_pwrite_stream &OS)
+      : W(OS, llvm::endianness::little), TargetObjectWriter(std::move(MOTW)) {}
+
+  void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
+                        const MCFixup &Fixup, MCValue Target,
+                        uint64_t &FixedValue) override {}
+
+  uint64_t writeObject(MCAssembler &Asm) override;
+};
 } // end namespace llvm
 
 #endif // LLVM_MC_MCDXCONTAINERWRITER_H

diff  --git a/llvm/lib/MC/MCAsmBackend.cpp b/llvm/lib/MC/MCAsmBackend.cpp
index bab3485b506145..9640e249d7680a 100644
--- a/llvm/lib/MC/MCAsmBackend.cpp
+++ b/llvm/lib/MC/MCAsmBackend.cpp
@@ -56,7 +56,7 @@ MCAsmBackend::createObjectWriter(raw_pwrite_stream &OS) const {
     return createXCOFFObjectWriter(
         cast<MCXCOFFObjectTargetWriter>(std::move(TW)), OS);
   case Triple::DXContainer:
-    return createDXContainerObjectWriter(
+    return std::make_unique<DXContainerObjectWriter>(
         cast<MCDXContainerTargetWriter>(std::move(TW)), OS);
   default:
     llvm_unreachable("unexpected object format");

diff  --git a/llvm/lib/MC/MCDXContainerWriter.cpp b/llvm/lib/MC/MCDXContainerWriter.cpp
index 6b42d38c567f17..ae86c435a041b1 100644
--- a/llvm/lib/MC/MCDXContainerWriter.cpp
+++ b/llvm/lib/MC/MCDXContainerWriter.cpp
@@ -13,35 +13,11 @@
 #include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCValue.h"
 #include "llvm/Support/Alignment.h"
-#include "llvm/Support/EndianStream.h"
 
 using namespace llvm;
 
 MCDXContainerTargetWriter::~MCDXContainerTargetWriter() {}
 
-namespace {
-class DXContainerObjectWriter : public MCObjectWriter {
-  ::support::endian::Writer W;
-
-  /// The target specific DXContainer writer instance.
-  std::unique_ptr<MCDXContainerTargetWriter> TargetObjectWriter;
-
-public:
-  DXContainerObjectWriter(std::unique_ptr<MCDXContainerTargetWriter> MOTW,
-                          raw_pwrite_stream &OS)
-      : W(OS, llvm::endianness::little), TargetObjectWriter(std::move(MOTW)) {}
-
-  ~DXContainerObjectWriter() override {}
-
-private:
-  void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
-                        const MCFixup &Fixup, MCValue Target,
-                        uint64_t &FixedValue) override {}
-
-  uint64_t writeObject(MCAssembler &Asm) override;
-};
-} // namespace
-
 uint64_t DXContainerObjectWriter::writeObject(MCAssembler &Asm) {
   // Start the file size as the header plus the size of the part offsets.
   // Presently DXContainer files usually contain 7-10 parts. Reserving space for
@@ -140,8 +116,3 @@ uint64_t DXContainerObjectWriter::writeObject(MCAssembler &Asm) {
   }
   return 0;
 }
-
-std::unique_ptr<MCObjectWriter> llvm::createDXContainerObjectWriter(
-    std::unique_ptr<MCDXContainerTargetWriter> MOTW, raw_pwrite_stream &OS) {
-  return std::make_unique<DXContainerObjectWriter>(std::move(MOTW), OS);
-}


        


More information about the llvm-commits mailing list