我可以设置一次变量的约束并在specman中生成几次吗?

时间:2008-12-05 07:32:23

标签: specman

我有一个变量,我想在同一个函数中生成几次,每次使用相同的约束集。我可以设置一次约束,只设置gen一次吗?也就是说,而不是:

var a:uint;
gen a keeping {it in [100..120];};
// some code that uses a
.
.
.
gen a keeping {it in [100..120];};
// some code that uses a
.
.
.
gen a keeping {it in [100..120];};
// some code that uses a
// etc...

我想这样做:

var a:uint;
keep a in [100..120];
.
.
.
gen a;
// some code that uses a
.
.
.
gen a;
// some code that uses a
.
.
.
gen a;
// some code that uses a
// etc...

这样,如果我想改变a的约束,我只需要做一次。

1 个答案:

答案 0 :(得分:1)

您可以通过使变量成为封闭对象的实例成员来完成此操作。

a : uint;
keep a in [100..120];
my_method()@qualified_clk_rise_e is {

    gen a;
    ...
    gen a;
    ...
    gen a; 
};

如果多个my_method()同时在同一个对象上运行,则此实现不是线程安全的。您可以通过将生成的“a”分配给'my_a来使[specman]线程安全'在方法范围内:

var my_a : uint;
gen a;
my_a = a;

或者你可以写一个方法来生成'a':

gen_a(): uint is {
    gen result keeping { it in [100..120] };
};

my_method()@qualified_clock_rise_e is {
    var a : uint;
    ...
    a = gen_a();
    ...
    a = gen_a();
    ...
    a = gen_a();
    ...
};