[llvm-commits] [llvm] r99474 - in /llvm/trunk: include/llvm/MC/MCAsmLayout.h include/llvm/MC/MCAssembler.h lib/MC/MCAssembler.cpp lib/MC/MachObjectWriter.cpp

Daniel Dunbar daniel at zuster.org
Wed Mar 24 19:00:07 PDT 2010


Author: ddunbar
Date: Wed Mar 24 21:00:07 2010
New Revision: 99474

URL: http://llvm.org/viewvc/llvm-project?rev=99474&view=rev
Log:
MC: Route access to SectionData offset and file size through MCAsmLayout.

Modified:
    llvm/trunk/include/llvm/MC/MCAsmLayout.h
    llvm/trunk/include/llvm/MC/MCAssembler.h
    llvm/trunk/lib/MC/MCAssembler.cpp
    llvm/trunk/lib/MC/MachObjectWriter.cpp

Modified: llvm/trunk/include/llvm/MC/MCAsmLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmLayout.h?rev=99474&r1=99473&r2=99474&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmLayout.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmLayout.h Wed Mar 24 21:00:07 2010
@@ -33,19 +33,58 @@
   /// Get the assembler object this is a layout for.
   MCAssembler &getAssembler() const { return Assembler; }
 
-  uint64_t getFragmentAddress(const MCFragment *F) const;
+  /// @name Fragment Layout Data
+  /// @{
 
+  /// \brief Get the effective size of the given fragment, as computed in the
+  /// current layout.
   uint64_t getFragmentEffectiveSize(const MCFragment *F) const;
+
+  /// \brief Set the effective size of the given fragment.
   void setFragmentEffectiveSize(MCFragment *F, uint64_t Value);
 
+  /// \brief Get the offset of the given fragment inside its containing section.
   uint64_t getFragmentOffset(const MCFragment *F) const;
+
+  /// \brief Set the offset of the given fragment inside its containing section.
   void setFragmentOffset(MCFragment *F, uint64_t Value);
 
+  /// @}
+  /// @name Section Layout Data
+  /// @{
+
+  /// \brief Get the computed address of the given section.
   uint64_t getSectionAddress(const MCSectionData *SD) const;
 
+  /// \brief Set the computed address of the given section.
+  void setSectionAddress(MCSectionData *SD, uint64_t Value);
+
+  /// \brief Get the data size of the given section, as emitted to the object
+  /// file. This may include additional padding, or be 0 for virtual sections.
+  uint64_t getSectionFileSize(const MCSectionData *SD) const;
+
+  /// \brief Set the data size of the given section.
+  void setSectionFileSize(MCSectionData *SD, uint64_t Value);
+
+  /// \brief Get the actual data size of the given section.
+  uint64_t getSectionSize(const MCSectionData *SD) const;
+
+  /// \brief Set the actual data size of the given section.
+  void setSectionSize(MCSectionData *SD, uint64_t Value);
+
+  /// @}
+  /// @name Utility Functions
+  /// @{
+
+  /// \brief Get the address of the given fragment, as computed in the current
+  /// layout.
+  uint64_t getFragmentAddress(const MCFragment *F) const;
+
+  /// \brief Get the address of the given symbol, as computed in the current
+  /// layout.
   uint64_t getSymbolAddress(const MCSymbolData *SD) const;
 
-  void setSectionAddress(MCSectionData *SD, uint64_t Value);
+  /// @}
 };
 
 } // end namespace llvm

Modified: llvm/trunk/include/llvm/MC/MCAssembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAssembler.h?rev=99474&r1=99473&r2=99474&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAssembler.h (original)
+++ llvm/trunk/include/llvm/MC/MCAssembler.h Wed Mar 24 21:00:07 2010
@@ -425,6 +425,9 @@
   unsigned getAlignment() const { return Alignment; }
   void setAlignment(unsigned Value) { Alignment = Value; }
 
+  bool hasInstructions() const { return HasInstructions; }
+  void setHasInstructions(bool Value) { HasInstructions = Value; }
+
   /// @name Fragment Access
   /// @{
 
@@ -447,29 +450,6 @@
 
   bool empty() const { return Fragments.empty(); }
 
-  /// @}
-  /// @name Assembler Backend Support
-  /// @{
-  //
-  // FIXME: This could all be kept private to the assembler implementation.
-
-  uint64_t getSize() const {
-    assert(Size != ~UINT64_C(0) && "File size not set!");
-    return Size;
-  }
-  void setSize(uint64_t Value) { Size = Value; }
-
-  uint64_t getFileSize() const {
-    assert(FileSize != ~UINT64_C(0) && "File size not set!");
-    return FileSize;
-  }
-  void setFileSize(uint64_t Value) { FileSize = Value; }
-
-  bool hasInstructions() const { return HasInstructions; }
-  void setHasInstructions(bool Value) { HasInstructions = Value; }
-
-  /// @}
-
   void dump();
 };
 

Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=99474&r1=99473&r2=99474&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Wed Mar 24 21:00:07 2010
@@ -82,6 +82,24 @@
   SD->Address = Value;
 }
 
+uint64_t MCAsmLayout::getSectionSize(const MCSectionData *SD) const {
+  assert(SD->Size != ~UINT64_C(0) && "File size not set!");
+  return SD->Size;
+}
+void MCAsmLayout::setSectionSize(MCSectionData *SD, uint64_t Value) {
+  SD->Size = Value;
+}
+
+uint64_t MCAsmLayout::getSectionFileSize(const MCSectionData *SD) const {
+  assert(SD->FileSize != ~UINT64_C(0) && "File size not set!");
+  return SD->FileSize;
+}
+void MCAsmLayout::setSectionFileSize(MCSectionData *SD, uint64_t Value) {
+  SD->FileSize = Value;
+}
+
+  /// @}
+
 /* *** */
 
 MCFragment::MCFragment() : Kind(FragmentType(~0)) {
@@ -419,11 +437,11 @@
   }
 
   // Set the section sizes.
-  SD.setSize(Address - StartAddress);
+  Layout.setSectionSize(&SD, Address - StartAddress);
   if (getBackend().isVirtualSection(SD.getSection()))
-    SD.setFileSize(0);
+    Layout.setSectionFileSize(&SD, 0);
   else
-    SD.setFileSize(Address - StartAddress);
+    Layout.setSectionFileSize(&SD, Address - StartAddress);
 }
 
 /// WriteFragmentData - Write the \arg F data to the output file.
@@ -522,9 +540,12 @@
 void MCAssembler::WriteSectionData(const MCSectionData *SD,
                                    const MCAsmLayout &Layout,
                                    MCObjectWriter *OW) const {
+  uint64_t SectionSize = Layout.getSectionSize(SD);
+  uint64_t SectionFileSize = Layout.getSectionFileSize(SD);
+
   // Ignore virtual sections.
   if (getBackend().isVirtualSection(SD->getSection())) {
-    assert(SD->getFileSize() == 0);
+    assert(SectionFileSize == 0 && "Invalid size for section!");
     return;
   }
 
@@ -536,10 +557,10 @@
     WriteFragmentData(*this, Layout, *it, OW);
 
   // Add section padding.
-  assert(SD->getFileSize() >= SD->getSize() && "Invalid section sizes!");
-  OW->WriteZeros(SD->getFileSize() - SD->getSize());
+  assert(SectionFileSize >= SectionSize && "Invalid section sizes!");
+  OW->WriteZeros(SectionFileSize - SectionSize);
 
-  assert(OW->getStream().tell() - Start == SD->getFileSize());
+  assert(OW->getStream().tell() - Start == SectionFileSize);
 }
 
 void MCAssembler::Finish() {
@@ -652,14 +673,14 @@
     // section.
     if (uint64_t Pad = OffsetToAlignment(Address, it->getAlignment())) {
       assert(Prev && "Missing prev section!");
-      Prev->setFileSize(Prev->getFileSize() + Pad);
+      Layout.setSectionFileSize(Prev, Layout.getSectionFileSize(Prev) + Pad);
       Address += Pad;
     }
 
     // Layout the section fragments and its size.
     Layout.setSectionAddress(&SD, Address);
     LayoutSection(SD, Layout);
-    Address += SD.getFileSize();
+    Address += Layout.getSectionFileSize(&SD);
 
     Prev = &SD;
   }
@@ -678,7 +699,7 @@
 
     Layout.setSectionAddress(&SD, Address);
     LayoutSection(SD, Layout);
-    Address += SD.getSize();
+    Address += Layout.getSectionSize(&SD);
   }
 
   // Scan for fragments that need relaxation.

Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=99474&r1=99473&r2=99474&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Wed Mar 24 21:00:07 2010
@@ -275,9 +275,12 @@
   void WriteSection(const MCAssembler &Asm, const MCAsmLayout &Layout,
                     const MCSectionData &SD, uint64_t FileOffset,
                     uint64_t RelocationsStart, unsigned NumRelocations) {
+    uint64_t SectionSize = Layout.getSectionSize(&SD);
+    uint64_t SectionFileSize = Layout.getSectionFileSize(&SD);
+
     // The offset is unused for virtual sections.
     if (Asm.getBackend().isVirtualSection(SD.getSection())) {
-      assert(SD.getFileSize() == 0 && "Invalid file size!");
+      assert(SectionFileSize == 0 && "Invalid file size!");
       FileOffset = 0;
     }
 
@@ -294,10 +297,10 @@
     WriteBytes(Section.getSegmentName(), 16);
     if (Is64Bit) {
       Write64(Layout.getSectionAddress(&SD)); // address
-      Write64(SD.getSize()); // size
+      Write64(SectionSize); // size
     } else {
       Write32(Layout.getSectionAddress(&SD)); // address
-      Write32(SD.getSize()); // size
+      Write32(SectionSize); // size
     }
     Write32(FileOffset);
 
@@ -965,15 +968,16 @@
            ie = Asm.end(); it != ie; ++it) {
       const MCSectionData &SD = *it;
       uint64_t Address = Layout.getSectionAddress(&SD);
+      uint64_t Size = Layout.getSectionSize(&SD);
+      uint64_t FileSize = Layout.getSectionFileSize(&SD);
 
-      VMSize = std::max(VMSize, Address + SD.getSize());
+      VMSize = std::max(VMSize, Address + Size);
 
       if (Asm.getBackend().isVirtualSection(SD.getSection()))
         continue;
 
-      SectionDataSize = std::max(SectionDataSize, Address + SD.getSize());
-      SectionDataFileSize = std::max(SectionDataFileSize,
-                                     Address + SD.getFileSize());
+      SectionDataSize = std::max(SectionDataSize, Address + Size);
+      SectionDataFileSize = std::max(SectionDataFileSize, Address + FileSize);
     }
 
     // The section data is padded to 4 bytes.





More information about the llvm-commits mailing list