diff options
author | Nicolai Haehnle <nhaehnle@gmail.com> | 2018-03-14 11:00:33 +0000 |
---|---|---|
committer | Nicolai Haehnle <nhaehnle@gmail.com> | 2018-03-14 11:00:33 +0000 |
commit | ef60a26817c68539125242b1b3cbf91fb850b657 (patch) | |
tree | 29591c18415f415a984df96cf31f9acabfd9df40 | |
parent | 6c118656380f5ee8827e73fb6e4fc5aa0950dee4 (diff) | |
download | bcm5719-llvm-ef60a26817c68539125242b1b3cbf91fb850b657.tar.gz bcm5719-llvm-ef60a26817c68539125242b1b3cbf91fb850b657.zip |
TableGen: Allow ? in lists
This makes using !dag more convenient in some cases.
Change-Id: I0a8c35e15ccd1ecec778fd1c8d64eee38d74517c
Differential revision: https://reviews.llvm.org/D44111
llvm-svn: 327493
-rw-r--r-- | llvm/docs/TableGen/LangIntro.rst | 6 | ||||
-rw-r--r-- | llvm/lib/TableGen/TGParser.cpp | 20 | ||||
-rw-r--r-- | llvm/test/TableGen/dag-functional.td | 4 |
3 files changed, 14 insertions, 16 deletions
diff --git a/llvm/docs/TableGen/LangIntro.rst b/llvm/docs/TableGen/LangIntro.rst index a4b198b8958..1f9b44586d9 100644 --- a/llvm/docs/TableGen/LangIntro.rst +++ b/llvm/docs/TableGen/LangIntro.rst @@ -178,10 +178,10 @@ supported include: Due to limitations of the type system, 'children' must be a list of items of a common type. In practice, this means that they should either have the same type or be records with a common superclass. Mixing dag and non-dag - items is not possible. + items is not possible. However, '?' can be used. - Example: !dag(op, [a1, a2], ["name1", "name2"]) results in - (op a1:$name1, a2:$name2). + Example: !dag(op, [a1, a2, ?], ["name1", "name2", "name3"]) results in + (op a1:$name1, a2:$name2, ?:$name3). ``!listconcat(a, b, ...)`` A list value that is the result of concatenating the 'a' and 'b' lists. diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index 629320975a6..0dd4da416d9 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -1676,18 +1676,16 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, RecTy *EltTy = nullptr; for (Init *V : Vals) { TypedInit *TArg = dyn_cast<TypedInit>(V); - if (!TArg) { - TokError("Untyped list element"); - return nullptr; - } - if (EltTy) { - EltTy = resolveTypes(EltTy, TArg->getType()); - if (!EltTy) { - TokError("Incompatible types in list elements"); - return nullptr; + if (TArg) { + if (EltTy) { + EltTy = resolveTypes(EltTy, TArg->getType()); + if (!EltTy) { + TokError("Incompatible types in list elements"); + return nullptr; + } + } else { + EltTy = TArg->getType(); } - } else { - EltTy = TArg->getType(); } } diff --git a/llvm/test/TableGen/dag-functional.td b/llvm/test/TableGen/dag-functional.td index 8a5fa8b4b02..b9be2bf6b09 100644 --- a/llvm/test/TableGen/dag-functional.td +++ b/llvm/test/TableGen/dag-functional.td @@ -8,7 +8,7 @@ // CHECK: } // CHECK: def A1 { -// CHECK: dag ret = (ops 1:$a, 2:$b); +// CHECK: dag ret = (ops ?:$a, 1:$b, 2); // CHECK: } // CHECK: def A2 { @@ -70,7 +70,7 @@ class B<list<Node> nodes> { } def A0 : Aint<[], []>; -def A1 : Aint<[1, 2], ["a", "b"]>; +def A1 : Aint<[?, 1, 2], ["a", "b", ?]>; def A2 : Adag<[(ops $name), (ops 1), (ops "foo")], ["a", "b", "c"]>; |