MCAsmParser: add support for .err directive

The .err directive produces an error whenever it is assembled.  This can be
useful for preventing assembly when an unexpected condition occurs.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201984 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Saleem Abdulrasool 2014-02-23 15:53:30 +00:00
parent da6ffb33d2
commit a0d16299c9
2 changed files with 35 additions and 0 deletions

View File

@ -361,6 +361,7 @@ private:
DK_CFI_REGISTER, DK_CFI_WINDOW_SAVE, DK_CFI_REGISTER, DK_CFI_WINDOW_SAVE,
DK_MACROS_ON, DK_MACROS_OFF, DK_MACRO, DK_ENDM, DK_ENDMACRO, DK_PURGEM, DK_MACROS_ON, DK_MACROS_OFF, DK_MACRO, DK_ENDM, DK_ENDMACRO, DK_PURGEM,
DK_SLEB128, DK_ULEB128, DK_SLEB128, DK_ULEB128,
DK_ERR,
DK_END DK_END
}; };
@ -471,6 +472,9 @@ private:
// "end" // "end"
bool parseDirectiveEnd(SMLoc DirectiveLoc); bool parseDirectiveEnd(SMLoc DirectiveLoc);
// "err"
bool parseDirectiveErr(SMLoc DirectiveLoc);
void initializeDirectiveKindMap(); void initializeDirectiveKindMap();
}; };
} }
@ -1526,6 +1530,8 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info) {
return parseDirectivePurgeMacro(IDLoc); return parseDirectivePurgeMacro(IDLoc);
case DK_END: case DK_END:
return parseDirectiveEnd(IDLoc); return parseDirectiveEnd(IDLoc);
case DK_ERR:
return parseDirectiveErr(IDLoc);
} }
return Error(IDLoc, "unknown directive"); return Error(IDLoc, "unknown directive");
@ -3931,6 +3937,15 @@ bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
return false; return false;
} }
/// parseDirectiveErr
/// ::= .err
bool AsmParser::parseDirectiveErr(SMLoc Loc) {
if (!TheCondStack.empty())
if (TheCondStack.back().Ignore)
return false;
return Error(Loc, ".err encountered");
}
/// parseDirectiveEndIf /// parseDirectiveEndIf
/// ::= .endif /// ::= .endif
bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) { bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {
@ -4054,6 +4069,7 @@ void AsmParser::initializeDirectiveKindMap() {
DirectiveKindMap[".endm"] = DK_ENDM; DirectiveKindMap[".endm"] = DK_ENDM;
DirectiveKindMap[".endmacro"] = DK_ENDMACRO; DirectiveKindMap[".endmacro"] = DK_ENDMACRO;
DirectiveKindMap[".purgem"] = DK_PURGEM; DirectiveKindMap[".purgem"] = DK_PURGEM;
DirectiveKindMap[".err"] = DK_ERR;
} }
MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) { MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) {

View File

@ -0,0 +1,19 @@
// RUN: not llvm-mc -triple i386 %s 2>&1 | FileCheck %s
.err
// CHECK: error: .err encountered
// CHECK-NEXT: .err
// CHECK-NEXT: ^
.ifc a,a
.err
.endif
// CHECK: error: .err encountered
// CHECK-NEXT: .err
// CHECK-NEXT: ^
.ifnc a,a
.err
.endif
// CHECK-NOT: error: .err encountered