17#include "llvm/Config/llvm-config.h"
56#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
58 errs() <<
"Multiclass:\n";
62 errs() <<
"Template args:\n";
72 for (
unsigned i = 0, e = BV->
getNumBits(); i != e; ++i) {
74 bool IsReference =
false;
75 if (
auto VBI = dyn_cast<VarBitInit>(Bit)) {
76 if (
auto VI = dyn_cast<VarInit>(VBI->getBitVar())) {
77 if (R.getValue(VI->getName()))
80 }
else if (isa<VarInit>(Bit)) {
83 if (!(IsReference || Bit->isConcrete()))
90 for (
const RecordVal &RV : R.getValues()) {
95 if (RV.isNonconcreteOK())
98 if (
Init *V = RV.getValue()) {
102 Twine(
"Initializer of '") + RV.getNameInitAsString() +
103 "' in '" + R.getNameInitAsString() +
104 "' could not be fully resolved: " +
105 RV.getValue()->getAsString());
120 if (
BinOpInit *BinOp = dyn_cast<BinOpInit>(NewName))
121 NewName = BinOp->Fold(&CurRec);
140 bool TrackReferenceLocs)
const {
142 auto It = Vars.find(
Name->getValue());
143 if (It != Vars.end())
152 assert(RV &&
"Template arg doesn't exist??");
154 if (TrackReferenceLocs)
158 return Name->getValue() ==
"NAME"
172 if (TrackReferenceLocs)
173 RV->addReferenceLoc(NameLoc);
179 if (
auto *V = FindValueInArgs(CurRec,
Name))
196 if (
auto *V = FindValueInArgs(&CurMultiClass->
Rec,
Name))
204 return Parent->getVar(Records, ParsingMultiClass,
Name, NameLoc,
212 CurRec = &CurMultiClass->
Rec;
217 return Error(Loc,
"New definition of '" + RV.
getName() +
"' of type '" +
219 "previous definition of type '" +
220 ERV->getType()->getAsString() +
"'");
231 bool AllowSelfAssignment,
bool OverrideDefLoc) {
232 if (!V)
return false;
234 if (!CurRec) CurRec = &CurMultiClass->
Rec;
244 if (
VarInit *VI = dyn_cast<VarInit>(V))
245 if (
VI->getNameInit() == ValName && !AllowSelfAssignment)
246 return Error(Loc,
"Recursion / self-assignment forbidden");
252 if (!BitList.
empty()) {
256 "' is not a bits type");
261 return Error(Loc,
"Initializer is not compatible with bit range");
266 for (
unsigned i = 0, e = BitList.
size(); i != e; ++i) {
267 unsigned Bit = BitList[i];
269 return Error(Loc,
"Cannot set bit #" +
Twine(Bit) +
" of value '" +
274 for (
unsigned i = 0, e = CurVal->
getNumBits(); i != e; ++i)
276 NewBits[i] = CurVal->
getBit(i);
282 std::string InitType;
283 if (
BitsInit *BI = dyn_cast<BitsInit>(V))
284 InitType = (
Twine(
"' of type bit initializer with length ") +
285 Twine(BI->getNumBits())).str();
286 else if (
TypedInit *TI = dyn_cast<TypedInit>(V))
287 InitType = (
Twine(
"' of type '") + TI->getType()->getAsString()).str();
290 "' is incompatible with value '" +
291 V->getAsString() + InitType +
"'");
305 if (!
Field.isTemplateArg())
309 if (resolveArgumentsOfClass(R, SC, SubClass.
TemplateArgs,
332 for (
const auto &SCPair : SCs) {
335 "Already subclass of '" + SCPair.first->getName() +
"'!\n");
341 "Already subclass of '" +
SC->getName() +
"'!\n");
348 return AddSubClass(Entry.Rec.get(), SubClass);
353 for (
auto &
E : Entry.Loop->Entries) {
354 if (AddSubClass(
E, SubClass))
364bool TGParser::AddSubMultiClass(
MultiClass *CurMC,
369 if (resolveArgumentsOfMultiClass(
382 assert((!!
E.Rec + !!
E.Loop + !!
E.Assertion + !!
E.Dump) == 1 &&
383 "RecordsEntry has invalid number of items");
386 if (!Loops.empty()) {
387 Loops.back()->Entries.push_back(std::move(
E));
394 return resolve(*
E.Loop, Stack, CurMultiClass ==
nullptr,
395 CurMultiClass ? &CurMultiClass->
Entries :
nullptr);
400 CurMultiClass->
Entries.push_back(std::move(
E));
406 CheckAssert(
E.Assertion->Loc,
E.Assertion->Condition,
E.Assertion->Message);
416 return addDefOne(std::move(
E.Rec));
425 bool Final, std::vector<RecordsEntry> *Dest,
429 for (
const auto &S : Substs)
430 R.set(S.first, S.second);
439 if (
auto *TI = dyn_cast<TernOpInit>(
List);
441 Init *OldLHS = TI->getLHS();
446 Twine(
"unable to resolve if condition '") +
447 LHS->getAsString() +
"' at end of containing scope");
450 Init *MHS = TI->getMHS();
456 auto LI = dyn_cast<ListInit>(
List);
459 Dest->emplace_back(std::make_unique<ForeachLoop>(
Loop.Loc,
Loop.IterVar,
461 return resolve(
Loop.Entries, Substs, Final, &Dest->back().Loop->Entries,
466 List->getAsString() +
"', expected a list");
471 for (
auto *Elt : *LI) {
473 Substs.emplace_back(
Loop.IterVar->getNameInit(), Elt);
474 Error = resolve(
Loop.Entries, Substs, Final, Dest);
488bool TGParser::resolve(
const std::vector<RecordsEntry> &Source,
489 SubstStack &Substs,
bool Final,
490 std::vector<RecordsEntry> *Dest,
SMLoc *Loc) {
492 for (
auto &
E : Source) {
494 Error = resolve(*
E.Loop, Substs, Final, Dest);
496 }
else if (
E.Assertion) {
498 for (
const auto &S : Substs)
499 R.set(S.first, S.second);
500 Init *Condition =
E.Assertion->Condition->resolveReferences(R);
501 Init *Message =
E.Assertion->Message->resolveReferences(R);
504 Dest->push_back(std::make_unique<Record::AssertionInfo>(
505 E.Assertion->Loc, Condition, Message));
511 for (
const auto &S : Substs)
512 R.set(S.first, S.second);
513 Init *Message =
E.Dump->Message->resolveReferences(R);
517 std::make_unique<Record::DumpInfo>(
E.Dump->Loc, Message));
522 auto Rec = std::make_unique<Record>(*
E.Rec);
524 Rec->appendLoc(*Loc);
527 for (
const auto &S : Substs)
528 R.set(S.first, S.second);
529 Rec->resolveReferences(R);
532 Dest->push_back(std::move(Rec));
534 Error = addDefOne(std::move(Rec));
543bool TGParser::addDefOne(std::unique_ptr<Record> Rec) {
544 Init *NewName =
nullptr;
545 if (
Record *Prev = Records.
getDef(Rec->getNameInitAsString())) {
546 if (!Rec->isAnonymous()) {
548 "def already exists: " + Rec->getNameInitAsString());
549 PrintNote(Prev->getLoc(),
"location of previous definition");
558 if (!isa<StringInit>(Rec->getNameInit())) {
560 Rec->getNameInit()->getAsString() +
561 "' could not be fully resolved");
566 Rec->checkRecordAssertions();
569 Rec->emitRecordDumps();
572 assert(Rec->getTemplateArgs().empty() &&
"How'd this get template args?");
576 if (!
I->getType()->typeIsA(
Defset->EltTy)) {
577 PrintError(Rec->getLoc(),
Twine(
"adding record of incompatible type '") +
578 I->getType()->getAsString() +
586 Records.
addDef(std::move(Rec));
591 SMLoc Loc, ArgValueHandler ArgValueHandler) {
594 "Too many template arguments allowed");
598 for (
auto *Arg : ArgValues) {
599 Init *ArgName =
nullptr;
600 Init *ArgValue = Arg->getValue();
601 if (Arg->isPositional())
602 ArgName = ArgNames[Arg->getIndex()];
604 ArgName = Arg->getName();
608 return Error(Loc,
"We can only specify the template argument '" +
611 ArgValueHandler(ArgName, ArgValue);
616 for (
auto *UnsolvedArgName : UnsolvedArgNames) {
619 std::string
Name = UnsolvedArgName->getAsUnquotedString();
620 Error(Loc,
"value not specified for template argument '" +
Name +
"'");
625 ArgValueHandler(UnsolvedArgName,
Default);
636 return resolveArguments(Rec, ArgValues, Loc,
642bool TGParser::resolveArgumentsOfMultiClass(SubstStack &Substs,
MultiClass *MC,
647 return resolveArguments(
648 &MC->
Rec, ArgValues, Loc,
685 CurRec = &CurMultiClass->
Rec;
694 Name->resolveReferences(R);
708Record *TGParser::ParseClassID() {
710 TokError(
"expected name for ClassID");
718 TokError(Msg +
". Use 'defm' if you meant to use multiclass '" +
722 }
else if (TrackReferenceLocs) {
737 TokError(
"expected name for MultiClassID");
756ParseSubClassReference(
Record *CurRec,
bool isDefm) {
764 Result.Rec = ParseClassID();
774 if (ParseTemplateArgValueList(
Result.TemplateArgs, CurRec,
Result.Rec)) {
779 if (CheckTemplateArgValues(
Result.TemplateArgs,
Result.RefRange.Start,
797ParseSubMultiClassReference(
MultiClass *CurMC) {
801 Result.MC = ParseMultiClassID();
810 if (ParseTemplateArgValueList(
Result.TemplateArgs, &CurMC->
Rec,
832 auto LHSLoc = Lex.
getLoc();
833 auto *CurVal = ParseValue(CurRec);
836 auto *
LHS = cast<TypedInit>(CurVal);
843 auto RHSLoc = Lex.
getLoc();
844 CurVal = ParseValue(CurRec);
847 RHS = cast<TypedInit>(CurVal);
858 TokError(
"invalid range, cannot be negative");
900 auto FlushElems = [&] {
901 if (!Elems.
empty()) {
908 auto LHSLoc = Lex.
getLoc();
909 CurVal = ParseSliceElement(CurRec);
912 auto *CurValTy = CurVal->
getType();
914 if (
auto *ListValTy = dyn_cast<ListRecTy>(CurValTy)) {
915 if (!isa<IntRecTy>(ListValTy->getElementType())) {
917 "expected list<int>, got " +
Twine(ListValTy->getAsString()));
925 }
else if (!isa<IntRecTy>(CurValTy)) {
927 "unhandled type " +
Twine(CurValTy->getAsString()) +
" in range");
955 for (
auto *Slice : Slices) {
971 Init *CurVal = FirstItem;
973 CurVal = ParseValue(
nullptr);
975 IntInit *II = dyn_cast_or_null<IntInit>(CurVal);
977 return TokError(
"expected integer or bitrange");
983 return TokError(
"invalid range, cannot be negative");
994 Init *I_End = ParseValue(
nullptr);
995 IntInit *II_End = dyn_cast_or_null<IntInit>(I_End);
997 TokError(
"expected integer value as end of range");
1011 return TokError(
"invalid range, cannot be negative");
1015 for (; Start <=
End; ++Start)
1018 for (; Start >=
End; --Start)
1029 if (ParseRangePiece(Result)) {
1035 if (ParseRangePiece(Result)) {
1050 ParseRangeList(Ranges);
1051 if (
Ranges.empty())
return true;
1054 TokError(
"expected '>' at end of range list");
1055 return Error(StartLoc,
"to match this '<'");
1069 ParseRangeList(Ranges);
1070 if (
Ranges.empty())
return true;
1073 TokError(
"expected '}' at end of bit list");
1074 return Error(StartLoc,
"to match this '{'");
1090RecTy *TGParser::ParseType() {
1092 default:
TokError(
"Unknown token when expecting a type");
return nullptr;
1107 if (
Record *R = ParseClassID())
1113 TokError(
"expected '<' after bits type");
1117 TokError(
"expected integer in bits<n> type");
1122 TokError(
"expected '>' at end of bits<n> type");
1130 TokError(
"expected '<' after list type");
1134 RecTy *SubType = ParseType();
1135 if (!SubType)
return nullptr;
1138 TokError(
"expected '>' at end of list<ty> type");
1149 if (
Init *
I = CurScope->getVar(Records, CurMultiClass,
Name, NameLoc,
1150 TrackReferenceLocs))
1153 if (Mode == ParseNameMode)
1158 if (TrackReferenceLocs) {
1159 if (
auto *Def = dyn_cast<DefInit>(
I))
1160 Def->getDef()->appendReferenceLoc(NameLoc);
1167 if (CurRec && !CurRec->
isClass() && !CurMultiClass &&
1171 Error(NameLoc.
Start,
"Variable not defined: '" +
Name->getValue() +
"'");
1204 Type = ParseOperatorType();
1207 TokError(
"did not get type for unary operator");
1261 Type = ParseOperatorType();
1264 TokError(
"did not get type for unary operator");
1268 if (!isa<RecordRecTy>(
Type)) {
1269 TokError(
"type for !getdagop must be a record type");
1279 TokError(
"expected '(' after unary operator");
1283 Init *
LHS = ParseValue(CurRec);
1284 if (!LHS)
return nullptr;
1287 ListInit *LHSl = dyn_cast<ListInit>(LHS);
1288 StringInit *LHSs = dyn_cast<StringInit>(LHS);
1289 DagInit *LHSd = dyn_cast<DagInit>(LHS);
1290 TypedInit *LHSt = dyn_cast<TypedInit>(LHS);
1291 if (!LHSl && !LHSs && !LHSd && !LHSt) {
1292 TokError(
"expected string, list, or dag type argument in unary operator");
1299 if (!LType && !SType && !DType) {
1300 TokError(
"expected string, list, or dag type argument in unary operator");
1307 ListInit *LHSl = dyn_cast<ListInit>(LHS);
1308 TypedInit *LHSt = dyn_cast<TypedInit>(LHS);
1309 if (!LHSl && !LHSt) {
1310 TokError(
"expected list type argument in unary operator");
1316 TokError(
"expected list type argument in unary operator");
1321 if (LHSl && LHSl->
empty()) {
1322 TokError(
"empty list argument in unary operator");
1327 TypedInit *Itemt = dyn_cast<TypedInit>(Item);
1329 TokError(
"untyped list element in unary operator");
1335 assert(LHSt &&
"expected list type argument in unary operator");
1342 TokError(
"expected ')' in unary operator");
1357 TokError(
"expected '(' after type of !isa");
1361 Init *
LHS = ParseValue(CurRec);
1382 TokError(
"expected '(' after type of !exists");
1387 Init *Expr = ParseValue(CurRec);
1391 TypedInit *ExprType = dyn_cast<TypedInit>(Expr);
1393 Error(ExprLoc,
"expected string type argument in !exists operator");
1400 "expected string type argument in !exists operator, please "
1401 "use !isa instead");
1407 Error(ExprLoc,
"expected string type argument in !exists operator");
1412 TokError(
"expected ')' in !exists");
1485 RecTy *ArgType =
nullptr;
1495 Type = ParseOperatorType();
1497 TokError(
"did not get type for !getdagarg operator");
1548 if (
Type && ItemType && !
Type->typeIsConvertibleTo(ItemType)) {
1549 Error(OpLoc,
Twine(
"expected value of type '") +
1551 Type->getAsString() +
"'");
1556 TokError(
"expected '(' after binary operator");
1566 InitList.
push_back(ParseValue(CurRec, ArgType));
1567 if (!InitList.
back())
return nullptr;
1569 TypedInit *InitListBack = dyn_cast<TypedInit>(InitList.
back());
1570 if (!InitListBack) {
1571 Error(OpLoc,
Twine(
"expected value to be a typed value, got '" +
1572 InitList.
back()->getAsString() +
"'"));
1583 if (!isa<ListRecTy>(ArgType)) {
1584 Error(InitLoc,
Twine(
"expected a list, got value of type '") +
1590 if (ItemType && InitList.
size() == 1) {
1591 if (!isa<ListRecTy>(ItemType)) {
1593 Twine(
"expected output type to be a list, got type '") +
1598 Error(OpLoc,
Twine(
"expected first arg type to be '") +
1600 "', got value of type '" +
1601 cast<ListRecTy>(ItemType)
1608 if (InitList.
size() == 2 && !isa<IntRecTy>(ArgType)) {
1609 Error(InitLoc,
Twine(
"expected second parameter to be an int, got "
1610 "value of type '") +
1617 if (!isa<ListRecTy>(ArgType)) {
1618 Error(InitLoc,
Twine(
"expected a list, got value of type '") +
1628 Error(InitLoc,
Twine(
"expected bit, bits, int, string, or record; "
1642 Error(InitLoc,
Twine(
"expected bit, bits, int, or string; "
1649 switch (InitList.
size()) {
1654 Error(InitLoc,
Twine(
"expected list of string, int, bits, or bit; "
1655 "got value of type '") +
1661 if (!isa<StringRecTy>(ArgType)) {
1662 Error(InitLoc,
Twine(
"expected second argument to be a string, "
1663 "got value of type '") +
1679 Error(InitLoc,
Twine(
"expected value of type '") +
1718 TokError(
"expected ')' in operator");
1727 Type = cast<TypedInit>(InitList.
front())->getType()->getListTy();
1738 while (InitList.
size() > 2) {
1745 if (InitList.
size() == 2)
1749 Error(OpLoc,
"expected two operands to operator");
1755 return ParseOperationForEachFilter(CurRec, ItemType);
1763 TokError(
"expected '(' after !range operator");
1768 bool FirstArgIsList =
false;
1770 if (
Args.size() >= 3) {
1771 TokError(
"expected at most three values of integer");
1776 Args.push_back(ParseValue(CurRec));
1782 Error(OpLoc,
Twine(
"expected value to be a typed value, got '" +
1783 Args.back()->getAsString() +
"'"));
1788 if (!FirstArgIsList ||
Args.size() == 1) {
1789 if (
Args.size() == 1 && isa<ListRecTy>(ArgBackType)) {
1790 FirstArgIsList =
true;
1791 }
else if (isa<IntRecTy>(ArgBackType)) {
1794 if (
Args.size() != 1)
1795 Error(InitLoc,
Twine(
"expected value of type 'int', got '" +
1798 Error(InitLoc,
Twine(
"expected list or int, got value of type '") +
1804 assert(isa<ListRecTy>(cast<TypedInit>(Args[0])->
getType()));
1805 Error(InitLoc,
Twine(
"expected one list, got extra value of type '") +
1814 TokError(
"expected ')' in operator");
1819 auto ArgCount =
Args.size();
1821 auto *Arg0 = cast<TypedInit>(Args[0]);
1822 auto *Arg0Ty = Arg0->getType();
1823 if (ArgCount == 1) {
1824 if (isa<ListRecTy>(Arg0Ty)) {
1831 assert(isa<IntRecTy>(Arg0Ty));
1838 assert(isa<IntRecTy>(Arg0Ty));
1839 auto *Arg1 = cast<TypedInit>(Args[1]);
1840 assert(isa<IntRecTy>(Arg1->getType()));
1843 if (ArgCount == 3) {
1845 auto *Arg2 = cast<TypedInit>(Args[2]);
1846 assert(isa<IntRecTy>(Arg2->getType()));
1892 TokError(
"expected '(' after ternary operator");
1896 Init *
LHS = ParseValue(CurRec);
1897 if (!LHS)
return nullptr;
1900 TokError(
"expected ',' in ternary operator");
1905 Init *MHS = ParseValue(CurRec, ItemType);
1910 TokError(
"expected ',' in ternary operator");
1915 Init *
RHS = ParseValue(CurRec, ItemType);
1920 TokError(
"expected ')' in binary operator");
1927 TypedInit *MHSt = dyn_cast<TypedInit>(MHS);
1928 if (!MHSt && !isa<UnsetInit>(MHS)) {
1929 Error(MHSLoc,
"could not determine type of the child list in !dag");
1932 if (MHSt && !isa<ListRecTy>(MHSt->
getType())) {
1933 Error(MHSLoc,
Twine(
"expected list of children, got type '") +
1938 TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
1939 if (!RHSt && !isa<UnsetInit>(RHS)) {
1940 Error(RHSLoc,
"could not determine type of the name list in !dag");
1944 Error(RHSLoc,
Twine(
"expected list<string>, got type '") +
1949 if (!MHSt && !RHSt) {
1951 "cannot have both unset children and unset names in !dag");
1957 RecTy *MHSTy =
nullptr;
1958 RecTy *RHSTy =
nullptr;
1960 if (
TypedInit *MHSt = dyn_cast<TypedInit>(MHS))
1962 if (
BitsInit *MHSbits = dyn_cast<BitsInit>(MHS))
1964 if (isa<BitInit>(MHS))
1967 if (
TypedInit *RHSt = dyn_cast<TypedInit>(RHS))
1969 if (
BitsInit *RHSbits = dyn_cast<BitsInit>(RHS))
1971 if (isa<BitInit>(RHS))
1975 if (isa<UnsetInit>(MHS))
1977 if (isa<UnsetInit>(RHS))
1980 if (!MHSTy || !RHSTy) {
1981 TokError(
"could not get type for !if");
1994 TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
1996 TokError(
"could not get type for !subst");
2003 TypedInit *MHSt = dyn_cast<TypedInit>(MHS);
2004 if (!MHSt || !isa<IntRecTy, StringRecTy>(MHSt->
getType())) {
2005 Error(MHSLoc,
Twine(
"expected integer index or string name, got ") +
2014 TypedInit *MHSt = dyn_cast<TypedInit>(MHS);
2015 if (!MHSt || !isa<IntRecTy, StringRecTy>(MHSt->
getType())) {
2016 Error(MHSLoc,
Twine(
"expected integer index or string name, got ") +
2022 TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
2024 if (RHSt && !isa<StringRecTy>(RHSt->
getType())) {
2025 Error(RHSLoc,
Twine(
"expected string or unset name, got type '") +
2036 return ParseOperationSubstr(CurRec, ItemType);
2039 return ParseOperationFind(CurRec, ItemType);
2042 return ParseOperationCond(CurRec, ItemType);
2048 TokError(
"expected '(' after !foldl");
2052 Init *StartUntyped = ParseValue(CurRec);
2056 TypedInit *Start = dyn_cast<TypedInit>(StartUntyped);
2064 TokError(
"expected ',' in !foldl");
2068 Init *ListUntyped = ParseValue(CurRec);
2081 TokError(
Twine(
"!foldl list must be a list, but is of type '") +
2082 List->getType()->getAsString());
2087 TokError(
"expected ',' in !foldl");
2092 TokError(
"third argument of !foldl must be an identifier");
2099 "' already defined")
2105 TokError(
"expected ',' in !foldl");
2110 TokError(
"fourth argument of !foldl must be an identifier");
2117 "' already defined")
2123 TokError(
"expected ',' in !foldl");
2130 std::unique_ptr<Record> ParseRecTmp;
2131 Record *ParseRec = CurRec;
2133 ParseRecTmp = std::make_unique<Record>(
".parse",
ArrayRef<SMLoc>{}, Records);
2134 ParseRec = ParseRecTmp.get();
2141 Init *ExprUntyped = ParseValue(ParseRec);
2142 ParseRec->removeValue(
A);
2143 ParseRec->removeValue(
B);
2148 TypedInit *Expr = dyn_cast<TypedInit>(ExprUntyped);
2150 TokError(
"could not get type of !foldl expression");
2154 if (Expr->
getType() != Start->getType()) {
2155 TokError(
Twine(
"!foldl expression must be of same type as start (") +
2156 Start->getType()->getAsString() +
"), but is of type " +
2162 TokError(
"expected ')' in fold operator");
2177RecTy *TGParser::ParseOperatorType() {
2181 TokError(
"expected type name for operator");
2186 TokError(
"the 'code' type is not allowed in bang operators; use 'string'");
2191 TokError(
"expected type name for operator");
2196 TokError(
"expected type name for operator");
2206Init *TGParser::ParseOperationSubstr(
Record *CurRec,
RecTy *ItemType) {
2213 TokError(
"expected '(' after !substr operator");
2217 Init *
LHS = ParseValue(CurRec);
2222 TokError(
"expected ',' in !substr operator");
2227 Init *MHS = ParseValue(CurRec);
2235 RHS = ParseValue(CurRec);
2243 TokError(
"expected ')' in !substr operator");
2247 if (ItemType && !
Type->typeIsConvertibleTo(ItemType)) {
2248 Error(RHSLoc,
Twine(
"expected value of type '") +
2250 Type->getAsString() +
"'");
2253 TypedInit *LHSt = dyn_cast<TypedInit>(LHS);
2254 if (!LHSt && !isa<UnsetInit>(LHS)) {
2255 TokError(
"could not determine type of the string in !substr");
2258 if (LHSt && !isa<StringRecTy>(LHSt->
getType())) {
2264 TypedInit *MHSt = dyn_cast<TypedInit>(MHS);
2265 if (!MHSt && !isa<UnsetInit>(MHS)) {
2266 TokError(
"could not determine type of the start position in !substr");
2269 if (MHSt && !isa<IntRecTy>(MHSt->
getType())) {
2270 Error(MHSLoc,
Twine(
"expected int, got type '") +
2276 TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
2277 if (!RHSt && !isa<UnsetInit>(RHS)) {
2278 TokError(
"could not determine type of the length in !substr");
2281 if (RHSt && !isa<IntRecTy>(RHSt->
getType())) {
2301 TokError(
"expected '(' after !find operator");
2305 Init *
LHS = ParseValue(CurRec);
2310 TokError(
"expected ',' in !find operator");
2315 Init *MHS = ParseValue(CurRec);
2323 RHS = ParseValue(CurRec);
2331 TokError(
"expected ')' in !find operator");
2335 if (ItemType && !
Type->typeIsConvertibleTo(ItemType)) {
2336 Error(RHSLoc,
Twine(
"expected value of type '") +
2338 Type->getAsString() +
"'");
2341 TypedInit *LHSt = dyn_cast<TypedInit>(LHS);
2342 if (!LHSt && !isa<UnsetInit>(LHS)) {
2343 TokError(
"could not determine type of the source string in !find");
2346 if (LHSt && !isa<StringRecTy>(LHSt->
getType())) {
2352 TypedInit *MHSt = dyn_cast<TypedInit>(MHS);
2353 if (!MHSt && !isa<UnsetInit>(MHS)) {
2354 TokError(
"could not determine type of the target string in !find");
2357 if (MHSt && !isa<StringRecTy>(MHSt->
getType())) {
2358 Error(MHSLoc,
Twine(
"expected string, got type '") +
2364 TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
2365 if (!RHSt && !isa<UnsetInit>(RHS)) {
2366 TokError(
"could not determine type of the start position in !find");
2369 if (RHSt && !isa<IntRecTy>(RHSt->
getType())) {
2383Init *TGParser::ParseOperationForEachFilter(
Record *CurRec,
RecTy *ItemType) {
2388 TokError(
"expected '(' after !foreach/!filter");
2393 TokError(
"first argument of !foreach/!filter must be an identifier");
2400 if (CurRec && CurRec->
getValue(LHS)) {
2402 "' is already defined")
2408 TokError(
"expected ',' in !foreach/!filter");
2412 Init *MHS = ParseValue(CurRec);
2417 TokError(
"expected ',' in !foreach/!filter");
2421 TypedInit *MHSt = dyn_cast<TypedInit>(MHS);
2423 TokError(
"could not get type of !foreach/!filter list or dag");
2427 RecTy *InEltType =
nullptr;
2428 RecTy *ExprEltType =
nullptr;
2432 InEltType = InListTy->getElementType();
2434 if (
ListRecTy *OutListTy = dyn_cast<ListRecTy>(ItemType)) {
2436 ? OutListTy->getElementType()
2440 "expected value of type '" +
2442 "', but got list type");
2448 TokError(
"!filter must have a list argument");
2451 InEltType = InDagTy;
2452 if (ItemType && !isa<DagRecTy>(ItemType)) {
2455 "', but got dag type");
2461 TokError(
"!foreach must have a list or dag argument");
2463 TokError(
"!filter must have a list argument");
2469 std::unique_ptr<Record> ParseRecTmp;
2470 Record *ParseRec = CurRec;
2474 ParseRec = ParseRecTmp.get();
2478 Init *
RHS = ParseValue(ParseRec, ExprEltType);
2479 ParseRec->removeValue(LHS);
2485 TokError(
"expected ')' in !foreach/!filter");
2489 RecTy *OutType = InEltType;
2491 TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
2493 TokError(
"could not get type of !foreach result expression");
2503 LHS, MHS, RHS, OutType))
2511 TokError(
"expected '(' after !cond operator");
2522 Init *
V = ParseValue(CurRec);
2528 TokError(
"expected ':' following a condition in !cond operator");
2532 V = ParseValue(CurRec, ItemType);
2541 TokError(
"expected ',' or ')' following a value in !cond operator");
2546 if (Case.
size() < 1) {
2547 TokError(
"there should be at least 1 'condition : value' in the !cond operator");
2553 for (
Init *V : Val) {
2554 RecTy *VTy =
nullptr;
2555 if (
TypedInit *Vt = dyn_cast<TypedInit>(V))
2556 VTy = Vt->getType();
2557 if (
BitsInit *Vbits = dyn_cast<BitsInit>(V))
2559 if (isa<BitInit>(V))
2562 if (
Type ==
nullptr) {
2563 if (!isa<UnsetInit>(V))
2566 if (!isa<UnsetInit>(V)) {
2579 TokError(
"could not determine type for !cond from its arguments");
2619 return ParseOperation(CurRec, ItemType);
2622 default:
TokError(
"Unknown or reserved token when parsing a value");
break;
2639 for (
unsigned i = 0, e = BinaryVal.second; i != e; ++i)
2673 return ParseIDValue(CurRec,
Name, NameLoc, Mode);
2681 "Expected a class name, got '" +
Name->getValue() +
"'");
2687 if (ParseTemplateArgValueList(Args, CurRec, Class))
2690 if (CheckTemplateArgValues(Args, NameLoc.
Start, Class))
2693 if (resolveArguments(Class, Args, NameLoc.
Start))
2696 if (TrackReferenceLocs)
2697 Class->appendReferenceLoc(NameLoc);
2706 ParseValueList(Vals, CurRec);
2707 if (Vals.
empty())
return nullptr;
2710 TokError(
"expected '}' at end of bit list value");
2719 for (
unsigned i = 0, e = Vals.
size(); i != e; ++i) {
2724 if (
BitsInit *BI = dyn_cast<BitsInit>(Vals[i])) {
2725 for (
unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
2730 if (
VarInit *VI = dyn_cast<VarInit>(Vals[i])) {
2731 if (
BitsRecTy *BitsRec = dyn_cast<BitsRecTy>(
VI->getType())) {
2732 for (
unsigned i = 0, e = BitsRec->getNumBits(); i != e; ++i)
2741 Error(BraceLoc,
"Element #" +
Twine(i) +
" (" + Vals[i]->getAsString() +
2742 ") is not convertable to a bit");
2747 std::reverse(NewBits.
begin(), NewBits.
end());
2754 RecTy *DeducedEltTy =
nullptr;
2758 ListRecTy *ListType = dyn_cast<ListRecTy>(ItemType);
2764 GivenListTy = ListType;
2768 ParseValueList(Vals, CurRec,
2770 if (Vals.
empty())
return nullptr;
2773 TokError(
"expected ']' at end of list value");
2777 RecTy *GivenEltTy =
nullptr;
2780 GivenEltTy = ParseType();
2787 TokError(
"expected '>' at end of list element type");
2793 RecTy *EltTy =
nullptr;
2794 for (
Init *V : Vals) {
2795 TypedInit *TArg = dyn_cast<TypedInit>(V);
2800 TokError(
"Incompatible types in list elements");
2813 TokError(
"Incompatible types in list elements");
2830 TokError(
Twine(
"Element type mismatch for list: element type '") +
2836 DeducedEltTy = EltTy;
2845 TokError(
"expected identifier in dag init");
2856 TokError(
"expected variable name in dag operator");
2865 ParseDagArgList(DagArgs, CurRec);
2866 if (DagArgs.
empty())
return nullptr;
2870 TokError(
"expected ')' in dag init");
2888Init *TGParser::ParseValue(
Record *CurRec,
RecTy *ItemType, IDParseMode Mode) {
2890 Init *
Result = ParseSimpleValue(CurRec, ItemType, Mode);
2891 if (!Result)
return nullptr;
2898 if (Mode == ParseNameMode)
2905 ParseRangeList(Ranges);
2906 if (
Ranges.empty())
return nullptr;
2912 Error(CurlyLoc,
"Invalid bit range for value");
2918 TokError(
"expected '}' at end of bit range list");
2924 auto *
LHS = dyn_cast<TypedInit>(Result);
2926 Error(LHSLoc,
"Invalid value, list expected");
2930 auto *LHSTy = dyn_cast<ListRecTy>(
LHS->
getType());
2933 "' is invalid, list expected");
2947 LHSTy->getElementType())
2955 TokError(
"expected ']' at end of list slice");
2962 TokError(
"expected field identifier after '.'");
2967 if (!
Result->getFieldType(FieldName)) {
2969 Result->getAsString() +
"'");
2974 if (TrackReferenceLocs) {
2975 if (
auto *DI = dyn_cast<DefInit>(Result)) {
2976 DI->getDef()->getValue(FieldName)->addReferenceLoc(FieldNameLoc);
2977 }
else if (
auto *TI = dyn_cast<TypedInit>(Result)) {
2978 if (
auto *
RecTy = dyn_cast<RecordRecTy>(TI->getType())) {
2980 if (
auto *RV =
R->getValue(FieldName))
2995 Error(PasteLoc,
"LHS of paste is not typed!");
3003 assert(Mode == ParseValueMode &&
"encountered paste of lists in name");
3012 Init *RHSResult = ParseValue(CurRec, ItemType, ParseValueMode);
3024 auto CastLHS = dyn_cast<TypedInit>(
3029 Twine(
"can't cast '") +
LHS->getAsString() +
"' to string");
3051 Init *RHSResult = ParseValue(CurRec,
nullptr, ParseNameMode);
3054 RHS = dyn_cast<TypedInit>(RHSResult);
3056 Error(PasteLoc,
"RHS of paste is not typed!");
3061 auto CastRHS = dyn_cast<TypedInit>(
3066 Twine(
"can't cast '") +
RHS->getAsString() +
"' to string");
3087void TGParser::ParseDagArgList(
3100 Init *Val = ParseValue(CurRec);
3110 TokError(
"expected variable name in dag literal");
3118 Result.push_back(std::make_pair(Val, VarName));
3134 Result.push_back(ParseValue(CurRec, ItemType));
3144 Result.push_back(ParseValue(CurRec, ItemType));
3160bool TGParser::ParseTemplateArgValueList(
3162 assert(
Result.empty() &&
"Result vector is not empty");
3168 bool HasNamedArg =
false;
3169 unsigned ArgIndex = 0;
3171 if (ArgIndex >= TArgs.
size()) {
3172 TokError(
"Too many template arguments: " + utostr(ArgIndex + 1));
3181 HasNamedArg ?
nullptr : ArgsRec->
getValue(TArgs[ArgIndex])->
getType());
3187 if (!isa<StringInit>(
Value))
3188 return Error(ValueLoc,
3189 "The name of named argument should be a valid identifier");
3195 return Error(ValueLoc,
3196 "Argument " +
Name->getAsString() +
" doesn't exist");
3200 Value = ParseValue(CurRec, NamedArg->getType());
3202 if (isa<UnsetInit>(
Value))
3203 return Error(ValueLoc,
3204 "The value of named argument should be initialized, "
3206 Value->getAsString() +
"'");
3213 return Error(ValueLoc,
3214 "Positional argument should be put before named argument");
3222 return TokError(
"Expected comma before next argument");
3237Init *TGParser::ParseDeclaration(
Record *CurRec,
3238 bool ParsingTemplateArgs) {
3243 if (!
Type)
return nullptr;
3246 TokError(
"Expected identifier in declaration");
3251 if (Str ==
"NAME") {
3252 TokError(
"'" + Str +
"' is a reserved variable name");
3256 if (!ParsingTemplateArgs && CurScope->varAlreadyDefined(Str)) {
3257 TokError(
"local variable of this name already exists");
3266 if (!ParsingTemplateArgs) {
3267 BadField = AddValue(CurRec, IdLoc,
3271 }
else if (CurRec) {
3274 AddValue(CurRec, IdLoc,
3277 assert(CurMultiClass &&
"invalid context for template argument");
3280 AddValue(CurRec, IdLoc,
3289 Init *Val = ParseValue(CurRec,
Type);
3291 SetValue(CurRec, ValLoc, DeclName, std::nullopt, Val,
3311VarInit *TGParser::ParseForeachDeclaration(
Init *&ForeachListValue) {
3313 TokError(
"Expected identifier in foreach declaration");
3322 TokError(
"Expected '=' in foreach declaration");
3326 RecTy *IterType =
nullptr;
3332 ParseRangeList(Ranges);
3334 TokError(
"expected '}' at end of bit range list");
3342 Init *
I = ParseValue(
nullptr);
3347 if (TI && isa<ListRecTy>(TI->
getType())) {
3348 ForeachListValue =
I;
3349 IterType = cast<ListRecTy>(TI->
getType())->getElementType();
3354 if (ParseRangePiece(Ranges, TI))
3359 Error(ValueLoc,
"expected a list, got '" +
I->getAsString() +
"'");
3360 if (CurMultiClass) {
3361 PrintNote({},
"references to multiclass template arguments cannot be "
3362 "resolved at this time");
3370 assert(!IterType &&
"Type already initialized?");
3372 std::vector<Init *> Values;
3373 for (
unsigned R : Ranges)
3391bool TGParser::ParseTemplateArgList(
Record *CurRec) {
3395 Record *TheRecToAddTo = CurRec ? CurRec : &CurMultiClass->
Rec;
3398 Init *TemplArg = ParseDeclaration(CurRec,
true);
3407 TemplArg = ParseDeclaration(CurRec,
true);
3412 return Error(Loc,
"template argument with the same name has already been "
3419 return TokError(
"expected '>' at end of template argument list");
3431bool TGParser::ParseBodyItem(
Record *CurRec) {
3433 return ParseAssert(
nullptr, CurRec);
3436 return ParseDefvar(CurRec);
3439 return ParseDump(
nullptr, CurRec);
3442 if (!ParseDeclaration(CurRec,
false))
3446 return TokError(
"expected ';' after declaration");
3452 return TokError(
"expected field identifier after let");
3459 if (ParseOptionalBitList(BitList))
3461 std::reverse(BitList.
begin(), BitList.
end());
3464 return TokError(
"expected '=' in let expression");
3471 if (!BitList.
empty() && isa<BitsRecTy>(
Type)) {
3477 Init *Val = ParseValue(CurRec,
Type);
3478 if (!Val)
return true;
3481 return TokError(
"expected ';' after let expression");
3483 return SetValue(CurRec, IdLoc, FieldName, BitList, Val);
3493bool TGParser::ParseBody(
Record *CurRec) {
3499 return TokError(
"Expected '{' to start body or ';' for declaration only");
3502 if (ParseBodyItem(CurRec))
3511 PrintError(SemiLoc,
"A class or def body should not end with a semicolon");
3512 PrintNote(
"Semicolon ignored; remove to eliminate this error");
3520bool TGParser::ApplyLetStack(
Record *CurRec) {
3523 if (SetValue(CurRec, LR.Loc, LR.Name, LR.Bits, LR.Value))
3531 return ApplyLetStack(Entry.Rec.get());
3534 if (Entry.Assertion)
3541 for (
auto &
E : Entry.Loop->Entries) {
3542 if (ApplyLetStack(
E))
3558bool TGParser::ParseObjectBody(
Record *CurRec) {
3568 if (!SubClass.
Rec)
return true;
3571 if (AddSubClass(CurRec, SubClass))
3576 SubClass = ParseSubClassReference(CurRec,
false);
3580 if (ApplyLetStack(CurRec))
3583 bool Result = ParseBody(CurRec);
3593bool TGParser::ParseDef(
MultiClass *CurMultiClass) {
3604 std::unique_ptr<Record> CurRec;
3605 Init *
Name = ParseObjectName(CurMultiClass);
3609 if (isa<UnsetInit>(
Name)) {
3613 CurRec = std::make_unique<Record>(
Name, NameLoc, Records);
3616 if (ParseObjectBody(CurRec.get()))
3619 return addEntry(std::move(CurRec));
3626bool TGParser::ParseDefset() {
3635 if (!isa<ListRecTy>(
Type))
3637 Defset.EltTy = cast<ListRecTy>(
Type)->getElementType();
3640 return TokError(
"expected identifier");
3643 return TokError(
"def or global variable of this name already exists");
3652 Defsets.push_back(&Defset);
3653 bool Err = ParseObjectList(
nullptr);
3659 TokError(
"expected '}' at end of defset");
3660 return Error(BraceLoc,
"to match this '{'");
3672bool TGParser::ParseDefvar(
Record *CurRec) {
3677 return TokError(
"expected identifier");
3679 if (CurScope->varAlreadyDefined(DeclName->
getValue()))
3680 return TokError(
"local variable of this name already exists");
3685 if (V && !
V->isTemplateArg())
3686 return TokError(
"field of this name already exists");
3692 return TokError(
"def or global variable of this name already exists");
3705 if (!CurScope->isOutermost())
3719bool TGParser::ParseForeach(
MultiClass *CurMultiClass) {
3726 Init *ListValue =
nullptr;
3727 VarInit *IterName = ParseForeachDeclaration(ListValue);
3729 return TokError(
"expected declaration in for");
3735 auto TheLoop = std::make_unique<ForeachLoop>(Loc, IterName, ListValue);
3738 Loops.push_back(std::move(TheLoop));
3742 if (ParseObject(CurMultiClass))
3750 if (ParseObjectList(CurMultiClass))
3754 TokError(
"expected '}' at end of foreach command");
3755 return Error(BraceLoc,
"to match this '{'");
3762 std::unique_ptr<ForeachLoop>
Loop = std::move(Loops.back());
3765 return addEntry(std::move(
Loop));
3773bool TGParser::ParseIf(
MultiClass *CurMultiClass) {
3780 Init *Condition = ParseValue(
nullptr);
3800 Init *ThenClauseList =
3804 Loops.push_back(std::make_unique<ForeachLoop>(Loc,
nullptr, ThenClauseList));
3806 if (ParseIfBody(CurMultiClass,
"then"))
3809 std::unique_ptr<ForeachLoop>
Loop = std::move(Loops.back());
3812 if (addEntry(std::move(
Loop)))
3822 Init *ElseClauseList =
3827 std::make_unique<ForeachLoop>(Loc,
nullptr, ElseClauseList));
3829 if (ParseIfBody(CurMultiClass,
"else"))
3832 Loop = std::move(Loops.back());
3835 if (addEntry(std::move(
Loop)))
3853 if (ParseObject(CurMultiClass))
3861 if (ParseObjectList(CurMultiClass))
3865 TokError(
"expected '}' at end of '" + Kind +
"' clause");
3866 return Error(BraceLoc,
"to match this '{'");
3882 Init *Condition = ParseValue(CurRec);
3887 TokError(
"expected ',' in assert statement");
3891 Init *Message = ParseValue(CurRec);
3899 CurRec->
addAssertion(ConditionLoc, Condition, Message);
3901 addEntry(std::make_unique<Record::AssertionInfo>(ConditionLoc, Condition,
3910bool TGParser::ParseClass() {
3915 return TokError(
"expected class name after 'class' keyword");
3924 "' already defined");
3931 CurRec = NewRec.get();
3932 Records.
addClass(std::move(NewRec));
3940 if (ParseTemplateArgList(CurRec))
3943 if (ParseObjectBody(CurRec))
3946 if (!NoWarnOnUnusedTemplateArgs)
3962 TokError(
"expected identifier in let definition");
3973 if (ParseOptionalRangeList(Bits)) {
3977 std::reverse(
Bits.begin(),
Bits.end());
3980 TokError(
"expected '=' in let expression");
3985 Init *Val = ParseValue(
nullptr);
3992 Result.emplace_back(
Name, Bits, Val, NameLoc);
4002bool TGParser::ParseTopLevelLet(
MultiClass *CurMultiClass) {
4008 ParseLetList(LetInfo);
4009 if (LetInfo.
empty())
return true;
4013 return TokError(
"expected 'in' at end of top-level 'let'");
4018 if (ParseObject(CurMultiClass))
4029 if (ParseObjectList(CurMultiClass))
4033 TokError(
"expected '}' at end of top level let command");
4034 return Error(BraceLoc,
"to match this '{'");
4058bool TGParser::ParseMultiClass() {
4063 return TokError(
"expected identifier after multiclass for name");
4067 MultiClasses.insert(std::make_pair(
Name,
4068 std::make_unique<MultiClass>(
Name, Lex.
getLoc(),Records)));
4071 return TokError(
"multiclass '" +
Name +
"' already defined");
4073 CurMultiClass =
Result.first->second.get();
4081 if (ParseTemplateArgList(
nullptr))
4084 bool inherits =
false;
4092 ParseSubMultiClassReference(CurMultiClass);
4095 if (!SubMultiClass.
MC)
return true;
4098 if (AddSubMultiClass(CurMultiClass, SubMultiClass))
4103 SubMultiClass = ParseSubMultiClassReference(CurMultiClass);
4109 return TokError(
"expected '{' in multiclass definition");
4111 return TokError(
"expected ';' in multiclass definition");
4114 return TokError(
"multiclass must contain at least one def");
4119 return TokError(
"expected 'assert', 'def', 'defm', 'defvar', 'dump', "
4120 "'foreach', 'if', or 'let' in multiclass body");
4130 if (ParseObject(CurMultiClass))
4140 PrintError(SemiLoc,
"A multiclass body should not end with a semicolon");
4141 PrintNote(
"Semicolon ignored; remove to eliminate this error");
4145 if (!NoWarnOnUnusedTemplateArgs)
4149 CurMultiClass =
nullptr;
4157bool TGParser::ParseDefm(
MultiClass *CurMultiClass) {
4161 Init *DefmName = ParseObjectName(CurMultiClass);
4164 if (isa<UnsetInit>(DefmName)) {
4174 return TokError(
"expected ':' after defm identifier");
4177 std::vector<RecordsEntry> NewEntries;
4180 bool InheritFromClass =
false;
4189 if (!
Ref.Rec)
return true;
4195 MultiClass *MC = MultiClasses[std::string(
Ref.Rec->getName())].get();
4196 assert(MC &&
"Didn't lookup multiclass correctly?");
4199 if (resolveArgumentsOfMultiClass(Substs, MC,
Ref.TemplateArgs, DefmName,
4203 if (resolve(MC->
Entries, Substs, !CurMultiClass && Loops.empty(),
4204 &NewEntries, &SubClassLoc))
4211 return TokError(
"expected identifier");
4213 SubClassLoc = Lex.
getLoc();
4219 if (InheritFromClass)
4222 Ref = ParseSubClassReference(
nullptr,
true);
4225 if (InheritFromClass) {
4231 if (!SubClass.
Rec)
return true;
4235 for (
auto &
E : NewEntries) {
4237 if (AddSubClass(
E, SubClass))
4243 SubClass = ParseSubClassReference(
nullptr,
false);
4247 for (
auto &
E : NewEntries) {
4248 if (ApplyLetStack(
E))
4251 addEntry(std::move(
E));
4255 return TokError(
"expected ';' at end of defm");
4275 "Expected assert, class, def, defm, defset, dump, foreach, if, or let");
4281 return ParseDump(MC);
4284 case tgtok::Let:
return ParseTopLevelLet(MC);
4287 return TokError(
"defset is not allowed inside multiclass");
4288 return ParseDefset();
4291 return TokError(
"class is not allowed inside multiclass");
4293 return TokError(
"class is not allowed inside foreach loop");
4294 return ParseClass();
4297 return TokError(
"multiclass is not allowed inside foreach loop");
4298 return ParseMultiClass();
4304bool TGParser::ParseObjectList(
MultiClass *MC) {
4306 if (ParseObject(MC))
4315 if (ParseObjectList())
4323 return TokError(
"Unexpected token at top level");
4330bool TGParser::CheckTemplateArgValues(
4334 for (
unsigned I = 0,
E = Values.
size();
I <
E; ++
I) {
4336 Init *ArgName =
nullptr;
4337 if (
Value->isPositional())
4338 ArgName = TArgs[
Value->getIndex()];
4339 if (
Value->isNamed())
4345 if (
TypedInit *ArgValue = dyn_cast<TypedInit>(
Value->getValue())) {
4346 auto *CastValue = ArgValue->
getCastTo(ArgType);
4348 assert((!isa<TypedInit>(CastValue) ||
4349 cast<TypedInit>(CastValue)->
getType()->typeIsA(ArgType)) &&
4350 "result of template arg value cast has wrong type");
4351 Values[
I] =
Value->cloneWithValue(CastValue);
4365#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4384 errs() <<
"Record:\n";
4387 errs() <<
"Defs:\n";
4399 Init *Message = ParseValue(CurRec);
4405 if (isa<DefInit>(Message))
4413 CurRec->
addDump(Loc, Message);
4415 addEntry(std::make_unique<Record::DumpInfo>(Loc, Message));
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
PowerPC Reduce CR logical Operation
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
static bool checkBitsConcrete(Record &R, const RecordVal &RV)
static Init * QualifyName(Record &CurRec, Init *Name)
Return an Init with a qualifier prefix referring to CurRec's name.
static Init * QualifiedNameOfImplicitName(Record &Rec)
Return the qualified version of the implicit 'NAME' template argument.
static void checkConcrete(Record &R)
static SymbolRef::Type getType(const Symbol *Sym)
static ArgumentInit * get(Init *Value, ArgAuxType Aux)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
!op (X, Y) - Combine two inits.
Init * Fold(Record *CurRec) const
static Init * getStrConcat(Init *lhs, Init *rhs)
static Init * getListConcat(TypedInit *lhs, Init *rhs)
static BinOpInit * get(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type)
static BitInit * get(RecordKeeper &RK, bool V)
static BitRecTy * get(RecordKeeper &RK)
'{ a, b, c }' - Represents an initializer for a BitsRecTy value.
Init * getBit(unsigned Bit) const override
Get the Init value of the specified bit.
unsigned getNumBits() const
static BitsInit * get(RecordKeeper &RK, ArrayRef< Init * > Range)
'bits<n>' - Represent a fixed number of bits
static BitsRecTy * get(RecordKeeper &RK, unsigned Sz)
static CondOpInit * get(ArrayRef< Init * > C, ArrayRef< Init * > V, RecTy *Type)
Init * Fold(Record *CurRec) const
(v a, b) - Represent a DAG tree value.
static DagInit * get(Init *V, StringInit *VN, ArrayRef< Init * > ArgRange, ArrayRef< StringInit * > NameRange)
'dag' - Represent a dag fragment
static DagRecTy * get(RecordKeeper &RK)
AL - Represent a reference to a 'def' in the description.
Lightweight error class with error context and mandatory checking.
static ExistsOpInit * get(RecTy *CheckType, Init *Expr)
Init * Fold(Record *CurRec) const
static FieldInit * get(Init *R, StringInit *FN)
Init * Fold(Record *CurRec) const
static FoldOpInit * get(Init *Start, Init *List, Init *A, Init *B, Init *Expr, RecTy *Type)
Do not resolve anything, but keep track of whether a given variable was referenced.
virtual Init * getBit(unsigned Bit) const =0
Get the Init value of the specified bit.
virtual Init * resolveReferences(Resolver &R) const
This function is used by classes that refer to other variables which may not be defined at the time t...
virtual std::string getAsUnquotedString() const
Convert this value to a literal form, without adding quotes around a string.
virtual std::string getAsString() const =0
Convert this value to a literal form.
virtual Init * getCastTo(RecTy *Ty) const =0
If this value is convertible to type Ty, return a value whose type is Ty, generating a !...
'7' - Represent an initialization by a literal integer value.
static IntInit * get(RecordKeeper &RK, int64_t V)
static IntRecTy * get(RecordKeeper &RK)
static IsAOpInit * get(RecTy *CheckType, Init *Expr)
[AL, AH, CL] - Represent a list of defs
static ListInit * get(ArrayRef< Init * > Range, RecTy *EltTy)
Init * getElement(unsigned i) const
'list<Ty>' - Represent a list of element values, all of which must be of the specified type.
bool typeIsConvertibleTo(const RecTy *RHS) const override
Return true if all values of 'this' type can be converted to the specified type.
RecTy * getElementType() const
static ListRecTy * get(RecTy *T)
Represents a single loop in the control flow graph.
Resolve arbitrary mappings.
This is a utility class that provides an abstraction for the common functionality between Instruction...
ListRecTy * getListTy()
Returns the type representing list<thistype>.
virtual bool typeIsConvertibleTo(const RecTy *RHS) const
Return true if all values of 'this' type can be converted to the specified type.
virtual std::string getAsString() const =0
void addDef(std::unique_ptr< Record > R)
void addClass(std::unique_ptr< Record > R)
Record * getDef(StringRef Name) const
Get the concrete record with the specified name.
Record * getClass(StringRef Name) const
Get the class with the specified name.
void addExtraGlobal(StringRef Name, Init *I)
Init * getNewAnonymousName()
GetNewAnonymousName - Generate a unique anonymous name that can be used as an identifier.
Init * getGlobal(StringRef Name) const
Get the Init value of the specified global variable.
'[classname]' - Type of record values that have zero or more superclasses.
static RecordRecTy * get(RecordKeeper &RK, ArrayRef< Record * > Classes)
Get the record type with the given non-redundant list of superclasses.
This class represents a field in a record, including its name, type, value, and source location.
bool setValue(Init *V)
Set the value of the field from an Init.
std::string getNameInitAsString() const
Get the name of the field as a std::string.
void setUsed(bool Used)
Whether this value is used.
StringRef getName() const
Get the name of the field as a StringRef.
void addReferenceLoc(SMRange Loc)
Add a reference to this record value.
RecTy * getType() const
Get the type of the field value as a RecTy.
Init * getNameInit() const
Get the name of the field as an Init.
Init * getValue() const
Get the value of the field as an Init.
void addAssertion(SMLoc Loc, Init *Condition, Init *Message)
void addDump(SMLoc Loc, Init *Message)
void checkUnusedTemplateArgs()
std::string getNameInitAsString() const
Init * getNameInit() const
RecordKeeper & getRecords() const
const RecordVal * getValue(const Init *Name) const
bool isMultiClass() const
void addValue(const RecordVal &RV)
void appendDumps(const Record *Rec)
void addTemplateArg(Init *Name)
ArrayRef< Init * > getTemplateArgs() const
bool isSubClassOf(const Record *R) const
ArrayRef< RecordVal > getValues() const
SMLoc getFieldLoc(StringRef FieldName) const
Return the source location for the named field.
void addSuperClass(Record *R, SMRange Range)
bool isTemplateArg(Init *Name) const
void updateClassLoc(SMLoc Loc)
void resolveReferences(Init *NewName=nullptr)
If there are any field references that refer to fields that have been filled in, we can propagate the...
void appendAssertions(const Record *Rec)
ArrayRef< std::pair< Record *, SMRange > > getSuperClasses() const
Represents a location in source code.
Represents a range in source code.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
"foo" - Represent an initialization by a string value.
StringRef getValue() const
static StringInit * get(RecordKeeper &RK, StringRef, StringFormat Fmt=SF_String)
'string' - Represent an string value
static StringRecTy * get(RecordKeeper &RK)
StringRef - Represent a constant reference to a string, i.e.
SMRange getLocRange() const
int64_t getCurIntVal() const
std::pair< int64_t, unsigned > getCurBinaryIntVal() const
const std::string & getCurStrVal() const
tgtok::TokKind getCode() const
void PopScope(TGVarScope *ExpectedStackTop)
bool TokError(const Twine &Msg) const
bool ParseFile()
ParseFile - Main entrypoint for parsing a tblgen file.
Init * getVar(RecordKeeper &Records, MultiClass *ParsingMultiClass, StringInit *Name, SMRange NameLoc, bool TrackReferenceLocs) const
Init * Fold(Record *CurRec) const
static TernOpInit * get(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
This is the common superclass of types that have a specific, explicit type, stored in ValueTy.
RecTy * getType() const
Get the type of the Init as a RecTy.
Init * Fold(Record *CurRec, bool IsFinal=false) const
static UnOpInit * get(UnaryOp opc, Init *lhs, RecTy *Type)
static UnsetInit * get(RecordKeeper &RK)
Get the singleton unset Init.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
StringRef getName() const
Return a constant reference to the value's name.
static VarDefInit * get(Record *Class, ArrayRef< ArgumentInit * > Args)
'Opcode' - Represent a reference to an entire variable object.
Init * getNameInit() const
std::string getAsString() const override
Convert this value to a literal form.
static VarInit * get(StringRef VN, RecTy *T)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
const CustomOperand< const MCSubtargetInfo & > Msg[]
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
@ Resolved
Queried, materialization begun.
NodeAddr< DefNode * > Def
NodeAddr< CodeNode * > Code
static bool isBangOperator(tgtok::TokKind Kind)
isBangOperator - Return true if this is a bang operator.