summaryrefslogtreecommitdiffstats
path: root/llvm/lib/TableGen/TGParser.cpp
diff options
context:
space:
mode:
authorNicolai Haehnle <nhaehnle@gmail.com>2018-03-09 12:24:30 +0000
committerNicolai Haehnle <nhaehnle@gmail.com>2018-03-09 12:24:30 +0000
commit8aa9d5839dbb4d457616a935eb2167ceb0087dfa (patch)
treee5febda9150690cc52ae82ecb324b0447fb0c781 /llvm/lib/TableGen/TGParser.cpp
parent2435855abe6ccb1cd874f0e5e699815a2697b73d (diff)
downloadbcm5719-llvm-8aa9d5839dbb4d457616a935eb2167ceb0087dfa.tar.gz
bcm5719-llvm-8aa9d5839dbb4d457616a935eb2167ceb0087dfa.zip
TableGen: Allow arbitrary list values as ranges of foreach
The changes to FieldInit are required to make field references (Def.field) work inside a ForeachDeclaration: previously, Def.field wasn't resolved immediately when Def was already a fully resolved DefInit. Change-Id: I9875baec2fc5aac8c2b249e45b9cf18c65ae699b llvm-svn: 327120
Diffstat (limited to 'llvm/lib/TableGen/TGParser.cpp')
-rw-r--r--llvm/lib/TableGen/TGParser.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 59f5e6e5866..a60fa90c190 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -1819,7 +1819,7 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
Result->getAsString() + "'");
return nullptr;
}
- Result = FieldInit::get(Result, FieldName);
+ Result = FieldInit::get(Result, FieldName)->Fold();
Lex.Lex(); // eat field name
break;
}
@@ -2038,9 +2038,9 @@ Init *TGParser::ParseDeclaration(Record *CurRec,
/// the name of the declared object or a NULL Init on error. Return
/// the name of the parsed initializer list through ForeachListName.
///
-/// ForeachDeclaration ::= ID '=' '[' ValueList ']'
/// ForeachDeclaration ::= ID '=' '{' RangeList '}'
/// ForeachDeclaration ::= ID '=' RangePiece
+/// ForeachDeclaration ::= ID '=' Value
///
VarInit *TGParser::ParseForeachDeclaration(ListInit *&ForeachListValue) {
if (Lex.getCode() != tgtok::Id) {
@@ -2062,24 +2062,6 @@ VarInit *TGParser::ParseForeachDeclaration(ListInit *&ForeachListValue) {
SmallVector<unsigned, 16> Ranges;
switch (Lex.getCode()) {
- default: TokError("Unknown token when expecting a range list"); return nullptr;
- case tgtok::l_square: { // '[' ValueList ']'
- Init *List = ParseSimpleValue(nullptr);
- ForeachListValue = dyn_cast<ListInit>(List);
- if (!ForeachListValue) {
- TokError("Expected a Value list");
- return nullptr;
- }
- RecTy *ValueType = ForeachListValue->getType();
- ListRecTy *ListType = dyn_cast<ListRecTy>(ValueType);
- if (!ListType) {
- TokError("Value list is not of list type");
- return nullptr;
- }
- IterType = ListType->getElementType();
- break;
- }
-
case tgtok::IntVal: { // RangePiece.
if (ParseRangePiece(Ranges))
return nullptr;
@@ -2096,6 +2078,21 @@ VarInit *TGParser::ParseForeachDeclaration(ListInit *&ForeachListValue) {
Lex.Lex();
break;
}
+
+ default: {
+ SMLoc ValueLoc = Lex.getLoc();
+ Init *I = ParseValue(nullptr);
+ if (!isa<ListInit>(I)) {
+ std::string Type;
+ if (TypedInit *TI = dyn_cast<TypedInit>(I))
+ Type = (Twine("' of type '") + TI->getType()->getAsString()).str();
+ Error(ValueLoc, "expected a list, got '" + I->getAsString() + Type + "'");
+ return nullptr;
+ }
+ ForeachListValue = dyn_cast<ListInit>(I);
+ IterType = ForeachListValue->getElementType();
+ break;
+ }
}
if (!Ranges.empty()) {
OpenPOWER on IntegriCloud