Skip to content

Commit 0f20d5a

Browse files
committed
[AsmParser] Deduplicate argument list parsing code (NFC)
The handling for parsing the first argument and all later arguments was duplicated. Consolidate them into a single loop.
1 parent d1a2f11 commit 0f20d5a

File tree

1 file changed

+7
-46
lines changed

1 file changed

+7
-46
lines changed

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2982,63 +2982,25 @@ bool LLParser::parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
29822982
assert(Lex.getKind() == lltok::lparen);
29832983
Lex.Lex(); // eat the (.
29842984

2985-
if (Lex.getKind() == lltok::rparen) {
2986-
// empty
2987-
} else if (Lex.getKind() == lltok::dotdotdot) {
2988-
IsVarArg = true;
2989-
Lex.Lex();
2990-
} else {
2991-
LocTy TypeLoc = Lex.getLoc();
2992-
Type *ArgTy = nullptr;
2993-
AttrBuilder Attrs(M->getContext());
2994-
std::string Name;
2995-
2996-
if (parseType(ArgTy) || parseOptionalParamAttrs(Attrs))
2997-
return true;
2998-
2999-
if (ArgTy->isVoidTy())
3000-
return error(TypeLoc, "argument can not have void type");
3001-
3002-
if (Lex.getKind() == lltok::LocalVar) {
3003-
Name = Lex.getStrVal();
3004-
Lex.Lex();
3005-
} else {
3006-
unsigned ArgID;
3007-
if (Lex.getKind() == lltok::LocalVarID) {
3008-
ArgID = Lex.getUIntVal();
3009-
if (checkValueID(TypeLoc, "argument", "%", CurValID, ArgID))
3010-
return true;
3011-
Lex.Lex();
3012-
} else {
3013-
ArgID = CurValID;
3014-
}
3015-
3016-
UnnamedArgNums.push_back(ArgID);
3017-
CurValID = ArgID + 1;
3018-
}
3019-
3020-
if (!FunctionType::isValidArgumentType(ArgTy))
3021-
return error(TypeLoc, "invalid type for function argument");
3022-
3023-
ArgList.emplace_back(TypeLoc, ArgTy,
3024-
AttributeSet::get(ArgTy->getContext(), Attrs),
3025-
std::move(Name));
3026-
3027-
while (EatIfPresent(lltok::comma)) {
2985+
if (Lex.getKind() != lltok::rparen) {
2986+
do {
30282987
// Handle ... at end of arg list.
30292988
if (EatIfPresent(lltok::dotdotdot)) {
30302989
IsVarArg = true;
30312990
break;
30322991
}
30332992

30342993
// Otherwise must be an argument type.
3035-
TypeLoc = Lex.getLoc();
2994+
LocTy TypeLoc = Lex.getLoc();
2995+
Type *ArgTy = nullptr;
2996+
AttrBuilder Attrs(M->getContext());
30362997
if (parseType(ArgTy) || parseOptionalParamAttrs(Attrs))
30372998
return true;
30382999

30393000
if (ArgTy->isVoidTy())
30403001
return error(TypeLoc, "argument can not have void type");
30413002

3003+
std::string Name;
30423004
if (Lex.getKind() == lltok::LocalVar) {
30433005
Name = Lex.getStrVal();
30443006
Lex.Lex();
@@ -3054,7 +3016,6 @@ bool LLParser::parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
30543016
}
30553017
UnnamedArgNums.push_back(ArgID);
30563018
CurValID = ArgID + 1;
3057-
Name = "";
30583019
}
30593020

30603021
if (!ArgTy->isFirstClassType())
@@ -3063,7 +3024,7 @@ bool LLParser::parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
30633024
ArgList.emplace_back(TypeLoc, ArgTy,
30643025
AttributeSet::get(ArgTy->getContext(), Attrs),
30653026
std::move(Name));
3066-
}
3027+
} while (EatIfPresent(lltok::comma));
30673028
}
30683029

30693030
return parseToken(lltok::rparen, "expected ')' at end of argument list");

0 commit comments

Comments
 (0)