Can I set constraints on a variable once and create multiple times in specman?

I have a variable that I want to generate multiple times in the same function, each time with the same set of constraints. Can I set limits once and just gen

do it many times? That is, instead of this:

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...

      

I would like to do this:

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...

      

This way, if I want to change the constraints a

, I only need to do it once.

+1


source to share


1 answer


You can do this by making the variable a member of an instance of the surrounding object.

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

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

      

This implementation is not thread safe if multiple my_method () are executed concurrently on the same object. You can make this [specman] thread safe by assigning the generated "a" to "my_a" inside the scope of the method:



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

      

Or you can just write a method to generate '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();
    ...
};

      

+1


source







All Articles