[llvm-commits] [llvm] r79324 - in /llvm/trunk: include/llvm/CodeGen/AsmPrinter.h include/llvm/MC/MCStreamer.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/MC/MCAsmStreamer.cpp lib/MC/MCStreamer.cpp

Chris Lattner sabre at nondot.org
Mon Aug 17 23:15:17 PDT 2009


Author: lattner
Date: Tue Aug 18 01:15:16 2009
New Revision: 79324

URL: http://llvm.org/viewvc/llvm-project?rev=79324&view=rev
Log:
Make AsmStreamer maintain a notion of the current section, pushing it up from the
MCAsmStreamer.  Based on this, eliminate the current section from AsmPrinter.

While I'm at it, clean up the last of the horrible "switch to null section" stuff
and add an assert.  This change is in preparation for completely eliminating 
asmprinter::switchtosection.

Modified:
    llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
    llvm/trunk/include/llvm/MC/MCStreamer.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/lib/MC/MCStreamer.cpp

Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=79324&r1=79323&r2=79324&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Tue Aug 18 01:15:16 2009
@@ -62,10 +62,6 @@
     typedef gcp_map_type::iterator gcp_iterator;
     gcp_map_type GCMetadataPrinters;
 
-    /// CurrentSection - The current section we are emitting to.  This is
-    /// controlled and used by the SwitchToSection method.
-    const MCSection *CurrentSection;
-    
     /// If ExuberantAsm is set, a pointer to the loop info for this
     /// function.
     ///
@@ -127,7 +123,7 @@
     std::string CurrentFnName;
     
     /// getCurrentSection() - Return the current section we are emitting to.
-    const MCSection *getCurrentSection() const { return CurrentSection; }
+    const MCSection *getCurrentSection() const;
     
 
     /// VerboseAsm - Emit comments in assembly output if this is true.

Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=79324&r1=79323&r2=79324&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Tue Aug 18 01:15:16 2009
@@ -69,6 +69,9 @@
   protected:
     MCStreamer(MCContext &Ctx);
 
+    /// CurSection - This is the current section code is being emitted to, it is
+    /// kept up to date by SwitchSection.
+    const MCSection *CurSection;
   public:
     virtual ~MCStreamer();
 
@@ -78,11 +81,16 @@
     /// @{
 
     /// SwitchSection - Set the current section where code is being emitted to
-    /// @param Section.
+    /// @param Section.  This is required to update CurSection.
     ///
     /// This corresponds to assembler directives like .section, .text, etc.
     virtual void SwitchSection(const MCSection *Section) = 0;
 
+    
+    /// getCurrentSection - Return the current seciton that the streamer is
+    /// emitting code to.
+    const MCSection *getCurrentSection() const { return CurSection; }
+    
     /// EmitLabel - Emit a label for @param Symbol into the current section.
     ///
     /// This corresponds to an assembler statement such as:

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=79324&r1=79323&r2=79324&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Tue Aug 18 01:15:16 2009
@@ -63,7 +63,6 @@
 
     LastMI(0), LastFn(0), Counter(~0U),
     PrevDLT(0, ~0U, ~0U) {
-  CurrentSection = 0;
   DW = 0; MMI = 0;
   switch (AsmVerbose) {
   case cl::BOU_UNSET: VerboseAsm = VDef;  break;
@@ -91,19 +90,18 @@
 }
 
 /// SwitchToSection - Switch to the specified section of the executable if we
-/// are not already in it!  If "NS" is null, then this causes us to exit the
-/// current section and not reenter another one.  This is generally used for
-/// asmprinter hacks.
-///
-/// FIXME: Remove support for null sections.
-///
+/// are not already in it!
 void AsmPrinter::SwitchToSection(const MCSection *NS) {
-  CurrentSection = NS;
-  // FIXME: Remove support for null sections!
-  if (NS)
-    OutStreamer.SwitchSection(NS);
+  assert(NS != 0 && "Must specify a section to switch to");
+  OutStreamer.SwitchSection(NS);
+}
+
+/// getCurrentSection() - Return the current section we are emitting to.
+const MCSection *AsmPrinter::getCurrentSection() const {
+  return OutStreamer.getCurrentSection();
 }
 
+
 void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.setPreservesAll();
   MachineFunctionPass::getAnalysisUsage(AU);
@@ -143,8 +141,6 @@
       << '\n' << TAI->getCommentString()
       << " End of file scope inline assembly\n";
 
-  SwitchToSection(0);   // Reset back to no section to close off sections.
-  
   if (TAI->doesSupportDebugInformation() ||
       TAI->doesSupportExceptionHandling()) {
     MMI = getAnalysisIfAvailable<MachineModuleInfo>();
@@ -174,7 +170,6 @@
     // to stuff that is actually used.  Note that doing so would require targets
     // to notice uses in operands (due to constant exprs etc).  This should
     // happen with the MC stuff eventually.
-    SwitchToSection(0);
 
     // Print out module-level global variables here.
     for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
@@ -776,7 +771,7 @@
   if (TAI->getAlignmentIsInBytes()) NumBits = 1 << NumBits;
   O << TAI->getAlignDirective() << NumBits;
 
-  if (CurrentSection && CurrentSection->getKind().isText())
+  if (getCurrentSection()->getKind().isText())
     if (unsigned FillValue = TAI->getTextAlignFillValue()) {
       O << ',';
       PrintHex(FillValue);

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=79324&r1=79323&r2=79324&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Tue Aug 18 01:15:16 2009
@@ -24,12 +24,10 @@
   raw_ostream &OS;
   const TargetAsmInfo &TAI;
   AsmPrinter *Printer;
-  const MCSection *CurSection;
 public:
   MCAsmStreamer(MCContext &Context, raw_ostream &_OS, const TargetAsmInfo &tai,
                 AsmPrinter *_AsmPrinter)
-    : MCStreamer(Context), OS(_OS), TAI(tai), Printer(_AsmPrinter),
-      CurSection(0) {}
+    : MCStreamer(Context), OS(_OS), TAI(tai), Printer(_AsmPrinter) {}
   ~MCAsmStreamer() {}
 
   /// @name MCStreamer Interface

Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=79324&r1=79323&r2=79324&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Tue Aug 18 01:15:16 2009
@@ -11,7 +11,7 @@
 
 using namespace llvm;
 
-MCStreamer::MCStreamer(MCContext &_Context) : Context(_Context) {
+MCStreamer::MCStreamer(MCContext &_Context) : Context(_Context), CurSection(0) {
 }
 
 MCStreamer::~MCStreamer() {





More information about the llvm-commits mailing list