@@ -295,10 +295,9 @@ class AsmParser : public MCAsmParser {
295
295
296
296
void checkForBadMacro (SMLoc DirectiveLoc, StringRef Name, StringRef Body,
297
297
ArrayRef<MCAsmMacroParameter> Parameters);
298
- bool expandMacro (raw_svector_ostream &OS, StringRef Body ,
298
+ bool expandMacro (raw_svector_ostream &OS, const MCAsmMacro &Macro ,
299
299
ArrayRef<MCAsmMacroParameter> Parameters,
300
- ArrayRef<MCAsmMacroArgument> A, bool EnableAtPseudoVariable,
301
- SMLoc L);
300
+ ArrayRef<MCAsmMacroArgument> A, bool EnableAtPseudoVariable);
302
301
303
302
// / Are macros enabled in the parser?
304
303
bool areMacrosEnabled () {return MacrosEnabledFlag;}
@@ -2496,17 +2495,16 @@ static bool isIdentifierChar(char c) {
2496
2495
c == ' .' ;
2497
2496
}
2498
2497
2499
- bool AsmParser::expandMacro (raw_svector_ostream &OS, StringRef Body ,
2498
+ bool AsmParser::expandMacro (raw_svector_ostream &OS, const MCAsmMacro &Macro ,
2500
2499
ArrayRef<MCAsmMacroParameter> Parameters,
2501
2500
ArrayRef<MCAsmMacroArgument> A,
2502
- bool EnableAtPseudoVariable, SMLoc L ) {
2501
+ bool EnableAtPseudoVariable) {
2503
2502
unsigned NParameters = Parameters.size ();
2504
2503
bool HasVararg = NParameters ? Parameters.back ().Vararg : false ;
2505
- if ((!IsDarwin || NParameters != 0 ) && NParameters != A.size ())
2506
- return Error (L, " Wrong number of arguments" );
2507
2504
2508
2505
// A macro without parameters is handled differently on Darwin:
2509
2506
// gas accepts no arguments and does no substitutions
2507
+ StringRef Body = Macro.Body ;
2510
2508
while (!Body.empty ()) {
2511
2509
// Scan for the next substitution.
2512
2510
std::size_t End = Body.size (), Pos = 0 ;
@@ -2882,10 +2880,11 @@ bool AsmParser::handleMacroEntry(const MCAsmMacro *M, SMLoc NameLoc) {
2882
2880
// Macro instantiation is lexical, unfortunately. We construct a new buffer
2883
2881
// to hold the macro body with substitutions.
2884
2882
SmallString<256 > Buf;
2885
- StringRef Body = M->Body ;
2886
2883
raw_svector_ostream OS (Buf);
2887
2884
2888
- if (expandMacro (OS, Body, M->Parameters , A, true , getTok ().getLoc ()))
2885
+ if ((!IsDarwin || M->Parameters .size ()) && M->Parameters .size () != A.size ())
2886
+ return Error (getTok ().getLoc (), " Wrong number of arguments" );
2887
+ if (expandMacro (OS, *M, M->Parameters , A, true ))
2889
2888
return true ;
2890
2889
2891
2890
// We include the .endmacro in the buffer as our cue to exit the macro
@@ -5694,8 +5693,7 @@ bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
5694
5693
raw_svector_ostream OS (Buf);
5695
5694
while (Count--) {
5696
5695
// Note that the AtPseudoVariable is disabled for instantiations of .rep(t).
5697
- if (expandMacro (OS, M->Body , std::nullopt, std::nullopt, false ,
5698
- getTok ().getLoc ()))
5696
+ if (expandMacro (OS, *M, std::nullopt, std::nullopt, false ))
5699
5697
return true ;
5700
5698
}
5701
5699
instantiateMacroLikeBody (M, DirectiveLoc, OS);
@@ -5726,7 +5724,7 @@ bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
5726
5724
for (const MCAsmMacroArgument &Arg : A) {
5727
5725
// Note that the AtPseudoVariable is enabled for instantiations of .irp.
5728
5726
// This is undocumented, but GAS seems to support it.
5729
- if (expandMacro (OS, M-> Body , Parameter, Arg, true , getTok (). getLoc () ))
5727
+ if (expandMacro (OS, *M , Parameter, Arg, true ))
5730
5728
return true ;
5731
5729
}
5732
5730
@@ -5768,7 +5766,7 @@ bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
5768
5766
5769
5767
// Note that the AtPseudoVariable is enabled for instantiations of .irpc.
5770
5768
// This is undocumented, but GAS seems to support it.
5771
- if (expandMacro (OS, M-> Body , Parameter, Arg, true , getTok (). getLoc () ))
5769
+ if (expandMacro (OS, *M , Parameter, Arg, true ))
5772
5770
return true ;
5773
5771
}
5774
5772
0 commit comments