48 errs() <<
"Multiclass:\n";
52 errs() <<
"Template args:\n";
53 for (std::vector<Init *>::const_iterator i =
TemplateArgs.begin(),
65 CurRec = &CurMultiClass->
Rec;
70 return Error(Loc,
"New definition of '" + RV.
getName() +
"' of type '" +
72 "previous definition of type '" +
73 ERV->getType()->getAsString() +
"'");
83 const std::vector<unsigned> &BitList,
Init *V) {
86 if (CurRec == 0) CurRec = &CurMultiClass->
Rec;
96 if (
VarInit *VI = dyn_cast<VarInit>(V))
97 if (VI->getNameInit() == ValName)
104 if (!BitList.empty()) {
108 +
"' is not a bits type");
113 return Error(Loc,
"Initializer is not compatible with bit range");
123 for (
unsigned i = 0, e = BitList.size(); i != e; ++i) {
124 unsigned Bit = BitList[i];
126 return Error(Loc,
"Cannot set bit #" +
utostr(Bit) +
" of value '" +
131 for (
unsigned i = 0, e = CurVal->
getNumBits(); i != e; ++i)
133 NewBits[i] = CurVal->
getBit(i);
141 "' is incompatible with initializer '" + V->
getAsString()
151 const std::vector<RecordVal> &Vals = SC->
getValues();
152 for (
unsigned i = 0, e = Vals.size(); i != e; ++i)
161 "More template args specified than expected");
165 for (
unsigned i = 0, e = TArgs.size(); i != e; ++i) {
180 "Value not specified for template argument #"
181 +
utostr(i) +
" (" + TArgs[i]->getAsUnquotedString()
190 for (
unsigned i = 0, e = SCs.size(); i != e; ++i) {
193 "Already subclass of '" + SCs[i]->getName() +
"'!\n");
199 "Already subclass of '" + SC->
getName() +
"'!\n");
207 bool TGParser::AddSubMultiClass(
MultiClass *CurMC,
212 const std::vector<RecordVal> &MCVals = CurRec->
getValues();
215 const std::vector<RecordVal> &SMCVals = SMC->
Rec.
getValues();
216 for (
unsigned i = 0, e = SMCVals.size(); i != e; ++i)
217 if (AddValue(CurRec, SubMultiClass.
RefRange.
Start, SMCVals[i]))
223 for (MultiClass::RecordVector::const_iterator i = SMC->
DefPrototypes.begin(),
231 for (
unsigned i = 0, e = MCVals.size(); i != e; ++i)
232 if (AddValue(NewDef, SubMultiClass.
RefRange.
Start, MCVals[i]))
242 if (SMCTArgs.size() < SubMultiClass.
TemplateArgs.size())
244 "More template args specified than expected");
248 for (
unsigned i = 0, e = SMCTArgs.size(); i != e; ++i) {
252 if (SetValue(CurRec, SubMultiClass.
RefRange.
Start, SMCTArgs[i],
253 std::vector<unsigned>(),
265 for (MultiClass::RecordVector::iterator j =
273 std::vector<unsigned>(),
285 "Value not specified for template argument #"
286 +
utostr(i) +
" (" + SMCTArgs[i]->getAsUnquotedString()
297 bool TGParser::ProcessForeachDefs(
Record *CurRec,
SMLoc Loc) {
305 return ProcessForeachDefs(CurRec, Loc, IterVals);
311 bool TGParser::ProcessForeachDefs(
Record *CurRec,
SMLoc Loc, IterSet &IterVals){
313 if (IterVals.size() != Loops.size()) {
314 assert(IterVals.size() < Loops.size());
318 Error(Loc,
"Loop list is not a list");
323 for (int64_t i = 0; i < List->
getSize(); ++i) {
325 IterVals.push_back(IterRecord(CurLoop.IterVar, ItemVal));
326 if (ProcessForeachDefs(CurRec, Loc, IterVals))
339 for (
unsigned i = 0, e = IterVals.size(); i != e; ++i) {
340 VarInit *IterVar = IterVals[i].IterVar;
343 Error(Loc,
"foreach iterator value is untyped");
349 if (SetValue(IterRec, Loc, IterVar->
getName(),
350 std::vector<unsigned>(), IVal)) {
351 Error(Loc,
"when instantiating this def");
384 static unsigned AnonCounter = 0;
385 unsigned Tmp = AnonCounter++;
386 return "anonymous." +
utostr(Tmp);
409 CurRec = &CurMultiClass->
Rec;
415 TokError(
"Record name is not typed!");
421 return ParseValue(CurRec, Type, ParseNameMode);
429 Record *TGParser::ParseClassID() {
431 TokError(
"expected name for ClassID");
450 TokError(
"expected name for MultiClassID");
469 ParseSubClassReference(
Record *CurRec,
bool isDefm) {
475 Result.
Rec = &MC->Rec;
477 Result.
Rec = ParseClassID();
479 if (Result.
Rec == 0)
return Result;
489 TokError(
"subclass reference requires a non-empty list of template values");
501 TokError(
"expected '>' in template value list");
519 ParseSubMultiClassReference(
MultiClass *CurMC) {
523 Result.
MC = ParseMultiClassID();
524 if (Result.
MC == 0)
return Result;
534 TokError(
"subclass reference requires a non-empty list of template values");
546 TokError(
"expected '>' in template value list");
560 bool TGParser::ParseRangePiece(std::vector<unsigned> &Ranges) {
562 TokError(
"expected integer or bitrange");
569 return TokError(
"invalid range, cannot be negative");
573 Ranges.push_back(Start);
577 TokError(
"expected integer value as end of range");
587 return TokError(
"invalid range, cannot be negative");
592 for (; Start <= End; ++Start)
593 Ranges.push_back(Start);
595 for (; Start >= End; --Start)
596 Ranges.push_back(Start);
605 std::vector<unsigned> TGParser::ParseRangeList() {
606 std::vector<unsigned> Result;
609 if (ParseRangePiece(Result))
610 return std::vector<unsigned>();
615 if (ParseRangePiece(Result))
616 return std::vector<unsigned>();
624 bool TGParser::ParseOptionalRangeList(std::vector<unsigned> &Ranges) {
632 Ranges = ParseRangeList();
633 if (Ranges.empty())
return true;
636 TokError(
"expected '>' at end of range list");
637 return Error(StartLoc,
"to match this '<'");
646 bool TGParser::ParseOptionalBitList(std::vector<unsigned> &Ranges) {
654 Ranges = ParseRangeList();
655 if (Ranges.empty())
return true;
658 TokError(
"expected '}' at end of bit list");
659 return Error(StartLoc,
"to match this '{'");
677 RecTy *TGParser::ParseType() {
679 default:
TokError(
"Unknown token when expecting a type");
return 0;
690 TokError(
"expected '<' after bits type");
694 TokError(
"expected integer in bits<n> type");
699 TokError(
"expected '>' at end of bits<n> type");
707 TokError(
"expected '<' after list type");
711 RecTy *SubType = ParseType();
712 if (SubType == 0)
return 0;
715 TokError(
"expected '>' at end of list<ty> type");
732 Init *TGParser::ParseIDValue(
Record *CurRec, IDParseMode Mode) {
737 return ParseIDValue(CurRec, Name, Loc);
743 const std::string &Name,
SMLoc NameLoc,
749 Init *TemplateArgName =
QualifyName(*CurRec, CurMultiClass, Name,
":");
752 TemplateArgName =
QualifyName(CurMultiClass->
Rec, CurMultiClass, Name,
757 assert(RV &&
"Template arg doesn't exist??");
768 assert(RV &&
"Template arg doesn't exist??");
774 for (LoopVector::iterator i = Loops.begin(), iend = Loops.end();
782 if (Mode == ParseNameMode)
788 if (Mode == ParseValueMode) {
789 Error(NameLoc,
"Variable not defined: '" + Name +
"'");
800 Init *TGParser::ParseOperation(
Record *CurRec) {
818 Type = ParseOperatorType();
821 TokError(
"did not get type for unary operator");
841 TokError(
"expected '(' after unary operator");
846 Init *LHS = ParseValue(CurRec);
847 if (LHS == 0)
return 0;
855 if (LHSl == 0 && LHSs == 0 && LHSt == 0) {
856 TokError(
"expected list or string type argument in unary operator");
862 if (LType == 0 && SType == 0) {
863 TokError(
"expected list or string type argumnet in unary operator");
870 if (LHSl == 0 && LHSt == 0) {
871 TokError(
"expected list type argumnet in unary operator");
875 if (LHSl && LHSl->
getSize() == 0) {
876 TokError(
"empty list argument in unary operator");
883 TokError(
"untyped list element in unary operator");
892 assert(LHSt &&
"expected list type argument in unary operator");
895 TokError(
"expected list type argumnet in unary operator");
908 TokError(
"expected ')' in unary operator");
912 return (
UnOpInit::get(Code, LHS, Type))->Fold(CurRec, CurMultiClass);
944 TokError(
"expected '(' after binary operator");
952 if (InitList.
back() == 0)
return 0;
958 if (InitList.
back() == 0)
return 0;
962 TokError(
"expected ')' in operator");
970 while (InitList.
size() > 2) {
973 ->Fold(CurRec, CurMultiClass);
974 InitList.
back() = RHS;
978 if (InitList.
size() == 2)
980 ->Fold(CurRec, CurMultiClass);
982 Error(OpLoc,
"expected two operands to operator");
1007 TokError(
"expected '(' after ternary operator");
1012 Init *LHS = ParseValue(CurRec);
1013 if (LHS == 0)
return 0;
1016 TokError(
"expected ',' in ternary operator");
1021 Init *MHS = ParseValue(CurRec);
1022 if (MHS == 0)
return 0;
1025 TokError(
"expected ',' in ternary operator");
1030 Init *RHS = ParseValue(CurRec);
1031 if (RHS == 0)
return 0;
1034 TokError(
"expected ')' in binary operator");
1045 if (
TypedInit *MHSt = dyn_cast<TypedInit>(MHS))
1046 MHSTy = MHSt->getType();
1047 if (
BitsInit *MHSbits = dyn_cast<BitsInit>(MHS))
1049 if (isa<BitInit>(MHS))
1052 if (
TypedInit *RHSt = dyn_cast<TypedInit>(RHS))
1053 RHSTy = RHSt->getType();
1054 if (
BitsInit *RHSbits = dyn_cast<BitsInit>(RHS))
1056 if (isa<BitInit>(RHS))
1060 if (isa<UnsetInit>(MHS))
1062 if (isa<UnsetInit>(RHS))
1065 if (!MHSTy || !RHSTy) {
1066 TokError(
"could not get type for !if");
1075 TokError(
"inconsistent types for !if");
1083 TokError(
"could not get type for !foreach");
1092 TokError(
"could not get type for !subst");
1110 RecTy *TGParser::ParseOperatorType() {
1114 TokError(
"expected type name for operator");
1122 TokError(
"expected type name for operator");
1127 TokError(
"expected type name for operator");
1158 default:
TokError(
"Unknown token when parsing a value");
break;
1163 return ParseSimpleValue(CurRec, ItemType, Mode);
1190 return ParseIDValue(CurRec, Name, NameLoc, Mode);
1194 TokError(
"expected non-empty value list");
1203 Error(NameLoc,
"Expected a class name, got '" + Name +
"'");
1207 std::vector<Init*> ValueList = ParseValueList(CurRec, Class);
1208 if (ValueList.empty())
return 0;
1211 TokError(
"expected '>' at end of value list");
1218 static unsigned AnonCounter = 0;
1228 if (AddSubClass(NewRec, SCRef))
1239 std::vector<Init*> Vals;
1242 Vals = ParseValueList(CurRec);
1243 if (Vals.empty())
return 0;
1246 TokError(
"expected '}' at end of bit list value");
1253 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
1256 Error(BraceLoc,
"Element #" +
utostr(i) +
" (" + Vals[i]->getAsString()+
1257 ") is not convertable to a bit");
1260 NewBits[Vals.size()-i-1] =
Bit;
1266 std::vector<Init*> Vals;
1268 RecTy *DeducedEltTy = 0;
1271 if (ItemType != 0) {
1273 if (ListType == 0) {
1276 ss <<
"Type mismatch for list, expected list type, got "
1281 GivenListTy = ListType;
1285 Vals = ParseValueList(CurRec, 0,
1287 if (Vals.empty())
return 0;
1290 TokError(
"expected ']' at end of list value");
1295 RecTy *GivenEltTy = 0;
1300 GivenEltTy = ParseType();
1301 if (GivenEltTy == 0) {
1307 TokError(
"expected '>' at end of list element type");
1315 for (std::vector<Init *>::iterator i = Vals.begin(), ie = Vals.end();
1326 TokError(
"Incompatible types in list elements");
1334 if (GivenEltTy != 0) {
1338 TokError(
"Incompatible types in list elements");
1346 if (ItemType == 0) {
1355 TokError(
"Element type mismatch for list");
1359 DeducedEltTy = EltTy;
1367 TokError(
"expected identifier in dag init");
1372 if (Operator == 0)
return 0;
1375 std::string OperatorName;
1378 TokError(
"expected variable name in dag operator");
1385 std::vector<std::pair<llvm::Init*, std::string> > DagArgs;
1387 DagArgs = ParseDagArgList(CurRec);
1388 if (DagArgs.empty())
return 0;
1392 TokError(
"expected ')' in dag init");
1414 return ParseOperation(CurRec);
1428 Init *TGParser::ParseValue(
Record *CurRec,
RecTy *ItemType, IDParseMode Mode) {
1429 Init *Result = ParseSimpleValue(CurRec, ItemType, Mode);
1430 if (Result == 0)
return 0;
1435 default:
return Result;
1437 if (Mode == ParseNameMode || Mode == ParseForeachMode)
1443 std::vector<unsigned> Ranges = ParseRangeList();
1444 if (Ranges.empty())
return 0;
1447 std::reverse(Ranges.begin(), Ranges.end());
1450 Error(CurlyLoc,
"Invalid bit range for value");
1456 TokError(
"expected '}' at end of bit range list");
1465 std::vector<unsigned> Ranges = ParseRangeList();
1466 if (Ranges.empty())
return 0;
1468 Result = Result->convertInitListSlice(Ranges);
1470 Error(SquareLoc,
"Invalid range for list slice");
1476 TokError(
"expected ']' at end of list slice");
1484 TokError(
"expected field identifier after '.'");
1489 Result->getAsString() +
"'");
1504 Error(PasteLoc,
"LHS of paste is not typed!");
1528 Init *RHSResult = ParseValue(CurRec, ItemType, ParseNameMode);
1531 Error(PasteLoc,
"RHS of paste is not typed!");
1555 std::vector<std::pair<llvm::Init*, std::string> >
1556 TGParser::ParseDagArgList(
Record *CurRec) {
1557 std::vector<std::pair<llvm::Init*, std::string> > Result;
1567 Init *Val = ParseValue(CurRec);
1569 return std::vector<std::pair<llvm::Init*, std::string> >();
1575 TokError(
"expected variable name in dag literal");
1576 return std::vector<std::pair<llvm::Init*, std::string> >();
1582 Result.push_back(std::make_pair(Val, VarName));
1598 std::vector<Init*> TGParser::ParseValueList(
Record *CurRec,
Record *ArgsRec,
1600 std::vector<Init*> Result;
1601 RecTy *ItemType = EltTy;
1602 unsigned int ArgN = 0;
1603 if (ArgsRec != 0 && EltTy == 0) {
1605 if (!TArgs.size()) {
1606 TokError(
"template argument provided to non-template class");
1607 return std::vector<Init*>();
1611 errs() <<
"Cannot find template arg " << ArgN <<
" (" << TArgs[ArgN]
1614 assert(RV &&
"Template argument record not found??");
1618 Result.push_back(ParseValue(CurRec, ItemType));
1619 if (Result.back() == 0)
return std::vector<Init*>();
1624 if (ArgsRec != 0 && EltTy == 0) {
1626 if (ArgN >= TArgs.size()) {
1627 TokError(
"too many template arguments");
1628 return std::vector<Init*>();
1631 assert(RV &&
"Template argument record not found??");
1635 Result.push_back(ParseValue(CurRec, ItemType));
1636 if (Result.back() == 0)
return std::vector<Init*>();
1653 Init *TGParser::ParseDeclaration(
Record *CurRec,
1654 bool ParsingTemplateArgs) {
1657 if (HasField) Lex.
Lex();
1659 RecTy *Type = ParseType();
1660 if (Type == 0)
return 0;
1663 TokError(
"Expected identifier in declaration");
1671 if (ParsingTemplateArgs) {
1673 DeclName =
QualifyName(*CurRec, CurMultiClass, DeclName,
":");
1675 assert(CurMultiClass);
1678 DeclName =
QualifyName(CurMultiClass->
Rec, CurMultiClass, DeclName,
1683 if (AddValue(CurRec, IdLoc,
RecordVal(DeclName, Type, HasField)))
1690 Init *Val = ParseValue(CurRec, Type);
1692 SetValue(CurRec, ValLoc, DeclName, std::vector<unsigned>(), Val))
1707 VarInit *TGParser::ParseForeachDeclaration(
ListInit *&ForeachListValue) {
1709 TokError(
"Expected identifier in foreach declaration");
1718 TokError(
"Expected '=' in foreach declaration");
1723 RecTy *IterType = 0;
1724 std::vector<unsigned> Ranges;
1727 default:
TokError(
"Unknown token when expecting a range list");
return 0;
1729 Init *List = ParseSimpleValue(0, 0, ParseForeachMode);
1731 if (ForeachListValue == 0) {
1737 if (ListType == 0) {
1738 TokError(
"Value list is not of list type");
1746 if (ParseRangePiece(Ranges))
1753 Ranges = ParseRangeList();
1755 TokError(
"expected '}' at end of bit range list");
1763 if (!Ranges.empty()) {
1764 assert(!IterType &&
"Type already initialized?");
1766 std::vector<Init*> Values;
1767 for (
unsigned i = 0, e = Ranges.size(); i != e; ++i)
1785 bool TGParser::ParseTemplateArgList(
Record *CurRec) {
1789 Record *TheRecToAddTo = CurRec ? CurRec : &CurMultiClass->
Rec;
1792 Init *TemplArg = ParseDeclaration(CurRec,
true);
1802 TemplArg = ParseDeclaration(CurRec,
true);
1809 return TokError(
"expected '>' at end of template argument list");
1819 bool TGParser::ParseBodyItem(
Record *CurRec) {
1821 if (ParseDeclaration(CurRec,
false) == 0)
1825 return TokError(
"expected ';' after declaration");
1832 return TokError(
"expected field identifier after let");
1838 std::vector<unsigned> BitList;
1839 if (ParseOptionalBitList(BitList))
1841 std::reverse(BitList.begin(), BitList.end());
1844 return TokError(
"expected '=' in let expression");
1849 return TokError(
"Value '" + FieldName +
"' unknown!");
1853 Init *Val = ParseValue(CurRec, Type);
1854 if (Val == 0)
return true;
1857 return TokError(
"expected ';' after let expression");
1860 return SetValue(CurRec, IdLoc, FieldName, BitList, Val);
1870 bool TGParser::ParseBody(
Record *CurRec) {
1878 return TokError(
"Expected ';' or '{' to start body");
1883 if (ParseBodyItem(CurRec))
1893 bool TGParser::ApplyLetStack(
Record *CurRec) {
1894 for (
unsigned i = 0, e = LetStack.size(); i != e; ++i)
1895 for (
unsigned j = 0, e = LetStack[i].size(); j != e; ++j)
1896 if (SetValue(CurRec, LetStack[i][j].Loc, LetStack[i][j].Name,
1897 LetStack[i][j].
Bits, LetStack[i][j].
Value))
1911 bool TGParser::ParseObjectBody(
Record *CurRec) {
1920 if (SubClass.
Rec == 0)
return true;
1923 if (AddSubClass(CurRec, SubClass))
1928 SubClass = ParseSubClassReference(CurRec,
false);
1932 if (ApplyLetStack(CurRec))
1935 return ParseBody(CurRec);
1943 bool TGParser::ParseDef(
MultiClass *CurMultiClass) {
1950 Init *Name = ParseObjectName(CurMultiClass);
1952 CurRec =
new Record(Name, DefLoc, Records);
1957 if (!CurMultiClass && Loops.empty()) {
1963 +
"' already defined");
1967 }
else if (CurMultiClass) {
1969 for (
unsigned i = 0, e = CurMultiClass->
DefPrototypes.size(); i != e; ++i)
1973 "' already defined in this multiclass!");
1979 if (ParseObjectBody(CurRec))
1982 if (CurMultiClass == 0)
1989 assert(CurRec->
getTemplateArgs().empty() &&
"How'd this get template args?");
1991 if (CurMultiClass) {
1993 const std::vector<Init *> &TArgs =
1996 for (
unsigned i = 0, e = TArgs.size(); i != e; ++i) {
1998 assert(RV &&
"Template arg doesn't exist?");
2003 if (ProcessForeachDefs(CurRec, DefLoc)) {
2018 bool TGParser::ParseForeach(
MultiClass *CurMultiClass) {
2025 VarInit *IterName = ParseForeachDeclaration(ListValue);
2027 return TokError(
"expected declaration in for");
2034 Loops.push_back(
ForeachLoop(IterName, ListValue));
2038 if (ParseObject(CurMultiClass))
2047 if (ParseObjectList(CurMultiClass))
2051 TokError(
"expected '}' at end of foreach command");
2052 return Error(BraceLoc,
"to match this '{'");
2067 bool TGParser::ParseClass() {
2072 return TokError(
"expected class name after 'class' keyword");
2081 +
"' already defined");
2091 if (ParseTemplateArgList(CurRec))
2095 return ParseObjectBody(CurRec);
2104 std::vector<LetRecord> TGParser::ParseLetList() {
2105 std::vector<LetRecord> Result;
2109 TokError(
"expected identifier in let definition");
2110 return std::vector<LetRecord>();
2117 std::vector<unsigned>
Bits;
2118 if (ParseOptionalRangeList(Bits))
2119 return std::vector<LetRecord>();
2120 std::reverse(Bits.begin(), Bits.end());
2123 TokError(
"expected '=' in let expression");
2124 return std::vector<LetRecord>();
2128 Init *Val = ParseValue(0);
2129 if (Val == 0)
return std::vector<LetRecord>();
2132 Result.push_back(
LetRecord(Name, Bits, Val, NameLoc));
2146 bool TGParser::ParseTopLevelLet(
MultiClass *CurMultiClass) {
2151 std::vector<LetRecord> LetInfo = ParseLetList();
2152 if (LetInfo.empty())
return true;
2153 LetStack.push_back(LetInfo);
2156 return TokError(
"expected 'in' at end of top-level 'let'");
2162 if (ParseObject(CurMultiClass))
2170 if (ParseObjectList(CurMultiClass))
2174 TokError(
"expected '}' at end of top level let command");
2175 return Error(BraceLoc,
"to match this '{'");
2181 LetStack.pop_back();
2195 bool TGParser::ParseMultiClass() {
2200 return TokError(
"expected identifier after multiclass for name");
2203 if (MultiClasses.count(Name))
2204 return TokError(
"multiclass '" + Name +
"' already defined");
2212 if (ParseTemplateArgList(0))
2215 bool inherits =
false;
2225 ParseSubMultiClassReference(CurMultiClass);
2228 if (SubMultiClass.
MC == 0)
return true;
2231 if (AddSubMultiClass(CurMultiClass, SubMultiClass))
2236 SubMultiClass = ParseSubMultiClassReference(CurMultiClass);
2242 return TokError(
"expected '{' in multiclass definition");
2244 return TokError(
"expected ';' in multiclass definition");
2249 return TokError(
"multiclass must contain at least one def");
2254 return TokError(
"expected 'let', 'def' or 'defm' in multiclass body");
2259 if (ParseObject(CurMultiClass))
2284 bool IsAnonymous =
false;
2285 if (DefmPrefix == 0) {
2294 if (DefNameString != 0) {
2306 Locs.append(DefProto->
getLoc().begin(), DefProto->
getLoc().end());
2307 Record *CurRec =
new Record(DefName, Locs, Records, IsAnonymous);
2312 AddSubClass(CurRec, Ref);
2317 if (SetValue(CurRec, Ref.
RefRange.
Start,
"NAME", std::vector<unsigned>(),
2319 Error(DefmPrefixRange.
Start,
"Could not resolve "
2328 if (DefNameString == 0) {
2333 if (!CurMultiClass) {
2351 "' already defined, instantiating defm with subdef '" +
2362 bool TGParser::ResolveMulticlassDefArgs(
MultiClass &MC,
2364 SMLoc DefmPrefixLoc,
2366 const std::vector<Init *> &TArgs,
2367 std::vector<Init *> &TemplateVals,
2371 for (
unsigned i = 0, e = TArgs.size(); i != e; ++i) {
2373 if (i < TemplateVals.size()) {
2375 if (SetValue(CurRec, DefmPrefixLoc, TArgs[i], std::vector<unsigned>(),
2387 return Error(SubClassLoc,
"value not specified for template argument #"+
2388 utostr(i) +
" (" + TArgs[i]->getAsUnquotedString()
2396 bool TGParser::ResolveMulticlassDef(
MultiClass &MC,
2399 SMLoc DefmPrefixLoc) {
2401 if (ApplyLetStack(CurRec))
2402 return Error(DefmPrefixLoc,
"when instantiating this defm");
2409 for (
unsigned i = 0, e = CurMultiClass->
DefPrototypes.size();
2414 "' already defined in this multiclass!");
2418 const std::vector<Init *> &
TA =
2421 for (
unsigned i = 0, e = TA.size(); i != e; ++i) {
2423 assert(RV &&
"Template arg doesn't exist?");
2434 bool TGParser::ParseDefm(
MultiClass *CurMultiClass) {
2437 Init *DefmPrefix = 0;
2440 DefmPrefix = ParseObjectName(CurMultiClass);
2445 return TokError(
"expected ':' after defm identifier");
2448 std::vector<Record*> NewRecDefs;
2451 bool InheritFromClass =
false;
2460 if (Ref.
Rec == 0)
return true;
2466 assert(MC &&
"Didn't lookup multiclass correctly?");
2471 if (TArgs.size() < TemplateVals.size())
2472 return Error(SubClassLoc,
2473 "more template args specified than multiclass expects");
2476 for (
unsigned i = 0, e = MC->
DefPrototypes.size(); i != e; ++i) {
2479 Record *CurRec = InstantiateMulticlassDef(*MC, DefProto, DefmPrefix,
2485 if (ResolveMulticlassDefArgs(*MC, CurRec, DefmLoc, SubClassLoc,
2486 TArgs, TemplateVals,
true))
2487 return Error(SubClassLoc,
"could not instantiate def");
2489 if (ResolveMulticlassDef(*MC, CurRec, DefProto, DefmLoc))
2490 return Error(SubClassLoc,
"could not instantiate def");
2492 NewRecDefs.push_back(CurRec);
2500 return TokError(
"expected identifier");
2502 SubClassLoc = Lex.
getLoc();
2508 if (InheritFromClass)
2511 Ref = ParseSubClassReference(0,
true);
2514 if (InheritFromClass) {
2520 if (SubClass.
Rec == 0)
return true;
2524 for (
unsigned i = 0, e = NewRecDefs.size(); i != e; ++i) {
2525 Record *CurRec = NewRecDefs[i];
2528 if (AddSubClass(CurRec, SubClass))
2531 if (ApplyLetStack(CurRec))
2537 SubClass = ParseSubClassReference(0,
false);
2542 for (
unsigned i = 0, e = NewRecDefs.size(); i != e; ++i)
2546 NewRecDefs[i]->resolveReferences();
2549 return TokError(
"expected ';' at end of defm");
2565 return TokError(
"Expected class, def, defm, multiclass or let definition");
2566 case tgtok::Let:
return ParseTopLevelLet(MC);
2577 bool TGParser::ParseObjectList(
MultiClass *MC) {
2579 if (ParseObject(MC))
2587 if (ParseObjectList())
return true;
2593 return TokError(
"Unexpected input at top level");
static BinOpInit * get(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type)
COFF::RelocationTypeX86 Type
void push_back(const T &Elt)
virtual bool isComplete() const
unsigned getNumBits() const
tgtok::TokKind getCode() const
virtual Init * getBit(unsigned Bit) const
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static UnOpInit * get(UnaryOp opc, Init *lhs, RecTy *Type)
const std::vector< Init * > & getTemplateArgs() const
Init * getElement(unsigned i) const
virtual Init * Fold(Record *CurRec, MultiClass *CurMultiClass) const
virtual std::string getAsUnquotedString() const
const std::string & getName() const
static IntInit * get(int64_t V)
void addSuperClass(Record *R, SMRange Range)
static BitsRecTy * get(unsigned Sz)
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
ArrayRef< SMRange > getSuperClassRanges() const
#define llvm_unreachable(msg)
static StringRecTy * get()
Record * getClass(const std::string &Name) const
const std::string getNameInitAsString() const
static std::string utostr(uint64_t X, bool isNeg=false)
const std::string & getName() const
static BitsInit * get(ArrayRef< Init * > Range)
void resolveReferencesTo(const RecordVal *RV)
virtual Init * convertInitializerTo(RecTy *Ty) const =0
Record * getDef(const std::string &Name) const
int64_t getCurIntVal() const
static VarInit * get(const std::string &VN, RecTy *T)
const std::string & getCurStrVal() const
RecordVector DefPrototypes
const RecordVal * getValue(const Init *Name) const
virtual bool typeIsConvertibleTo(const RecTy *RHS) const =0
static FieldInit * get(Init *R, const std::string &FN)
const std::vector< Record * > & getSuperClasses() const
static bool isObjectStart(tgtok::TokKind K)
isObjectStart - Return true if this is a valid first token for an Object.
Init * QualifyName(Record &CurRec, MultiClass *CurMultiClass, Init *Name, const std::string &Scoper)
const Init * getNameInit() const
void addTemplateArg(Init *Name)
bool Error(SMLoc L, const Twine &Msg) const
ArrayRef< SMLoc > getLoc() const
static StringInit * get(StringRef)
static RecordRecTy * get(Record *R)
Init * getNameInit() const
static DefInit * get(Record *)
const std::vector< RecordVal > & getValues() const
bool isTemplateArg(Init *Name) const
void removeValue(Init *Name)
static std::string GetNewAnonymousName()
std::vector< Init * > TemplateArgs
RecTy * getElementType() const
static DagInit * get(Init *V, const std::string &VN, ArrayRef< Init * > ArgRange, ArrayRef< std::string > NameRange)
bool isSubClassOf(const Record *R) const
virtual Init * convertInitializerBitRange(const std::vector< unsigned > &Bits) const
std::vector< Init * > TemplateArgs
void addValue(const RecordVal &RV)
static TernOpInit * get(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type)
virtual Init * resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) const
RecTy * resolveTypes(RecTy *T1, RecTy *T2)
static ListInit * get(ArrayRef< Init * > Range, RecTy *EltTy)
static ListRecTy * get(RecTy *T)
const std::string & getName() const
LLVM Value Representation.
virtual std::string getAsString() const =0
getAsString - 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