mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
MCAsmParser: change representation of MCAsmMacroParameter
Rather than using std::pair, create a structure to represent the type. This is a preliminary refactoring to enable required parameter handling. Additional state is needed to indicate required parameters. This has a minor side effect of improving readability by providing more accurate names compared to first and second. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201629 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
070b5745ae
commit
5bbd4d2bd4
@ -51,11 +51,15 @@ FatalAssemblerWarnings("fatal-assembler-warnings",
|
|||||||
MCAsmParserSemaCallback::~MCAsmParserSemaCallback() {}
|
MCAsmParserSemaCallback::~MCAsmParserSemaCallback() {}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/// \brief Helper types for tracking macro definitions.
|
/// \brief Helper types for tracking macro definitions.
|
||||||
typedef std::vector<AsmToken> MCAsmMacroArgument;
|
typedef std::vector<AsmToken> MCAsmMacroArgument;
|
||||||
typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
|
typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
|
||||||
typedef std::pair<StringRef, MCAsmMacroArgument> MCAsmMacroParameter;
|
|
||||||
|
struct MCAsmMacroParameter {
|
||||||
|
StringRef Name;
|
||||||
|
MCAsmMacroArgument Value;
|
||||||
|
};
|
||||||
|
|
||||||
typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
|
typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
|
||||||
|
|
||||||
struct MCAsmMacro {
|
struct MCAsmMacro {
|
||||||
@ -1793,7 +1797,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
|
|||||||
StringRef Argument(Begin, I - (Pos + 1));
|
StringRef Argument(Begin, I - (Pos + 1));
|
||||||
unsigned Index = 0;
|
unsigned Index = 0;
|
||||||
for (; Index < NParameters; ++Index)
|
for (; Index < NParameters; ++Index)
|
||||||
if (Parameters[Index].first == Argument)
|
if (Parameters[Index].Name == Argument)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (Index == NParameters) {
|
if (Index == NParameters) {
|
||||||
@ -1939,8 +1943,8 @@ bool AsmParser::parseMacroArguments(const MCAsmMacro *M,
|
|||||||
|
|
||||||
A.resize(NParameters);
|
A.resize(NParameters);
|
||||||
for (unsigned PI = 0; PI < NParameters; ++PI)
|
for (unsigned PI = 0; PI < NParameters; ++PI)
|
||||||
if (!M->Parameters[PI].second.empty())
|
if (!M->Parameters[PI].Value.empty())
|
||||||
A[PI] = M->Parameters[PI].second;
|
A[PI] = M->Parameters[PI].Value;
|
||||||
|
|
||||||
bool NamedParametersFound = false;
|
bool NamedParametersFound = false;
|
||||||
|
|
||||||
@ -1954,7 +1958,7 @@ bool AsmParser::parseMacroArguments(const MCAsmMacro *M,
|
|||||||
|
|
||||||
if (Lexer.is(AsmToken::Identifier) && Lexer.peekTok().is(AsmToken::Equal)) {
|
if (Lexer.is(AsmToken::Identifier) && Lexer.peekTok().is(AsmToken::Equal)) {
|
||||||
L = Lexer.getLoc();
|
L = Lexer.getLoc();
|
||||||
if (parseIdentifier(FA.first)) {
|
if (parseIdentifier(FA.Name)) {
|
||||||
Error(L, "invalid argument identifier for formal argument");
|
Error(L, "invalid argument identifier for formal argument");
|
||||||
eatToEndOfStatement();
|
eatToEndOfStatement();
|
||||||
return true;
|
return true;
|
||||||
@ -1970,34 +1974,34 @@ bool AsmParser::parseMacroArguments(const MCAsmMacro *M,
|
|||||||
NamedParametersFound = true;
|
NamedParametersFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NamedParametersFound && FA.first.empty()) {
|
if (NamedParametersFound && FA.Name.empty()) {
|
||||||
Error(Lexer.getLoc(), "cannot mix positional and keyword arguments");
|
Error(Lexer.getLoc(), "cannot mix positional and keyword arguments");
|
||||||
eatToEndOfStatement();
|
eatToEndOfStatement();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseMacroArgument(FA.second))
|
if (parseMacroArgument(FA.Value))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
unsigned PI = Parameter;
|
unsigned PI = Parameter;
|
||||||
if (!FA.first.empty()) {
|
if (!FA.Name.empty()) {
|
||||||
unsigned FAI = 0;
|
unsigned FAI = 0;
|
||||||
for (FAI = 0; FAI < NParameters; ++FAI)
|
for (FAI = 0; FAI < NParameters; ++FAI)
|
||||||
if (M->Parameters[FAI].first == FA.first)
|
if (M->Parameters[FAI].Name == FA.Name)
|
||||||
break;
|
break;
|
||||||
if (FAI >= NParameters) {
|
if (FAI >= NParameters) {
|
||||||
Error(L,
|
Error(L,
|
||||||
"parameter named '" + FA.first + "' does not exist for macro '" +
|
"parameter named '" + FA.Name + "' does not exist for macro '" +
|
||||||
M->Name + "'");
|
M->Name + "'");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PI = FAI;
|
PI = FAI;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FA.second.empty()) {
|
if (!FA.Value.empty()) {
|
||||||
if (A.size() <= PI)
|
if (A.size() <= PI)
|
||||||
A.resize(PI + 1);
|
A.resize(PI + 1);
|
||||||
A[PI] = FA.second;
|
A[PI] = FA.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// At the end of the statement, fill in remaining arguments that have
|
// At the end of the statement, fill in remaining arguments that have
|
||||||
@ -3203,12 +3207,12 @@ bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
|
|||||||
MCAsmMacroParameters Parameters;
|
MCAsmMacroParameters Parameters;
|
||||||
while (getLexer().isNot(AsmToken::EndOfStatement)) {
|
while (getLexer().isNot(AsmToken::EndOfStatement)) {
|
||||||
MCAsmMacroParameter Parameter;
|
MCAsmMacroParameter Parameter;
|
||||||
if (parseIdentifier(Parameter.first))
|
if (parseIdentifier(Parameter.Name))
|
||||||
return TokError("expected identifier in '.macro' directive");
|
return TokError("expected identifier in '.macro' directive");
|
||||||
|
|
||||||
if (getLexer().is(AsmToken::Equal)) {
|
if (getLexer().is(AsmToken::Equal)) {
|
||||||
Lex();
|
Lex();
|
||||||
if (parseMacroArgument(Parameter.second))
|
if (parseMacroArgument(Parameter.Value))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3346,7 +3350,7 @@ void AsmParser::checkForBadMacro(SMLoc DirectiveLoc, StringRef Name,
|
|||||||
StringRef Argument(Begin, I - (Pos + 1));
|
StringRef Argument(Begin, I - (Pos + 1));
|
||||||
unsigned Index = 0;
|
unsigned Index = 0;
|
||||||
for (; Index < NParameters; ++Index)
|
for (; Index < NParameters; ++Index)
|
||||||
if (Parameters[Index].first == Argument)
|
if (Parameters[Index].Name == Argument)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (Index == NParameters) {
|
if (Index == NParameters) {
|
||||||
@ -4114,7 +4118,7 @@ bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
|
|||||||
bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
|
bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
|
||||||
MCAsmMacroParameter Parameter;
|
MCAsmMacroParameter Parameter;
|
||||||
|
|
||||||
if (parseIdentifier(Parameter.first))
|
if (parseIdentifier(Parameter.Name))
|
||||||
return TokError("expected identifier in '.irp' directive");
|
return TokError("expected identifier in '.irp' directive");
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
@ -4154,7 +4158,7 @@ bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
|
|||||||
bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
|
bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
|
||||||
MCAsmMacroParameter Parameter;
|
MCAsmMacroParameter Parameter;
|
||||||
|
|
||||||
if (parseIdentifier(Parameter.first))
|
if (parseIdentifier(Parameter.Name))
|
||||||
return TokError("expected identifier in '.irpc' directive");
|
return TokError("expected identifier in '.irpc' directive");
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user