summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2012-05-12 11:18:42 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2012-05-12 11:18:42 +0000
commit62c18b088122822cf70a375866ce45dfc4aae2c8 (patch)
tree2937aaee89f4bf9b98a8234bbdf879c26c4b6f91
parent0beab5e1cde833214271d533afea5405aae7e0ce (diff)
downloadbcm5719-llvm-62c18b088122822cf70a375866ce45dfc4aae2c8.tar.gz
bcm5719-llvm-62c18b088122822cf70a375866ce45dfc4aae2c8.zip
AsmParser: Add support for .ifb and .ifnb directives.
Based on a patch from PaX Team. llvm-svn: 156705
-rw-r--r--llvm/lib/MC/MCParser/AsmParser.cpp29
-rw-r--r--llvm/test/MC/AsmParser/ifb.s67
2 files changed, 96 insertions, 0 deletions
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 25419916c71..b0491e79fe8 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -245,6 +245,8 @@ private:
bool ParseDirectiveIncbin(); // ".incbin"
bool ParseDirectiveIf(SMLoc DirectiveLoc); // ".if"
+ // ".ifb" or ".ifnb", depending on ExpectBlank.
+ bool ParseDirectiveIfb(SMLoc DirectiveLoc, bool ExpectBlank);
// ".ifdef" or ".ifndef", depending on expect_defined
bool ParseDirectiveIfdef(SMLoc DirectiveLoc, bool expect_defined);
bool ParseDirectiveElseIf(SMLoc DirectiveLoc); // ".elseif"
@@ -1042,6 +1044,10 @@ bool AsmParser::ParseStatement() {
// example.
if (IDVal == ".if")
return ParseDirectiveIf(IDLoc);
+ if (IDVal == ".ifb")
+ return ParseDirectiveIfb(IDLoc, true);
+ if (IDVal == ".ifnb")
+ return ParseDirectiveIfb(IDLoc, false);
if (IDVal == ".ifdef")
return ParseDirectiveIfdef(IDLoc, true);
if (IDVal == ".ifndef" || IDVal == ".ifnotdef")
@@ -2313,6 +2319,29 @@ bool AsmParser::ParseDirectiveIf(SMLoc DirectiveLoc) {
return false;
}
+/// ParseDirectiveIfb
+/// ::= .ifb string
+bool AsmParser::ParseDirectiveIfb(SMLoc DirectiveLoc, bool ExpectBlank) {
+ TheCondStack.push_back(TheCondState);
+ TheCondState.TheCond = AsmCond::IfCond;
+
+ if(TheCondState.Ignore) {
+ EatToEndOfStatement();
+ } else {
+ StringRef Str = ParseStringToEndOfStatement();
+
+ if (getLexer().isNot(AsmToken::EndOfStatement))
+ return TokError("unexpected token in '.ifb' directive");
+
+ Lex();
+
+ TheCondState.CondMet = ExpectBlank == Str.empty();
+ TheCondState.Ignore = !TheCondState.CondMet;
+ }
+
+ return false;
+}
+
bool AsmParser::ParseDirectiveIfdef(SMLoc DirectiveLoc, bool expect_defined) {
StringRef Name;
TheCondStack.push_back(TheCondState);
diff --git a/llvm/test/MC/AsmParser/ifb.s b/llvm/test/MC/AsmParser/ifb.s
new file mode 100644
index 00000000000..48d69f4fc2b
--- /dev/null
+++ b/llvm/test/MC/AsmParser/ifb.s
@@ -0,0 +1,67 @@
+# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
+
+defined:
+
+# CHECK-NOT: .byte 0
+# CHECK: .byte 1
+.ifb
+ .byte 1
+.else
+ .byte 0
+.endif
+
+# CHECK-NOT: .byte 0
+# CHECK: .byte 1
+.ifb defined
+ .byte 0
+.else
+ .byte 1
+.endif
+
+# CHECK-NOT: .byte 0
+# CHECK: .byte 1
+.ifb undefined
+ .byte 0
+.else
+ .byte 1
+.endif
+
+# CHECK-NOT: .byte 0
+# CHECK: .byte 1
+.ifb ""
+ .byte 0
+.else
+ .byte 1
+.endif
+
+# CHECK-NOT: .byte 0
+# CHECK: .byte 1
+.ifnb
+ .byte 0
+.else
+ .byte 1
+.endif
+
+# CHECK-NOT: .byte 0
+# CHECK: .byte 1
+.ifnb defined
+ .byte 1
+.else
+ .byte 0
+.endif
+
+# CHECK-NOT: .byte 0
+# CHECK: .byte 1
+.ifnb undefined
+ .byte 1
+.else
+ .byte 0
+.endif
+
+# CHECK-NOT: .byte 0
+# CHECK: .byte 1
+.ifnb ""
+ .byte 1
+.else
+ .byte 0
+.endif
OpenPOWER on IntegriCloud