Reputation: 21
I am familiar with the ternary constraints:
Keep exp1 ? exp2 : exp3;
Where exp2 is kept true if exp1 is true, and exp3 is kept true if exp1 is false. However, in my case exp1 can hold multiple values, and I would like to that many expressions affected by it. accordingly, and would like all this to be done through the generator (not procedurally).
For example I would like something like this:
keep a => a==1 : exp1
a==2 : exp2
a==3: exp3
…
Thanks,
Upvotes: 1
Views: 495
Reputation: 700
You can express this easily in a structured way as:
keep c_switch is all of {
a==1 => exp1;
a==2 => exp2;
...
};
Upvotes: 1
Reputation: 331
Such switch-case constraining capabilities are not implemented in specman. However, the developers have granted us with macros with which we can realize many Creative ideas such as this one.
The switch-case constraint that you are asking for can be easily implemented by using concatenation of ternary constraints:
Keep a==1 ? exp1 : a==2 ? exp2 : exp3;
Of course, a macro that will create such constraints should be able to handle any number of different cases. Consider this macro:
define <switch_case_gen'struct_member> "keep map <exp> \[<exp>,...\] to <exp> \[<exp>,...\]" as computed {
var num_s:string = str_expand_dots(<2>);
var str_s: string = str_expand_dots(<4>);
var ln:list of string = str_split(num_s,",");;
var ls:list of string = str_split(str_s,",");
if (ln.size() != ls.size()) {
error("keep map - you need to specify an equal number for items for both lists");
};
if (ln.size()<2) {
error("keep map - this macro should recieve lists of at least size 2");
};
var constraint:string;
constraint="keep ";
for each in ln {
if (index == ln.size()-1) {constraint = append(constraint,<3>,"==",ls[index],";");}
else {constraint = append(constraint,<1>,"==",ln[index]," ? ", <3>,"==",ls[index],":");};
};
out("parsed constraint is : ",constraint);
return constraint;
};
A usage example in this case would be :
struct s {
id:uint(bits:2);
str:string;
keep map id [0,1,2,3] to str ["id0","id1","id2","id3"]
};
Upvotes: 2