[llvm-commits] [llvm] r125120 - in /llvm/trunk: lib/MC/MCParser/AsmParser.cpp test/MC/AsmParser/ifdef.s test/MC/AsmParser/ifndef.s
Benjamin Kramer
benny.kra at googlemail.com
Tue Feb 8 14:29:56 PST 2011
Author: d0k
Date: Tue Feb 8 16:29:56 2011
New Revision: 125120
URL: http://llvm.org/viewvc/llvm-project?rev=125120&view=rev
Log:
Support for .ifdef / .ifndef in the assembler parser. Patch by Joerg Sonnenberger.
Added:
llvm/trunk/test/MC/AsmParser/ifdef.s
llvm/trunk/test/MC/AsmParser/ifndef.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=125120&r1=125119&r2=125120&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Tue Feb 8 16:29:56 2011
@@ -202,6 +202,8 @@
bool ParseDirectiveInclude(); // ".include"
bool ParseDirectiveIf(SMLoc DirectiveLoc); // ".if"
+ // ".ifdef" or ".ifndef", depending on expect_defined
+ bool ParseDirectiveIfdef(SMLoc DirectiveLoc, bool expect_defined);
bool ParseDirectiveElseIf(SMLoc DirectiveLoc); // ".elseif"
bool ParseDirectiveElse(SMLoc DirectiveLoc); // ".else"
bool ParseDirectiveEndIf(SMLoc DirectiveLoc); // .endif
@@ -222,7 +224,6 @@
getParser().AddDirectiveHandler(this, Directive,
HandleDirective<GenericAsmParser, Handler>);
}
-
public:
GenericAsmParser() {}
@@ -887,6 +888,10 @@
// example.
if (IDVal == ".if")
return ParseDirectiveIf(IDLoc);
+ if (IDVal == ".ifdef")
+ return ParseDirectiveIfdef(IDLoc, true);
+ if (IDVal == ".ifndef" || IDVal == ".ifnotdef")
+ return ParseDirectiveIfdef(IDLoc, false);
if (IDVal == ".elseif")
return ParseDirectiveElseIf(IDLoc);
if (IDVal == ".else")
@@ -1933,6 +1938,31 @@
return false;
}
+bool AsmParser::ParseDirectiveIfdef(SMLoc DirectiveLoc, bool expect_defined) {
+ StringRef Name;
+ TheCondStack.push_back(TheCondState);
+ TheCondState.TheCond = AsmCond::IfCond;
+
+ if (TheCondState.Ignore) {
+ EatToEndOfStatement();
+ } else {
+ if (ParseIdentifier(Name))
+ return TokError("expected identifier after '.ifdef'");
+
+ Lex();
+
+ MCSymbol *Sym = getContext().LookupSymbol(Name);
+
+ if (expect_defined)
+ TheCondState.CondMet = (Sym != NULL && !Sym->isUndefined());
+ else
+ TheCondState.CondMet = (Sym == NULL || Sym->isUndefined());
+ TheCondState.Ignore = !TheCondState.CondMet;
+ }
+
+ return false;
+}
+
/// ParseDirectiveElseIf
/// ::= .elseif expression
bool AsmParser::ParseDirectiveElseIf(SMLoc DirectiveLoc) {
Added: llvm/trunk/test/MC/AsmParser/ifdef.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/ifdef.s?rev=125120&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/ifdef.s (added)
+++ llvm/trunk/test/MC/AsmParser/ifdef.s Tue Feb 8 16:29:56 2011
@@ -0,0 +1,29 @@
+# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
+
+# CHECK-NOT: .byte 0
+# CHECK: .byte 1
+.ifdef undefined
+ .byte 0
+.else
+ .byte 1
+.endif
+
+defined:
+
+# CHECK: .byte 1
+# CHECK-NOT: .byte 0
+.ifdef defined
+ .byte 1
+.else
+ .byte 0
+.endif
+
+ movl %eax, undefined
+
+# CHECK-NOT: .byte 0
+# CHECK: .byte 1
+.ifdef undefined
+ .byte 0
+.else
+ .byte 1
+.endif
Added: llvm/trunk/test/MC/AsmParser/ifndef.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/ifndef.s?rev=125120&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/ifndef.s (added)
+++ llvm/trunk/test/MC/AsmParser/ifndef.s Tue Feb 8 16:29:56 2011
@@ -0,0 +1,29 @@
+# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
+
+# CHECK: .byte 1
+# CHECK-NOT: byte 0
+.ifndef undefined
+ .byte 1
+.else
+ .byte 0
+.endif
+
+defined:
+
+# CHECK-NOT: byte 0
+# CHECK: .byte 1
+.ifndef defined
+ .byte 0
+.else
+ .byte 1
+.endif
+
+ movl %eax, undefined
+
+# CHECK: .byte 1
+# CHECK-NOT: byte 0
+.ifndef undefined
+ .byte 1
+.else
+ .byte 0
+.endif
More information about the llvm-commits
mailing list