mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
AsmParser: Parse (and ignore) nested .macro definitions.
This enables a slightly odd feature of gas. The macro is defined when the outermost macro is instantiated. PR18599 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201045 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
965e3bc5ff
commit
275f653307
@ -3183,6 +3183,7 @@ bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
|
|||||||
Lex();
|
Lex();
|
||||||
|
|
||||||
AsmToken EndToken, StartToken = getTok();
|
AsmToken EndToken, StartToken = getTok();
|
||||||
|
unsigned MacroDepth = 0;
|
||||||
|
|
||||||
// Lex the macro definition.
|
// Lex the macro definition.
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -3191,15 +3192,25 @@ bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
|
|||||||
return Error(DirectiveLoc, "no matching '.endmacro' in definition");
|
return Error(DirectiveLoc, "no matching '.endmacro' in definition");
|
||||||
|
|
||||||
// Otherwise, check whether we have reach the .endmacro.
|
// Otherwise, check whether we have reach the .endmacro.
|
||||||
if (getLexer().is(AsmToken::Identifier) &&
|
if (getLexer().is(AsmToken::Identifier)) {
|
||||||
(getTok().getIdentifier() == ".endm" ||
|
if (getTok().getIdentifier() == ".endm" ||
|
||||||
getTok().getIdentifier() == ".endmacro")) {
|
getTok().getIdentifier() == ".endmacro") {
|
||||||
EndToken = getTok();
|
if (MacroDepth == 0) { // Outermost macro.
|
||||||
Lex();
|
EndToken = getTok();
|
||||||
if (getLexer().isNot(AsmToken::EndOfStatement))
|
Lex();
|
||||||
return TokError("unexpected token in '" + EndToken.getIdentifier() +
|
if (getLexer().isNot(AsmToken::EndOfStatement))
|
||||||
"' directive");
|
return TokError("unexpected token in '" + EndToken.getIdentifier() +
|
||||||
break;
|
"' directive");
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// Otherwise we just found the end of an inner macro.
|
||||||
|
--MacroDepth;
|
||||||
|
}
|
||||||
|
} else if (getTok().getIdentifier() == ".macro") {
|
||||||
|
// We allow nested macros. Those aren't instantiated until the outermost
|
||||||
|
// macro is expanded so just ignore them for now.
|
||||||
|
++MacroDepth;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, scan til the end of the statement.
|
// Otherwise, scan til the end of the statement.
|
||||||
|
@ -11,3 +11,23 @@ $4
|
|||||||
.data
|
.data
|
||||||
// CHECK: .byte 10
|
// CHECK: .byte 10
|
||||||
.mybyte 10
|
.mybyte 10
|
||||||
|
|
||||||
|
// PR18599
|
||||||
|
.macro macro_a
|
||||||
|
|
||||||
|
.macro macro_b
|
||||||
|
.byte 10
|
||||||
|
.macro macro_c
|
||||||
|
.endm
|
||||||
|
|
||||||
|
macro_c
|
||||||
|
.purgem macro_c
|
||||||
|
.endm
|
||||||
|
|
||||||
|
macro_b
|
||||||
|
.endm
|
||||||
|
|
||||||
|
macro_a
|
||||||
|
macro_b
|
||||||
|
// CHECK: .byte 10
|
||||||
|
// CHECK: .byte 10
|
||||||
|
Loading…
x
Reference in New Issue
Block a user