1
votes

I would like to add a new input to an existing method, but do not change all previous calls to the method. Does Specman support optional parameters to a method? Like in C++:

void cpp_func(int bla, int foo = 0) {
   //do something ...
};

and then you can call it both cpp_func(10) and cpp_func(10, 0). Really appreciate any help.

2

2 Answers

4
votes

Yes, Specman supports default value expressions in method parameters.

For example, the following code:

extend sys {
    goo() : uint is { return 111; };
    boo() : uint is { return 222; };

    foo(x: uint, y: uint = 100, z: uint = boo() + goo()) is {
        print x;
        print y;
        print z;
    };

    run() is only {
        foo(11);
        foo(11,22);
        foo(11,22,33);
    };
};

Will result in:

  x = 11
  y = 100
  z = 333

  x = 11
  y = 22
  z = 333

  x = 11
  y = 22
  z = 33
0
votes

You can also do the following:

Have to set default value of parameter that is "optional" (exp_fail: bit = 1).

 check_bit(field: field_to_be_checked, exp_fail: bit = 1)@driver.clock is{};

So by default it will be 1, and you don't need to pass it:

check_bist_in_reg(BIT_NUM);

if you want to, just pass it like normal:

check_bist_in_reg(BIT_NUM, 0);