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
This commit is contained in:
Nicolai Haehnle 2018-03-14 11:00:33 +00:00
parent 6c11865638
commit ef60a26817
3 changed files with 14 additions and 16 deletions

View File

@ -178,10 +178,10 @@ supported include:
Due to limitations of the type system, 'children' must be a list of items 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 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 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 Example: !dag(op, [a1, a2, ?], ["name1", "name2", "name3"]) results in
(op a1:$name1, a2:$name2). (op a1:$name1, a2:$name2, ?:$name3).
``!listconcat(a, b, ...)`` ``!listconcat(a, b, ...)``
A list value that is the result of concatenating the 'a' and 'b' lists. A list value that is the result of concatenating the 'a' and 'b' lists.

View File

@ -1676,18 +1676,16 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
RecTy *EltTy = nullptr; RecTy *EltTy = nullptr;
for (Init *V : Vals) { for (Init *V : Vals) {
TypedInit *TArg = dyn_cast<TypedInit>(V); TypedInit *TArg = dyn_cast<TypedInit>(V);
if (!TArg) { if (TArg) {
TokError("Untyped list element"); if (EltTy) {
return nullptr; EltTy = resolveTypes(EltTy, TArg->getType());
} if (!EltTy) {
if (EltTy) { TokError("Incompatible types in list elements");
EltTy = resolveTypes(EltTy, TArg->getType()); return nullptr;
if (!EltTy) { }
TokError("Incompatible types in list elements"); } else {
return nullptr; EltTy = TArg->getType();
} }
} else {
EltTy = TArg->getType();
} }
} }

View File

@ -8,7 +8,7 @@
// CHECK: } // CHECK: }
// CHECK: def A1 { // CHECK: def A1 {
// CHECK: dag ret = (ops 1:$a, 2:$b); // CHECK: dag ret = (ops ?:$a, 1:$b, 2);
// CHECK: } // CHECK: }
// CHECK: def A2 { // CHECK: def A2 {
@ -70,7 +70,7 @@ class B<list<Node> nodes> {
} }
def A0 : Aint<[], []>; 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"]>; def A2 : Adag<[(ops $name), (ops 1), (ops "foo")], ["a", "b", "c"]>;