nickg / nvc

VHDL compiler and simulator
https://www.nickg.me.uk/nvc/
GNU General Public License v3.0
589 stars 75 forks source link

COCOTB : Unable to acess VHDL packages. #891

Closed aqeelmahroof closed 1 month ago

aqeelmahroof commented 1 month ago

Hi,

It's common to have constants defined in VHDL packages. Based on cocotb issue 1833, the only way to access the packages is using

my_pkg = cocotb.handle.SimHandle(cocotb.simulator.get_root_handle("my_pkg"))

In NVC, there seems to be a check, which doesn't allow this. When Cocotb tries to access the package, it gives the following error:

2.00ns WARNING  gpi                                VHPI: DUT 'MY_DUT' doesn't match requested toplevel my_pkg 
2.00ns ERROR    gpi                                No root handle found
2.00ns INFO     cocotb.regression                  pu_filter_random_test.basic_pu_filter_test failed
                                                   Traceback (most recent call last):
                                                     File "/cocotb/regression.py", line 158, in func
                                                       res = await cocotb.triggers.with_timeout(
                                                     File "/cocotb/triggers.py", line 1014, in with_timeout
                                                       res = await First(timeout_timer, trigger)
                                                     File "/cocotb/triggers.py", line 902, in _wait
                                                       return await first_trigger  # the first of multiple triggers that fired
                                                     File "/cocotb/triggers.py", line 136, in __await__
                                                       return (yield self)
                                                     File "/cocotb/task.py", line 235, in __await__
                                                       return (yield self)
                                                     File "my_test.py", line 98, in run_phase
                                                       my_pkg = cocotb.handle.SimHandle(cocotb.simulator.get_root_handle("my_pkg"))
                                                     File "/cocotb/handle.py", line 1033, in SimHandle
                                                       t = handle.get_type()
                                                   AttributeError: 'NoneType' object has no attribute 'get_type'

nvc version

nvc 1.13-devel (1.12.0.r41.g3edb4fec) (Using LLVM 14.0.0)
Copyright (C) 2011-2024  Nick Gasson

cocotb version = 2.0.0.dev0+65d102f2

Is it possible to relax that check ?

nickg commented 1 month ago

I've added support for accessing package constants through VHPI but it needs some cocotb changes as well, see cocotb/cocotb#3899.