Skip to content

Commit 3cc445a

Browse files
committed
[MCAsmParser] Simplify expandMacro
The error checking is only for .macro directives. Move it to the .macro parser to remove one parameter.
1 parent 526553b commit 3cc445a

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,9 @@ class AsmParser : public MCAsmParser {
295295

296296
void checkForBadMacro(SMLoc DirectiveLoc, StringRef Name, StringRef Body,
297297
ArrayRef<MCAsmMacroParameter> Parameters);
298-
bool expandMacro(raw_svector_ostream &OS, StringRef Body,
298+
bool expandMacro(raw_svector_ostream &OS, const MCAsmMacro &Macro,
299299
ArrayRef<MCAsmMacroParameter> Parameters,
300-
ArrayRef<MCAsmMacroArgument> A, bool EnableAtPseudoVariable,
301-
SMLoc L);
300+
ArrayRef<MCAsmMacroArgument> A, bool EnableAtPseudoVariable);
302301

303302
/// Are macros enabled in the parser?
304303
bool areMacrosEnabled() {return MacrosEnabledFlag;}
@@ -2496,17 +2495,16 @@ static bool isIdentifierChar(char c) {
24962495
c == '.';
24972496
}
24982497

2499-
bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
2498+
bool AsmParser::expandMacro(raw_svector_ostream &OS, const MCAsmMacro &Macro,
25002499
ArrayRef<MCAsmMacroParameter> Parameters,
25012500
ArrayRef<MCAsmMacroArgument> A,
2502-
bool EnableAtPseudoVariable, SMLoc L) {
2501+
bool EnableAtPseudoVariable) {
25032502
unsigned NParameters = Parameters.size();
25042503
bool HasVararg = NParameters ? Parameters.back().Vararg : false;
2505-
if ((!IsDarwin || NParameters != 0) && NParameters != A.size())
2506-
return Error(L, "Wrong number of arguments");
25072504

25082505
// A macro without parameters is handled differently on Darwin:
25092506
// gas accepts no arguments and does no substitutions
2507+
StringRef Body = Macro.Body;
25102508
while (!Body.empty()) {
25112509
// Scan for the next substitution.
25122510
std::size_t End = Body.size(), Pos = 0;
@@ -2882,10 +2880,11 @@ bool AsmParser::handleMacroEntry(const MCAsmMacro *M, SMLoc NameLoc) {
28822880
// Macro instantiation is lexical, unfortunately. We construct a new buffer
28832881
// to hold the macro body with substitutions.
28842882
SmallString<256> Buf;
2885-
StringRef Body = M->Body;
28862883
raw_svector_ostream OS(Buf);
28872884

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))
28892888
return true;
28902889

28912890
// 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) {
56945693
raw_svector_ostream OS(Buf);
56955694
while (Count--) {
56965695
// 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))
56995697
return true;
57005698
}
57015699
instantiateMacroLikeBody(M, DirectiveLoc, OS);
@@ -5726,7 +5724,7 @@ bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
57265724
for (const MCAsmMacroArgument &Arg : A) {
57275725
// Note that the AtPseudoVariable is enabled for instantiations of .irp.
57285726
// 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))
57305728
return true;
57315729
}
57325730

@@ -5768,7 +5766,7 @@ bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
57685766

57695767
// Note that the AtPseudoVariable is enabled for instantiations of .irpc.
57705768
// 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))
57725770
return true;
57735771
}
57745772

0 commit comments

Comments
 (0)