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] part_select in nested case #86

Closed ShreyanJabade closed 3 years ago

ShreyanJabade commented 3 years ago

Hello, Using part_select with nested case gives Attempting to slice an expression I request you to look into this aspect. Thank you

import vsc 
from vsc import *

@vsc.randobj
class Parent:
    def __init__(self):
        self.id = 0
        self.c1 = vsc.rand_list_t(vsc.attr(Child1()))
        for i in range(10):    
            self.c1.append(vsc.attr(Child1()))

        self.c2 = vsc.rand_list_t(vsc.attr(Child2()))
        for i in range(10):
            self.c2.append(vsc.attr(Child2()))

    # Fails
    @vsc.constraint
    def parent_c(self):
        self.c1[0].test_bit[4:2] == 0

@vsc.randobj
class Field():
    def __init__(self, name, def_value):
        self.name = name
        self.value = vsc.rand_uint8_t(def_value)

@vsc.randobj
class Child1:
    def __init__(self):
        self.a = vsc.rand_list_t(vsc.attr(Field('a', 10)))
        for i in range(5):    
            self.a.append(vsc.attr(Field('a', 10)))

        self.b = vsc.rand_list_t(vsc.attr(Field('b', 10)))
        for i in range(5):    
            self.b.append(vsc.attr(Field('b', 10)))

        #
        self.test_bit =  vsc.rand_bit_t(8)

    @vsc.constraint
    def test_c(self):
        #self.test_bit[4:2] == 0
        self.a[0].value < self.a[1].value

@vsc.randobj
class Child2:
    def __init__(self):
        self.x = vsc.rand_list_t(vsc.attr(Field('x', 10)))
        for i in range(5):    
            self.x.append(vsc.attr(Field('x', 10)))

        self.y = vsc.rand_list_t(vsc.attr(Field('y', 10)))
        for i in range(5):    
            self.y.append(vsc.attr(Field('y', 10)))

    @vsc.constraint
    def test_c(self):
        self.x[0].value < self.x[1].value

inst=Parent()
inst.randomize()
print(f"{inst.c1[0].test_bit:b}")

Output is:

Exception while processing constraint: Attempting to slice an expression

mballance commented 3 years ago

Corrected in 0.4.4. Added support for applying part selects to array-element expressions