Code Monkey home page Code Monkey logo

Comments (4)

mballance avatar mballance commented on June 16, 2024

Hi @ShraddhaDevaiya,
In order to use an expression in a constraint (eg in vsc.if_then), at least one element in the expression needs to be a vsc variable. Several of the variables in the class are non-vsc variables, so expressions evaluate to a constant when the constraint is constructed. The vast majority of the time, this behavior is undesirable in the context of constraints because the constraint is effectively eliminated.
The error message, unfortunately, is not very helpful. I'll look to see whether this can be improved.
Would it work to use vsc variables for has_rs1, has_rs2, format, etc? The constraints would be properly constructed in this case.

Best Regards,
Matthew

from pyvsc.

ShraddhaDevaiya avatar ShraddhaDevaiya commented on June 16, 2024

Yeah, I have tried that way, has_rs1, has_rs2, format as a vsc variables.

@vsc.randobj
class my_sub_s(object):
    def __init__(self):
        self.has_rs1 = vsc.uint8_t(1)
        self.has_rs2 = vsc.uint8_t(1)
        self.has_rd = vsc.uint8_t(1)
        self.avail_regs = vsc.rand_list_t(vsc.uint8_t(0), 10)
        self.reserved_rd = vsc.rand_list_t(vsc.uint8_t(0), 10)
        self.reserved_regs = vsc.rand_list_t(vsc.uint8_t(0), 10)
        self.rd = vsc.rand_uint8_t(0)
        self.rs1 = vsc.rand_uint8_t(0)
        self.rs2 = vsc.rand_uint8_t(0)
        self.format = vsc.uint8_t(2)

obj = my_sub_s()

with obj.randomize_with() as it:
            with vsc.if_then(obj.avail_regs.size > 0): 
                with vsc.if_then(obj.has_rs1):
                    obj.rs1.inside(vsc.rangelist(obj.avail_regs))
                with vsc.if_then(obj.has_rs2):
                    obj.rs2.inside(vsc.rangelist(obj.avail_regs))
                with vsc.if_then(obj.has_rd):
                    obj.rd.inside(vsc.rangelist(obj.avail_regs))   
            with vsc.foreach(obj.reserved_rd, idx = True) as i:
                with vsc.if_then(obj.has_rd):
                    obj.rd != obj.reserved_rd[i]
                with vsc.if_then(obj.format == 2):
                    obj.rs1 != obj.reserved_rd[i]
            with vsc.foreach(obj.reserved_regs, idx = True) as i:
                with vsc.if_then(obj.has_rd):
                    obj.rd != obj.reserved_regs[i]
                with vsc.if_then(obj.format == 2):
                    obj.rs1 != obj.reserved_regs[i]

But then also it is giving an error like following:

Traceback (most recent call last):
  File "9usecase.py", line 36, in <module>
    obj.rs1 != obj.reserved_regs[i]
  File "/home/adduser/.local/lib/python3.8/site-packages/vsc/rand_obj.py", line 186, in __exit__
    Randomizer.do_randomize([model], [c])
  File "/home/adduser/.local/lib/python3.8/site-packages/vsc/model/randomizer.py", line 694, in do_randomize
    constraint_l.extend(ArrayConstraintBuilder.build(
  File "/home/adduser/.local/lib/python3.8/site-packages/vsc/visitors/array_constraint_builder.py", line 45, in build
    m.accept(builder)
  File "/home/adduser/.local/lib/python3.8/site-packages/vsc/model/constraint_block_model.py", 
line 42, in accept
    v.visit_constraint_block(self)
  File "/home/adduser/.local/lib/python3.8/site-packages/vsc/visitors/constraint_copy_builder.py", line 85, in visit_constraint_block
    super().visit_constraint_block(c)
  File "/home/adduser/.local/lib/python3.8/site-packages/vsc/model/model_visitor.py", line 102, in visit_constraint_block
    self.visit_constraint_scope(c)
  File "/home/adduser/.local/lib/python3.8/site-packages/vsc/visitors/constraint_override_visitor.py", line 26, in visit_constraint_scope
    cc.accept(self)
  File "/home/adduser/.local/lib/python3.8/site-packages/vsc/model/constraint_foreach_model.py", line 47, in accept
    v.visit_constraint_foreach(self)
  File "/home/adduser/.local/lib/python3.8/site-packages/vsc/visitors/array_constraint_builder.py", line 61, in visit_constraint_foreach
    self.override_constraint(scope)
  File "/home/adduser/.local/lib/python3.8/site-packages/vsc/visitors/constraint_override_visitor.py", line 37, in override_constraint
    self.scope_s[-1].constraint_l[self.scope_i],
IndexError: list index out of range

What can I do for this ?

Thanks & Regards,
Shraddha Devaiya.

from pyvsc.

mballance avatar mballance commented on June 16, 2024

Hi @ShraddhaDevaiya,
Okay, thanks for confirming, and thanks for the testcase. I'm investigating now and will let you know what I find.

Best Regards,
Matthew

from pyvsc.

mballance avatar mballance commented on June 16, 2024

Hi @ShraddhaDevaiya,
The testcase was very helpful. It turns out there was an issue with nesting and combining if_then and foreach in certain ways. I've corrected the issue and your testcase (now part of the test suite) now passes. Release 0.2.6 contains the fix.

Thanks and Best Regards,
Matthew

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.