@@ -3183,6 +3183,7 @@ bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
3183
3183
Lex ();
3184
3184
3185
3185
AsmToken EndToken, StartToken = getTok ();
3186
+ unsigned MacroDepth = 0 ;
3186
3187
3187
3188
// Lex the macro definition.
3188
3189
for (;;) {
@@ -3191,15 +3192,25 @@ bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
3191
3192
return Error (DirectiveLoc, " no matching '.endmacro' in definition" );
3192
3193
3193
3194
// Otherwise, check whether we have reach the .endmacro.
3194
- if (getLexer ().is (AsmToken::Identifier) &&
3195
- (getTok ().getIdentifier () == " .endm" ||
3196
- getTok ().getIdentifier () == " .endmacro" )) {
3197
- EndToken = getTok ();
3198
- Lex ();
3199
- if (getLexer ().isNot (AsmToken::EndOfStatement))
3200
- return TokError (" unexpected token in '" + EndToken.getIdentifier () +
3201
- " ' directive" );
3202
- break ;
3195
+ if (getLexer ().is (AsmToken::Identifier)) {
3196
+ if (getTok ().getIdentifier () == " .endm" ||
3197
+ getTok ().getIdentifier () == " .endmacro" ) {
3198
+ if (MacroDepth == 0 ) { // Outermost macro.
3199
+ EndToken = getTok ();
3200
+ Lex ();
3201
+ if (getLexer ().isNot (AsmToken::EndOfStatement))
3202
+ return TokError (" unexpected token in '" + EndToken.getIdentifier () +
3203
+ " ' directive" );
3204
+ break ;
3205
+ } else {
3206
+ // Otherwise we just found the end of an inner macro.
3207
+ --MacroDepth;
3208
+ }
3209
+ } else if (getTok ().getIdentifier () == " .macro" ) {
3210
+ // We allow nested macros. Those aren't instantiated until the outermost
3211
+ // macro is expanded so just ignore them for now.
3212
+ ++MacroDepth;
3213
+ }
3203
3214
}
3204
3215
3205
3216
// Otherwise, scan til the end of the statement.
0 commit comments