MC: Add MCAssembler::addFixup, which enforces that fixups are added in order.
authorDaniel Dunbar <daniel@zuster.org>
Fri, 12 Mar 2010 21:00:38 +0000 (21:00 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 12 Mar 2010 21:00:38 +0000 (21:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98379 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAssembler.h
lib/MC/MCMachOStreamer.cpp

index 4ac7ef19df864bc627826e46f5731e140264609e..f0efb6ce4a27f6711afebc4d92d18323930a9969 100644 (file)
@@ -162,6 +162,13 @@ public:
   /// @name Fixup Access
   /// @{
 
+  void addFixup(MCAsmFixup Fixup) {
+    // Enforce invariant that fixups are in offset order.
+    assert(Fixups.empty() || Fixup.Offset > Fixups.back().Offset &&
+           "Fixups must be added in order!");
+    Fixups.push_back(Fixup);
+  }
+
   std::vector<MCAsmFixup> &getFixups() { return Fixups; }
   const std::vector<MCAsmFixup> &getFixups() const { return Fixups; }
 
index 1a6fa41169217b3c7d93a82dca36d3d3425ab34f..2d833ba351fe2e39f56dc3b628f719a6d571d1e7 100644 (file)
@@ -327,9 +327,8 @@ void MCMachOStreamer::EmitValue(const MCExpr *Value, unsigned Size,
     for (unsigned i = 0; i != Size; ++i)
       DF->getContents().push_back(uint8_t(AbsValue >> (i * 8)));
   } else {
-    DF->getFixups().push_back(MCAsmFixup(DF->getContents().size(),
-                                         *AddValueSymbols(Value),
-                                         MCFixup::getKindForSize(Size)));
+    DF->addFixup(MCAsmFixup(DF->getContents().size(), *AddValueSymbols(Value),
+                            MCFixup::getKindForSize(Size)));
     DF->getContents().resize(DF->getContents().size() + Size, 0);
   }
 }
@@ -388,9 +387,8 @@ void MCMachOStreamer::EmitInstruction(const MCInst &Inst) {
     DF = new MCDataFragment(CurSectionData);
   for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
     MCFixup &F = Fixups[i];
-    DF->getFixups().push_back(MCAsmFixup(DF->getContents().size()+F.getOffset(),
-                                         *F.getValue(),
-                                         F.getKind()));
+    DF->addFixup(MCAsmFixup(DF->getContents().size()+F.getOffset(),
+                            *F.getValue(), F.getKind()));
   }
   DF->getContents().append(Code.begin(), Code.end());
 }