Code Monkey home page Code Monkey logo

Comments (5)

mballance avatar mballance commented on July 18, 2024 1

Thanks for raising the question, @SkAditAziz. Can you supply a testcase/example that exposes a problem with this code?
The intent is to detect whether the type specified to vsc.rand_attr() is derived from an enum type. Python plays some games with enumerated types, which (if I remember correctly) is why vsc is checking for the meta-class type.

from pyvsc.

mballance avatar mballance commented on July 18, 2024 1

This is an interesting case, @SkAditAziz. Thanks for sharing.
You want to constrain a set of values using an enumerated-type declaration. Now, PyVSC doesn't support directly specifying this. However, it does support specifying 'inside' on a list of values, and Python supports iterating over enumerators. Here is the last part of your testcase showing this approach:

        @vsc.randobj
        class my_item:
            def __init__(self):
                self.loop_cnt_reg = vsc.randsz_list_t(vsc.enum_t(riscv_reg_t))
                self.loop_init_val = vsc.randsz_list_t(vsc.int32_t())
        
            @vsc.constraint
            def loop_c(self):
                self.loop_init_val.size.inside(vsc.rangelist(1, 2))
                self.loop_cnt_reg.size.inside(vsc.rangelist(1, 2))
                self.loop_cnt_reg.size == self.loop_init_val.size
                with vsc.foreach(self.loop_init_val, idx = True ) as i:
                    self.loop_cnt_reg[i].inside(vsc.rangelist(list(compressed_gpr)))
        
        obj = my_item()
        obj.randomize()

Note that I have made two changes beyond wrapping 'compressed_gpr' with a list:

  • Constrained the size of loop_cnt_reg to be the same as loop_init_val, and limited the size. PyVSC currently is a bit limited in terms of calculating the max size of lists, so a bit of extra hinting is in order.
  • Added a call to 'randomize' at the end of the example

With these changes, the example runs correctly. Let me know if this approach works for you.

Thanks,
Matthew

from pyvsc.

SkAditAziz avatar SkAditAziz commented on July 18, 2024

I was working with riscv-dv and got this issue. Now I have made a demo code portraying the problem. Please check it:

import vsc
from enum import Enum, IntEnum, auto

class riscv_reg_t(IntEnum):
    ZERO = 0
    RA = auto()
    SP = auto()
    GP = auto()
    TP = auto()
    T0 = auto()
    T1 = auto()
    T2 = auto()
    S0 = auto()
    S1 = auto()
    A0 = auto()
    A1 = auto()
    A2 = auto()
    A3 = auto()
    A4 = auto()
    A5 = auto()
    A6 = auto()
    A7 = auto()
    S2 = auto()
    S3 = auto()
    S4 = auto()
    S5 = auto()
    S6 = auto()
    S7 = auto()
    S8 = auto()
    S9 = auto()
    S10 = auto()
    S11 = auto()
    T3 = auto()
    T4 = auto()
    T5 = auto()
    T6 = auto()

class compressed_gpr(IntEnum):
    S0 = 8
    S1 = auto()
    A0 = auto()
    A1 = auto()
    A2 = auto()
    A3 = auto()
    A4 = auto()
    A5 = auto()

@vsc.randobj
class my_item:
    def __init__(self):
        self.loop_cnt_reg = vsc.randsz_list_t(vsc.enum_t(riscv_reg_t))
        self.loop_init_val = vsc.randsz_list_t(vsc.int32_t())

    @vsc.constraint
    def loop_c(self):
        self.loop_init_val.size.inside(vsc.rangelist(1, 2))
        with vsc.foreach(self.loop_init_val, idx = True ) as i:
            self.loop_cnt_reg[i].inside(vsc.rangelist(compressed_gpr))

print("Using isinstance(t,type)")
print(isinstance(compressed_gpr,(EnumMeta, IntEnum)))

print("Using isinstance(type(t),type)")
print(isinstance(type(compressed_gpr),(EnumMeta, IntEnum)))

obj = my_item()
obj.loop_c()

from pyvsc.

mballance avatar mballance commented on July 18, 2024

Thanks for the testcase, @SkAditAziz. I would not have expected this code to trigger a bug in the code (ie looks fine to me). I'll investigate.

from pyvsc.

SkAditAziz avatar SkAditAziz commented on July 18, 2024

@mballance Thanks for your feedback. Its working now. Wrapping 'compressed_gpr' with a list solves the issue in the riscv-dv code.

from pyvsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.