mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
Support for .ifdef / .ifndef in the assembler parser. Patch by Joerg Sonnenberger.
llvm-svn: 125120
This commit is contained in:
parent
e0a74b3dcf
commit
8ff71a1384
@ -202,6 +202,8 @@ private:
|
||||
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 @@ class GenericAsmParser : public MCAsmParserExtension {
|
||||
getParser().AddDirectiveHandler(this, Directive,
|
||||
HandleDirective<GenericAsmParser, Handler>);
|
||||
}
|
||||
|
||||
public:
|
||||
GenericAsmParser() {}
|
||||
|
||||
@ -887,6 +888,10 @@ bool AsmParser::ParseStatement() {
|
||||
// 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 @@ bool AsmParser::ParseDirectiveIf(SMLoc DirectiveLoc) {
|
||||
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) {
|
||||
|
29
test/MC/AsmParser/ifdef.s
Normal file
29
test/MC/AsmParser/ifdef.s
Normal file
@ -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
|
29
test/MC/AsmParser/ifndef.s
Normal file
29
test/MC/AsmParser/ifndef.s
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user