Currently, some TableGen expressions are forced to use multiple embedded '!if' which makes the the expression cumbersome. Below is an example (from an actual td file):
list<SubRegIndex> ret = !if(!eq(size, 2), ret2, !if(!eq(size, 3), ret3, !if(!eq(size, 4), ret4, !if(!eq(size, 8), ret8, ret16))));
This patch will allow such expession to be more easily written as:
list<SubRegIndex> ret =
!ifs(!eq(size, 2) : ret2, !eq(size, 3) : ret3, !eq(size, 4) : ret4, !eq(size, 8) : ret8, default: ret16);
The default can appear in the begining, end or anywhere within the !ifs.
The grammer of !ifs is :
SimpleValue ::= IFS '(' [Value ':' Value,]+ DEFAULT ':' Value ')'
We could call 'ifs' 'switch' although it is slightly different from C language switch as the case value is not a constant.
Some of the tests below are ported from !if as those check are required of !ifs as well.
`!ifs(cond1: val1, cond2 : val2, ..., default : valn)`
Instead of embedding !if inside !if which can get cumbersome, one can use !ifs. !ifs returns 'val1' if the result of 'int' or 'bit' operator 'cond1' is nonzero. Otherwise, checks 'cond2'. If 'cond2' is nonzero, returns 'val2', and so on. If all conditions are zero, the default value 'valn' is returned. The default value can appear anywhere, but there must be one and only one default value. Below is an example to convert an integer 'x' into string form: string S = !ifs(!lt(x,0) : "Negative", !eq(x,0) : "zero", !eq(x,1) : "one", default : "MoreThanOne");
I've just remembered that docs/TableGen/LangRef.rst contains a BNF description of the entire TableGen grammar, which should be updated if you're adding a new !foo operator at all (it includes a list of them all in the production for BangOperator). In this case, your new operator doesn't even have the same syntax as the rest of them, because of the unprecedented colon that separates the halves of each case, so it'll need a whole extra grammar rule :-)