57 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
59 errs() <<
"Multiclass:\n";
63 errs() <<
"Template args:\n";
73 CurRec = &CurMultiClass->
Rec;
78 return Error(Loc,
"New definition of '" + RV.
getName() +
"' of type '" +
80 "previous definition of type '" +
81 ERV->getType()->getAsString() +
"'");
92 bool AllowSelfAssignment) {
95 if (!CurRec) CurRec = &CurMultiClass->
Rec;
106 if (
VI->getNameInit() == ValName && !AllowSelfAssignment)
113 if (!BitList.
empty()) {
117 "' is not a bits type");
122 return Error(Loc,
"Initializer is not compatible with bit range");
125 BitsInit *BInit = cast<BitsInit>(BI);
130 for (
unsigned i = 0, e = BitList.
size(); i != e; ++i) {
131 unsigned Bit = BitList[i];
133 return Error(Loc,
"Cannot set bit #" +
Twine(Bit) +
" of value '" +
138 for (
unsigned i = 0, e = CurVal->
getNumBits(); i != e; ++i)
140 NewBits[i] = CurVal->
getBit(i);
146 std::string InitType;
147 if (
BitsInit *BI = dyn_cast<BitsInit>(V))
148 InitType = (
Twine(
"' of type bit initializer with length ") +
149 Twine(BI->getNumBits())).str();
152 "' is incompatible with initializer '" + V->
getAsString() +
172 "More template args specified than expected");
176 for (
unsigned i = 0, e = TArgs.
size(); i != e; ++i) {
191 "Value not specified for template argument #" +
192 Twine(i) +
" (" + TArgs[i]->getAsUnquotedString() +
200 for (
const auto &SCPair : SCs) {
203 "Already subclass of '" + SCPair.first->getName() +
"'!\n");
209 "Already subclass of '" + SC->
getName() +
"'!\n");
217 bool TGParser::AddSubMultiClass(
MultiClass *CurMC,
230 for (
const std::unique_ptr<Record> &R : SMC->
DefPrototypes) {
232 auto NewDef = make_unique<Record>(*R);
235 for (
const auto &MCVal : CurRec->
getValues())
236 if (AddValue(NewDef.get(), SubMultiClass.
RefRange.
Start, MCVal))
248 "More template args specified than expected");
252 for (
unsigned i = 0, e = SMCTArgs.
size(); i != e; ++i) {
256 if (SetValue(CurRec, SubMultiClass.
RefRange.
Start, SMCTArgs[i],
268 for (
const auto &
Def :
275 Def->resolveReferencesTo(
Def->getValue(SMCTArgs[i]));
278 Def->removeValue(SMCTArgs[i]);
282 "Value not specified for template argument #" +
283 Twine(i) +
" (" + SMCTArgs[i]->getAsUnquotedString() +
294 bool TGParser::ProcessForeachDefs(
Record *CurRec,
SMLoc Loc) {
302 return ProcessForeachDefs(CurRec, Loc, IterVals);
308 bool TGParser::ProcessForeachDefs(
Record *CurRec,
SMLoc Loc, IterSet &IterVals){
310 if (IterVals.size() != Loops.size()) {
311 assert(IterVals.size() < Loops.size());
315 Error(Loc,
"Loop list is not a list");
320 for (
unsigned i = 0; i < List->
size(); ++i) {
322 IterVals.push_back(IterRecord(CurLoop.IterVar, ItemVal));
323 if (ProcessForeachDefs(CurRec, Loc, IterVals))
333 auto IterRec = make_unique<Record>(*CurRec);
336 for (IterRecord &
IR : IterVals) {
340 return Error(Loc,
"foreach iterator value is untyped");
345 return Error(Loc,
"when instantiating this def");
348 IterRec->resolveReferencesTo(IterRec->getValue(IterVar->
getNameInit()));
354 if (Records.
getDef(IterRec->getNameInitAsString())) {
356 if (!IterRec->isAnonymous())
357 return Error(Loc,
"def already exists: " +IterRec->getNameInitAsString());
359 IterRec->setName(GetNewAnonymousName());
362 Record *IterRecSave = IterRec.get();
363 Records.
addDef(std::move(IterRec));
381 Init *TGParser::GetNewAnonymousName() {
405 CurRec = &CurMultiClass->
Rec;
411 TokError(
"Record name is not typed!");
417 return ParseValue(CurRec, Type, ParseNameMode);
425 Record *TGParser::ParseClassID() {
427 TokError(
"expected name for ClassID");
446 TokError(
"expected name for MultiClassID");
465 ParseSubClassReference(
Record *CurRec,
bool isDefm) {
471 Result.
Rec = &MC->Rec;
473 Result.
Rec = ParseClassID();
475 if (!Result.
Rec)
return Result;
485 TokError(
"subclass reference requires a non-empty list of template values");
486 Result.
Rec =
nullptr;
492 Result.
Rec =
nullptr;
497 TokError(
"expected '>' in template value list");
498 Result.
Rec =
nullptr;
515 ParseSubMultiClassReference(
MultiClass *CurMC) {
519 Result.
MC = ParseMultiClassID();
520 if (!Result.
MC)
return Result;
530 TokError(
"subclass reference requires a non-empty list of template values");
542 TokError(
"expected '>' in template value list");
558 TokError(
"expected integer or bitrange");
565 return TokError(
"invalid range, cannot be negative");
573 TokError(
"expected integer value as end of range");
583 return TokError(
"invalid range, cannot be negative");
588 for (; Start <=
End; ++Start)
591 for (; Start >=
End; --Start)
602 if (ParseRangePiece(Result)) {
610 if (ParseRangePiece(Result)) {
628 ParseRangeList(Ranges);
629 if (Ranges.
empty())
return true;
632 TokError(
"expected '>' at end of range list");
633 return Error(StartLoc,
"to match this '<'");
650 ParseRangeList(Ranges);
651 if (Ranges.
empty())
return true;
654 TokError(
"expected '}' at end of bit list");
655 return Error(StartLoc,
"to match this '{'");
672 RecTy *TGParser::ParseType() {
674 default:
TokError(
"Unknown token when expecting a type");
return nullptr;
685 TokError(
"expected '<' after bits type");
689 TokError(
"expected integer in bits<n> type");
694 TokError(
"expected '>' at end of bits<n> type");
702 TokError(
"expected '<' after list type");
706 RecTy *SubType = ParseType();
707 if (!SubType)
return nullptr;
710 TokError(
"expected '>' at end of list<ty> type");
727 Init *TemplateArgName =
QualifyName(*CurRec, CurMultiClass, Name,
":");
730 TemplateArgName =
QualifyName(CurMultiClass->
Rec, CurMultiClass, Name,
735 assert(RV &&
"Template arg doesn't exist??");
745 assert(RV &&
"Template arg doesn't exist??");
751 for (
const auto &
L : Loops) {
757 if (Mode == ParseNameMode)
763 if (Mode == ParseValueMode) {
764 Error(NameLoc,
"Variable not defined: '" + Name->
getValue() +
"'");
785 RecTy *Type =
nullptr;
793 Type = ParseOperatorType();
796 TokError(
"did not get type for unary operator");
816 TokError(
"expected '(' after unary operator");
821 Init *LHS = ParseValue(CurRec);
822 if (!LHS)
return nullptr;
830 if (!LHSl && !LHSs && !LHSt) {
831 TokError(
"expected list or string type argument in unary operator");
837 if (!LType && !SType) {
838 TokError(
"expected list or string type argument in unary operator");
844 if (!LHSl && !LHSt) {
845 TokError(
"expected list type argument in unary operator");
849 if (LHSl && LHSl->
empty()) {
850 TokError(
"empty list argument in unary operator");
857 TokError(
"untyped list element in unary operator");
863 assert(LHSt &&
"expected list type argument in unary operator");
866 TokError(
"expected list type argument in unary operator");
875 TokError(
"expected ')' in unary operator");
879 return (
UnOpInit::get(Code, LHS, Type))->Fold(CurRec, CurMultiClass);
897 RecTy *Type =
nullptr;
920 TokError(
"expected '(' after binary operator");
928 if (!InitList.
back())
return nullptr;
934 if (!InitList.
back())
return nullptr;
938 TokError(
"expected ')' in operator");
945 if (
VarInit *Arg0 = dyn_cast<VarInit>(InitList[0]))
946 Type = Arg0->getType();
947 else if (
ListInit *Arg0 = dyn_cast<ListInit>(InitList[0]))
948 Type = Arg0->getType();
950 InitList[0]->print(
errs());
951 Error(OpLoc,
"expected a list");
959 while (InitList.
size() > 2) {
962 ->Fold(CurRec, CurMultiClass);
963 InitList.
back() = RHS;
967 if (InitList.
size() == 2)
969 ->Fold(CurRec, CurMultiClass);
971 Error(OpLoc,
"expected two operands to operator");
979 RecTy *Type =
nullptr;
996 TokError(
"expected '(' after ternary operator");
1001 Init *LHS = ParseValue(CurRec);
1002 if (!LHS)
return nullptr;
1005 TokError(
"expected ',' in ternary operator");
1010 Init *MHS = ParseValue(CurRec, ItemType);
1015 TokError(
"expected ',' in ternary operator");
1020 Init *RHS = ParseValue(CurRec, ItemType);
1025 TokError(
"expected ')' in binary operator");
1033 RecTy *MHSTy =
nullptr;
1034 RecTy *RHSTy =
nullptr;
1036 if (
TypedInit *MHSt = dyn_cast<TypedInit>(MHS))
1037 MHSTy = MHSt->getType();
1038 if (
BitsInit *MHSbits = dyn_cast<BitsInit>(MHS))
1040 if (isa<BitInit>(MHS))
1043 if (
TypedInit *RHSt = dyn_cast<TypedInit>(RHS))
1044 RHSTy = RHSt->getType();
1045 if (
BitsInit *RHSbits = dyn_cast<BitsInit>(RHS))
1047 if (isa<BitInit>(RHS))
1051 if (isa<UnsetInit>(MHS))
1053 if (isa<UnsetInit>(RHS))
1056 if (!MHSTy || !RHSTy) {
1057 TokError(
"could not get type for !if");
1066 TokError(
"inconsistent types for !if");
1074 TokError(
"could not get type for !foreach");
1083 TokError(
"could not get type for !subst");
1101 RecTy *TGParser::ParseOperatorType() {
1102 RecTy *Type =
nullptr;
1105 TokError(
"expected type name for operator");
1113 TokError(
"expected type name for operator");
1118 TokError(
"expected type name for operator");
1149 default:
TokError(
"Unknown token when parsing a value");
break;
1154 return ParseSimpleValue(CurRec, ItemType, Mode);
1159 for (
unsigned i = 0, e = BinaryVal.second; i != e; ++i)
1190 return ParseIDValue(CurRec, Name, NameLoc, Mode);
1194 TokError(
"expected non-empty value list");
1203 Error(NameLoc,
"Expected a class name, got '" + Name->
getValue() +
"'");
1212 TokError(
"expected '>' at end of value list");
1219 auto NewRecOwner = llvm::make_unique<Record>(GetNewAnonymousName(), NameLoc,
1221 Record *NewRec = NewRecOwner.get();
1225 if (AddSubClass(NewRec, SCRef))
1228 if (!CurMultiClass) {
1230 Records.addDef(std::move(NewRecOwner));
1234 NewRec->setResolveFirst(
true);
1236 CurMultiClass->
DefPrototypes.push_back(std::move(NewRecOwner));
1241 assert(RV &&
"Template arg doesn't exist?");
1242 NewRec->addValue(*RV);
1248 assert(MCNameRV &&
"multiclass record must have a NAME");
1268 ParseValueList(Vals, CurRec);
1269 if (Vals.
empty())
return nullptr;
1272 TokError(
"expected '}' at end of bit list value");
1282 for (
unsigned i = 0, e = Vals.
size(); i != e; ++i) {
1287 if (
BitsInit *BI = dyn_cast<BitsInit>(Vals[i])) {
1288 for (
unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
1289 NewBits.
push_back(BI->getBit((e - i) - 1));
1293 if (
VarInit *
VI = dyn_cast<VarInit>(Vals[i])) {
1294 if (
BitsRecTy *BitsRec = dyn_cast<BitsRecTy>(
VI->getType())) {
1295 for (
unsigned i = 0, e = BitsRec->getNumBits(); i != e; ++i)
1304 Error(BraceLoc,
"Element #" +
Twine(i) +
" (" + Vals[i]->getAsString() +
1305 ") is not convertable to a bit");
1317 RecTy *DeducedEltTy =
nullptr;
1323 TokError(
Twine(
"Type mismatch for list, expected list type, got ") +
1327 GivenListTy = ListType;
1331 ParseValueList(Vals, CurRec,
nullptr,
1333 if (Vals.
empty())
return nullptr;
1336 TokError(
"expected ']' at end of list value");
1341 RecTy *GivenEltTy =
nullptr;
1346 GivenEltTy = ParseType();
1353 TokError(
"expected '>' at end of list element type");
1360 RecTy *EltTy =
nullptr;
1361 for (
Init *V : Vals) {
1370 TokError(
"Incompatible types in list elements");
1382 TokError(
"Incompatible types in list elements");
1399 TokError(
"Element type mismatch for list");
1403 DeducedEltTy = EltTy;
1411 TokError(
"expected identifier in dag init");
1416 if (!Operator)
return nullptr;
1422 TokError(
"expected variable name in dag operator");
1431 ParseDagArgList(DagArgs, CurRec);
1432 if (DagArgs.
empty())
return nullptr;
1436 TokError(
"expected ')' in dag init");
1461 return ParseOperation(CurRec, ItemType);
1475 Init *TGParser::ParseValue(
Record *CurRec,
RecTy *ItemType, IDParseMode Mode) {
1476 Init *Result = ParseSimpleValue(CurRec, ItemType, Mode);
1477 if (!Result)
return nullptr;
1482 default:
return Result;
1484 if (Mode == ParseNameMode || Mode == ParseForeachMode)
1491 ParseRangeList(Ranges);
1492 if (Ranges.
empty())
return nullptr;
1498 Error(CurlyLoc,
"Invalid bit range for value");
1504 TokError(
"expected '}' at end of bit range list");
1514 ParseRangeList(Ranges);
1515 if (Ranges.
empty())
return nullptr;
1517 Result = Result->convertInitListSlice(Ranges);
1519 Error(SquareLoc,
"Invalid range for list slice");
1525 TokError(
"expected ']' at end of list slice");
1533 TokError(
"expected field identifier after '.'");
1537 if (!Result->getFieldType(FieldName)) {
1539 Result->getAsString() +
"'");
1555 Error(PasteLoc,
"LHS of paste is not typed!");
1579 Init *RHSResult = ParseValue(CurRec, ItemType, ParseNameMode);
1582 Error(PasteLoc,
"RHS of paste is not typed!");
1606 void TGParser::ParseDagArgList(
1619 Init *Val = ParseValue(CurRec);
1629 TokError(
"expected variable name in dag literal");
1637 Result.push_back(std::make_pair(Val, VarName));
1652 RecTy *ItemType = EltTy;
1653 unsigned int ArgN = 0;
1654 if (ArgsRec && !EltTy) {
1656 if (TArgs.
empty()) {
1657 TokError(
"template argument provided to non-template class");
1663 errs() <<
"Cannot find template arg " << ArgN <<
" (" << TArgs[ArgN]
1666 assert(RV &&
"Template argument record not found??");
1670 Result.
push_back(ParseValue(CurRec, ItemType));
1671 if (!Result.
back()) {
1679 if (ArgsRec && !EltTy) {
1681 if (ArgN >= TArgs.
size()) {
1682 TokError(
"too many template arguments");
1687 assert(RV &&
"Template argument record not found??");
1691 Result.
push_back(ParseValue(CurRec, ItemType));
1692 if (!Result.
back()) {
1709 Init *TGParser::ParseDeclaration(
Record *CurRec,
1710 bool ParsingTemplateArgs) {
1713 if (HasField) Lex.
Lex();
1715 RecTy *Type = ParseType();
1716 if (!Type)
return nullptr;
1719 TokError(
"Expected identifier in declaration");
1727 if (ParsingTemplateArgs) {
1729 DeclName =
QualifyName(*CurRec, CurMultiClass, DeclName,
":");
1733 DeclName =
QualifyName(CurMultiClass->
Rec, CurMultiClass, DeclName,
1738 if (AddValue(CurRec, IdLoc,
RecordVal(DeclName, Type, HasField)))
1745 Init *Val = ParseValue(CurRec, Type);
1747 SetValue(CurRec, ValLoc, DeclName, None, Val))
1765 VarInit *TGParser::ParseForeachDeclaration(
ListInit *&ForeachListValue) {
1767 TokError(
"Expected identifier in foreach declaration");
1776 TokError(
"Expected '=' in foreach declaration");
1781 RecTy *IterType =
nullptr;
1785 default:
TokError(
"Unknown token when expecting a range list");
return nullptr;
1787 Init *List = ParseSimpleValue(
nullptr,
nullptr, ParseForeachMode);
1789 if (!ForeachListValue) {
1796 TokError(
"Value list is not of list type");
1804 if (ParseRangePiece(Ranges))
1811 ParseRangeList(Ranges);
1813 TokError(
"expected '}' at end of bit range list");
1821 if (!Ranges.
empty()) {
1822 assert(!IterType &&
"Type already initialized?");
1824 std::vector<Init*> Values;
1825 for (
unsigned R : Ranges)
1843 bool TGParser::ParseTemplateArgList(
Record *CurRec) {
1847 Record *TheRecToAddTo = CurRec ? CurRec : &CurMultiClass->
Rec;
1850 Init *TemplArg = ParseDeclaration(CurRec,
true);
1860 TemplArg = ParseDeclaration(CurRec,
true);
1867 return TokError(
"expected '>' at end of template argument list");
1876 bool TGParser::ParseBodyItem(
Record *CurRec) {
1878 if (!ParseDeclaration(CurRec,
false))
1882 return TokError(
"expected ';' after declaration");
1889 return TokError(
"expected field identifier after let");
1896 if (ParseOptionalBitList(BitList))
1901 return TokError(
"expected '=' in let expression");
1910 Init *Val = ParseValue(CurRec, Type);
1911 if (!Val)
return true;
1914 return TokError(
"expected ';' after let expression");
1917 return SetValue(CurRec, IdLoc, FieldName, BitList, Val);
1927 bool TGParser::ParseBody(
Record *CurRec) {
1935 return TokError(
"Expected ';' or '{' to start body");
1940 if (ParseBodyItem(CurRec))
1950 bool TGParser::ApplyLetStack(
Record *CurRec) {
1953 if (SetValue(CurRec, LR.Loc, LR.Name, LR.Bits, LR.Value))
1967 bool TGParser::ParseObjectBody(
Record *CurRec) {
1976 if (!SubClass.
Rec)
return true;
1979 if (AddSubClass(CurRec, SubClass))
1984 SubClass = ParseSubClassReference(CurRec,
false);
1988 if (ApplyLetStack(CurRec))
1991 return ParseBody(CurRec);
1999 bool TGParser::ParseDef(
MultiClass *CurMultiClass) {
2005 std::unique_ptr<Record> CurRecOwner;
2006 Init *Name = ParseObjectName(CurMultiClass);
2008 CurRecOwner = make_unique<Record>(
Name, DefLoc, Records);
2010 CurRecOwner = llvm::make_unique<Record>(GetNewAnonymousName(), DefLoc,
2012 Record *CurRec = CurRecOwner.get();
2014 if (!CurMultiClass && Loops.empty()) {
2018 if (Records.getDef(CurRec->getNameInitAsString()))
2019 return Error(DefLoc,
"def '" + CurRec->getNameInitAsString()+
2020 "' already defined");
2021 Records.addDef(std::move(CurRecOwner));
2023 if (ParseObjectBody(CurRec))
2025 }
else if (CurMultiClass) {
2031 if (ParseObjectBody(CurRec))
2036 if (Proto->getNameInit() == CurRec->getNameInit())
2037 return Error(DefLoc,
"def '" + CurRec->getNameInitAsString() +
2038 "' already defined in this multiclass!");
2039 CurMultiClass->
DefPrototypes.push_back(std::move(CurRecOwner));
2040 }
else if (ParseObjectBody(CurRec)) {
2048 CurRec->resolveReferences();
2051 assert(CurRec->getTemplateArgs().empty() &&
"How'd this get template args?");
2053 if (CurMultiClass) {
2057 assert(RV &&
"Template arg doesn't exist?");
2058 CurRec->addValue(*RV);
2062 if (ProcessForeachDefs(CurRec, DefLoc))
2063 return Error(DefLoc,
"Could not process loops for def" +
2064 CurRec->getNameInitAsString());
2075 bool TGParser::ParseForeach(
MultiClass *CurMultiClass) {
2082 VarInit *IterName = ParseForeachDeclaration(ListValue);
2084 return TokError(
"expected declaration in for");
2091 Loops.push_back(
ForeachLoop(IterName, ListValue));
2095 if (ParseObject(CurMultiClass))
2103 if (ParseObjectList(CurMultiClass))
2107 TokError(
"expected '}' at end of foreach command");
2108 return Error(BraceLoc,
"to match this '{'");
2123 bool TGParser::ParseClass() {
2128 return TokError(
"expected class name after 'class' keyword");
2137 "' already defined");
2142 CurRec = NewRec.get();
2143 Records.addClass(std::move(NewRec));
2149 if (ParseTemplateArgList(CurRec))
2153 return ParseObjectBody(CurRec);
2165 TokError(
"expected identifier in let definition");
2176 if (ParseOptionalRangeList(Bits)) {
2183 TokError(
"expected '=' in let expression");
2189 Init *Val = ParseValue(
nullptr);
2210 bool TGParser::ParseTopLevelLet(
MultiClass *CurMultiClass) {
2216 ParseLetList(LetInfo);
2217 if (LetInfo.
empty())
return true;
2221 return TokError(
"expected 'in' at end of top-level 'let'");
2227 if (ParseObject(CurMultiClass))
2235 if (ParseObjectList(CurMultiClass))
2239 TokError(
"expected '}' at end of top level let command");
2240 return Error(BraceLoc,
"to match this '{'");
2260 bool TGParser::ParseMultiClass() {
2265 return TokError(
"expected identifier after multiclass for name");
2269 MultiClasses.insert(std::make_pair(Name,
2270 llvm::make_unique<MultiClass>(Name, Lex.
getLoc(),Records)));
2273 return TokError(
"multiclass '" + Name +
"' already defined");
2275 CurMultiClass = Result.first->second.get();
2280 if (ParseTemplateArgList(
nullptr))
2283 bool inherits =
false;
2293 ParseSubMultiClassReference(CurMultiClass);
2296 if (!SubMultiClass.
MC)
return true;
2299 if (AddSubMultiClass(CurMultiClass, SubMultiClass))
2304 SubMultiClass = ParseSubMultiClassReference(CurMultiClass);
2310 return TokError(
"expected '{' in multiclass definition");
2312 return TokError(
"expected ';' in multiclass definition");
2316 return TokError(
"multiclass must contain at least one def");
2321 return TokError(
"expected 'let', 'def' or 'defm' in multiclass body");
2326 if (ParseObject(CurMultiClass))
2334 CurMultiClass =
nullptr;
2351 bool IsAnonymous =
false;
2353 DefmPrefix = GetNewAnonymousName();
2360 if (DefNameString) {
2372 Locs.append(DefProto->
getLoc().begin(), DefProto->
getLoc().end());
2373 auto CurRec = make_unique<Record>(DefName, Locs, Records, IsAnonymous);
2378 AddSubClass(CurRec.get(), Ref);
2384 DefmPrefix,
true)) {
2385 Error(DefmPrefixRange.
Start,
"Could not resolve " +
2386 CurRec->getNameInitAsString() +
":NAME to '" +
2387 DefmPrefix->getAsUnquotedString() +
"'");
2394 if (!DefNameString) {
2396 CurRec->resolveReferencesTo(DefNameRV);
2399 if (!CurMultiClass) {
2403 CurRec->resolveReferencesTo(DefNameRV);
2407 DefName = CurRec->getNameInit();
2412 if (!DefNameString) {
2413 ResolveMulticlassDefArgs(MC, CurRec.get(), DefmPrefixRange.
Start,
2414 Lex.
getLoc(), TArgs, TemplateVals,
2416 DefName = CurRec->getNameInit();
2424 if (!DefNameString) {
2426 DefName->getAsUnquotedString() +
" is not a string.");
2430 CurRec->setName(DefName);
2443 if (Records.getDef(CurRec->getNameInitAsString())) {
2444 Error(DefmPrefixRange.
Start,
"def '" + CurRec->getNameInitAsString() +
2445 "' already defined, instantiating defm with subdef '" +
2450 Record *CurRecSave = CurRec.get();
2451 Records.addDef(std::move(CurRec));
2457 return CurRec.release();
2467 for (
unsigned i = 0, e = TArgs.
size(); i != e; ++i) {
2469 if (i < TemplateVals.
size()) {
2471 if (SetValue(CurRec, DefmPrefixLoc, TArgs[i], None, TemplateVals[i]))
2482 return Error(SubClassLoc,
"value not specified for template argument #" +
2483 Twine(i) +
" (" + TArgs[i]->getAsUnquotedString() +
2491 bool TGParser::ResolveMulticlassDef(
MultiClass &MC,
2494 SMLoc DefmPrefixLoc) {
2496 if (ApplyLetStack(CurRec))
2497 return Error(DefmPrefixLoc,
"when instantiating this defm");
2505 if (Proto->getNameInit() == CurRec->
getNameInit())
2507 "' already defined in this multiclass!");
2508 CurMultiClass->
DefPrototypes.push_back(std::unique_ptr<Record>(CurRec));
2513 assert(RV &&
"Template arg doesn't exist?");
2524 bool TGParser::ParseDefm(
MultiClass *CurMultiClass) {
2527 Init *DefmPrefix =
nullptr;
2530 DefmPrefix = ParseObjectName(CurMultiClass);
2535 return TokError(
"expected ':' after defm identifier");
2538 std::vector<Record*> NewRecDefs;
2541 bool InheritFromClass =
false;
2550 if (!Ref.
Rec)
return true;
2556 assert(MC &&
"Didn't lookup multiclass correctly?");
2561 if (TArgs.
size() < TemplateVals.
size())
2562 return Error(SubClassLoc,
2563 "more template args specified than multiclass expects");
2566 for (
const std::unique_ptr<Record> &DefProto : MC->
DefPrototypes) {
2572 Record *CurRec = InstantiateMulticlassDef(*MC, DefProto.get(), DefmPrefix,
2575 TArgs, TemplateVals);
2580 if (ResolveMulticlassDefArgs(*MC, CurRec, DefmLoc, SubClassLoc,
2581 TArgs, TemplateVals,
true))
2582 return Error(SubClassLoc,
"could not instantiate def");
2584 if (ResolveMulticlassDef(*MC, CurRec, DefProto.get(), DefmLoc))
2585 return Error(SubClassLoc,
"could not instantiate def");
2589 if (DefProto->isResolveFirst() && !CurMultiClass) {
2593 NewRecDefs.push_back(CurRec);
2601 return TokError(
"expected identifier");
2603 SubClassLoc = Lex.
getLoc();
2607 InheritFromClass = (Records.getClass(Lex.
getCurStrVal()) !=
nullptr);
2609 if (InheritFromClass)
2612 Ref = ParseSubClassReference(
nullptr,
true);
2615 if (InheritFromClass) {
2621 if (!SubClass.
Rec)
return true;
2625 for (
Record *CurRec : NewRecDefs) {
2627 if (AddSubClass(CurRec, SubClass))
2630 if (ApplyLetStack(CurRec))
2636 SubClass = ParseSubClassReference(
nullptr,
false);
2641 for (
Record *CurRec : NewRecDefs)
2648 return TokError(
"expected ';' at end of defm");
2664 return TokError(
"Expected class, def, defm, multiclass or let definition");
2665 case tgtok::Let:
return ParseTopLevelLet(MC);
2676 bool TGParser::ParseObjectList(
MultiClass *MC) {
2678 if (ParseObject(MC))
2686 if (ParseObjectList())
return true;
2692 return TokError(
"Unexpected input at top level");
static BinOpInit * get(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type)
Represents a range in source code.
void push_back(const T &Elt)
std::pair< int64_t, unsigned > getCurBinaryIntVal() const
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
virtual bool isComplete() const
This virtual method should be overridden by values that may not be completely specified yet...
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
unsigned getNumBits() const
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
tgtok::TokKind getCode() const
[AL, AH, CL] - Represent a list of defs
'list<Ty>' - Represent a list of values, all of which must be of the specified type.
virtual bool typeIsConvertibleTo(const RecTy *RHS) const
Return true if all values of 'this' type can be converted to the specified type.
static UnOpInit * get(UnaryOp opc, Init *lhs, RecTy *Type)
void addDef(std::unique_ptr< Record > R)
Init * resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) const override
This method is used to implement VarListElementInit::resolveReferences.
static VarInit * get(StringRef VN, RecTy *T)
Init * getElement(unsigned i) const
void setResolveFirst(bool b)
'{ a, b, c }' - Represents an initializer for a BitsRecTy value.
virtual std::string getAsUnquotedString() const
Convert this value to a string form, without adding quote markers.
ArrayRef< Init * > getTemplateArgs() const
static IntInit * get(int64_t V)
void addSuperClass(Record *R, SMRange Range)
StringRef getName() const
static BitsRecTy * get(unsigned Sz)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This is the common super-class of types that have a specific, explicit, type.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
static StringRecTy * get()
static DagInit * get(Init *V, StringInit *VN, ArrayRef< Init * > ArgRange, ArrayRef< StringInit * > NameRange)
Init * convertInitializerTo(RecTy *Ty) const override
This virtual function converts to the appropriate Init based on the passed in type.
StringRef getName() const
LLVM_NODISCARD bool empty() const
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
'bits<n>' - Represent a fixed number of bits
const std::string getNameInitAsString() const
void resolveReferences()
If there are any field references that refer to fields that have been filled in, we can propagate the...
static std::string utostr(uint64_t X, bool isNeg=false)
Record * getDef(StringRef Name) const
size_t size() const
size - Get the array size.
static BitsInit * get(ArrayRef< Init * > Range)
void resolveReferencesTo(const RecordVal *RV)
If anything in this record refers to RV, replace the reference to RV with the RHS of RV...
virtual Init * convertInitializerTo(RecTy *Ty) const =0
This virtual function converts to the appropriate Init based on the passed in type.
int64_t getCurIntVal() const
The instances of the Type class are immutable: once they are created, they are never changed...
const std::string & getCurStrVal() const
"foo" - Represent an initialization by a string value.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
RecordVector DefPrototypes
const RecordVal * getValue(const Init *Name) const
static const unsigned End
'string' - Represent an string value
static BitInit * get(bool V)
bool empty() const
empty - Check if the array is empty.
virtual Init * convertInitializerBitRange(ArrayRef< unsigned > Bits) const
This method is used to implement the bitrange selection operator.
static CodeInit * get(StringRef)
DefInit * getDefInit()
get the corresponding DefInit.
static bool isObjectStart(tgtok::TokKind K)
isObjectStart - Return true if this is a valid first token for an Object.
ForeachLoop - Record the iteration state associated with a for loop.
static FieldInit * get(Init *R, StringInit *FN)
void addTemplateArg(Init *Name)
bool Error(SMLoc L, const Twine &Msg) const
ArrayRef< SMLoc > getLoc() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
This is a utility class that provides an abstraction for the common functionality between Instruction...
static StringInit * get(StringRef)
Init * QualifyName(Record &CurRec, MultiClass *CurMultiClass, Init *Name, StringRef Scoper)
Return an Init with a qualifier prefix referring to CurRec's name.
static RecordRecTy * get(Record *R)
SmallVector< Init *, 4 > TemplateArgs
LLVM_NODISCARD T pop_back_val()
CHAIN = SC CHAIN, Imm128 - System call.
SmallVector< Init *, 4 > TemplateArgs
Init * getNameInit() const
Init * getNameInit() const
static DefInit * get(Record *)
Record * getClass(StringRef Name) const
LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const Twine &Msg)
bool isTemplateArg(Init *Name) const
void removeValue(Init *Name)
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
llvm_unreachable("Unknown RegBank!")
ArrayRef< RecordVal > getValues() const
RecTy * getElementType() const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
void emplace_back(ArgTypes &&...Args)
bool isSubClassOf(const Record *R) const
void addValue(const RecordVal &RV)
static TernOpInit * get(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
RecTy * resolveTypes(RecTy *T1, RecTy *T2)
Find a common type that T1 and T2 convert to.
'Opcode' - Represent a reference to an entire variable object.
static ListInit * get(ArrayRef< Init * > Range, RecTy *EltTy)
bool ParseFile()
ParseFile - Main entrypoint for parsing a tblgen file.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static ListRecTy * get(RecTy *T)
Init * Fold(Record *CurRec, MultiClass *CurMultiClass) const override
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef getValue() const
Init * getNameInit() const
virtual std::string getAsString() const =0
Convert this value to a string form.
virtual std::string getAsString() const =0
Represents a location in source code.
bool TokError(const Twine &Msg) const
Statically lint checks LLVM IR
ArrayRef< std::pair< Record *, SMRange > > getSuperClasses() const