58 errs() <<
"Multiclass:\n";
62 errs() <<
"Template args:\n";
71 CurRec = &CurMultiClass->
Rec;
76 return Error(Loc,
"New definition of '" + RV.
getName() +
"' of type '" +
78 "previous definition of type '" +
79 ERV->getType()->getAsString() +
"'");
90 bool AllowSelfAssignment) {
93 if (!CurRec) CurRec = &CurMultiClass->
Rec;
104 if (
VI->getNameInit() == ValName && !AllowSelfAssignment)
111 if (!BitList.
empty()) {
115 "' is not a bits type");
120 return Error(Loc,
"Initializer is not compatible with bit range");
123 BitsInit *BInit = cast<BitsInit>(BI);
128 for (
unsigned i = 0, e = BitList.
size();
i != e; ++
i) {
129 unsigned Bit = BitList[
i];
131 return Error(Loc,
"Cannot set bit #" +
Twine(Bit) +
" of value '" +
138 NewBits[
i] = CurVal->
getBit(i);
144 std::string InitType;
145 if (
BitsInit *BI = dyn_cast<BitsInit>(V))
146 InitType = (
Twine(
"' of type bit initializer with length ") +
147 Twine(BI->getNumBits())).str();
150 "' is incompatible with initializer '" + V->
getAsString() +
170 "More template args specified than expected");
174 for (
unsigned i = 0, e = TArgs.
size(); i != e; ++
i) {
189 "Value not specified for template argument #" +
190 Twine(i) +
" (" + TArgs[i]->getAsUnquotedString() +
198 for (
const auto &SCPair : SCs) {
201 "Already subclass of '" + SCPair.first->getName() +
"'!\n");
207 "Already subclass of '" + SC->
getName() +
"'!\n");
215 bool TGParser::AddSubMultiClass(
MultiClass *CurMC,
228 for (
const std::unique_ptr<Record> &R : SMC->
DefPrototypes) {
230 auto NewDef = make_unique<Record>(*R);
233 for (
const auto &MCVal : CurRec->
getValues())
234 if (AddValue(NewDef.get(), SubMultiClass.
RefRange.
Start, MCVal))
246 "More template args specified than expected");
250 for (
unsigned i = 0, e = SMCTArgs.
size(); i != e; ++
i) {
254 if (SetValue(CurRec, SubMultiClass.
RefRange.
Start, SMCTArgs[i],
266 for (
const auto &
Def :
273 Def->resolveReferencesTo(
Def->getValue(SMCTArgs[i]));
276 Def->removeValue(SMCTArgs[i]);
280 "Value not specified for template argument #" +
281 Twine(i) +
" (" + SMCTArgs[i]->getAsUnquotedString() +
292 bool TGParser::ProcessForeachDefs(
Record *CurRec,
SMLoc Loc) {
300 return ProcessForeachDefs(CurRec, Loc, IterVals);
306 bool TGParser::ProcessForeachDefs(
Record *CurRec,
SMLoc Loc, IterSet &IterVals){
308 if (IterVals.size() != Loops.size()) {
309 assert(IterVals.size() < Loops.size());
313 Error(Loc,
"Loop list is not a list");
318 for (
unsigned i = 0; i < List->
size(); ++
i) {
320 IterVals.push_back(IterRecord(CurLoop.IterVar, ItemVal));
321 if (ProcessForeachDefs(CurRec, Loc, IterVals))
331 auto IterRec = make_unique<Record>(*CurRec);
334 for (IterRecord &
IR : IterVals) {
338 return Error(Loc,
"foreach iterator value is untyped");
343 return Error(Loc,
"when instantiating this def");
346 IterRec->resolveReferencesTo(IterRec->getValue(IterVar->
getNameInit()));
352 if (Records.
getDef(IterRec->getNameInitAsString())) {
354 if (!IterRec->isAnonymous())
355 return Error(Loc,
"def already exists: " +IterRec->getNameInitAsString());
357 IterRec->setName(GetNewAnonymousName());
360 Record *IterRecSave = IterRec.get();
361 Records.
addDef(std::move(IterRec));
379 std::string TGParser::GetNewAnonymousName() {
380 return "anonymous_" +
utostr(AnonCounter++);
403 CurRec = &CurMultiClass->
Rec;
409 TokError(
"Record name is not typed!");
415 return ParseValue(CurRec, Type, ParseNameMode);
423 Record *TGParser::ParseClassID() {
425 TokError(
"expected name for ClassID");
444 TokError(
"expected name for MultiClassID");
463 ParseSubClassReference(
Record *CurRec,
bool isDefm) {
469 Result.
Rec = &MC->Rec;
471 Result.
Rec = ParseClassID();
473 if (!Result.
Rec)
return Result;
483 TokError(
"subclass reference requires a non-empty list of template values");
484 Result.
Rec =
nullptr;
490 Result.
Rec =
nullptr;
495 TokError(
"expected '>' in template value list");
496 Result.
Rec =
nullptr;
513 ParseSubMultiClassReference(
MultiClass *CurMC) {
517 Result.
MC = ParseMultiClassID();
518 if (!Result.
MC)
return Result;
528 TokError(
"subclass reference requires a non-empty list of template values");
540 TokError(
"expected '>' in template value list");
556 TokError(
"expected integer or bitrange");
563 return TokError(
"invalid range, cannot be negative");
571 TokError(
"expected integer value as end of range");
581 return TokError(
"invalid range, cannot be negative");
586 for (; Start <=
End; ++Start)
589 for (; Start >=
End; --Start)
600 if (ParseRangePiece(Result)) {
608 if (ParseRangePiece(Result)) {
626 ParseRangeList(Ranges);
627 if (Ranges.
empty())
return true;
630 TokError(
"expected '>' at end of range list");
631 return Error(StartLoc,
"to match this '<'");
648 ParseRangeList(Ranges);
649 if (Ranges.
empty())
return true;
652 TokError(
"expected '}' at end of bit list");
653 return Error(StartLoc,
"to match this '{'");
670 RecTy *TGParser::ParseType() {
672 default:
TokError(
"Unknown token when expecting a type");
return nullptr;
683 TokError(
"expected '<' after bits type");
687 TokError(
"expected integer in bits<n> type");
692 TokError(
"expected '>' at end of bits<n> type");
700 TokError(
"expected '<' after list type");
704 RecTy *SubType = ParseType();
705 if (!SubType)
return nullptr;
708 TokError(
"expected '>' at end of list<ty> type");
725 Init *TemplateArgName =
QualifyName(*CurRec, CurMultiClass, Name,
":");
728 TemplateArgName =
QualifyName(CurMultiClass->
Rec, CurMultiClass, Name,
733 assert(RV &&
"Template arg doesn't exist??");
743 assert(RV &&
"Template arg doesn't exist??");
749 for (
const auto &
L : Loops) {
755 if (Mode == ParseNameMode)
761 if (Mode == ParseValueMode) {
762 Error(NameLoc,
"Variable not defined: '" + Name->
getValue() +
"'");
783 RecTy *Type =
nullptr;
791 Type = ParseOperatorType();
794 TokError(
"did not get type for unary operator");
814 TokError(
"expected '(' after unary operator");
819 Init *LHS = ParseValue(CurRec);
820 if (!LHS)
return nullptr;
828 if (!LHSl && !LHSs && !LHSt) {
829 TokError(
"expected list or string type argument in unary operator");
835 if (!LType && !SType) {
836 TokError(
"expected list or string type argument in unary operator");
842 if (!LHSl && !LHSt) {
843 TokError(
"expected list type argument in unary operator");
847 if (LHSl && LHSl->
empty()) {
848 TokError(
"empty list argument in unary operator");
855 TokError(
"untyped list element in unary operator");
861 assert(LHSt &&
"expected list type argument in unary operator");
864 TokError(
"expected list type argument in unary operator");
873 TokError(
"expected ')' in unary operator");
877 return (
UnOpInit::get(Code, LHS, Type))->Fold(CurRec, CurMultiClass);
895 RecTy *Type =
nullptr;
918 TokError(
"expected '(' after binary operator");
926 if (!InitList.
back())
return nullptr;
932 if (!InitList.
back())
return nullptr;
936 TokError(
"expected ')' in operator");
943 if (
VarInit *Arg0 = dyn_cast<VarInit>(InitList[0]))
944 Type = Arg0->getType();
945 else if (
ListInit *Arg0 = dyn_cast<ListInit>(InitList[0]))
946 Type = Arg0->getType();
949 Error(OpLoc,
"expected a list");
957 while (InitList.
size() > 2) {
960 ->Fold(CurRec, CurMultiClass);
961 InitList.
back() = RHS;
965 if (InitList.
size() == 2)
967 ->Fold(CurRec, CurMultiClass);
969 Error(OpLoc,
"expected two operands to operator");
977 RecTy *Type =
nullptr;
994 TokError(
"expected '(' after ternary operator");
999 Init *LHS = ParseValue(CurRec);
1000 if (!LHS)
return nullptr;
1003 TokError(
"expected ',' in ternary operator");
1008 Init *MHS = ParseValue(CurRec, ItemType);
1013 TokError(
"expected ',' in ternary operator");
1018 Init *RHS = ParseValue(CurRec, ItemType);
1023 TokError(
"expected ')' in binary operator");
1031 RecTy *MHSTy =
nullptr;
1032 RecTy *RHSTy =
nullptr;
1034 if (
TypedInit *MHSt = dyn_cast<TypedInit>(MHS))
1035 MHSTy = MHSt->getType();
1036 if (
BitsInit *MHSbits = dyn_cast<BitsInit>(MHS))
1038 if (isa<BitInit>(MHS))
1041 if (
TypedInit *RHSt = dyn_cast<TypedInit>(RHS))
1042 RHSTy = RHSt->getType();
1043 if (
BitsInit *RHSbits = dyn_cast<BitsInit>(RHS))
1045 if (isa<BitInit>(RHS))
1049 if (isa<UnsetInit>(MHS))
1051 if (isa<UnsetInit>(RHS))
1054 if (!MHSTy || !RHSTy) {
1055 TokError(
"could not get type for !if");
1064 TokError(
"inconsistent types for !if");
1072 TokError(
"could not get type for !foreach");
1081 TokError(
"could not get type for !subst");
1099 RecTy *TGParser::ParseOperatorType() {
1100 RecTy *Type =
nullptr;
1103 TokError(
"expected type name for operator");
1111 TokError(
"expected type name for operator");
1116 TokError(
"expected type name for operator");
1147 default:
TokError(
"Unknown token when parsing a value");
break;
1152 return ParseSimpleValue(CurRec, ItemType, Mode);
1157 for (
unsigned i = 0, e = BinaryVal.second; i != e; ++i)
1188 return ParseIDValue(CurRec, Name, NameLoc, Mode);
1192 TokError(
"expected non-empty value list");
1201 Error(NameLoc,
"Expected a class name, got '" + Name->
getValue() +
"'");
1210 TokError(
"expected '>' at end of value list");
1217 auto NewRecOwner = llvm::make_unique<Record>(GetNewAnonymousName(), NameLoc,
1219 Record *NewRec = NewRecOwner.get();
1223 if (AddSubClass(NewRec, SCRef))
1226 if (!CurMultiClass) {
1228 Records.addDef(std::move(NewRecOwner));
1232 NewRec->setResolveFirst(
true);
1234 CurMultiClass->
DefPrototypes.push_back(std::move(NewRecOwner));
1239 assert(RV &&
"Template arg doesn't exist?");
1240 NewRec->addValue(*RV);
1246 assert(MCNameRV &&
"multiclass record must have a NAME");
1266 ParseValueList(Vals, CurRec);
1267 if (Vals.
empty())
return nullptr;
1270 TokError(
"expected '}' at end of bit list value");
1280 for (
unsigned i = 0, e = Vals.
size(); i != e; ++
i) {
1285 if (
BitsInit *BI = dyn_cast<BitsInit>(Vals[i])) {
1286 for (
unsigned i = 0, e = BI->getNumBits(); i != e; ++
i)
1287 NewBits.
push_back(BI->getBit((e - i) - 1));
1291 if (
VarInit *
VI = dyn_cast<VarInit>(Vals[i])) {
1292 if (
BitsRecTy *BitsRec = dyn_cast<BitsRecTy>(
VI->getType())) {
1293 for (
unsigned i = 0, e = BitsRec->getNumBits(); i != e; ++
i)
1302 Error(BraceLoc,
"Element #" +
Twine(i) +
" (" + Vals[i]->getAsString() +
1303 ") is not convertable to a bit");
1315 RecTy *DeducedEltTy =
nullptr;
1321 TokError(
Twine(
"Type mismatch for list, expected list type, got ") +
1325 GivenListTy = ListType;
1329 ParseValueList(Vals, CurRec,
nullptr,
1331 if (Vals.
empty())
return nullptr;
1334 TokError(
"expected ']' at end of list value");
1339 RecTy *GivenEltTy =
nullptr;
1344 GivenEltTy = ParseType();
1351 TokError(
"expected '>' at end of list element type");
1358 RecTy *EltTy =
nullptr;
1359 for (
Init *V : Vals) {
1368 TokError(
"Incompatible types in list elements");
1380 TokError(
"Incompatible types in list elements");
1397 TokError(
"Element type mismatch for list");
1401 DeducedEltTy = EltTy;
1409 TokError(
"expected identifier in dag init");
1414 if (!Operator)
return nullptr;
1420 TokError(
"expected variable name in dag operator");
1429 ParseDagArgList(DagArgs, CurRec);
1430 if (DagArgs.
empty())
return nullptr;
1434 TokError(
"expected ')' in dag init");
1459 return ParseOperation(CurRec, ItemType);
1473 Init *TGParser::ParseValue(
Record *CurRec,
RecTy *ItemType, IDParseMode Mode) {
1474 Init *Result = ParseSimpleValue(CurRec, ItemType, Mode);
1475 if (!Result)
return nullptr;
1480 default:
return Result;
1482 if (Mode == ParseNameMode || Mode == ParseForeachMode)
1489 ParseRangeList(Ranges);
1490 if (Ranges.
empty())
return nullptr;
1496 Error(CurlyLoc,
"Invalid bit range for value");
1502 TokError(
"expected '}' at end of bit range list");
1512 ParseRangeList(Ranges);
1513 if (Ranges.
empty())
return nullptr;
1515 Result = Result->convertInitListSlice(Ranges);
1517 Error(SquareLoc,
"Invalid range for list slice");
1523 TokError(
"expected ']' at end of list slice");
1531 TokError(
"expected field identifier after '.'");
1535 if (!Result->getFieldType(FieldName)) {
1537 Result->getAsString() +
"'");
1553 Error(PasteLoc,
"LHS of paste is not typed!");
1577 Init *RHSResult = ParseValue(CurRec, ItemType, ParseNameMode);
1580 Error(PasteLoc,
"RHS of paste is not typed!");
1604 void TGParser::ParseDagArgList(
1617 Init *Val = ParseValue(CurRec);
1627 TokError(
"expected variable name in dag literal");
1635 Result.push_back(std::make_pair(Val, VarName));
1650 RecTy *ItemType = EltTy;
1651 unsigned int ArgN = 0;
1652 if (ArgsRec && !EltTy) {
1654 if (TArgs.
empty()) {
1655 TokError(
"template argument provided to non-template class");
1661 errs() <<
"Cannot find template arg " << ArgN <<
" (" << TArgs[ArgN]
1664 assert(RV &&
"Template argument record not found??");
1668 Result.
push_back(ParseValue(CurRec, ItemType));
1669 if (!Result.
back()) {
1677 if (ArgsRec && !EltTy) {
1679 if (ArgN >= TArgs.
size()) {
1680 TokError(
"too many template arguments");
1685 assert(RV &&
"Template argument record not found??");
1689 Result.
push_back(ParseValue(CurRec, ItemType));
1690 if (!Result.
back()) {
1707 Init *TGParser::ParseDeclaration(
Record *CurRec,
1708 bool ParsingTemplateArgs) {
1711 if (HasField) Lex.
Lex();
1713 RecTy *Type = ParseType();
1714 if (!Type)
return nullptr;
1717 TokError(
"Expected identifier in declaration");
1725 if (ParsingTemplateArgs) {
1727 DeclName =
QualifyName(*CurRec, CurMultiClass, DeclName,
":");
1731 DeclName =
QualifyName(CurMultiClass->
Rec, CurMultiClass, DeclName,
1736 if (AddValue(CurRec, IdLoc,
RecordVal(DeclName, Type, HasField)))
1743 Init *Val = ParseValue(CurRec, Type);
1745 SetValue(CurRec, ValLoc, DeclName, None, Val))
1763 VarInit *TGParser::ParseForeachDeclaration(
ListInit *&ForeachListValue) {
1765 TokError(
"Expected identifier in foreach declaration");
1774 TokError(
"Expected '=' in foreach declaration");
1779 RecTy *IterType =
nullptr;
1783 default:
TokError(
"Unknown token when expecting a range list");
return nullptr;
1785 Init *List = ParseSimpleValue(
nullptr,
nullptr, ParseForeachMode);
1787 if (!ForeachListValue) {
1794 TokError(
"Value list is not of list type");
1802 if (ParseRangePiece(Ranges))
1809 ParseRangeList(Ranges);
1811 TokError(
"expected '}' at end of bit range list");
1819 if (!Ranges.
empty()) {
1820 assert(!IterType &&
"Type already initialized?");
1822 std::vector<Init*> Values;
1823 for (
unsigned R : Ranges)
1841 bool TGParser::ParseTemplateArgList(
Record *CurRec) {
1845 Record *TheRecToAddTo = CurRec ? CurRec : &CurMultiClass->
Rec;
1848 Init *TemplArg = ParseDeclaration(CurRec,
true);
1858 TemplArg = ParseDeclaration(CurRec,
true);
1865 return TokError(
"expected '>' at end of template argument list");
1874 bool TGParser::ParseBodyItem(
Record *CurRec) {
1876 if (!ParseDeclaration(CurRec,
false))
1880 return TokError(
"expected ';' after declaration");
1887 return TokError(
"expected field identifier after let");
1894 if (ParseOptionalBitList(BitList))
1899 return TokError(
"expected '=' in let expression");
1908 Init *Val = ParseValue(CurRec, Type);
1909 if (!Val)
return true;
1912 return TokError(
"expected ';' after let expression");
1915 return SetValue(CurRec, IdLoc, FieldName, BitList, Val);
1925 bool TGParser::ParseBody(
Record *CurRec) {
1933 return TokError(
"Expected ';' or '{' to start body");
1938 if (ParseBodyItem(CurRec))
1948 bool TGParser::ApplyLetStack(
Record *CurRec) {
1951 if (SetValue(CurRec, LR.Loc, LR.Name, LR.Bits, LR.Value))
1965 bool TGParser::ParseObjectBody(
Record *CurRec) {
1974 if (!SubClass.
Rec)
return true;
1977 if (AddSubClass(CurRec, SubClass))
1982 SubClass = ParseSubClassReference(CurRec,
false);
1986 if (ApplyLetStack(CurRec))
1989 return ParseBody(CurRec);
1997 bool TGParser::ParseDef(
MultiClass *CurMultiClass) {
2003 std::unique_ptr<Record> CurRecOwner;
2004 Init *Name = ParseObjectName(CurMultiClass);
2006 CurRecOwner = make_unique<Record>(
Name, DefLoc, Records);
2008 CurRecOwner = llvm::make_unique<Record>(GetNewAnonymousName(), DefLoc,
2010 Record *CurRec = CurRecOwner.get();
2012 if (!CurMultiClass && Loops.empty()) {
2016 if (Records.getDef(CurRec->getNameInitAsString()))
2017 return Error(DefLoc,
"def '" + CurRec->getNameInitAsString()+
2018 "' already defined");
2019 Records.addDef(std::move(CurRecOwner));
2021 if (ParseObjectBody(CurRec))
2023 }
else if (CurMultiClass) {
2029 if (ParseObjectBody(CurRec))
2034 if (Proto->getNameInit() == CurRec->getNameInit())
2035 return Error(DefLoc,
"def '" + CurRec->getNameInitAsString() +
2036 "' already defined in this multiclass!");
2037 CurMultiClass->
DefPrototypes.push_back(std::move(CurRecOwner));
2038 }
else if (ParseObjectBody(CurRec)) {
2046 CurRec->resolveReferences();
2049 assert(CurRec->getTemplateArgs().empty() &&
"How'd this get template args?");
2051 if (CurMultiClass) {
2055 assert(RV &&
"Template arg doesn't exist?");
2056 CurRec->addValue(*RV);
2060 if (ProcessForeachDefs(CurRec, DefLoc))
2061 return Error(DefLoc,
"Could not process loops for def" +
2062 CurRec->getNameInitAsString());
2073 bool TGParser::ParseForeach(
MultiClass *CurMultiClass) {
2080 VarInit *IterName = ParseForeachDeclaration(ListValue);
2082 return TokError(
"expected declaration in for");
2089 Loops.push_back(
ForeachLoop(IterName, ListValue));
2093 if (ParseObject(CurMultiClass))
2101 if (ParseObjectList(CurMultiClass))
2105 TokError(
"expected '}' at end of foreach command");
2106 return Error(BraceLoc,
"to match this '{'");
2121 bool TGParser::ParseClass() {
2126 return TokError(
"expected class name after 'class' keyword");
2135 "' already defined");
2140 CurRec = NewRec.get();
2141 Records.addClass(std::move(NewRec));
2147 if (ParseTemplateArgList(CurRec))
2151 return ParseObjectBody(CurRec);
2163 TokError(
"expected identifier in let definition");
2174 if (ParseOptionalRangeList(Bits)) {
2181 TokError(
"expected '=' in let expression");
2187 Init *Val = ParseValue(
nullptr);
2208 bool TGParser::ParseTopLevelLet(
MultiClass *CurMultiClass) {
2214 ParseLetList(LetInfo);
2215 if (LetInfo.
empty())
return true;
2219 return TokError(
"expected 'in' at end of top-level 'let'");
2225 if (ParseObject(CurMultiClass))
2233 if (ParseObjectList(CurMultiClass))
2237 TokError(
"expected '}' at end of top level let command");
2238 return Error(BraceLoc,
"to match this '{'");
2258 bool TGParser::ParseMultiClass() {
2263 return TokError(
"expected identifier after multiclass for name");
2267 MultiClasses.insert(std::make_pair(Name,
2268 llvm::make_unique<MultiClass>(Name, Lex.
getLoc(),Records)));
2271 return TokError(
"multiclass '" + Name +
"' already defined");
2273 CurMultiClass = Result.first->second.get();
2278 if (ParseTemplateArgList(
nullptr))
2281 bool inherits =
false;
2291 ParseSubMultiClassReference(CurMultiClass);
2294 if (!SubMultiClass.
MC)
return true;
2297 if (AddSubMultiClass(CurMultiClass, SubMultiClass))
2302 SubMultiClass = ParseSubMultiClassReference(CurMultiClass);
2308 return TokError(
"expected '{' in multiclass definition");
2310 return TokError(
"expected ';' in multiclass definition");
2314 return TokError(
"multiclass must contain at least one def");
2319 return TokError(
"expected 'let', 'def' or 'defm' in multiclass body");
2324 if (ParseObject(CurMultiClass))
2332 CurMultiClass =
nullptr;
2349 bool IsAnonymous =
false;
2358 if (DefNameString) {
2370 Locs.append(DefProto->
getLoc().begin(), DefProto->
getLoc().end());
2371 auto CurRec = make_unique<Record>(DefName, Locs, Records, IsAnonymous);
2376 AddSubClass(CurRec.get(), Ref);
2382 DefmPrefix,
true)) {
2383 Error(DefmPrefixRange.
Start,
"Could not resolve " +
2384 CurRec->getNameInitAsString() +
":NAME to '" +
2385 DefmPrefix->getAsUnquotedString() +
"'");
2392 if (!DefNameString) {
2394 CurRec->resolveReferencesTo(DefNameRV);
2397 if (!CurMultiClass) {
2401 CurRec->resolveReferencesTo(DefNameRV);
2405 DefName = CurRec->getNameInit();
2410 if (!DefNameString) {
2411 ResolveMulticlassDefArgs(MC, CurRec.get(), DefmPrefixRange.
Start,
2412 Lex.
getLoc(), TArgs, TemplateVals,
2414 DefName = CurRec->getNameInit();
2422 if (!DefNameString) {
2424 DefName->getAsUnquotedString() +
" is not a string.");
2428 CurRec->setName(DefName);
2441 if (Records.getDef(CurRec->getNameInitAsString())) {
2442 Error(DefmPrefixRange.
Start,
"def '" + CurRec->getNameInitAsString() +
2443 "' already defined, instantiating defm with subdef '" +
2448 Record *CurRecSave = CurRec.get();
2449 Records.addDef(std::move(CurRec));
2455 return CurRec.release();
2465 for (
unsigned i = 0, e = TArgs.
size(); i != e; ++
i) {
2467 if (i < TemplateVals.
size()) {
2469 if (SetValue(CurRec, DefmPrefixLoc, TArgs[i], None, TemplateVals[i]))
2480 return Error(SubClassLoc,
"value not specified for template argument #" +
2481 Twine(i) +
" (" + TArgs[i]->getAsUnquotedString() +
2489 bool TGParser::ResolveMulticlassDef(
MultiClass &MC,
2492 SMLoc DefmPrefixLoc) {
2494 if (ApplyLetStack(CurRec))
2495 return Error(DefmPrefixLoc,
"when instantiating this defm");
2503 if (Proto->getNameInit() == CurRec->
getNameInit())
2505 "' already defined in this multiclass!");
2506 CurMultiClass->
DefPrototypes.push_back(std::unique_ptr<Record>(CurRec));
2511 assert(RV &&
"Template arg doesn't exist?");
2522 bool TGParser::ParseDefm(
MultiClass *CurMultiClass) {
2525 Init *DefmPrefix =
nullptr;
2528 DefmPrefix = ParseObjectName(CurMultiClass);
2533 return TokError(
"expected ':' after defm identifier");
2536 std::vector<Record*> NewRecDefs;
2539 bool InheritFromClass =
false;
2548 if (!Ref.
Rec)
return true;
2554 assert(MC &&
"Didn't lookup multiclass correctly?");
2559 if (TArgs.
size() < TemplateVals.
size())
2560 return Error(SubClassLoc,
2561 "more template args specified than multiclass expects");
2564 for (
const std::unique_ptr<Record> &DefProto : MC->
DefPrototypes) {
2570 Record *CurRec = InstantiateMulticlassDef(*MC, DefProto.get(), DefmPrefix,
2573 TArgs, TemplateVals);
2578 if (ResolveMulticlassDefArgs(*MC, CurRec, DefmLoc, SubClassLoc,
2579 TArgs, TemplateVals,
true))
2580 return Error(SubClassLoc,
"could not instantiate def");
2582 if (ResolveMulticlassDef(*MC, CurRec, DefProto.get(), DefmLoc))
2583 return Error(SubClassLoc,
"could not instantiate def");
2587 if (DefProto->isResolveFirst() && !CurMultiClass) {
2591 NewRecDefs.push_back(CurRec);
2599 return TokError(
"expected identifier");
2601 SubClassLoc = Lex.
getLoc();
2605 InheritFromClass = (Records.getClass(Lex.
getCurStrVal()) !=
nullptr);
2607 if (InheritFromClass)
2610 Ref = ParseSubClassReference(
nullptr,
true);
2613 if (InheritFromClass) {
2619 if (!SubClass.
Rec)
return true;
2623 for (
Record *CurRec : NewRecDefs) {
2625 if (AddSubClass(CurRec, SubClass))
2628 if (ApplyLetStack(CurRec))
2634 SubClass = ParseSubClassReference(
nullptr,
false);
2639 for (
Record *CurRec : NewRecDefs)
2646 return TokError(
"expected ';' at end of defm");
2662 return TokError(
"Expected class, def, defm, multiclass or let definition");
2663 case tgtok::Let:
return ParseTopLevelLet(MC);
2674 bool TGParser::ParseObjectList(
MultiClass *MC) {
2676 if (ParseObject(MC))
2684 if (ParseObjectList())
return true;
2690 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...
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.
StringRef getName() const
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)
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
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
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
Statically lint checks LLVM IR
ArrayRef< std::pair< Record *, SMRange > > getSuperClasses() const