tablegen foreach question

What’s the best (most concise) way to create the following four defs?

D0 = (0, “A”)
D1 = (1, “B”)
D2 = (2, “C”)
D3 = (3, “D”)

I tried to use list of strings and the foreach construct, but apparently tablegen doesn’t allow using identifiers to access array elements.

$ cat tbl3.td

def StrList {
list ls = [“A”, “B”, “C”, “D”];
}

class Base0 {
int I = i;
}

class Base1 {
string S1 = s;
}

foreach i = 0-3 in
def D#i: Base0, Base1<StrList.ls[i]>;

$ llvm-tblgen tbl3.td

tbl3.td:15:37: error: expected integer or bitrange
def D#i: Base0, Base1<StrList.ls[i]>;

Akira Hatanaka <ahatanak@gmail.com> writes:

foreach i = 0-3 in
def D#i: Base0<i>, Base1<StrList.ls[i]>;

I can't recall if this works but you might try:

def D#i: Base0<i>, Base1<StrList.ls[#i]>;

That is, paste the value of i against an empty string.

                       -David