我熟悉三元约束:
Keep exp1 ? exp2 : exp3;
如果exp1为真,则exp2保持为真,如果exp1为假,则exp3保持为真。 但是,在我的情况下,exp1可以包含多个值,我希望受到它影响的许多表达式。 因此,并希望所有这一切都通过生成器完成(不是程序性的)。
例如我想要这样的东西:
keep a => a==1 : exp1
a==2 : exp2
a==3: exp3
…
谢谢,
答案 0 :(得分:2)
这种开关盒约束功能没有在specman中实现。 但是,开发人员已经授予我们宏,我们可以实现很多 像这样的创意。
通过使用三元约束的连接,可以轻松实现您要求的switch-case约束:
Keep a==1 ? exp1 : a==2 ? exp2 : exp3;
当然,创建此类约束的宏应该能够处理任意数量的不同情况。 考虑一下这个宏:
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;
};
在这种情况下的用法示例是:
struct s {
id:uint(bits:2);
str:string;
keep map id [0,1,2,3] to str ["id0","id1","id2","id3"]
};
答案 1 :(得分:1)
您可以通过以下结构轻松表达:
keep c_switch is all of {
a==1 => exp1;
a==2 => exp2;
...
};