<div dir="ltr">On Wed, Jun 11, 2014 at 12:20 PM, Janne Grunau <span dir="ltr"><<a href="mailto:j@jannau.net" target="_blank">j@jannau.net</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
switched to switch/case which looks nicer but is longer<br>
added .if diagnostics tests<br>
<br>
lib/MC/MCParser/AsmParser.cpp | 46 +++++++++++++++++++++++-----<br>
test/MC/AsmParser/conditional_asm.s | 60 +++++++++++++++++++++++++++++++++++++<br>
test/MC/AsmParser/if-diagnostics.s | 29 ++++++++++++++++++<br>
3 files changed, 127 insertions(+), 8 deletions(-)<br>
create mode 100644 test/MC/AsmParser/if-diagnostics.s<br>
<br>
diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp<br>
index cbff7be..408097a 100644<br>
--- a/lib/MC/MCParser/AsmParser.cpp<br>
+++ b/lib/MC/MCParser/AsmParser.cpp<br>
@@ -345,8 +345,9 @@ private:<br>
<div class=""> DK_REFERENCE, DK_WEAK_DEFINITION, DK_WEAK_REFERENCE,<br>
DK_WEAK_DEF_CAN_BE_HIDDEN, DK_COMM, DK_COMMON, DK_LCOMM, DK_ABORT,<br>
DK_INCLUDE, DK_INCBIN, DK_CODE16, DK_CODE16GCC, DK_REPT, DK_IRP, DK_IRPC,<br>
- DK_IF, DK_IFNE, DK_IFB, DK_IFNB, DK_IFC, DK_IFEQS, DK_IFNC, DK_IFDEF,<br>
- DK_IFNDEF, DK_IFNOTDEF, DK_ELSEIF, DK_ELSE, DK_ENDIF,<br>
+ DK_IF, DK_IFEQ, DK_IFGE, DK_IFGT, DK_IFLE, DK_IFLT, DK_IFNE, DK_IFB,<br>
+ DK_IFNB, DK_IFC, DK_IFEQS, DK_IFNC, DK_IFDEF, DK_IFNDEF, DK_IFNOTDEF,<br>
+ DK_ELSEIF, DK_ELSE, DK_ENDIF,<br>
DK_SPACE, DK_SKIP, DK_FILE, DK_LINE, DK_LOC, DK_STABS,<br>
DK_CFI_SECTIONS, DK_CFI_STARTPROC, DK_CFI_ENDPROC, DK_CFI_DEF_CFA,<br>
DK_CFI_DEF_CFA_OFFSET, DK_CFI_ADJUST_CFA_OFFSET, DK_CFI_DEF_CFA_REGISTER,<br>
</div>@@ -433,8 +434,8 @@ private:<br>
<div class=""> bool parseDirectiveInclude(); // ".include"<br>
bool parseDirectiveIncbin(); // ".incbin"<br>
<br>
- // ".if" or ".ifne"<br>
- bool parseDirectiveIf(SMLoc DirectiveLoc);<br>
+ // ".if", ".ifeq", ".ifge", ".ifgt" , ".ifle", ".iflt" or ".ifne"<br>
+ bool parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind);<br>
// ".ifb" or ".ifnb", depending on ExpectBlank.<br>
bool parseDirectiveIfb(SMLoc DirectiveLoc, bool ExpectBlank);<br>
// ".ifc" or ".ifnc", depending on ExpectEqual.<br>
</div>@@ -1229,8 +1230,13 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info) {<br>
<div class=""> default:<br>
break;<br>
case DK_IF:<br>
+ case DK_IFEQ:<br>
+ case DK_IFGE:<br>
+ case DK_IFGT:<br>
+ case DK_IFLE:<br>
+ case DK_IFLT:<br>
case DK_IFNE:<br>
- return parseDirectiveIf(IDLoc);<br>
+ return parseDirectiveIf(IDLoc, DirKind);<br>
case DK_IFB:<br>
return parseDirectiveIfb(IDLoc, true);<br>
case DK_IFNB:<br>
</div>@@ -3792,9 +3798,8 @@ bool AsmParser::parseDirectiveIncbin() {<br>
<div class=""> }<br>
<br>
/// parseDirectiveIf<br>
-/// ::= .if expression<br>
-/// ::= .ifne expression<br>
-bool AsmParser::parseDirectiveIf(SMLoc DirectiveLoc) {<br>
+/// ::= .if{,eq,ge,gt,le,lt,ne} expression<br>
+bool AsmParser::parseDirectiveIf(SMLoc DirectiveLoc, DirectiveKind DirKind) {<br>
TheCondStack.push_back(TheCondState);<br>
TheCondState.TheCond = AsmCond::IfCond;<br>
if (TheCondState.Ignore) {<br>
</div>@@ -3809,6 +3814,26 @@ bool AsmParser::parseDirectiveIf(SMLoc DirectiveLoc) {<br>
<br>
Lex();<br>
<br>
+ switch (DirKind) {<br>
+ default:<br>
+ break;<br></blockquote><div><br></div><div>Cant this be marked as unreachable? All of the cases below should take care of any directive kind that we have encountered. Something like should do the trick: llvm_unreachable("unsupported directive");</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ case DK_IFEQ:<br>
<div class="">+ ExprValue = ExprValue == 0;<br>
</div>+ break;<br>
+ case DK_IFGE:<br>
<div class="">+ ExprValue = ExprValue >= 0;<br>
</div>+ break;<br>
+ case DK_IFGT:<br>
<div class="">+ ExprValue = ExprValue > 0;<br>
</div>+ break;<br>
+ case DK_IFLE:<br>
<div class="">+ ExprValue = ExprValue <= 0;<br>
</div>+ break;<br>
+ case DK_IFLT:<br>
<div class="">+ ExprValue = ExprValue < 0;<br>
</div>+ break;<br>
+ }<br>
<div class="">+<br>
TheCondState.CondMet = ExprValue;<br>
TheCondState.Ignore = !TheCondState.CondMet;<br>
}<br>
</div>@@ -4111,6 +4136,11 @@ void AsmParser::initializeDirectiveKindMap() {<br>
<div><div class="h5"> DirectiveKindMap[".bundle_lock"] = DK_BUNDLE_LOCK;<br>
DirectiveKindMap[".bundle_unlock"] = DK_BUNDLE_UNLOCK;<br>
DirectiveKindMap[".if"] = DK_IF;<br>
+ DirectiveKindMap[".ifeq"] = DK_IFEQ;<br>
+ DirectiveKindMap[".ifge"] = DK_IFGE;<br>
+ DirectiveKindMap[".ifgt"] = DK_IFGT;<br>
+ DirectiveKindMap[".ifle"] = DK_IFLE;<br>
+ DirectiveKindMap[".iflt"] = DK_IFLT;<br>
DirectiveKindMap[".ifne"] = DK_IFNE;<br>
DirectiveKindMap[".ifb"] = DK_IFB;<br>
DirectiveKindMap[".ifnb"] = DK_IFNB;<br>
diff --git a/test/MC/AsmParser/conditional_asm.s b/test/MC/AsmParser/conditional_asm.s<br>
index b9bee33..ecbceb1 100644<br>
--- a/test/MC/AsmParser/conditional_asm.s<br>
+++ b/test/MC/AsmParser/conditional_asm.s<br>
@@ -11,6 +11,66 @@<br>
.endif<br>
.endif<br>
<br>
+# CHECK: .byte 0<br>
+# CHECK-NOT: .byte 1<br>
+.ifeq 32 - 32<br>
+ .byte 0<br>
+.else<br>
+ .byte 1<br>
+.endif<br>
+<br>
+# CHECK: .byte 0<br>
+# CHECK: .byte 1<br>
+# CHECK-NOT: .byte 2<br>
+.ifge 32 - 31<br>
+ .byte 0<br>
+.endif<br>
+.ifge 32 - 32<br>
+ .byte 1<br>
+.endif<br>
+.ifge 32 - 33<br>
+ .byte 2<br>
+.endif<br>
+<br>
+# CHECK: .byte 0<br>
+# CHECK-NOT: .byte 1<br>
+# CHECK-NOT: .byte 2<br>
+.ifgt 32 - 31<br>
+ .byte 0<br>
+.endif<br>
+.ifgt 32 - 32<br>
+ .byte 1<br>
+.endif<br>
+.ifgt 32 - 33<br>
+ .byte 2<br>
+.endif<br>
+<br>
+# CHECK-NOT: .byte 0<br>
+# CHECK: .byte 1<br>
+# CHECK: .byte 2<br>
+.ifle 32 - 31<br>
+ .byte 0<br>
+.endif<br>
+.ifle 32 - 32<br>
+ .byte 1<br>
+.endif<br>
+.ifle 32 - 33<br>
+ .byte 2<br>
+.endif<br>
+<br>
+# CHECK-NOT: .byte 0<br>
+# CHECK-NOT: .byte 1<br>
+# CHECK: .byte 2<br>
+.iflt 32 - 31<br>
+ .byte 0<br>
+.endif<br>
+.iflt 32 - 32<br>
+ .byte 1<br>
+.endif<br>
+.iflt 32 - 33<br>
+ .byte 2<br>
+.endif<br>
+<br>
# CHECK: .byte 1<br>
# CHECK-NOT: .byte 0<br>
.ifne 32 - 32<br>
</div></div>diff --git a/test/MC/AsmParser/if-diagnostics.s b/test/MC/AsmParser/if-diagnostics.s<br>
new file mode 100644<br>
index 0000000..d102a56<br>
--- /dev/null<br>
+++ b/test/MC/AsmParser/if-diagnostics.s<br>
@@ -0,0 +1,29 @@<br>
+// RUN: not llvm-mc -triple i386 %s -o /dev/null 2>&1 | FileCheck %s<br>
+<br>
+.if<br>
+.endif<br>
+<br>
+// CHECK: error: unknown token in expression<br>
+// CHECK: .if<br>
+// CHECK: ^<br>
+<br>
+.ifeq 0, 3<br>
+.endif<br>
+<br>
+// CHECK:error: unexpected token in '.if' directive<br>
+// CHECK: .ifeq 0, 3<br>
+// CHECK: ^<br>
+<br>
+.iflt "string1"<br>
+.endif<br>
+<br>
+// CHECK: error: expected absolute expression<br>
+// CHECK: .iflt "string1"<br>
+// CHECK: ^<br>
+<br>
+.ifge test<br>
+.endif<br>
+<br>
+// CHECK: error: expected absolute expression<br>
+// CHECK: .ifge test<br>
+// CHECK: ^<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.0.0<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>Saleem Abdulrasool<br>compnerd (at) compnerd (dot) org
</div></div>