summaryrefslogtreecommitdiffstats
path: root/llvm/lib/TableGen/TGParser.cpp
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2012-05-24 22:17:39 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2012-05-24 22:17:39 +0000
commit36a5c8e55074b76eff6ddaf962413ad779c540b2 (patch)
tree68213715b0179f8a4f3f813286e8c75474c7113d /llvm/lib/TableGen/TGParser.cpp
parent74fd80e8fc5866f12818b3b54c6099efde871527 (diff)
downloadbcm5719-llvm-36a5c8e55074b76eff6ddaf962413ad779c540b2.tar.gz
bcm5719-llvm-36a5c8e55074b76eff6ddaf962413ad779c540b2.zip
Add support for range expressions in TableGen foreach loops.
Like this: foreach i = 0-127 in ... Use braces for composite ranges: foreach i = {0-3,9-7} in ... llvm-svn: 157432
Diffstat (limited to 'llvm/lib/TableGen/TGParser.cpp')
-rw-r--r--llvm/lib/TableGen/TGParser.cpp65
1 files changed, 50 insertions, 15 deletions
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index b23f4100136..94246778007 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -1697,7 +1697,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 '=' Value
+/// ForeachDeclaration ::= ID '=' '[' ValueList ']'
+/// ForeachDeclaration ::= ID '=' '{' RangeList '}'
+/// ForeachDeclaration ::= ID '=' RangePiece
///
VarInit *TGParser::ParseForeachDeclaration(ListInit *&ForeachListValue) {
if (Lex.getCode() != tgtok::Id) {
@@ -1715,26 +1717,59 @@ VarInit *TGParser::ParseForeachDeclaration(ListInit *&ForeachListValue) {
}
Lex.Lex(); // Eat the '='
- // Expect a list initializer.
- Init *List = ParseSimpleValue(0, 0, ParseForeachMode);
+ RecTy *IterType = 0;
+ std::vector<unsigned> Ranges;
- ForeachListValue = dynamic_cast<ListInit*>(List);
- if (ForeachListValue == 0) {
- TokError("Expected a Value list");
- return 0;
+ switch (Lex.getCode()) {
+ default: TokError("Unknown token when expecting a range list"); return 0;
+ case tgtok::l_square: { // '[' ValueList ']'
+ Init *List = ParseSimpleValue(0, 0, ParseForeachMode);
+ ForeachListValue = dynamic_cast<ListInit*>(List);
+ if (ForeachListValue == 0) {
+ TokError("Expected a Value list");
+ return 0;
+ }
+ RecTy *ValueType = ForeachListValue->getType();
+ ListRecTy *ListType = dynamic_cast<ListRecTy *>(ValueType);
+ if (ListType == 0) {
+ TokError("Value list is not of list type");
+ return 0;
+ }
+ IterType = ListType->getElementType();
+ break;
}
- RecTy *ValueType = ForeachListValue->getType();
- ListRecTy *ListType = dynamic_cast<ListRecTy *>(ValueType);
- if (ListType == 0) {
- TokError("Value list is not of list type");
- return 0;
+ case tgtok::IntVal: { // RangePiece.
+ if (ParseRangePiece(Ranges))
+ return 0;
+ break;
+ }
+
+ case tgtok::l_brace: { // '{' RangeList '}'
+ Lex.Lex(); // eat the '{'
+ Ranges = ParseRangeList();
+ if (Lex.getCode() != tgtok::r_brace) {
+ TokError("expected '}' at end of bit range list");
+ return 0;
+ }
+ Lex.Lex();
+ break;
+ }
}
- RecTy *IterType = ListType->getElementType();
- VarInit *IterVar = VarInit::get(DeclName, IterType);
+ if (!Ranges.empty()) {
+ assert(!IterType && "Type already initialized?");
+ IterType = IntRecTy::get();
+ std::vector<Init*> Values;
+ for (unsigned i = 0, e = Ranges.size(); i != e; ++i)
+ Values.push_back(IntInit::get(Ranges[i]));
+ ForeachListValue = ListInit::get(Values, IterType);
+ }
+
+ if (!IterType)
+ return 0;
- return IterVar;
+ return VarInit::get(DeclName, IterType);
}
/// ParseTemplateArgList - Read a template argument list, which is a non-empty
OpenPOWER on IntegriCloud