From f8a954f1edbb1e6e6e046b4b4a10b922cac63236 Mon Sep 17 00:00:00 2001 From: Rahul Joshi Date: Thu, 31 Jul 2025 05:41:27 -0700 Subject: [PATCH] [NFC] Run clang-format on TGLexer and TGParser In https://github.com/llvm/llvm-project/pull/149248, clang-format applied some formatting to lines untouched by that PR, because the existing code is not clang-formatted well. Hence applying clang-format on the entire files here. --- llvm/lib/TableGen/TGLexer.cpp | 62 +++--- llvm/lib/TableGen/TGLexer.h | 8 +- llvm/lib/TableGen/TGParser.cpp | 389 ++++++++++++++++++++------------- llvm/lib/TableGen/TGParser.h | 12 +- 4 files changed, 277 insertions(+), 194 deletions(-) diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp index c369916a48f0d..7b23736169bba 100644 --- a/llvm/lib/TableGen/TGLexer.cpp +++ b/llvm/lib/TableGen/TGLexer.cpp @@ -93,9 +93,7 @@ TGLexer::TGLexer(SourceMgr &SM, ArrayRef Macros) : SrcMgr(SM) { } } -SMLoc TGLexer::getLoc() const { - return SMLoc::getFromPointer(TokStart); -} +SMLoc TGLexer::getLoc() const { return SMLoc::getFromPointer(TokStart); } SMRange TGLexer::getLocRange() const { return {getLoc(), SMLoc::getFromPointer(CurPtr)}; @@ -162,16 +160,13 @@ int TGLexer::getNextChar() { // Handle the newline character by ignoring it and incrementing the line // count. However, be careful about 'dos style' files with \n\r in them. // Only treat a \n\r or \r\n as a single line. - if ((*CurPtr == '\n' || (*CurPtr == '\r')) && - *CurPtr != CurChar) - ++CurPtr; // Eat the two char newline sequence. + if ((*CurPtr == '\n' || (*CurPtr == '\r')) && *CurPtr != CurChar) + ++CurPtr; // Eat the two char newline sequence. return '\n'; } } -int TGLexer::peekNextChar(int Index) const { - return *(CurPtr + Index); -} +int TGLexer::peekNextChar(int Index) const { return *(CurPtr + Index); } tgtok::TokKind TGLexer::LexToken(bool FileOrLineStart) { while (true) { @@ -367,7 +362,9 @@ tgtok::TokKind TGLexer::LexString() { ++CurPtr; switch (*CurPtr) { - case '\\': case '\'': case '"': + case '\\': + case '\'': + case '"': // These turn into their literal character. CurStrVal += *CurPtr++; break; @@ -421,7 +418,7 @@ tgtok::TokKind TGLexer::LexIdentifier() { ++CurPtr; // Check to see if this identifier is a reserved keyword. - StringRef Str(IdentStart, CurPtr-IdentStart); + StringRef Str(IdentStart, CurPtr - IdentStart); tgtok::TokKind Kind = StringSwitch(Str) .Case("int", tgtok::Int) @@ -454,14 +451,15 @@ tgtok::TokKind TGLexer::LexIdentifier() { // A couple of tokens require special processing. switch (Kind) { - case tgtok::Include: - if (LexInclude()) return tgtok::Error; - return Lex(); - case tgtok::Id: - CurStrVal.assign(Str.begin(), Str.end()); - break; - default: - break; + case tgtok::Include: + if (LexInclude()) + return tgtok::Error; + return Lex(); + case tgtok::Id: + CurStrVal.assign(Str.begin(), Str.end()); + break; + default: + break; } return Kind; @@ -472,7 +470,8 @@ tgtok::TokKind TGLexer::LexIdentifier() { bool TGLexer::LexInclude() { // The token after the include must be a string. tgtok::TokKind Tok = LexToken(); - if (Tok == tgtok::Error) return true; + if (Tok == tgtok::Error) + return true; if (Tok != tgtok::StrVal) { PrintError(getLoc(), "expected filename after include"); return true; @@ -501,7 +500,7 @@ bool TGLexer::LexInclude() { /// SkipBCPLComment - Skip over the comment by finding the next CR or LF. /// Or we may end up at the end of the buffer. void TGLexer::SkipBCPLComment() { - ++CurPtr; // skip the second slash. + ++CurPtr; // skip the second slash. auto EOLPos = CurBuf.find_first_of("\r\n", CurPtr - CurBuf.data()); CurPtr = (EOLPos == StringRef::npos) ? CurBuf.end() : CurBuf.data() + EOLPos; } @@ -509,7 +508,7 @@ void TGLexer::SkipBCPLComment() { /// SkipCComment - This skips C-style /**/ comments. The only difference from C /// is that we allow nesting. bool TGLexer::SkipCComment() { - ++CurPtr; // skip the star. + ++CurPtr; // skip the star. unsigned CommentDepth = 1; while (true) { @@ -520,15 +519,17 @@ bool TGLexer::SkipCComment() { return true; case '*': // End of the comment? - if (CurPtr[0] != '/') break; + if (CurPtr[0] != '/') + break; - ++CurPtr; // End the */. + ++CurPtr; // End the */. if (--CommentDepth == 0) return false; break; case '/': // Start of a nested comment? - if (CurPtr[0] != '*') break; + if (CurPtr[0] != '*') + break; ++CurPtr; ++CommentDepth; break; @@ -608,14 +609,17 @@ tgtok::TokKind TGLexer::LexBracket() { const char *CodeStart = CurPtr; while (true) { int Char = getNextChar(); - if (Char == EOF) break; + if (Char == EOF) + break; - if (Char != '}') continue; + if (Char != '}') + continue; Char = getNextChar(); - if (Char == EOF) break; + if (Char == EOF) + break; if (Char == ']') { - CurStrVal.assign(CodeStart, CurPtr-2); + CurStrVal.assign(CodeStart, CurPtr - 2); return tgtok::CodeFragment; } } diff --git a/llvm/lib/TableGen/TGLexer.h b/llvm/lib/TableGen/TGLexer.h index 5725e391d0c4d..753470dfb5374 100644 --- a/llvm/lib/TableGen/TGLexer.h +++ b/llvm/lib/TableGen/TGLexer.h @@ -216,13 +216,9 @@ class TGLexer { public: TGLexer(SourceMgr &SrcMgr, ArrayRef Macros); - tgtok::TokKind Lex() { - return CurCode = LexToken(CurPtr == CurBuf.begin()); - } + tgtok::TokKind Lex() { return CurCode = LexToken(CurPtr == CurBuf.begin()); } - const DependenciesSetTy &getDependencies() const { - return Dependencies; - } + const DependenciesSetTy &getDependencies() const { return Dependencies; } tgtok::TokKind getCode() const { return CurCode; } diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index 81b61b19f687b..0c6add59cb282 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -99,11 +99,11 @@ static void checkConcrete(Record &R) { if (const Init *V = RV.getValue()) { bool Ok = isa(V) ? checkBitsConcrete(R, RV) : V->isConcrete(); if (!Ok) { - PrintError(R.getLoc(), - Twine("Initializer of '") + RV.getNameInitAsString() + - "' in '" + R.getNameInitAsString() + - "' could not be fully resolved: " + - RV.getValue()->getAsString()); + PrintError(R.getLoc(), Twine("Initializer of '") + + RV.getNameInitAsString() + "' in '" + + R.getNameInitAsString() + + "' could not be fully resolved: " + + RV.getValue()->getAsString()); } } } @@ -218,9 +218,10 @@ bool TGParser::AddValue(Record *CurRec, SMLoc Loc, const RecordVal &RV) { // The value already exists in the class, treat this as a set. if (ERV->setValue(RV.getValue())) return Error(Loc, "New definition of '" + RV.getName() + "' of type '" + - RV.getType()->getAsString() + "' is incompatible with " + - "previous definition of type '" + - ERV->getType()->getAsString() + "'"); + RV.getType()->getAsString() + + "' is incompatible with " + + "previous definition of type '" + + ERV->getType()->getAsString() + "'"); } else { CurRec->addValue(RV); } @@ -232,14 +233,16 @@ bool TGParser::AddValue(Record *CurRec, SMLoc Loc, const RecordVal &RV) { bool TGParser::SetValue(Record *CurRec, SMLoc Loc, const Init *ValName, ArrayRef BitList, const Init *V, bool AllowSelfAssignment, bool OverrideDefLoc) { - if (!V) return false; + if (!V) + return false; - if (!CurRec) CurRec = &CurMultiClass->Rec; + if (!CurRec) + CurRec = &CurMultiClass->Rec; RecordVal *RV = CurRec->getValue(ValName); if (!RV) - return Error(Loc, "Value '" + ValName->getAsUnquotedString() + - "' unknown!"); + return Error(Loc, + "Value '" + ValName->getAsUnquotedString() + "' unknown!"); // Do not allow assignments like 'X = X'. This will just cause infinite loops // in the resolution machinery. @@ -254,7 +257,7 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, const Init *ValName, const auto *CurVal = dyn_cast(RV->getValue()); if (!CurVal) return Error(Loc, "Value '" + ValName->getAsUnquotedString() + - "' is not a bits type"); + "' is not a bits type"); // Convert the incoming value to a bits type of the appropriate size... const Init *BI = V->getCastTo(BitsRecTy::get(Records, BitList.size())); @@ -268,7 +271,8 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, const Init *ValName, unsigned Bit = BitList[i]; if (NewBits[Bit]) return Error(Loc, "Cannot set bit #" + Twine(Bit) + " of value '" + - ValName->getAsUnquotedString() + "' more than once"); + ValName->getAsUnquotedString() + + "' more than once"); NewBits[Bit] = BI->getBit(i); } @@ -283,7 +287,8 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, const Init *ValName, std::string InitType; if (const auto *BI = dyn_cast(V)) InitType = (Twine("' of type bit initializer with length ") + - Twine(BI->getNumBits())).str(); + Twine(BI->getNumBits())) + .str(); else if (const auto *TI = dyn_cast(V)) InitType = (Twine("' of type '") + TI->getType()->getAsString() + "'").str(); @@ -416,9 +421,8 @@ bool TGParser::addEntry(RecordsEntry E) { /// /// The resulting records are stored in \p Dest if non-null. Otherwise, they /// are added to the global record keeper. -bool TGParser::resolve(const ForeachLoop &Loop, SubstStack &Substs, - bool Final, std::vector *Dest, - SMLoc *Loc) { +bool TGParser::resolve(const ForeachLoop &Loop, SubstStack &Substs, bool Final, + std::vector *Dest, SMLoc *Loc) { MapResolver R; for (const auto &S : Substs) @@ -437,28 +441,28 @@ bool TGParser::resolve(const ForeachLoop &Loop, SubstStack &Substs, R.setFinal(true); const Init *LHS = OldLHS->resolveReferences(R); if (LHS == OldLHS) { - PrintError(Loop.Loc, - Twine("unable to resolve if condition '") + - LHS->getAsString() + "' at end of containing scope"); + PrintError(Loop.Loc, Twine("unable to resolve if condition '") + + LHS->getAsString() + + "' at end of containing scope"); return true; } const Init *MHS = TI->getMHS(); const Init *RHS = TI->getRHS(); List = TernOpInit::get(TernOpInit::IF, LHS, MHS, RHS, TI->getType()) - ->Fold(nullptr); + ->Fold(nullptr); } const auto *LI = dyn_cast(List); if (!LI) { if (!Final) { - Dest->emplace_back(std::make_unique(Loop.Loc, Loop.IterVar, - List)); + Dest->emplace_back( + std::make_unique(Loop.Loc, Loop.IterVar, List)); return resolve(Loop.Entries, Substs, Final, &Dest->back().Loop->Entries, Loc); } PrintError(Loop.Loc, Twine("attempting to loop over '") + - List->getAsString() + "', expected a list"); + List->getAsString() + "', expected a list"); return true; } @@ -571,7 +575,7 @@ bool TGParser::addDefOne(std::unique_ptr Rec) { if (!I->getType()->typeIsA(Defset->EltTy)) { PrintError(Rec->getLoc(), Twine("adding record of incompatible type '") + I->getType()->getAsString() + - "' to defset"); + "' to defset"); PrintNote(Defset->Loc, "location of defset declaration"); return true; } @@ -751,8 +755,8 @@ MultiClass *TGParser::ParseMultiClassID() { /// SubClassRef ::= ClassID /// SubClassRef ::= ClassID '<' ArgValueList '>' /// -SubClassReference TGParser:: -ParseSubClassReference(Record *CurRec, bool isDefm) { +SubClassReference TGParser::ParseSubClassReference(Record *CurRec, + bool isDefm) { SubClassReference Result; Result.RefRange.Start = Lex.getLoc(); @@ -762,7 +766,8 @@ ParseSubClassReference(Record *CurRec, bool isDefm) { } else { Result.Rec = ParseClassID(); } - if (!Result.Rec) return Result; + if (!Result.Rec) + return Result; // If there is no template arg list, we're done. if (!consume(tgtok::less)) { @@ -793,13 +798,14 @@ ParseSubClassReference(Record *CurRec, bool isDefm) { /// SubMultiClassRef ::= MultiClassID /// SubMultiClassRef ::= MultiClassID '<' ArgValueList '>' /// -SubMultiClassReference TGParser:: -ParseSubMultiClassReference(MultiClass *CurMC) { +SubMultiClassReference +TGParser::ParseSubMultiClassReference(MultiClass *CurMC) { SubMultiClassReference Result; Result.RefRange.Start = Lex.getLoc(); Result.MC = ParseMultiClassID(); - if (!Result.MC) return Result; + if (!Result.MC) + return Result; // If there is no template arg list, we're done. if (!consume(tgtok::less)) { @@ -1049,7 +1055,8 @@ bool TGParser::ParseOptionalRangeList(SmallVectorImpl &Ranges) { // Parse the range list. ParseRangeList(Ranges); - if (Ranges.empty()) return true; + if (Ranges.empty()) + return true; if (!consume(tgtok::greater)) { TokError("expected '>' at end of range list"); @@ -1068,7 +1075,8 @@ bool TGParser::ParseOptionalBitList(SmallVectorImpl &Ranges) { // Parse the range list. ParseRangeList(Ranges); - if (Ranges.empty()) return true; + if (Ranges.empty()) + return true; if (!consume(tgtok::r_brace)) { TokError("expected '}' at end of bit list"); @@ -1090,7 +1098,9 @@ bool TGParser::ParseOptionalBitList(SmallVectorImpl &Ranges) { /// const RecTy *TGParser::ParseType() { switch (Lex.getCode()) { - default: TokError("Unknown token when expecting a type"); return nullptr; + default: + TokError("Unknown token when expecting a type"); + return nullptr; case tgtok::String: case tgtok::Code: Lex.Lex(); @@ -1129,7 +1139,7 @@ const RecTy *TGParser::ParseType() { TokError("expected '>' at end of bits type"); return nullptr; } - Lex.Lex(); // Eat '>' + Lex.Lex(); // Eat '>' return BitsRecTy::get(Records, Val); } case tgtok::List: { @@ -1137,9 +1147,10 @@ const RecTy *TGParser::ParseType() { TokError("expected '<' after list type"); return nullptr; } - Lex.Lex(); // Eat '<' + Lex.Lex(); // Eat '<' const RecTy *SubType = ParseType(); - if (!SubType) return nullptr; + if (!SubType) + return nullptr; if (!consume(tgtok::greater)) { TokError("expected '>' at end of list type"); @@ -1206,9 +1217,10 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { const RecTy *Type = nullptr; switch (Lex.getCode()) { - default: llvm_unreachable("Unhandled code!"); + default: + llvm_unreachable("Unhandled code!"); case tgtok::XCast: - Lex.Lex(); // eat the operation + Lex.Lex(); // eat the operation Code = UnOpInit::CAST; Type = ParseOperatorType(); @@ -1235,7 +1247,7 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { Type = StringRecTy::get(Records); break; case tgtok::XNOT: - Lex.Lex(); // eat the operation + Lex.Lex(); // eat the operation Code = UnOpInit::NOT; Type = IntRecTy::get(Records); break; @@ -1245,16 +1257,16 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { Type = IntRecTy::get(Records); // Bogus type used here. break; case tgtok::XLOG2: - Lex.Lex(); // eat the operation + Lex.Lex(); // eat the operation Code = UnOpInit::LOG2; Type = IntRecTy::get(Records); break; case tgtok::XHead: - Lex.Lex(); // eat the operation + Lex.Lex(); // eat the operation Code = UnOpInit::HEAD; break; case tgtok::XTail: - Lex.Lex(); // eat the operation + Lex.Lex(); // eat the operation Code = UnOpInit::TAIL; break; case tgtok::XSize: @@ -1263,12 +1275,12 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { Type = IntRecTy::get(Records); break; case tgtok::XEmpty: - Lex.Lex(); // eat the operation + Lex.Lex(); // eat the operation Code = UnOpInit::EMPTY; Type = IntRecTy::get(Records); break; case tgtok::XGetDagOp: - Lex.Lex(); // eat the operation + Lex.Lex(); // eat the operation if (Lex.getCode() == tgtok::less) { // Parse an optional type suffix, so that you can say // !getdagop(someDag) as a shorthand for @@ -1306,7 +1318,8 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { } const Init *LHS = ParseValue(CurRec); - if (!LHS) return nullptr; + if (!LHS) + return nullptr; if (Code == UnOpInit::EMPTY || Code == UnOpInit::SIZE) { const auto *LHSl = dyn_cast(LHS); @@ -1314,12 +1327,14 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { const auto *LHSd = dyn_cast(LHS); const auto *LHSt = dyn_cast(LHS); if (!LHSl && !LHSs && !LHSd && !LHSt) { - TokError("expected string, list, or dag type argument in unary operator"); + TokError( + "expected string, list, or dag type argument in unary operator"); return nullptr; } if (LHSt) { if (!isa(LHSt->getType())) { - TokError("expected string, list, or dag type argument in unary operator"); + TokError( + "expected string, list, or dag type argument in unary operator"); return nullptr; } } @@ -1525,39 +1540,84 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { case tgtok::XSetDagOpName: { // Value ::= !binop '(' Value ',' Value ')' tgtok::TokKind OpTok = Lex.getCode(); SMLoc OpLoc = Lex.getLoc(); - Lex.Lex(); // eat the operation + Lex.Lex(); // eat the operation BinOpInit::BinaryOp Code; switch (OpTok) { - default: llvm_unreachable("Unhandled code!"); - case tgtok::XConcat: Code = BinOpInit::CONCAT; break; + default: + llvm_unreachable("Unhandled code!"); + case tgtok::XConcat: + Code = BinOpInit::CONCAT; + break; case tgtok::XMatch: Code = BinOpInit::MATCH; break; - case tgtok::XADD: Code = BinOpInit::ADD; break; - case tgtok::XSUB: Code = BinOpInit::SUB; break; - case tgtok::XMUL: Code = BinOpInit::MUL; break; - case tgtok::XDIV: Code = BinOpInit::DIV; break; - case tgtok::XAND: Code = BinOpInit::AND; break; - case tgtok::XOR: Code = BinOpInit::OR; break; - case tgtok::XXOR: Code = BinOpInit::XOR; break; - case tgtok::XSRA: Code = BinOpInit::SRA; break; - case tgtok::XSRL: Code = BinOpInit::SRL; break; - case tgtok::XSHL: Code = BinOpInit::SHL; break; - case tgtok::XEq: Code = BinOpInit::EQ; break; - case tgtok::XNe: Code = BinOpInit::NE; break; - case tgtok::XLe: Code = BinOpInit::LE; break; - case tgtok::XLt: Code = BinOpInit::LT; break; - case tgtok::XGe: Code = BinOpInit::GE; break; - case tgtok::XGt: Code = BinOpInit::GT; break; - case tgtok::XListConcat: Code = BinOpInit::LISTCONCAT; break; - case tgtok::XListSplat: Code = BinOpInit::LISTSPLAT; break; + case tgtok::XADD: + Code = BinOpInit::ADD; + break; + case tgtok::XSUB: + Code = BinOpInit::SUB; + break; + case tgtok::XMUL: + Code = BinOpInit::MUL; + break; + case tgtok::XDIV: + Code = BinOpInit::DIV; + break; + case tgtok::XAND: + Code = BinOpInit::AND; + break; + case tgtok::XOR: + Code = BinOpInit::OR; + break; + case tgtok::XXOR: + Code = BinOpInit::XOR; + break; + case tgtok::XSRA: + Code = BinOpInit::SRA; + break; + case tgtok::XSRL: + Code = BinOpInit::SRL; + break; + case tgtok::XSHL: + Code = BinOpInit::SHL; + break; + case tgtok::XEq: + Code = BinOpInit::EQ; + break; + case tgtok::XNe: + Code = BinOpInit::NE; + break; + case tgtok::XLe: + Code = BinOpInit::LE; + break; + case tgtok::XLt: + Code = BinOpInit::LT; + break; + case tgtok::XGe: + Code = BinOpInit::GE; + break; + case tgtok::XGt: + Code = BinOpInit::GT; + break; + case tgtok::XListConcat: + Code = BinOpInit::LISTCONCAT; + break; + case tgtok::XListSplat: + Code = BinOpInit::LISTSPLAT; + break; case tgtok::XListRemove: Code = BinOpInit::LISTREMOVE; break; - case tgtok::XStrConcat: Code = BinOpInit::STRCONCAT; break; - case tgtok::XInterleave: Code = BinOpInit::INTERLEAVE; break; - case tgtok::XSetDagOp: Code = BinOpInit::SETDAGOP; break; + case tgtok::XStrConcat: + Code = BinOpInit::STRCONCAT; + break; + case tgtok::XInterleave: + Code = BinOpInit::INTERLEAVE; + break; + case tgtok::XSetDagOp: + Code = BinOpInit::SETDAGOP; + break; case tgtok::XSetDagOpName: Code = BinOpInit::SETDAGOPNAME; break; @@ -1642,9 +1702,8 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { } if (Type && ItemType && !Type->typeIsConvertibleTo(ItemType)) { - Error(OpLoc, Twine("expected value of type '") + - ItemType->getAsString() + "', got '" + - Type->getAsString() + "'"); + Error(OpLoc, Twine("expected value of type '") + ItemType->getAsString() + + "', got '" + Type->getAsString() + "'"); return nullptr; } @@ -1660,7 +1719,8 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { for (;;) { SMLoc InitLoc = Lex.getLoc(); InitList.push_back(ParseValue(CurRec, ArgType)); - if (!InitList.back()) return nullptr; + if (!InitList.back()) + return nullptr; const auto *InitListBack = dyn_cast(InitList.back()); if (!InitListBack) { @@ -1678,7 +1738,7 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { case BinOpInit::LISTCONCAT: if (!isa(ArgType)) { Error(InitLoc, Twine("expected a list, got value of type '") + - ArgType->getAsString() + "'"); + ArgType->getAsString() + "'"); return nullptr; } break; @@ -1747,9 +1807,10 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { if (ArgType != StringRecTy::get(Records)->getListTy() && !ArgType->typeIsConvertibleTo( IntRecTy::get(Records)->getListTy())) { - Error(InitLoc, Twine("expected list of string, int, bits, or bit; " - "got value of type '") + - ArgType->getAsString() + "'"); + Error(InitLoc, + Twine("expected list of string, int, bits, or bit; " + "got value of type '") + + ArgType->getAsString() + "'"); return nullptr; } break; @@ -1761,11 +1822,12 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { return nullptr; } break; - default: ; + default:; } ArgType = nullptr; // Broken invariant: types not identical. break; - default: llvm_unreachable("other ops have fixed argument types"); + default: + llvm_unreachable("other ops have fixed argument types"); } } else { @@ -1966,7 +2028,8 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { tgtok::TokKind LexCode = Lex.getCode(); Lex.Lex(); // Eat the operation. switch (LexCode) { - default: llvm_unreachable("Unhandled code!"); + default: + llvm_unreachable("Unhandled code!"); case tgtok::XDag: Code = TernOpInit::DAG; Type = DagRecTy::get(Records); @@ -1995,7 +2058,8 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { } const Init *LHS = ParseValue(CurRec); - if (!LHS) return nullptr; + if (!LHS) + return nullptr; if (!consume(tgtok::comma)) { TokError("expected ',' in ternary operator"); @@ -2023,7 +2087,8 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { } switch (LexCode) { - default: llvm_unreachable("Unhandled code!"); + default: + llvm_unreachable("Unhandled code!"); case tgtok::XDag: { const auto *MHSt = dyn_cast(MHS); if (!MHSt && !isa(MHS)) { @@ -2231,7 +2296,8 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) { std::unique_ptr ParseRecTmp; Record *ParseRec = CurRec; if (!ParseRec) { - ParseRecTmp = std::make_unique(".parse", ArrayRef{}, Records); + ParseRecTmp = + std::make_unique(".parse", ArrayRef{}, Records); ParseRec = ParseRecTmp.get(); } @@ -2347,9 +2413,8 @@ const Init *TGParser::ParseOperationSubstr(Record *CurRec, } if (ItemType && !Type->typeIsConvertibleTo(ItemType)) { - Error(RHSLoc, Twine("expected value of type '") + - ItemType->getAsString() + "', got '" + - Type->getAsString() + "'"); + Error(RHSLoc, Twine("expected value of type '") + ItemType->getAsString() + + "', got '" + Type->getAsString() + "'"); } const auto *LHSt = dyn_cast(LHS); @@ -2436,9 +2501,8 @@ const Init *TGParser::ParseOperationFind(Record *CurRec, } if (ItemType && !Type->typeIsConvertibleTo(ItemType)) { - Error(RHSLoc, Twine("expected value of type '") + - ItemType->getAsString() + "', got '" + - Type->getAsString() + "'"); + Error(RHSLoc, Twine("expected value of type '") + ItemType->getAsString() + + "', got '" + Type->getAsString() + "'"); } const auto *LHSt = dyn_cast(LHS); @@ -2540,10 +2604,9 @@ const Init *TGParser::ParseOperationForEachFilter(Record *CurRec, ? OutListTy->getElementType() : IntRecTy::get(Records); } else { - Error(OpLoc, - "expected value of type '" + - Twine(ItemType->getAsString()) + - "', but got list type"); + Error(OpLoc, "expected value of type '" + + Twine(ItemType->getAsString()) + + "', but got list type"); return nullptr; } } @@ -2554,9 +2617,8 @@ const Init *TGParser::ParseOperationForEachFilter(Record *CurRec, } InEltType = InDagTy; if (ItemType && !isa(ItemType)) { - Error(OpLoc, - "expected value of type '" + Twine(ItemType->getAsString()) + - "', but got dag type"); + Error(OpLoc, "expected value of type '" + Twine(ItemType->getAsString()) + + "', but got dag type"); return nullptr; } IsDAG = true; @@ -2610,7 +2672,7 @@ const Init *TGParser::ParseOperationForEachFilter(Record *CurRec, const Init *TGParser::ParseOperationCond(Record *CurRec, const RecTy *ItemType) { - Lex.Lex(); // eat the operation 'cond' + Lex.Lex(); // eat the operation 'cond' if (!consume(tgtok::l_paren)) { TokError("expected '(' after !cond operator"); @@ -2649,7 +2711,8 @@ const Init *TGParser::ParseOperationCond(Record *CurRec, } if (Case.size() < 1) { - TokError("there should be at least 1 'condition : value' in the !cond operator"); + TokError( + "there should be at least 1 'condition : value' in the !cond operator"); return nullptr; } @@ -2672,7 +2735,7 @@ const Init *TGParser::ParseOperationCond(Record *CurRec, const RecTy *RType = resolveTypes(Type, VTy); if (!RType) { TokError(Twine("inconsistent types '") + Type->getAsString() + - "' and '" + VTy->getAsString() + "' for !cond"); + "' and '" + VTy->getAsString() + "' for !cond"); return nullptr; } Type = RType; @@ -2724,7 +2787,9 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, const RecTy *ItemType, return ParseOperation(CurRec, ItemType); switch (Code) { - default: TokError("Unknown or reserved token when parsing a value"); break; + default: + TokError("Unknown or reserved token when parsing a value"); + break; case tgtok::TrueVal: R = IntInit::get(Records, 1); @@ -2740,7 +2805,7 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, const RecTy *ItemType, break; case tgtok::BinaryIntVal: { auto BinaryVal = Lex.getCurBinaryIntVal(); - SmallVector Bits(BinaryVal.second); + SmallVector Bits(BinaryVal.second); for (unsigned i = 0, e = BinaryVal.second; i != e; ++i) Bits[i] = BitInit::get(Records, BinaryVal.first & (1LL << i)); R = BitsInit::get(Records, Bits); @@ -2803,14 +2868,15 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, const RecTy *ItemType, Class->appendReferenceLoc(NameLoc); return VarDefInit::get(NameLoc.Start, Class, Args)->Fold(); } - case tgtok::l_brace: { // Value ::= '{' ValueList '}' + case tgtok::l_brace: { // Value ::= '{' ValueList '}' SMLoc BraceLoc = Lex.getLoc(); Lex.Lex(); // eat the '{' SmallVector Vals; if (Lex.getCode() != tgtok::r_brace) { ParseValueList(Vals, CurRec); - if (Vals.empty()) return nullptr; + if (Vals.empty()) + return nullptr; } if (!consume(tgtok::r_brace)) { TokError("expected '}' at end of bit list value"); @@ -2845,7 +2911,7 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, const RecTy *ItemType, const Init *Bit = Vals[i]->getCastTo(BitRecTy::get(Records)); if (!Bit) { Error(BraceLoc, "Element #" + Twine(i) + " (" + Vals[i]->getAsString() + - ") is not convertable to a bit"); + ") is not convertable to a bit"); return nullptr; } NewBits.push_back(Bit); @@ -2853,8 +2919,8 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, const RecTy *ItemType, std::reverse(NewBits.begin(), NewBits.end()); return BitsInit::get(Records, NewBits); } - case tgtok::l_square: { // Value ::= '[' ValueList ']' - Lex.Lex(); // eat the '[' + case tgtok::l_square: { // Value ::= '[' ValueList ']' + Lex.Lex(); // eat the '[' SmallVector Vals; const RecTy *DeducedEltTy = nullptr; @@ -2873,7 +2939,8 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, const RecTy *ItemType, if (Lex.getCode() != tgtok::r_square) { ParseValueList(Vals, CurRec, GivenListTy ? GivenListTy->getElementType() : nullptr); - if (Vals.empty()) return nullptr; + if (Vals.empty()) + return nullptr; } if (!consume(tgtok::r_square)) { TokError("expected ']' at end of list value"); @@ -2946,7 +3013,7 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, const RecTy *ItemType, } case tgtok::l_paren: { // Value ::= '(' IDValue DagArgList ')' // Value ::= '(' '[' ValueList ']' DagArgList ')' - Lex.Lex(); // eat the '(' + Lex.Lex(); // eat the '(' if (Lex.getCode() != tgtok::Id && Lex.getCode() != tgtok::XCast && Lex.getCode() != tgtok::question && Lex.getCode() != tgtok::XGetDagOp && Lex.getCode() != tgtok::l_square) { @@ -2955,7 +3022,8 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, const RecTy *ItemType, } const Init *Operator = ParseValue(CurRec); - if (!Operator) return nullptr; + if (!Operator) + return nullptr; // If the operator name is present, parse it. const StringInit *OperatorName = nullptr; @@ -2965,13 +3033,14 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, const RecTy *ItemType, return nullptr; } OperatorName = StringInit::get(Records, Lex.getCurStrVal()); - Lex.Lex(); // eat the VarName. + Lex.Lex(); // eat the VarName. } SmallVector, 8> DagArgs; if (Lex.getCode() != tgtok::r_paren) { ParseDagArgList(DagArgs, CurRec); - if (DagArgs.empty()) return nullptr; + if (DagArgs.empty()) + return nullptr; } if (!consume(tgtok::r_paren)) { @@ -2997,12 +3066,14 @@ const Init *TGParser::ParseValue(Record *CurRec, const RecTy *ItemType, IDParseMode Mode) { SMLoc LHSLoc = Lex.getLoc(); const Init *Result = ParseSimpleValue(CurRec, ItemType, Mode); - if (!Result) return nullptr; + if (!Result) + return nullptr; // Parse the suffixes now if present. while (true) { switch (Lex.getCode()) { - default: return Result; + default: + return Result; case tgtok::l_brace: { if (Mode == ParseNameMode) // This is the beginning of the object body. @@ -3012,7 +3083,8 @@ const Init *TGParser::ParseValue(Record *CurRec, const RecTy *ItemType, Lex.Lex(); // eat the '{' SmallVector Ranges; ParseRangeList(Ranges); - if (Ranges.empty()) return nullptr; + if (Ranges.empty()) + return nullptr; // Reverse the bitlist. std::reverse(Ranges.begin(), Ranges.end()); @@ -3095,7 +3167,7 @@ const Init *TGParser::ParseValue(Record *CurRec, const RecTy *ItemType, } Result = FieldInit::get(Result, FieldName)->Fold(CurRec); - Lex.Lex(); // eat field name + Lex.Lex(); // eat field name break; } @@ -3109,7 +3181,7 @@ const Init *TGParser::ParseValue(Record *CurRec, const RecTy *ItemType, // Check if it's a 'listA # listB' if (isa(LHS->getType())) { - Lex.Lex(); // Eat the '#'. + Lex.Lex(); // Eat the '#'. assert(Mode == ParseValueMode && "encountered paste of lists in name"); @@ -3145,7 +3217,7 @@ const Init *TGParser::ParseValue(Record *CurRec, const RecTy *ItemType, const TypedInit *RHS = nullptr; - Lex.Lex(); // Eat the '#'. + Lex.Lex(); // Eat the '#'. switch (Lex.getCode()) { case tgtok::colon: case tgtok::semi: @@ -3223,7 +3295,7 @@ void TGParser::ParseDagArgList( return; } VarName = StringInit::get(Records, Lex.getCurStrVal()); - Lex.Lex(); // eat the VarName. + Lex.Lex(); // eat the VarName. } Result.emplace_back(Val, VarName); @@ -3351,7 +3423,8 @@ const Init *TGParser::ParseDeclaration(Record *CurRec, bool HasField = consume(tgtok::Field); const RecTy *Type = ParseType(); - if (!Type) return nullptr; + if (!Type) + return nullptr; if (Lex.getCode() != tgtok::Id) { TokError("Expected identifier in declaration"); @@ -3440,7 +3513,7 @@ TGParser::ParseForeachDeclaration(const Init *&ForeachListValue) { switch (Lex.getCode()) { case tgtok::l_brace: { // '{' RangeList '}' - Lex.Lex(); // eat the '{' + Lex.Lex(); // eat the '{' ParseRangeList(Ranges); if (!consume(tgtok::r_brace)) { TokError("expected '}' at end of bit range list"); @@ -3471,13 +3544,12 @@ TGParser::ParseForeachDeclaration(const Init *&ForeachListValue) { Error(ValueLoc, "expected a list, got '" + I->getAsString() + "'"); if (CurMultiClass) { PrintNote({}, "references to multiclass template arguments cannot be " - "resolved at this time"); + "resolved at this time"); } return nullptr; } } - if (!Ranges.empty()) { assert(!IterType && "Type already initialized?"); IterType = IntRecTy::get(Records); @@ -3516,7 +3588,7 @@ bool TGParser::ParseTemplateArgList(Record *CurRec) { while (consume(tgtok::comma)) { // Read the following declarations. SMLoc Loc = Lex.getLoc(); - TemplArg = ParseDeclaration(CurRec, true/*templateargs*/); + TemplArg = ParseDeclaration(CurRec, true /*templateargs*/); if (!TemplArg) return true; @@ -3565,7 +3637,7 @@ bool TGParser::ParseBodyItem(Record *CurRec) { SMLoc IdLoc = Lex.getLoc(); const StringInit *FieldName = StringInit::get(Records, Lex.getCurStrVal()); - Lex.Lex(); // eat the field name. + Lex.Lex(); // eat the field name. SmallVector BitList; if (ParseOptionalBitList(BitList)) @@ -3587,7 +3659,8 @@ bool TGParser::ParseBodyItem(Record *CurRec) { } const Init *Val = ParseValue(CurRec, Type); - if (!Val) return true; + if (!Val) + return true; if (!consume(tgtok::semi)) return TokError("expected ';' after let expression"); @@ -3677,7 +3750,8 @@ bool TGParser::ParseObjectBody(Record *CurRec) { SubClassReference SubClass = ParseSubClassReference(CurRec, false); while (true) { // Check for error. - if (!SubClass.Rec) return true; + if (!SubClass.Rec) + return true; // Add it. if (AddSubClass(CurRec, SubClass)) @@ -3705,7 +3779,7 @@ bool TGParser::ParseObjectBody(Record *CurRec) { bool TGParser::ParseDef(MultiClass *CurMultiClass) { SMLoc DefLoc = Lex.getLoc(); assert(Lex.getCode() == tgtok::Def && "Unknown tok"); - Lex.Lex(); // Eat the 'def' token. + Lex.Lex(); // Eat the 'def' token. // If the name of the def is an Id token, use that for the location. // Otherwise, the name is more complex and we use the location of the 'def' @@ -3867,7 +3941,7 @@ bool TGParser::ParseDefvar(Record *CurRec) { bool TGParser::ParseForeach(MultiClass *CurMultiClass) { SMLoc Loc = Lex.getLoc(); assert(Lex.getCode() == tgtok::Foreach && "Unknown tok"); - Lex.Lex(); // Eat the 'for' token. + Lex.Lex(); // Eat the 'for' token. // Make a temporary object to record items associated with the for // loop. @@ -3892,7 +3966,7 @@ bool TGParser::ParseForeach(MultiClass *CurMultiClass) { } else { SMLoc BraceLoc = Lex.getLoc(); // Otherwise, this is a group foreach. - Lex.Lex(); // eat the '{'. + Lex.Lex(); // eat the '{'. // Parse the object list. if (ParseObjectList(CurMultiClass)) @@ -4119,7 +4193,7 @@ void TGParser::ParseLetList(SmallVectorImpl &Result) { const StringInit *Name = StringInit::get(Records, Lex.getCurStrVal()); SMLoc NameLoc = Lex.getLoc(); - Lex.Lex(); // Eat the identifier. + Lex.Lex(); // Eat the identifier. // Check for an optional RangeList. SmallVector Bits; @@ -4159,7 +4233,8 @@ bool TGParser::ParseTopLevelLet(MultiClass *CurMultiClass) { // Add this entry to the let stack. SmallVector LetInfo; ParseLetList(LetInfo); - if (LetInfo.empty()) return true; + if (LetInfo.empty()) + return true; LetStack.push_back(std::move(LetInfo)); if (!consume(tgtok::In)) @@ -4170,10 +4245,10 @@ bool TGParser::ParseTopLevelLet(MultiClass *CurMultiClass) { // LET LetList IN Object if (ParseObject(CurMultiClass)) return true; - } else { // Object ::= LETCommand '{' ObjectList '}' + } else { // Object ::= LETCommand '{' ObjectList '}' SMLoc BraceLoc = Lex.getLoc(); // Otherwise, this is a group let. - Lex.Lex(); // eat the '{'. + Lex.Lex(); // eat the '{'. // A group let introduces a new scope for local variables. TGVarScope *LetScope = PushScope(); @@ -4210,7 +4285,7 @@ bool TGParser::ParseTopLevelLet(MultiClass *CurMultiClass) { /// bool TGParser::ParseMultiClass() { assert(Lex.getCode() == tgtok::MultiClass && "Unexpected token"); - Lex.Lex(); // Eat the multiclass token. + Lex.Lex(); // Eat the multiclass token. if (Lex.getCode() != tgtok::Id) return TokError("expected identifier after multiclass for name"); @@ -4223,7 +4298,7 @@ bool TGParser::ParseMultiClass() { return TokError("multiclass '" + Name + "' already defined"); CurMultiClass = Result.first->second.get(); - Lex.Lex(); // Eat the identifier. + Lex.Lex(); // Eat the identifier. // A multiclass body introduces a new scope for local variables. TGVarScope *MulticlassScope = PushScope(CurMultiClass); @@ -4241,10 +4316,11 @@ bool TGParser::ParseMultiClass() { // Read all of the submulticlasses. SubMultiClassReference SubMultiClass = - ParseSubMultiClassReference(CurMultiClass); + ParseSubMultiClassReference(CurMultiClass); while (true) { // Check for error. - if (!SubMultiClass.MC) return true; + if (!SubMultiClass.MC) + return true; // Add it. if (AddSubMultiClass(CurMultiClass, SubMultiClass)) @@ -4262,7 +4338,7 @@ bool TGParser::ParseMultiClass() { if (!consume(tgtok::semi)) return TokError("expected ';' in multiclass definition"); } else { - if (Lex.Lex() == tgtok::r_brace) // eat the '{'. + if (Lex.Lex() == tgtok::r_brace) // eat the '{'. return TokError("multiclass must contain at least one def"); while (Lex.getCode() != tgtok::r_brace) { @@ -4284,7 +4360,7 @@ bool TGParser::ParseMultiClass() { break; } } - Lex.Lex(); // eat the '}'. + Lex.Lex(); // eat the '}'. // If we have a semicolon, print a gentle error. SMLoc SemiLoc = Lex.getLoc(); @@ -4338,7 +4414,8 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) { SubClassReference Ref = ParseSubClassReference(nullptr, true); while (true) { - if (!Ref.Rec) return true; + if (!Ref.Rec) + return true; // To instantiate a multiclass, we get the multiclass and then loop // through its template argument names. Substs contains a substitution @@ -4380,7 +4457,8 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) { SubClassReference SubClass = ParseSubClassReference(nullptr, false); while (true) { // Check for error. - if (!SubClass.Rec) return true; + if (!SubClass.Rec) + return true; // Get the expanded definition prototypes and teach them about // the record values the current class to inherit has @@ -4426,17 +4504,24 @@ bool TGParser::ParseObject(MultiClass *MC) { default: return TokError( "Expected assert, class, def, defm, defset, dump, foreach, if, or let"); - case tgtok::Assert: return ParseAssert(MC); - case tgtok::Def: return ParseDef(MC); - case tgtok::Defm: return ParseDefm(MC); + case tgtok::Assert: + return ParseAssert(MC); + case tgtok::Def: + return ParseDef(MC); + case tgtok::Defm: + return ParseDefm(MC); case tgtok::Deftype: return ParseDeftype(); - case tgtok::Defvar: return ParseDefvar(); + case tgtok::Defvar: + return ParseDefvar(); case tgtok::Dump: return ParseDump(MC); - case tgtok::Foreach: return ParseForeach(MC); - case tgtok::If: return ParseIf(MC); - case tgtok::Let: return ParseTopLevelLet(MC); + case tgtok::Foreach: + return ParseForeach(MC); + case tgtok::If: + return ParseIf(MC); + case tgtok::Let: + return ParseTopLevelLet(MC); case tgtok::Defset: if (MC) return TokError("defset is not allowed inside multiclass"); diff --git a/llvm/lib/TableGen/TGParser.h b/llvm/lib/TableGen/TGParser.h index 2a5a1925343cf..7edb6c7a9aac6 100644 --- a/llvm/lib/TableGen/TGParser.h +++ b/llvm/lib/TableGen/TGParser.h @@ -167,9 +167,9 @@ class TGParser { // in the middle of creating in. For those situations, allow the // parser to ignore missing object errors. enum IDParseMode { - ParseValueMode, // We are parsing a value we expect to look up. - ParseNameMode, // We are parsing a name of an object that does not yet - // exist. + ParseValueMode, // We are parsing a value we expect to look up. + ParseNameMode, // We are parsing a name of an object that does not yet + // exist. }; bool NoWarnOnUnusedTemplateArgs = false; @@ -191,9 +191,7 @@ class TGParser { PrintError(L, Msg); return true; } - bool TokError(const Twine &Msg) const { - return Error(Lex.getLoc(), Msg); - } + bool TokError(const Twine &Msg) const { return Error(Lex.getLoc(), Msg); } const TGLexer::DependenciesSetTy &getDependencies() const { return Lex.getDependencies(); } @@ -257,7 +255,7 @@ class TGParser { ArrayRef ArgValues, const Init *DefmName, SMLoc Loc); -private: // Parser methods. +private: // Parser methods. bool consume(tgtok::TokKind K); bool ParseObjectList(MultiClass *MC = nullptr); bool ParseObject(MultiClass *MC);