[llvm-commits] [llvm] r156709 - in /llvm/trunk: lib/MC/MCParser/AsmParser.cpp test/MC/AsmParser/purgem.s

Benjamin Kramer benny.kra at googlemail.com
Sat May 12 04:21:47 PDT 2012


Author: d0k
Date: Sat May 12 06:21:46 2012
New Revision: 156709

URL: http://llvm.org/viewvc/llvm-project?rev=156709&view=rev
Log:
AsmParser: Add support for the .purgem directive.

Based on a patch by Team PaX.

Added:
    llvm/trunk/test/MC/AsmParser/purgem.s
Modified:
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=156709&r1=156708&r2=156709&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Sat May 12 06:21:46 2012
@@ -336,6 +336,7 @@
     AddDirectiveHandler<&GenericAsmParser::ParseDirectiveMacro>(".macro");
     AddDirectiveHandler<&GenericAsmParser::ParseDirectiveEndMacro>(".endm");
     AddDirectiveHandler<&GenericAsmParser::ParseDirectiveEndMacro>(".endmacro");
+    AddDirectiveHandler<&GenericAsmParser::ParseDirectivePurgeMacro>(".purgem");
 
     AddDirectiveHandler<&GenericAsmParser::ParseDirectiveLEB128>(".sleb128");
     AddDirectiveHandler<&GenericAsmParser::ParseDirectiveLEB128>(".uleb128");
@@ -367,6 +368,7 @@
   bool ParseDirectiveMacrosOnOff(StringRef, SMLoc DirectiveLoc);
   bool ParseDirectiveMacro(StringRef, SMLoc DirectiveLoc);
   bool ParseDirectiveEndMacro(StringRef, SMLoc DirectiveLoc);
+  bool ParseDirectivePurgeMacro(StringRef, SMLoc DirectiveLoc);
 
   bool ParseDirectiveLEB128(StringRef, SMLoc);
 };
@@ -3083,6 +3085,27 @@
                   "no current macro definition");
 }
 
+/// ParseDirectivePurgeMacro
+/// ::= .purgem
+bool GenericAsmParser::ParseDirectivePurgeMacro(StringRef Directive,
+                                                SMLoc DirectiveLoc) {
+  StringRef Name;
+  if (getParser().ParseIdentifier(Name))
+    return TokError("expected identifier in '.purgem' directive");
+
+  if (getLexer().isNot(AsmToken::EndOfStatement))
+    return TokError("unexpected token in '.purgem' directive");
+
+  StringMap<Macro*>::iterator I = getParser().MacroMap.find(Name);
+  if (I == getParser().MacroMap.end())
+    return Error(DirectiveLoc, "macro '" + Name + "' is not defined");
+
+  // Undefine the macro.
+  delete I->getValue();
+  getParser().MacroMap.erase(I);
+  return false;
+}
+
 bool GenericAsmParser::ParseDirectiveLEB128(StringRef DirName, SMLoc) {
   getParser().CheckForValidSection();
 

Added: llvm/trunk/test/MC/AsmParser/purgem.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/purgem.s?rev=156709&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/purgem.s (added)
+++ llvm/trunk/test/MC/AsmParser/purgem.s Sat May 12 06:21:46 2012
@@ -0,0 +1,12 @@
+# RUN: not llvm-mc -triple i386-unknown-unknown %s |& FileCheck %s
+
+.macro foo
+.err
+.endm
+
+.purgem bar
+# CHECK: error: macro 'bar' is not defined
+
+.purgem foo
+foo
+# CHECK: error: invalid instruction mnemonic 'foo'





More information about the llvm-commits mailing list