18#include "llvm/Config/llvm-config.h"
57#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
59 errs() <<
"Multiclass:\n";
63 errs() <<
"Template args:\n";
73 for (
unsigned i = 0, e = BV->
getNumBits(); i != e; ++i) {
75 bool IsReference =
false;
76 if (
auto VBI = dyn_cast<VarBitInit>(Bit)) {
77 if (
auto VI = dyn_cast<VarInit>(VBI->getBitVar())) {
78 if (R.getValue(VI->getName()))
81 }
else if (isa<VarInit>(Bit)) {
84 if (!(IsReference || Bit->isConcrete()))
91 for (
const RecordVal &RV : R.getValues()) {
96 if (RV.isNonconcreteOK())
99 if (
Init *V = RV.getValue()) {
103 Twine(
"Initializer of '") + RV.getNameInitAsString() +
104 "' in '" + R.getNameInitAsString() +
105 "' could not be fully resolved: " +
106 RV.getValue()->getAsString());
121 if (
BinOpInit *BinOp = dyn_cast<BinOpInit>(NewName))
122 NewName = BinOp->Fold(&CurRec);
139 bool TrackReferenceLocs)
const {
141 auto It = Vars.find(
Name->getValue());
142 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,
329 for (
const auto &SCPair : SCs) {
332 "Already subclass of '" + SCPair.first->getName() +
"'!\n");
338 "Already subclass of '" +
SC->getName() +
"'!\n");
345 return AddSubClass(Entry.Rec.get(), SubClass);
350 for (
auto &
E : Entry.Loop->Entries) {
351 if (AddSubClass(
E, SubClass))
361bool TGParser::AddSubMultiClass(
MultiClass *CurMC,
366 if (resolveArgumentsOfMultiClass(
379 assert((!!
E.Rec + !!
E.Loop + !!
E.Assertion) == 1 &&
380 "RecordsEntry has invalid number of items");
383 if (!Loops.empty()) {
384 Loops.back()->Entries.push_back(std::move(
E));
391 return resolve(*
E.Loop, Stack, CurMultiClass ==
nullptr,
392 CurMultiClass ? &CurMultiClass->
Entries :
nullptr);
397 CurMultiClass->
Entries.push_back(std::move(
E));
403 CheckAssert(
E.Assertion->Loc,
E.Assertion->Condition,
E.Assertion->Message);
408 return addDefOne(std::move(
E.Rec));
417 bool Final, std::vector<RecordsEntry> *Dest,
421 for (
const auto &S : Substs)
422 R.set(S.first, S.second);
431 if (
auto *TI = dyn_cast<TernOpInit>(
List);
433 Init *OldLHS = TI->getLHS();
438 Twine(
"unable to resolve if condition '") +
439 LHS->getAsString() +
"' at end of containing scope");
442 Init *MHS = TI->getMHS();
448 auto LI = dyn_cast<ListInit>(
List);
451 Dest->emplace_back(std::make_unique<ForeachLoop>(
Loop.Loc,
Loop.IterVar,
453 return resolve(
Loop.Entries, Substs, Final, &Dest->back().Loop->Entries,
458 List->getAsString() +
"', expected a list");
463 for (
auto *Elt : *LI) {
465 Substs.emplace_back(
Loop.IterVar->getNameInit(), Elt);
466 Error = resolve(
Loop.Entries, Substs, Final, Dest);
480bool TGParser::resolve(
const std::vector<RecordsEntry> &Source,
481 SubstStack &Substs,
bool Final,
482 std::vector<RecordsEntry> *Dest,
SMLoc *Loc) {
484 for (
auto &
E : Source) {
486 Error = resolve(*
E.Loop, Substs, Final, Dest);
488 }
else if (
E.Assertion) {
490 for (
const auto &S : Substs)
491 R.set(S.first, S.second);
492 Init *Condition =
E.Assertion->Condition->resolveReferences(R);
493 Init *Message =
E.Assertion->Message->resolveReferences(R);
496 Dest->push_back(std::make_unique<Record::AssertionInfo>(
497 E.Assertion->Loc, Condition, Message));
502 auto Rec = std::make_unique<Record>(*
E.Rec);
504 Rec->appendLoc(*Loc);
507 for (
const auto &S : Substs)
508 R.set(S.first, S.second);
509 Rec->resolveReferences(R);
512 Dest->push_back(std::move(Rec));
514 Error = addDefOne(std::move(Rec));
523bool TGParser::addDefOne(std::unique_ptr<Record> Rec) {
524 Init *NewName =
nullptr;
525 if (
Record *Prev = Records.
getDef(Rec->getNameInitAsString())) {
526 if (!Rec->isAnonymous()) {
528 "def already exists: " + Rec->getNameInitAsString());
529 PrintNote(Prev->getLoc(),
"location of previous definition");
538 if (!isa<StringInit>(Rec->getNameInit())) {
540 Rec->getNameInit()->getAsString() +
541 "' could not be fully resolved");
546 Rec->checkRecordAssertions();
549 assert(Rec->getTemplateArgs().empty() &&
"How'd this get template args?");
553 if (!
I->getType()->typeIsA(
Defset->EltTy)) {
554 PrintError(Rec->getLoc(),
Twine(
"adding record of incompatible type '") +
555 I->getType()->getAsString() +
563 Records.
addDef(std::move(Rec));
568 SMLoc Loc, ArgValueHandler ArgValueHandler) {
571 "Too many template arguments allowed");
575 for (
auto *Arg : ArgValues) {
576 Init *ArgName =
nullptr;
577 Init *ArgValue = Arg->getValue();
578 if (Arg->isPositional())
579 ArgName = ArgNames[Arg->getIndex()];
581 ArgName = Arg->getName();
585 return Error(Loc,
"We can only specify the template argument '" +
588 ArgValueHandler(ArgName, ArgValue);
593 for (
auto *UnsolvedArgName : UnsolvedArgNames) {
596 std::string
Name = UnsolvedArgName->getAsUnquotedString();
597 Error(Loc,
"value not specified for template argument '" +
Name +
"'");
602 ArgValueHandler(UnsolvedArgName,
Default);
613 return resolveArguments(Rec, ArgValues, Loc,
619bool TGParser::resolveArgumentsOfMultiClass(SubstStack &Substs,
MultiClass *MC,
624 return resolveArguments(
625 &MC->
Rec, ArgValues, Loc,
662 CurRec = &CurMultiClass->
Rec;
671 Name->resolveReferences(R);
685Record *TGParser::ParseClassID() {
687 TokError(
"expected name for ClassID");
695 TokError(Msg +
". Use 'defm' if you meant to use multiclass '" +
699 }
else if (TrackReferenceLocs) {
714 TokError(
"expected name for MultiClassID");
733ParseSubClassReference(
Record *CurRec,
bool isDefm) {
741 Result.Rec = ParseClassID();
751 if (ParseTemplateArgValueList(
Result.TemplateArgs, CurRec,
Result.Rec,
757 if (CheckTemplateArgValues(
Result.TemplateArgs,
Result.RefRange.Start,
775ParseSubMultiClassReference(
MultiClass *CurMC) {
779 Result.MC = ParseMultiClassID();
788 if (ParseTemplateArgValueList(
Result.TemplateArgs, &CurMC->
Rec,
810 auto LHSLoc = Lex.
getLoc();
811 auto *CurVal = ParseValue(CurRec);
814 auto *
LHS = cast<TypedInit>(CurVal);
821 auto RHSLoc = Lex.
getLoc();
822 CurVal = ParseValue(CurRec);
825 RHS = cast<TypedInit>(CurVal);
836 TokError(
"invalid range, cannot be negative");
878 auto FlushElems = [&] {
879 if (!Elems.
empty()) {
886 auto LHSLoc = Lex.
getLoc();
887 CurVal = ParseSliceElement(CurRec);
890 auto *CurValTy = CurVal->
getType();
892 if (
auto *ListValTy = dyn_cast<ListRecTy>(CurValTy)) {
893 if (!isa<IntRecTy>(ListValTy->getElementType())) {
895 "expected list<int>, got " +
Twine(ListValTy->getAsString()));
903 }
else if (!isa<IntRecTy>(CurValTy)) {
905 "unhandled type " +
Twine(CurValTy->getAsString()) +
" in range");
933 for (
auto *Slice : Slices) {
949 Init *CurVal = FirstItem;
951 CurVal = ParseValue(
nullptr);
953 IntInit *II = dyn_cast_or_null<IntInit>(CurVal);
955 return TokError(
"expected integer or bitrange");
961 return TokError(
"invalid range, cannot be negative");
972 Init *I_End = ParseValue(
nullptr);
973 IntInit *II_End = dyn_cast_or_null<IntInit>(I_End);
975 TokError(
"expected integer value as end of range");
989 return TokError(
"invalid range, cannot be negative");
993 for (; Start <=
End; ++Start)
996 for (; Start >=
End; --Start)
1007 if (ParseRangePiece(Result)) {
1013 if (ParseRangePiece(Result)) {
1028 ParseRangeList(Ranges);
1029 if (
Ranges.empty())
return true;
1032 TokError(
"expected '>' at end of range list");
1033 return Error(StartLoc,
"to match this '<'");
1047 ParseRangeList(Ranges);
1048 if (
Ranges.empty())
return true;
1051 TokError(
"expected '}' at end of bit list");
1052 return Error(StartLoc,
"to match this '{'");
1068RecTy *TGParser::ParseType() {
1070 default:
TokError(
"Unknown token when expecting a type");
return nullptr;
1085 if (
Record *R = ParseClassID())
1091 TokError(
"expected '<' after bits type");
1095 TokError(
"expected integer in bits<n> type");
1100 TokError(
"expected '>' at end of bits<n> type");
1108 TokError(
"expected '<' after list type");
1112 RecTy *SubType = ParseType();
1113 if (!SubType)
return nullptr;
1116 TokError(
"expected '>' at end of list<ty> type");
1127 if (
Init *
I = CurScope->getVar(Records, CurMultiClass,
Name, NameLoc,
1128 TrackReferenceLocs))
1131 if (Mode == ParseNameMode)
1136 if (TrackReferenceLocs) {
1137 if (
auto *Def = dyn_cast<DefInit>(
I))
1138 Def->getDef()->appendReferenceLoc(NameLoc);
1145 if (CurRec && !CurRec->
isClass() && !CurMultiClass &&
1149 Error(NameLoc.
Start,
"Variable not defined: '" +
Name->getValue() +
"'");
1181 Type = ParseOperatorType();
1184 TokError(
"did not get type for unary operator");
1233 Type = ParseOperatorType();
1236 TokError(
"did not get type for unary operator");
1240 if (!isa<RecordRecTy>(
Type)) {
1241 TokError(
"type for !getdagop must be a record type");
1251 TokError(
"expected '(' after unary operator");
1255 Init *
LHS = ParseValue(CurRec);
1256 if (!LHS)
return nullptr;
1259 ListInit *LHSl = dyn_cast<ListInit>(LHS);
1260 StringInit *LHSs = dyn_cast<StringInit>(LHS);
1261 DagInit *LHSd = dyn_cast<DagInit>(LHS);
1262 TypedInit *LHSt = dyn_cast<TypedInit>(LHS);
1263 if (!LHSl && !LHSs && !LHSd && !LHSt) {
1264 TokError(
"expected string, list, or dag type argument in unary operator");
1271 if (!LType && !SType && !DType) {
1272 TokError(
"expected string, list, or dag type argument in unary operator");
1279 ListInit *LHSl = dyn_cast<ListInit>(LHS);
1280 TypedInit *LHSt = dyn_cast<TypedInit>(LHS);
1281 if (!LHSl && !LHSt) {
1282 TokError(
"expected list type argument in unary operator");
1288 TokError(
"expected list type argument in unary operator");
1293 if (LHSl && LHSl->
empty()) {
1294 TokError(
"empty list argument in unary operator");
1299 TypedInit *Itemt = dyn_cast<TypedInit>(Item);
1301 TokError(
"untyped list element in unary operator");
1307 assert(LHSt &&
"expected list type argument in unary operator");
1314 TokError(
"expected ')' in unary operator");
1329 TokError(
"expected '(' after type of !isa");
1333 Init *
LHS = ParseValue(CurRec);
1354 TokError(
"expected '(' after type of !exists");
1359 Init *Expr = ParseValue(CurRec);
1363 TypedInit *ExprType = dyn_cast<TypedInit>(Expr);
1365 Error(ExprLoc,
"expected string type argument in !exists operator");
1372 "expected string type argument in !exists operator, please "
1373 "use !isa instead");
1379 Error(ExprLoc,
"expected string type argument in !exists operator");
1384 TokError(
"expected ')' in !exists");
1457 RecTy *ArgType =
nullptr;
1467 Type = ParseOperatorType();
1469 TokError(
"did not get type for !getdagarg operator");
1524 if (
Type && ItemType && !
Type->typeIsConvertibleTo(ItemType)) {
1525 Error(OpLoc,
Twine(
"expected value of type '") +
1527 Type->getAsString() +
"'");
1532 TokError(
"expected '(' after binary operator");
1542 InitList.
push_back(ParseValue(CurRec, ArgType));
1543 if (!InitList.
back())
return nullptr;
1545 TypedInit *InitListBack = dyn_cast<TypedInit>(InitList.
back());
1546 if (!InitListBack) {
1547 Error(OpLoc,
Twine(
"expected value to be a typed value, got '" +
1548 InitList.
back()->getAsString() +
"'"));
1559 if (!isa<ListRecTy>(ArgType)) {
1560 Error(InitLoc,
Twine(
"expected a list, got value of type '") +
1566 if (ItemType && InitList.
size() == 1) {
1567 if (!isa<ListRecTy>(ItemType)) {
1569 Twine(
"expected output type to be a list, got type '") +
1574 Error(OpLoc,
Twine(
"expected first arg type to be '") +
1576 "', got value of type '" +
1577 cast<ListRecTy>(ItemType)
1584 if (InitList.
size() == 2 && !isa<IntRecTy>(ArgType)) {
1585 Error(InitLoc,
Twine(
"expected second parameter to be an int, got "
1586 "value of type '") +
1593 if (!isa<ListRecTy>(ArgType)) {
1594 Error(InitLoc,
Twine(
"expected a list, got value of type '") +
1600 if (InitList.
size() == 1) {
1601 if (isa<ListRecTy>(ArgType)) {
1603 }
else if (isa<IntRecTy>(ArgType)) {
1607 Twine(
"expected list or int, got value of type '") +
1613 assert(isa<ListRecTy>(cast<TypedInit>(InitList[0])->
getType()));
1615 Twine(
"expected one list, got extra value of type '") +
1625 Error(InitLoc,
Twine(
"expected bit, bits, int, string, or record; "
1639 Error(InitLoc,
Twine(
"expected bit, bits, int, or string; "
1646 switch (InitList.
size()) {
1651 Error(InitLoc,
Twine(
"expected list of string, int, bits, or bit; "
1652 "got value of type '") +
1658 if (!isa<StringRecTy>(ArgType)) {
1659 Error(InitLoc,
Twine(
"expected second argument to be a string, "
1660 "got value of type '") +
1676 Error(InitLoc,
Twine(
"expected value of type '") +
1715 TokError(
"expected ')' in operator");
1724 Type = cast<TypedInit>(InitList.
front())->getType()->getListTy();
1731 auto ArgCount = InitList.
size();
1733 auto *Arg0 = cast<TypedInit>(InitList[0]);
1734 auto *Arg0Ty = Arg0->getType();
1735 if (ArgCount == 1) {
1736 if (isa<ListRecTy>(Arg0Ty)) {
1742 assert(isa<IntRecTy>(Arg0Ty));
1747 }
else if (ArgCount == 2) {
1748 assert(isa<IntRecTy>(Arg0Ty));
1749 auto *Arg1 = cast<TypedInit>(InitList[1]);
1750 assert(isa<IntRecTy>(Arg1->getType()));
1754 Error(OpLoc,
"expected at most two values of integer");
1766 while (InitList.
size() > 2) {
1773 if (InitList.
size() == 2)
1777 Error(OpLoc,
"expected two operands to operator");
1783 return ParseOperationForEachFilter(CurRec, ItemType);
1821 TokError(
"expected '(' after ternary operator");
1825 Init *
LHS = ParseValue(CurRec);
1826 if (!LHS)
return nullptr;
1829 TokError(
"expected ',' in ternary operator");
1834 Init *MHS = ParseValue(CurRec, ItemType);
1839 TokError(
"expected ',' in ternary operator");
1844 Init *
RHS = ParseValue(CurRec, ItemType);
1849 TokError(
"expected ')' in binary operator");
1856 TypedInit *MHSt = dyn_cast<TypedInit>(MHS);
1857 if (!MHSt && !isa<UnsetInit>(MHS)) {
1858 Error(MHSLoc,
"could not determine type of the child list in !dag");
1861 if (MHSt && !isa<ListRecTy>(MHSt->
getType())) {
1862 Error(MHSLoc,
Twine(
"expected list of children, got type '") +
1867 TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
1868 if (!RHSt && !isa<UnsetInit>(RHS)) {
1869 Error(RHSLoc,
"could not determine type of the name list in !dag");
1873 Error(RHSLoc,
Twine(
"expected list<string>, got type '") +
1878 if (!MHSt && !RHSt) {
1880 "cannot have both unset children and unset names in !dag");
1886 RecTy *MHSTy =
nullptr;
1887 RecTy *RHSTy =
nullptr;
1889 if (
TypedInit *MHSt = dyn_cast<TypedInit>(MHS))
1891 if (
BitsInit *MHSbits = dyn_cast<BitsInit>(MHS))
1893 if (isa<BitInit>(MHS))
1896 if (
TypedInit *RHSt = dyn_cast<TypedInit>(RHS))
1898 if (
BitsInit *RHSbits = dyn_cast<BitsInit>(RHS))
1900 if (isa<BitInit>(RHS))
1904 if (isa<UnsetInit>(MHS))
1906 if (isa<UnsetInit>(RHS))
1909 if (!MHSTy || !RHSTy) {
1910 TokError(
"could not get type for !if");
1923 TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
1925 TokError(
"could not get type for !subst");
1932 TypedInit *MHSt = dyn_cast<TypedInit>(MHS);
1933 if (!MHSt || !isa<IntRecTy, StringRecTy>(MHSt->
getType())) {
1934 Error(MHSLoc,
Twine(
"expected integer index or string name, got ") +
1943 TypedInit *MHSt = dyn_cast<TypedInit>(MHS);
1944 if (!MHSt || !isa<IntRecTy, StringRecTy>(MHSt->
getType())) {
1945 Error(MHSLoc,
Twine(
"expected integer index or string name, got ") +
1951 TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
1953 if (RHSt && !isa<StringRecTy>(RHSt->
getType())) {
1954 Error(RHSLoc,
Twine(
"expected string or unset name, got type '") +
1965 return ParseOperationSubstr(CurRec, ItemType);
1968 return ParseOperationFind(CurRec, ItemType);
1971 return ParseOperationCond(CurRec, ItemType);
1977 TokError(
"expected '(' after !foldl");
1981 Init *StartUntyped = ParseValue(CurRec);
1985 TypedInit *Start = dyn_cast<TypedInit>(StartUntyped);
1993 TokError(
"expected ',' in !foldl");
1997 Init *ListUntyped = ParseValue(CurRec);
2010 TokError(
Twine(
"!foldl list must be a list, but is of type '") +
2011 List->getType()->getAsString());
2016 TokError(
"expected ',' in !foldl");
2021 TokError(
"third argument of !foldl must be an identifier");
2028 "' already defined")
2034 TokError(
"expected ',' in !foldl");
2039 TokError(
"fourth argument of !foldl must be an identifier");
2046 "' already defined")
2052 TokError(
"expected ',' in !foldl");
2059 std::unique_ptr<Record> ParseRecTmp;
2060 Record *ParseRec = CurRec;
2062 ParseRecTmp = std::make_unique<Record>(
".parse",
ArrayRef<SMLoc>{}, Records);
2063 ParseRec = ParseRecTmp.get();
2070 Init *ExprUntyped = ParseValue(ParseRec);
2071 ParseRec->removeValue(
A);
2072 ParseRec->removeValue(
B);
2077 TypedInit *Expr = dyn_cast<TypedInit>(ExprUntyped);
2079 TokError(
"could not get type of !foldl expression");
2083 if (Expr->
getType() != Start->getType()) {
2084 TokError(
Twine(
"!foldl expression must be of same type as start (") +
2085 Start->getType()->getAsString() +
"), but is of type " +
2091 TokError(
"expected ')' in fold operator");
2106RecTy *TGParser::ParseOperatorType() {
2110 TokError(
"expected type name for operator");
2115 TokError(
"the 'code' type is not allowed in bang operators; use 'string'");
2120 TokError(
"expected type name for operator");
2125 TokError(
"expected type name for operator");
2135Init *TGParser::ParseOperationSubstr(
Record *CurRec,
RecTy *ItemType) {
2142 TokError(
"expected '(' after !substr operator");
2146 Init *
LHS = ParseValue(CurRec);
2151 TokError(
"expected ',' in !substr operator");
2156 Init *MHS = ParseValue(CurRec);
2164 RHS = ParseValue(CurRec);
2172 TokError(
"expected ')' in !substr operator");
2176 if (ItemType && !
Type->typeIsConvertibleTo(ItemType)) {
2177 Error(RHSLoc,
Twine(
"expected value of type '") +
2179 Type->getAsString() +
"'");
2182 TypedInit *LHSt = dyn_cast<TypedInit>(LHS);
2183 if (!LHSt && !isa<UnsetInit>(LHS)) {
2184 TokError(
"could not determine type of the string in !substr");
2187 if (LHSt && !isa<StringRecTy>(LHSt->
getType())) {
2193 TypedInit *MHSt = dyn_cast<TypedInit>(MHS);
2194 if (!MHSt && !isa<UnsetInit>(MHS)) {
2195 TokError(
"could not determine type of the start position in !substr");
2198 if (MHSt && !isa<IntRecTy>(MHSt->
getType())) {
2199 Error(MHSLoc,
Twine(
"expected int, got type '") +
2205 TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
2206 if (!RHSt && !isa<UnsetInit>(RHS)) {
2207 TokError(
"could not determine type of the length in !substr");
2210 if (RHSt && !isa<IntRecTy>(RHSt->
getType())) {
2230 TokError(
"expected '(' after !find operator");
2234 Init *
LHS = ParseValue(CurRec);
2239 TokError(
"expected ',' in !find operator");
2244 Init *MHS = ParseValue(CurRec);
2252 RHS = ParseValue(CurRec);
2260 TokError(
"expected ')' in !find operator");
2264 if (ItemType && !
Type->typeIsConvertibleTo(ItemType)) {
2265 Error(RHSLoc,
Twine(
"expected value of type '") +
2267 Type->getAsString() +
"'");
2270 TypedInit *LHSt = dyn_cast<TypedInit>(LHS);
2271 if (!LHSt && !isa<UnsetInit>(LHS)) {
2272 TokError(
"could not determine type of the source string in !find");
2275 if (LHSt && !isa<StringRecTy>(LHSt->
getType())) {
2281 TypedInit *MHSt = dyn_cast<TypedInit>(MHS);
2282 if (!MHSt && !isa<UnsetInit>(MHS)) {
2283 TokError(
"could not determine type of the target string in !find");
2286 if (MHSt && !isa<StringRecTy>(MHSt->
getType())) {
2287 Error(MHSLoc,
Twine(
"expected string, got type '") +
2293 TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
2294 if (!RHSt && !isa<UnsetInit>(RHS)) {
2295 TokError(
"could not determine type of the start position in !find");
2298 if (RHSt && !isa<IntRecTy>(RHSt->
getType())) {
2312Init *TGParser::ParseOperationForEachFilter(
Record *CurRec,
RecTy *ItemType) {
2317 TokError(
"expected '(' after !foreach/!filter");
2322 TokError(
"first argument of !foreach/!filter must be an identifier");
2329 if (CurRec && CurRec->
getValue(LHS)) {
2331 "' is already defined")
2337 TokError(
"expected ',' in !foreach/!filter");
2341 Init *MHS = ParseValue(CurRec);
2346 TokError(
"expected ',' in !foreach/!filter");
2350 TypedInit *MHSt = dyn_cast<TypedInit>(MHS);
2352 TokError(
"could not get type of !foreach/!filter list or dag");
2356 RecTy *InEltType =
nullptr;
2357 RecTy *ExprEltType =
nullptr;
2361 InEltType = InListTy->getElementType();
2363 if (
ListRecTy *OutListTy = dyn_cast<ListRecTy>(ItemType)) {
2365 ? OutListTy->getElementType()
2369 "expected value of type '" +
2371 "', but got list type");
2377 TokError(
"!filter must have a list argument");
2380 InEltType = InDagTy;
2381 if (ItemType && !isa<DagRecTy>(ItemType)) {
2384 "', but got dag type");
2390 TokError(
"!foreach must have a list or dag argument");
2392 TokError(
"!filter must have a list argument");
2398 std::unique_ptr<Record> ParseRecTmp;
2399 Record *ParseRec = CurRec;
2403 ParseRec = ParseRecTmp.get();
2407 Init *
RHS = ParseValue(ParseRec, ExprEltType);
2408 ParseRec->removeValue(LHS);
2414 TokError(
"expected ')' in !foreach/!filter");
2418 RecTy *OutType = InEltType;
2420 TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
2422 TokError(
"could not get type of !foreach result expression");
2432 LHS, MHS, RHS, OutType))
2440 TokError(
"expected '(' after !cond operator");
2451 Init *
V = ParseValue(CurRec);
2457 TokError(
"expected ':' following a condition in !cond operator");
2461 V = ParseValue(CurRec, ItemType);
2470 TokError(
"expected ',' or ')' following a value in !cond operator");
2475 if (Case.
size() < 1) {
2476 TokError(
"there should be at least 1 'condition : value' in the !cond operator");
2482 for (
Init *V : Val) {
2483 RecTy *VTy =
nullptr;
2484 if (
TypedInit *Vt = dyn_cast<TypedInit>(V))
2485 VTy = Vt->getType();
2486 if (
BitsInit *Vbits = dyn_cast<BitsInit>(V))
2488 if (isa<BitInit>(V))
2491 if (
Type ==
nullptr) {
2492 if (!isa<UnsetInit>(V))
2495 if (!isa<UnsetInit>(V)) {
2508 TokError(
"could not determine type for !cond from its arguments");
2547 return ParseOperation(CurRec, ItemType);
2550 default:
TokError(
"Unknown or reserved token when parsing a value");
break;
2567 for (
unsigned i = 0, e = BinaryVal.second; i != e; ++i)
2601 return ParseIDValue(CurRec,
Name, NameLoc, Mode);
2609 "Expected a class name, got '" +
Name->getValue() +
"'");
2615 if (ParseTemplateArgValueList(Args, CurRec, Class))
2618 if (CheckTemplateArgValues(Args, NameLoc.
Start, Class))
2621 if (resolveArguments(Class, Args, NameLoc.
Start))
2624 if (TrackReferenceLocs)
2625 Class->appendReferenceLoc(NameLoc);
2634 ParseValueList(Vals, CurRec);
2635 if (Vals.
empty())
return nullptr;
2638 TokError(
"expected '}' at end of bit list value");
2647 for (
unsigned i = 0, e = Vals.
size(); i != e; ++i) {
2652 if (
BitsInit *BI = dyn_cast<BitsInit>(Vals[i])) {
2653 for (
unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
2658 if (
VarInit *VI = dyn_cast<VarInit>(Vals[i])) {
2659 if (
BitsRecTy *BitsRec = dyn_cast<BitsRecTy>(
VI->getType())) {
2660 for (
unsigned i = 0, e = BitsRec->getNumBits(); i != e; ++i)
2669 Error(BraceLoc,
"Element #" +
Twine(i) +
" (" + Vals[i]->getAsString() +
2670 ") is not convertable to a bit");
2675 std::reverse(NewBits.
begin(), NewBits.
end());
2682 RecTy *DeducedEltTy =
nullptr;
2686 ListRecTy *ListType = dyn_cast<ListRecTy>(ItemType);
2692 GivenListTy = ListType;
2696 ParseValueList(Vals, CurRec,
2698 if (Vals.
empty())
return nullptr;
2701 TokError(
"expected ']' at end of list value");
2705 RecTy *GivenEltTy =
nullptr;
2708 GivenEltTy = ParseType();
2715 TokError(
"expected '>' at end of list element type");
2721 RecTy *EltTy =
nullptr;
2722 for (
Init *V : Vals) {
2723 TypedInit *TArg = dyn_cast<TypedInit>(V);
2728 TokError(
"Incompatible types in list elements");
2741 TokError(
"Incompatible types in list elements");
2758 TokError(
Twine(
"Element type mismatch for list: element type '") +
2764 DeducedEltTy = EltTy;
2773 TokError(
"expected identifier in dag init");
2784 TokError(
"expected variable name in dag operator");
2793 ParseDagArgList(DagArgs, CurRec);
2794 if (DagArgs.
empty())
return nullptr;
2798 TokError(
"expected ')' in dag init");
2816Init *TGParser::ParseValue(
Record *CurRec,
RecTy *ItemType, IDParseMode Mode) {
2818 Init *
Result = ParseSimpleValue(CurRec, ItemType, Mode);
2819 if (!Result)
return nullptr;
2826 if (Mode == ParseNameMode)
2833 ParseRangeList(Ranges);
2834 if (
Ranges.empty())
return nullptr;
2840 Error(CurlyLoc,
"Invalid bit range for value");
2846 TokError(
"expected '}' at end of bit range list");
2852 auto *
LHS = dyn_cast<TypedInit>(Result);
2854 Error(LHSLoc,
"Invalid value, list expected");
2858 auto *LHSTy = dyn_cast<ListRecTy>(
LHS->
getType());
2861 "' is invalid, list expected");
2875 LHSTy->getElementType())
2883 TokError(
"expected ']' at end of list slice");
2890 TokError(
"expected field identifier after '.'");
2895 if (!
Result->getFieldType(FieldName)) {
2897 Result->getAsString() +
"'");
2902 if (TrackReferenceLocs) {
2903 if (
auto *DI = dyn_cast<DefInit>(Result)) {
2904 DI->getDef()->getValue(FieldName)->addReferenceLoc(FieldNameLoc);
2905 }
else if (
auto *TI = dyn_cast<TypedInit>(Result)) {
2906 if (
auto *
RecTy = dyn_cast<RecordRecTy>(TI->getType())) {
2908 if (
auto *RV =
R->getValue(FieldName))
2923 Error(PasteLoc,
"LHS of paste is not typed!");
2931 assert(Mode == ParseValueMode &&
"encountered paste of lists in name");
2940 Init *RHSResult = ParseValue(CurRec, ItemType, ParseValueMode);
2952 auto CastLHS = dyn_cast<TypedInit>(
2957 Twine(
"can't cast '") +
LHS->getAsString() +
"' to string");
2979 Init *RHSResult = ParseValue(CurRec,
nullptr, ParseNameMode);
2982 RHS = dyn_cast<TypedInit>(RHSResult);
2984 Error(PasteLoc,
"RHS of paste is not typed!");
2989 auto CastRHS = dyn_cast<TypedInit>(
2994 Twine(
"can't cast '") +
RHS->getAsString() +
"' to string");
3015void TGParser::ParseDagArgList(
3028 Init *Val = ParseValue(CurRec);
3038 TokError(
"expected variable name in dag literal");
3046 Result.push_back(std::make_pair(Val, VarName));
3062 Result.push_back(ParseValue(CurRec, ItemType));
3072 Result.push_back(ParseValue(CurRec, ItemType));
3088bool TGParser::ParseTemplateArgValueList(
3091 assert(
Result.empty() &&
"Result vector is not empty");
3097 bool HasNamedArg =
false;
3098 unsigned ArgIndex = 0;
3100 if (ArgIndex >= TArgs.
size()) {
3101 TokError(
"Too many template arguments: " + utostr(ArgIndex + 1));
3110 HasNamedArg ?
nullptr : ArgsRec->
getValue(TArgs[ArgIndex])->
getType());
3116 if (!isa<StringInit>(
Value))
3117 return Error(ValueLoc,
3118 "The name of named argument should be a valid identifier");
3125 return Error(ValueLoc,
3126 "Argument " +
Name->getAsString() +
" doesn't exist");
3130 Value = ParseValue(CurRec, NamedArg->getType());
3132 if (isa<UnsetInit>(
Value))
3133 return Error(ValueLoc,
3134 "The value of named argument should be initialized, "
3136 Value->getAsString() +
"'");
3143 return Error(ValueLoc,
3144 "Positional argument should be put before named argument");
3152 return TokError(
"Expected comma before next argument");
3167Init *TGParser::ParseDeclaration(
Record *CurRec,
3168 bool ParsingTemplateArgs) {
3173 if (!
Type)
return nullptr;
3176 TokError(
"Expected identifier in declaration");
3181 if (Str ==
"NAME") {
3182 TokError(
"'" + Str +
"' is a reserved variable name");
3186 if (!ParsingTemplateArgs && CurScope->varAlreadyDefined(Str)) {
3187 TokError(
"local variable of this name already exists");
3196 if (!ParsingTemplateArgs) {
3197 BadField = AddValue(CurRec, IdLoc,
3202 }
else if (CurRec) {
3203 DeclName =
QualifyName(*CurRec, CurMultiClass, DeclName,
":");
3204 BadField = AddValue(CurRec, IdLoc,
RecordVal(DeclName, IdLoc,
Type,
3208 assert(CurMultiClass &&
"invalid context for template argument");
3209 DeclName =
QualifyName(CurMultiClass->
Rec, CurMultiClass, DeclName,
"::");
3210 BadField = AddValue(CurRec, IdLoc,
RecordVal(DeclName, IdLoc,
Type,
3219 Init *Val = ParseValue(CurRec,
Type);
3221 SetValue(CurRec, ValLoc, DeclName, std::nullopt, Val,
3241VarInit *TGParser::ParseForeachDeclaration(
Init *&ForeachListValue) {
3243 TokError(
"Expected identifier in foreach declaration");
3252 TokError(
"Expected '=' in foreach declaration");
3256 RecTy *IterType =
nullptr;
3262 ParseRangeList(Ranges);
3264 TokError(
"expected '}' at end of bit range list");
3272 Init *
I = ParseValue(
nullptr);
3277 if (TI && isa<ListRecTy>(TI->
getType())) {
3278 ForeachListValue =
I;
3279 IterType = cast<ListRecTy>(TI->
getType())->getElementType();
3284 if (ParseRangePiece(Ranges, TI))
3289 Error(ValueLoc,
"expected a list, got '" +
I->getAsString() +
"'");
3290 if (CurMultiClass) {
3291 PrintNote({},
"references to multiclass template arguments cannot be "
3292 "resolved at this time");
3300 assert(!IterType &&
"Type already initialized?");
3302 std::vector<Init *> Values;
3303 for (
unsigned R : Ranges)
3321bool TGParser::ParseTemplateArgList(
Record *CurRec) {
3325 Record *TheRecToAddTo = CurRec ? CurRec : &CurMultiClass->
Rec;
3328 Init *TemplArg = ParseDeclaration(CurRec,
true);
3337 TemplArg = ParseDeclaration(CurRec,
true);
3342 return Error(Loc,
"template argument with the same name has already been "
3349 return TokError(
"expected '>' at end of template argument list");
3360bool TGParser::ParseBodyItem(
Record *CurRec) {
3362 return ParseAssert(
nullptr, CurRec);
3365 return ParseDefvar(CurRec);
3368 if (!ParseDeclaration(CurRec,
false))
3372 return TokError(
"expected ';' after declaration");
3378 return TokError(
"expected field identifier after let");
3385 if (ParseOptionalBitList(BitList))
3387 std::reverse(BitList.
begin(), BitList.
end());
3390 return TokError(
"expected '=' in let expression");
3397 if (!BitList.
empty() && isa<BitsRecTy>(
Type)) {
3403 Init *Val = ParseValue(CurRec,
Type);
3404 if (!Val)
return true;
3407 return TokError(
"expected ';' after let expression");
3409 return SetValue(CurRec, IdLoc, FieldName, BitList, Val);
3419bool TGParser::ParseBody(
Record *CurRec) {
3425 return TokError(
"Expected '{' to start body or ';' for declaration only");
3428 if (ParseBodyItem(CurRec))
3437 PrintError(SemiLoc,
"A class or def body should not end with a semicolon");
3438 PrintNote(
"Semicolon ignored; remove to eliminate this error");
3446bool TGParser::ApplyLetStack(
Record *CurRec) {
3449 if (SetValue(CurRec, LR.Loc, LR.Name, LR.Bits, LR.Value))
3457 return ApplyLetStack(Entry.Rec.get());
3460 if (Entry.Assertion)
3463 for (
auto &
E : Entry.Loop->Entries) {
3464 if (ApplyLetStack(
E))
3480bool TGParser::ParseObjectBody(
Record *CurRec) {
3490 if (!SubClass.
Rec)
return true;
3493 if (AddSubClass(CurRec, SubClass))
3498 SubClass = ParseSubClassReference(CurRec,
false);
3502 if (ApplyLetStack(CurRec))
3505 bool Result = ParseBody(CurRec);
3515bool TGParser::ParseDef(
MultiClass *CurMultiClass) {
3526 std::unique_ptr<Record> CurRec;
3527 Init *
Name = ParseObjectName(CurMultiClass);
3531 if (isa<UnsetInit>(
Name)) {
3536 CurRec = std::make_unique<Record>(
Name, NameLoc, Records);
3539 if (ParseObjectBody(CurRec.get()))
3542 return addEntry(std::move(CurRec));
3549bool TGParser::ParseDefset() {
3558 if (!isa<ListRecTy>(
Type))
3560 Defset.EltTy = cast<ListRecTy>(
Type)->getElementType();
3563 return TokError(
"expected identifier");
3566 return TokError(
"def or global variable of this name already exists");
3575 Defsets.push_back(&Defset);
3576 bool Err = ParseObjectList(
nullptr);
3582 TokError(
"expected '}' at end of defset");
3583 return Error(BraceLoc,
"to match this '{'");
3595bool TGParser::ParseDefvar(
Record *CurRec) {
3600 return TokError(
"expected identifier");
3602 if (CurScope->varAlreadyDefined(DeclName->
getValue()))
3603 return TokError(
"local variable of this name already exists");
3608 if (V && !
V->isTemplateArg())
3609 return TokError(
"field of this name already exists");
3615 return TokError(
"def or global variable of this name already exists");
3628 if (!CurScope->isOutermost())
3642bool TGParser::ParseForeach(
MultiClass *CurMultiClass) {
3649 Init *ListValue =
nullptr;
3650 VarInit *IterName = ParseForeachDeclaration(ListValue);
3652 return TokError(
"expected declaration in for");
3658 auto TheLoop = std::make_unique<ForeachLoop>(Loc, IterName, ListValue);
3661 Loops.push_back(std::move(TheLoop));
3665 if (ParseObject(CurMultiClass))
3673 if (ParseObjectList(CurMultiClass))
3677 TokError(
"expected '}' at end of foreach command");
3678 return Error(BraceLoc,
"to match this '{'");
3685 std::unique_ptr<ForeachLoop>
Loop = std::move(Loops.back());
3688 return addEntry(std::move(
Loop));
3696bool TGParser::ParseIf(
MultiClass *CurMultiClass) {
3703 Init *Condition = ParseValue(
nullptr);
3723 Init *ThenClauseList =
3727 Loops.push_back(std::make_unique<ForeachLoop>(Loc,
nullptr, ThenClauseList));
3729 if (ParseIfBody(CurMultiClass,
"then"))
3732 std::unique_ptr<ForeachLoop>
Loop = std::move(Loops.back());
3735 if (addEntry(std::move(
Loop)))
3745 Init *ElseClauseList =
3750 std::make_unique<ForeachLoop>(Loc,
nullptr, ElseClauseList));
3752 if (ParseIfBody(CurMultiClass,
"else"))
3755 Loop = std::move(Loops.back());
3758 if (addEntry(std::move(
Loop)))
3776 if (ParseObject(CurMultiClass))
3784 if (ParseObjectList(CurMultiClass))
3788 TokError(
"expected '}' at end of '" + Kind +
"' clause");
3789 return Error(BraceLoc,
"to match this '{'");
3805 Init *Condition = ParseValue(CurRec);
3810 TokError(
"expected ',' in assert statement");
3814 Init *Message = ParseValue(CurRec);
3822 CurRec->
addAssertion(ConditionLoc, Condition, Message);
3824 addEntry(std::make_unique<Record::AssertionInfo>(ConditionLoc, Condition,
3833bool TGParser::ParseClass() {
3838 return TokError(
"expected class name after 'class' keyword");
3847 "' already defined");
3855 CurRec = NewRec.get();
3856 Records.
addClass(std::move(NewRec));
3864 if (ParseTemplateArgList(CurRec))
3867 if (ParseObjectBody(CurRec))
3870 if (!NoWarnOnUnusedTemplateArgs)
3886 TokError(
"expected identifier in let definition");
3897 if (ParseOptionalRangeList(Bits)) {
3901 std::reverse(
Bits.begin(),
Bits.end());
3904 TokError(
"expected '=' in let expression");
3909 Init *Val = ParseValue(
nullptr);
3916 Result.emplace_back(
Name, Bits, Val, NameLoc);
3926bool TGParser::ParseTopLevelLet(
MultiClass *CurMultiClass) {
3932 ParseLetList(LetInfo);
3933 if (LetInfo.
empty())
return true;
3937 return TokError(
"expected 'in' at end of top-level 'let'");
3942 if (ParseObject(CurMultiClass))
3953 if (ParseObjectList(CurMultiClass))
3957 TokError(
"expected '}' at end of top level let command");
3958 return Error(BraceLoc,
"to match this '{'");
3982bool TGParser::ParseMultiClass() {
3987 return TokError(
"expected identifier after multiclass for name");
3991 MultiClasses.insert(std::make_pair(
Name,
3992 std::make_unique<MultiClass>(
Name, Lex.
getLoc(),Records)));
3995 return TokError(
"multiclass '" +
Name +
"' already defined");
3997 CurMultiClass =
Result.first->second.get();
4005 if (ParseTemplateArgList(
nullptr))
4008 bool inherits =
false;
4016 ParseSubMultiClassReference(CurMultiClass);
4019 if (!SubMultiClass.
MC)
return true;
4022 if (AddSubMultiClass(CurMultiClass, SubMultiClass))
4027 SubMultiClass = ParseSubMultiClassReference(CurMultiClass);
4033 return TokError(
"expected '{' in multiclass definition");
4035 return TokError(
"expected ';' in multiclass definition");
4038 return TokError(
"multiclass must contain at least one def");
4043 return TokError(
"expected 'assert', 'def', 'defm', 'defvar', "
4044 "'foreach', 'if', or 'let' in multiclass body");
4053 if (ParseObject(CurMultiClass))
4063 PrintError(SemiLoc,
"A multiclass body should not end with a semicolon");
4064 PrintNote(
"Semicolon ignored; remove to eliminate this error");
4068 if (!NoWarnOnUnusedTemplateArgs)
4072 CurMultiClass =
nullptr;
4080bool TGParser::ParseDefm(
MultiClass *CurMultiClass) {
4084 Init *DefmName = ParseObjectName(CurMultiClass);
4087 if (isa<UnsetInit>(DefmName)) {
4097 return TokError(
"expected ':' after defm identifier");
4100 std::vector<RecordsEntry> NewEntries;
4103 bool InheritFromClass =
false;
4112 if (!
Ref.Rec)
return true;
4118 MultiClass *MC = MultiClasses[std::string(
Ref.Rec->getName())].get();
4119 assert(MC &&
"Didn't lookup multiclass correctly?");
4122 if (resolveArgumentsOfMultiClass(Substs, MC,
Ref.TemplateArgs, DefmName,
4126 if (resolve(MC->
Entries, Substs, !CurMultiClass && Loops.empty(),
4127 &NewEntries, &SubClassLoc))
4134 return TokError(
"expected identifier");
4136 SubClassLoc = Lex.
getLoc();
4142 if (InheritFromClass)
4145 Ref = ParseSubClassReference(
nullptr,
true);
4148 if (InheritFromClass) {
4154 if (!SubClass.
Rec)
return true;
4158 for (
auto &
E : NewEntries) {
4160 if (AddSubClass(
E, SubClass))
4166 SubClass = ParseSubClassReference(
nullptr,
false);
4170 for (
auto &
E : NewEntries) {
4171 if (ApplyLetStack(
E))
4174 addEntry(std::move(
E));
4178 return TokError(
"expected ';' at end of defm");
4197 "Expected assert, class, def, defm, defset, foreach, if, or let");
4204 case tgtok::Let:
return ParseTopLevelLet(MC);
4207 return TokError(
"defset is not allowed inside multiclass");
4208 return ParseDefset();
4211 return TokError(
"class is not allowed inside multiclass");
4213 return TokError(
"class is not allowed inside foreach loop");
4214 return ParseClass();
4217 return TokError(
"multiclass is not allowed inside foreach loop");
4218 return ParseMultiClass();
4224bool TGParser::ParseObjectList(
MultiClass *MC) {
4226 if (ParseObject(MC))
4235 if (ParseObjectList())
4243 return TokError(
"Unexpected token at top level");
4250bool TGParser::CheckTemplateArgValues(
4254 for (
unsigned I = 0,
E = Values.
size();
I <
E; ++
I) {
4256 Init *ArgName =
nullptr;
4257 if (
Value->isPositional())
4258 ArgName = TArgs[
Value->getIndex()];
4259 if (
Value->isNamed())
4265 if (
TypedInit *ArgValue = dyn_cast<TypedInit>(
Value->getValue())) {
4266 auto *CastValue = ArgValue->
getCastTo(ArgType);
4268 assert((!isa<TypedInit>(CastValue) ||
4269 cast<TypedInit>(CastValue)->
getType()->typeIsA(ArgType)) &&
4270 "result of template arg value cast has wrong type");
4271 Values[
I] =
Value->cloneWithValue(CastValue);
4285#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4304 errs() <<
"Record:\n";
4307 errs() <<
"Defs:\n";
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.
This file defines DenseMapInfo traits for DenseMap.
PowerPC Reduce CR logical Operation
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
static Init * QualifyName(Record &CurRec, MultiClass *CurMultiClass, Init *Name, StringRef Scoper)
Return an Init with a qualifier prefix referring to CurRec's name.
static Init * QualifiedNameOfImplicitName(Record &Rec, MultiClass *MC=nullptr)
Return the qualified version of the implicit 'NAME' template argument.
static bool checkBitsConcrete(Record &R, const RecordVal &RV)
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 checkUnusedTemplateArgs()
std::string getNameInitAsString() const
Init * getNameInit() const
RecordKeeper & getRecords() const
const RecordVal * getValue(const Init *Name) const
void addValue(const RecordVal &RV)
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.