fvutils / pyvsc

Python packages providing a library for Verification Stimulus and Coverage
https://fvutils.github.io/pyvsc
Apache License 2.0
113 stars 26 forks source link

[Low] Inheritance in constraint blocks #91

Closed ShreyanJabade closed 3 years ago

ShreyanJabade commented 3 years ago

Hello, The same example used in readthedocs for inheritance gives an error.

I request you to look into this aspect. Thank you

@vsc.randobj
class my_base_s(object):

    def __init__(self):
        self.a = vsc.rand_bit_t(8)
        self.b = vsc.rand_bit_t(8)
        self.c = vsc.rand_bit_t(8)
        self.d = vsc.rand_bit_t(8)

    @vsc.constraint
    def ab_c(self):
       self.a < self.b

@vsc.randobj
class my_ext_s(my_base_s):

    def __init__(self):
        super().__init__()
        self.a = vsc.rand_bit_t(8)
        self.b = vsc.rand_bit_t(8)
        self.c = vsc.rand_bit_t(8)
        self.d = vsc.rand_bit_t(8)

    @vsc.constraint
    def ab_c(self):
       self.a > self.b

inst = my_ext_s()
inst.randomize()
print(inst.a)

Output is:

int() argument must be a string, a bytes-like object or a number, not 'rand_bit_t'

mballance commented 3 years ago

This example highlights an interesting case, since the inheriting class is re-defining fields that were previously defined by the base class. I've corrected the operator overloading logic to support re-assigning.