[llvm-commits] [llvm] r106141 - in /llvm/trunk: include/llvm/MC/MCObjectStreamer.h lib/MC/MCMachOStreamer.cpp lib/MC/MCObjectStreamer.cpp

Daniel Dunbar daniel at zuster.org
Wed Jun 16 13:04:25 PDT 2010


Author: ddunbar
Date: Wed Jun 16 15:04:25 2010
New Revision: 106141

URL: http://llvm.org/viewvc/llvm-project?rev=106141&view=rev
Log:
MC: Lift SwitchSection() and Finish() into MCObjectStreamer.

Modified:
    llvm/trunk/include/llvm/MC/MCObjectStreamer.h
    llvm/trunk/lib/MC/MCMachOStreamer.cpp
    llvm/trunk/lib/MC/MCObjectStreamer.cpp

Modified: llvm/trunk/include/llvm/MC/MCObjectStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectStreamer.h?rev=106141&r1=106140&r2=106141&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectStreamer.h Wed Jun 16 15:04:25 2010
@@ -28,14 +28,27 @@
 /// implementation.
 class MCObjectStreamer : public MCStreamer {
   MCAssembler *Assembler;
+  MCSectionData *CurSectionData;
 
 protected:
   MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB,
                    raw_ostream &_OS, MCCodeEmitter *_Emitter);
   ~MCObjectStreamer();
 
+  MCSectionData *getCurrentSectionData() const {
+    return CurSectionData;
+  }
+
 public:
   MCAssembler &getAssembler() { return *Assembler; }
+
+  /// @name MCStreamer Interface
+  /// @{
+
+  virtual void SwitchSection(const MCSection *Section);
+  virtual void Finish();
+
+  /// @}
 };
 
 } // end namespace llvm

Modified: llvm/trunk/lib/MC/MCMachOStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCMachOStreamer.cpp?rev=106141&r1=106140&r2=106141&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCMachOStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCMachOStreamer.cpp Wed Jun 16 15:04:25 2010
@@ -27,19 +27,16 @@
 namespace {
 
 class MCMachOStreamer : public MCObjectStreamer {
-
 private:
-  MCSectionData *CurSectionData;
-
   /// Track the current atom for each section.
   DenseMap<const MCSectionData*, MCSymbolData*> CurrentAtomMap;
 
 private:
   MCFragment *getCurrentFragment() const {
-    assert(CurSectionData && "No current section!");
+    assert(getCurrentSectionData() && "No current section!");
 
-    if (!CurSectionData->empty())
-      return &CurSectionData->getFragmentList().back();
+    if (!getCurrentSectionData()->empty())
+      return &getCurrentSectionData()->getFragmentList().back();
 
     return 0;
   }
@@ -55,8 +52,8 @@
 
   /// Create a new data fragment in the current section.
   MCDataFragment *createDataFragment() const {
-    MCDataFragment *DF = new MCDataFragment(CurSectionData);
-    DF->setAtom(CurrentAtomMap.lookup(CurSectionData));
+    MCDataFragment *DF = new MCDataFragment(getCurrentSectionData());
+    DF->setAtom(CurrentAtomMap.lookup(getCurrentSectionData()));
     return DF;
   }
 
@@ -66,7 +63,7 @@
 public:
   MCMachOStreamer(MCContext &Context, TargetAsmBackend &TAB,
                   raw_ostream &OS, MCCodeEmitter *Emitter)
-    : MCObjectStreamer(Context, TAB, OS, Emitter), CurSectionData(0) {}
+    : MCObjectStreamer(Context, TAB, OS, Emitter) {}
 
   const MCExpr *AddValueSymbols(const MCExpr *Value) {
     switch (Value->getKind()) {
@@ -97,7 +94,6 @@
   /// @name MCStreamer Interface
   /// @{
 
-  virtual void SwitchSection(const MCSection *Section);
   virtual void EmitLabel(MCSymbol *Symbol);
   virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
   virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
@@ -148,23 +144,12 @@
   }
 
   virtual void EmitInstruction(const MCInst &Inst);
-  virtual void Finish();
 
   /// @}
 };
 
 } // end anonymous namespace.
 
-void MCMachOStreamer::SwitchSection(const MCSection *Section) {
-  assert(Section && "Cannot switch to a null section!");
-
-  // If already in this section, then this is a noop.
-  if (Section == CurSection) return;
-
-  CurSection = Section;
-  CurSectionData = &getAssembler().getOrCreateSectionData(*Section);
-}
-
 void MCMachOStreamer::EmitLabel(MCSymbol *Symbol) {
   assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
   assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
@@ -175,7 +160,7 @@
   // Update the current atom map, if necessary.
   bool MustCreateFragment = false;
   if (getAssembler().isSymbolLinkerVisible(&SD)) {
-    CurrentAtomMap[CurSectionData] = &SD;
+    CurrentAtomMap[getCurrentSectionData()] = &SD;
 
     // We have to create a new fragment, fragments cannot span atoms.
     MustCreateFragment = true;
@@ -228,7 +213,7 @@
     // important for matching the string table that 'as' generates.
     IndirectSymbolData ISD;
     ISD.Symbol = Symbol;
-    ISD.SectionData = CurSectionData;
+    ISD.SectionData = getCurrentSectionData();
     getAssembler().getIndirectSymbols().push_back(ISD);
     return;
   }
@@ -389,12 +374,12 @@
   if (MaxBytesToEmit == 0)
     MaxBytesToEmit = ByteAlignment;
   MCFragment *F = new MCAlignFragment(ByteAlignment, Value, ValueSize,
-                                      MaxBytesToEmit, CurSectionData);
-  F->setAtom(CurrentAtomMap.lookup(CurSectionData));
+                                      MaxBytesToEmit, getCurrentSectionData());
+  F->setAtom(CurrentAtomMap.lookup(getCurrentSectionData()));
 
   // Update the maximum alignment on the current section if necessary.
-  if (ByteAlignment > CurSectionData->getAlignment())
-    CurSectionData->setAlignment(ByteAlignment);
+  if (ByteAlignment > getCurrentSectionData()->getAlignment())
+    getCurrentSectionData()->setAlignment(ByteAlignment);
 }
 
 void MCMachOStreamer::EmitCodeAlignment(unsigned ByteAlignment,
@@ -402,24 +387,24 @@
   if (MaxBytesToEmit == 0)
     MaxBytesToEmit = ByteAlignment;
   MCAlignFragment *F = new MCAlignFragment(ByteAlignment, 0, 1, MaxBytesToEmit,
-                                           CurSectionData);
+                                           getCurrentSectionData());
   F->setEmitNops(true);
-  F->setAtom(CurrentAtomMap.lookup(CurSectionData));
+  F->setAtom(CurrentAtomMap.lookup(getCurrentSectionData()));
 
   // Update the maximum alignment on the current section if necessary.
-  if (ByteAlignment > CurSectionData->getAlignment())
-    CurSectionData->setAlignment(ByteAlignment);
+  if (ByteAlignment > getCurrentSectionData()->getAlignment())
+    getCurrentSectionData()->setAlignment(ByteAlignment);
 }
 
 void MCMachOStreamer::EmitValueToOffset(const MCExpr *Offset,
                                         unsigned char Value) {
-  MCFragment *F = new MCOrgFragment(*Offset, Value, CurSectionData);
-  F->setAtom(CurrentAtomMap.lookup(CurSectionData));
+  MCFragment *F = new MCOrgFragment(*Offset, Value, getCurrentSectionData());
+  F->setAtom(CurrentAtomMap.lookup(getCurrentSectionData()));
 }
 
 void MCMachOStreamer::EmitInstToFragment(const MCInst &Inst) {
-  MCInstFragment *IF = new MCInstFragment(Inst, CurSectionData);
-  IF->setAtom(CurrentAtomMap.lookup(CurSectionData));
+  MCInstFragment *IF = new MCInstFragment(Inst, getCurrentSectionData());
+  IF->setAtom(CurrentAtomMap.lookup(getCurrentSectionData()));
 
   // Add the fixups and data.
   //
@@ -458,7 +443,7 @@
     if (Inst.getOperand(i).isExpr())
       AddValueSymbols(Inst.getOperand(i).getExpr());
 
-  CurSectionData->setHasInstructions(true);
+  getCurrentSectionData()->setHasInstructions(true);
 
   // If this instruction doesn't need relaxation, just emit it as data.
   if (!getAssembler().getBackend().MayNeedRelaxation(Inst)) {
@@ -481,10 +466,6 @@
   EmitInstToFragment(Inst);
 }
 
-void MCMachOStreamer::Finish() {
-  getAssembler().Finish();
-}
-
 MCStreamer *llvm::createMachOStreamer(MCContext &Context, TargetAsmBackend &TAB,
                                       raw_ostream &OS, MCCodeEmitter *CE,
                                       bool RelaxAll) {

Modified: llvm/trunk/lib/MC/MCObjectStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectStreamer.cpp?rev=106141&r1=106140&r2=106141&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectStreamer.cpp Wed Jun 16 15:04:25 2010
@@ -14,11 +14,26 @@
 
 MCObjectStreamer::MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB,
                                    raw_ostream &_OS, MCCodeEmitter *_Emitter)
-  : MCStreamer(Context),
-    Assembler(new MCAssembler(Context, TAB, *_Emitter, _OS))
+  : MCStreamer(Context), Assembler(new MCAssembler(Context, TAB,
+                                                   *_Emitter, _OS)),
+    CurSectionData(0)
 {
 }
 
 MCObjectStreamer::~MCObjectStreamer() {
   delete Assembler;
 }
+
+void MCObjectStreamer::SwitchSection(const MCSection *Section) {
+  assert(Section && "Cannot switch to a null section!");
+
+  // If already in this section, then this is a noop.
+  if (Section == CurSection) return;
+
+  CurSection = Section;
+  CurSectionData = &getAssembler().getOrCreateSectionData(*Section);
+}
+
+void MCObjectStreamer::Finish() {
+  getAssembler().Finish();
+}





More information about the llvm-commits mailing list