aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/TableGen/TGParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/TableGen/TGParser.cpp')
-rw-r--r--llvm/lib/TableGen/TGParser.cpp389
1 files changed, 237 insertions, 152 deletions
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 81b61b1..0c6add5 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<BitsInit>(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<unsigned> 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<BitsInit>(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<BitsInit>(V))
InitType = (Twine("' of type bit initializer with length ") +
- Twine(BI->getNumBits())).str();
+ Twine(BI->getNumBits()))
+ .str();
else if (const auto *TI = dyn_cast<TypedInit>(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<RecordsEntry> *Dest,
- SMLoc *Loc) {
+bool TGParser::resolve(const ForeachLoop &Loop, SubstStack &Substs, bool Final,
+ std::vector<RecordsEntry> *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<ListInit>(List);
if (!LI) {
if (!Final) {
- Dest->emplace_back(std::make_unique<ForeachLoop>(Loop.Loc, Loop.IterVar,
- List));
+ Dest->emplace_back(
+ std::make_unique<ForeachLoop>(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<Record> 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<unsigned> &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<unsigned> &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<unsigned> &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<n> 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<ty> 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<BaseClass>(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<ListInit>(LHS);
@@ -1314,12 +1327,14 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) {
const auto *LHSd = dyn_cast<DagInit>(LHS);
const auto *LHSt = dyn_cast<TypedInit>(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<ListRecTy, StringRecTy, DagRecTy>(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<TypedInit>(InitList.back());
if (!InitListBack) {
@@ -1678,7 +1738,7 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) {
case BinOpInit::LISTCONCAT:
if (!isa<ListRecTy>(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<TypedInit>(MHS);
if (!MHSt && !isa<UnsetInit>(MHS)) {
@@ -2231,7 +2296,8 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) {
std::unique_ptr<Record> ParseRecTmp;
Record *ParseRec = CurRec;
if (!ParseRec) {
- ParseRecTmp = std::make_unique<Record>(".parse", ArrayRef<SMLoc>{}, Records);
+ ParseRecTmp =
+ std::make_unique<Record>(".parse", ArrayRef<SMLoc>{}, 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<TypedInit>(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<TypedInit>(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<DagRecTy>(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<Init*, 16> Bits(BinaryVal.second);
+ SmallVector<Init *, 16> 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<const Init *, 16> 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<const Init *, 16> 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<std::pair<const Init *, const StringInit *>, 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<unsigned, 16> 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<ListRecTy>(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<unsigned, 16> 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<LetRecord> &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<unsigned, 16> Bits;
@@ -4159,7 +4233,8 @@ bool TGParser::ParseTopLevelLet(MultiClass *CurMultiClass) {
// Add this entry to the let stack.
SmallVector<LetRecord, 8> 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");