[llvm-commits] [llvm] r112849 - in /llvm/trunk: include/llvm/MC/MCStreamer.h lib/MC/MCAsmStreamer.cpp lib/MC/MCNullStreamer.cpp lib/MC/MCObjectStreamer.cpp lib/MC/MCParser/ELFAsmParser.cpp lib/MC/MCStreamer.cpp test/MC/AsmParser/ELF/directive_previous.s

Benjamin Kramer benny.kra at googlemail.com
Thu Sep 2 11:53:37 PDT 2010


Author: d0k
Date: Thu Sep  2 13:53:37 2010
New Revision: 112849

URL: http://llvm.org/viewvc/llvm-project?rev=112849&view=rev
Log:
Add AsmParser support for the ELF .previous directive. Patch by Roman Divacky.

Added:
    llvm/trunk/test/MC/AsmParser/ELF/directive_previous.s
Modified:
    llvm/trunk/include/llvm/MC/MCStreamer.h
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/lib/MC/MCNullStreamer.cpp
    llvm/trunk/lib/MC/MCObjectStreamer.cpp
    llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
    llvm/trunk/lib/MC/MCStreamer.cpp

Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=112849&r1=112848&r2=112849&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Thu Sep  2 13:53:37 2010
@@ -54,6 +54,10 @@
     /// kept up to date by SwitchSection.
     const MCSection *CurSection;
 
+    /// PrevSection - This is the previous section code is being emitted to, it is
+    /// kept up to date by SwitchSection.
+    const MCSection *PrevSection;
+
   public:
     virtual ~MCStreamer();
 
@@ -96,6 +100,10 @@
     /// emitting code to.
     const MCSection *getCurrentSection() const { return CurSection; }
 
+    /// getPreviousSection - Return the previous section that the streamer is
+    /// emitting code to.
+    const MCSection *getPreviousSection() const { return PrevSection; }
+
     /// SwitchSection - Set the current section where code is being emitted to
     /// @p Section.  This is required to update CurSection.
     ///

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=112849&r1=112848&r2=112849&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Thu Sep  2 13:53:37 2010
@@ -217,6 +217,7 @@
 void MCAsmStreamer::SwitchSection(const MCSection *Section) {
   assert(Section && "Cannot switch to a null section!");
   if (Section != CurSection) {
+    PrevSection = CurSection;
     CurSection = Section;
     Section->PrintSwitchToSection(MAI, OS);
   }

Modified: llvm/trunk/lib/MC/MCNullStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCNullStreamer.cpp?rev=112849&r1=112848&r2=112849&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCNullStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCNullStreamer.cpp Thu Sep  2 13:53:37 2010
@@ -26,6 +26,7 @@
     /// @{
 
     virtual void SwitchSection(const MCSection *Section) {
+      PrevSection = CurSection;
       CurSection = Section;
     }
 

Modified: llvm/trunk/lib/MC/MCObjectStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectStreamer.cpp?rev=112849&r1=112848&r2=112849&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectStreamer.cpp Thu Sep  2 13:53:37 2010
@@ -77,6 +77,7 @@
   // If already in this section, then this is a noop.
   if (Section == CurSection) return;
 
+  PrevSection = CurSection;
   CurSection = Section;
   CurSectionData = &getAssembler().getOrCreateSectionData(*Section);
 }

Modified: llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp?rev=112849&r1=112848&r2=112849&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp Thu Sep  2 13:53:37 2010
@@ -50,6 +50,7 @@
     AddDirectiveHandler<&ELFAsmParser::ParseDirectiveSize>(".size");
     AddDirectiveHandler<&ELFAsmParser::ParseDirectiveLEB128>(".sleb128");
     AddDirectiveHandler<&ELFAsmParser::ParseDirectiveLEB128>(".uleb128");
+    AddDirectiveHandler<&ELFAsmParser::ParseDirectivePrevious>(".previous");
   }
 
   bool ParseSectionDirectiveData(StringRef, SMLoc) {
@@ -111,6 +112,7 @@
   bool ParseDirectiveLEB128(StringRef, SMLoc);
   bool ParseDirectiveSection(StringRef, SMLoc);
   bool ParseDirectiveSize(StringRef, SMLoc);
+  bool ParseDirectivePrevious(StringRef, SMLoc);
 };
 
 }
@@ -272,6 +274,14 @@
   return TokError("LEB128 not supported yet");
 }
 
+bool ELFAsmParser::ParseDirectivePrevious(StringRef DirName, SMLoc) {
+  const MCSection *PreviousSection = getStreamer().getPreviousSection();
+  if (PreviousSection != NULL)
+    getStreamer().SwitchSection(PreviousSection);
+
+  return false;
+}
+
 namespace llvm {
 
 MCAsmParserExtension *createELFAsmParser() {

Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=112849&r1=112848&r2=112849&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Thu Sep  2 13:53:37 2010
@@ -15,7 +15,8 @@
 #include <cstdlib>
 using namespace llvm;
 
-MCStreamer::MCStreamer(MCContext &Ctx) : Context(Ctx), CurSection(0) {
+MCStreamer::MCStreamer(MCContext &Ctx) : Context(Ctx), CurSection(0),
+                                         PrevSection(0) {
 }
 
 MCStreamer::~MCStreamer() {

Added: llvm/trunk/test/MC/AsmParser/ELF/directive_previous.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/ELF/directive_previous.s?rev=112849&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/ELF/directive_previous.s (added)
+++ llvm/trunk/test/MC/AsmParser/ELF/directive_previous.s Thu Sep  2 13:53:37 2010
@@ -0,0 +1,13 @@
+# RUN: llvm-mc -triple i386-pc-linux-gnu %s | FileCheck %s
+
+.bss
+# CHECK: .bss
+
+.text
+# CHECK: .text
+
+.previous
+# CHECK: .bss
+
+.previous
+# CHECK: .text





More information about the llvm-commits mailing list