MC: Use accessors for access to MCAsmFixup.
[oota-llvm.git] / include / llvm / MC / MCAssembler.h
index e0e009526dd0700b88eba7a736e972460411a92e..c34042bd5221f1712fee8025b5a69fbcd1e2526a 100644 (file)
@@ -42,7 +42,6 @@ class TargetAsmBackend;
 //
 // FIXME: This should probably just be merged with MCFixup.
 class MCAsmFixup {
-public:
   /// Offset - The offset inside the fragment which needs to be rewritten.
   uint64_t Offset;
 
@@ -55,6 +54,13 @@ public:
 public:
   MCAsmFixup(uint64_t _Offset, const MCExpr &_Value, MCFixupKind _Kind)
     : Offset(_Offset), Value(&_Value), Kind(_Kind) {}
+
+  MCFixupKind getKind() const { return MCFixupKind(Kind); }
+
+  uint64_t getOffset() const { return Offset; }
+  void setOffset(uint64_t Value) { Offset = Value; }
+
+  const MCExpr *getValue() const { return Value; }
 };
 
 class MCFragment : public ilist_node<MCFragment> {
@@ -96,9 +102,9 @@ private:
   /// initialized.
   uint64_t EffectiveSize;
 
-  /// Ordinal - The global index of this fragment. This is the index across all
-  /// sections, not just the parent section.
-  unsigned Ordinal;
+  /// LayoutOrder - The global layout order of this fragment. This is the index
+  /// across all fragments in the file, not just within the section.
+  unsigned LayoutOrder;
 
   /// @}
 
@@ -108,7 +114,6 @@ protected:
 public:
   // Only for sentinel.
   MCFragment();
-  virtual ~MCFragment();
 
   FragmentType getKind() const { return Kind; }
 
@@ -118,12 +123,12 @@ public:
   MCSymbolData *getAtom() const { return Atom; }
   void setAtom(MCSymbolData *Value) { Atom = Value; }
 
-  unsigned getOrdinal() const { return Ordinal; }
-  void setOrdinal(unsigned Value) { Ordinal = Value; }
+  unsigned getLayoutOrder() const { return LayoutOrder; }
+  void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
 
   static bool classof(const MCFragment *O) { return true; }
 
-  virtual void dump();
+  void dump();
 };
 
 class MCDataFragment : public MCFragment {
@@ -151,7 +156,7 @@ public:
 
   void addFixup(MCAsmFixup Fixup) {
     // Enforce invariant that fixups are in offset order.
-    assert((Fixups.empty() || Fixup.Offset > Fixups.back().Offset) &&
+    assert((Fixups.empty() || Fixup.getOffset() > Fixups.back().getOffset()) &&
            "Fixups must be added in order!");
     Fixups.push_back(Fixup);
   }
@@ -173,8 +178,6 @@ public:
     return F->getKind() == MCFragment::FT_Data;
   }
   static bool classof(const MCDataFragment *) { return true; }
-
-  virtual void dump();
 };
 
 // FIXME: This current incarnation of MCInstFragment doesn't make much sense, as
@@ -235,8 +238,6 @@ public:
     return F->getKind() == MCFragment::FT_Inst;
   }
   static bool classof(const MCInstFragment *) { return true; }
-
-  virtual void dump();
 };
 
 class MCAlignFragment : public MCFragment {
@@ -258,12 +259,19 @@ class MCAlignFragment : public MCFragment {
   /// target dependent.
   bool EmitNops : 1;
 
+  /// OnlyAlignAddress - Flag to indicate that this align is only used to adjust
+  /// the address space size of a section and that it should not be included as
+  /// part of the section size. This flag can only be used on the last fragment
+  /// in a section.
+  bool OnlyAlignAddress : 1;
+
 public:
   MCAlignFragment(unsigned _Alignment, int64_t _Value, unsigned _ValueSize,
                   unsigned _MaxBytesToEmit, MCSectionData *SD = 0)
     : MCFragment(FT_Align, SD), Alignment(_Alignment),
       Value(_Value),ValueSize(_ValueSize),
-      MaxBytesToEmit(_MaxBytesToEmit), EmitNops(false) {}
+      MaxBytesToEmit(_MaxBytesToEmit), EmitNops(false),
+      OnlyAlignAddress(false) {}
 
   /// @name Accessors
   /// @{
@@ -279,14 +287,15 @@ public:
   bool hasEmitNops() const { return EmitNops; }
   void setEmitNops(bool Value) { EmitNops = Value; }
 
+  bool hasOnlyAlignAddress() const { return OnlyAlignAddress; }
+  void setOnlyAlignAddress(bool Value) { OnlyAlignAddress = Value; }
+
   /// @}
 
   static bool classof(const MCFragment *F) {
     return F->getKind() == MCFragment::FT_Align;
   }
   static bool classof(const MCAlignFragment *) { return true; }
-
-  virtual void dump();
 };
 
 class MCFillFragment : public MCFragment {
@@ -324,8 +333,6 @@ public:
     return F->getKind() == MCFragment::FT_Fill;
   }
   static bool classof(const MCFillFragment *) { return true; }
-
-  virtual void dump();
 };
 
 class MCOrgFragment : public MCFragment {
@@ -353,8 +360,6 @@ public:
     return F->getKind() == MCFragment::FT_Org;
   }
   static bool classof(const MCOrgFragment *) { return true; }
-
-  virtual void dump();
 };
 
 // FIXME: Should this be a separate class, or just merged into MCSection? Since
@@ -382,6 +387,9 @@ private:
   /// Ordinal - The section index in the assemblers section list.
   unsigned Ordinal;
 
+  /// LayoutOrder - The index of this section in the layout order.
+  unsigned LayoutOrder;
+
   /// Alignment - The maximum alignment seen in this section.
   unsigned Alignment;
 
@@ -394,13 +402,6 @@ private:
   /// initialized.
   uint64_t Address;
 
-  /// Size - The content size of this section. This is ~0 until initialized.
-  uint64_t Size;
-
-  /// FileSize - The size of this section in the object file. This is ~0 until
-  /// initialized.
-  uint64_t FileSize;
-
   /// HasInstructions - Whether this section has had instructions emitted into
   /// it.
   unsigned HasInstructions : 1;
@@ -423,6 +424,9 @@ public:
   unsigned getOrdinal() const { return Ordinal; }
   void setOrdinal(unsigned Value) { Ordinal = Value; }
 
+  unsigned getLayoutOrder() const { return LayoutOrder; }
+  void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
+
   /// @name Fragment Access
   /// @{
 
@@ -641,15 +645,11 @@ private:
   bool FragmentNeedsRelaxation(const MCInstFragment *IF,
                                const MCAsmLayout &Layout) const;
 
-  /// LayoutFragment - Performs layout of the given \arg Fragment; assuming that
-  /// the previous fragment has already been layed out correctly, and the parent
-  /// section has been initialized.
-  void LayoutFragment(MCAsmLayout &Layout, MCFragment &Fragment);
-
-  /// LayoutSection - Performs layout of the section referenced by the given
-  /// \arg SectionOrderIndex. The layout assumes that the previous section has
-  /// already been layed out correctly.
-  void LayoutSection(MCAsmLayout &Layout, unsigned SectionOrderIndex);
+  /// Compute the effective fragment size assuming it is layed out at the given
+  /// \arg SectionAddress and \arg FragmentOffset.
+  uint64_t ComputeFragmentSize(MCAsmLayout &Layout, const MCFragment &F,
+                               uint64_t SectionAddress,
+                               uint64_t FragmentOffset) const;
 
   /// LayoutOnce - Perform one layout iteration and return true if any offsets
   /// were adjusted.