-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse vpi_user.h to extract all defines. #41
Conversation
…ator Namespace so they can be used from Python code (e.g., simulator.vpiNet)
The problem here is that we break the abstraction of GPI if we introduce any VPI names into Python. We want it to be possible to use cocotb with other simulator interfaces like VHPI since VPI isn't always available. The GPI (Generic Procedural Interface) layer is supposed to provide an abstraction to the simulator module such that in Python no VPI is exposed. To address issue #17 and (issue #40) I was going to propose something like the following:
Your walk_nets test would then look like this: @cocotb.test()
def walk_nets(dut):
for thing in dut:
if isinstance(thing, SignalHandle):
thing.log.info("Found signal with value %s" % repr(thing.value)) That way we provide a more "Pythonic" API to iterating the design and preserve the abstraction so that no understanding of VPI is required inside Python itself. |
I get the goal of trying to wrap the VPI into a GPI so that you have a generic/ retargetable API that can also encapsulate the VHDL interfaces in a similar way and even mix/ match across simulations. I think trying to do wrapped objects for every type is going to introduce a whole lot of types though (there look to be 70 iterateable object types in the IEEE spec for the VPI. What I've found useful in the past was something like : http://www.fivecomputers.com/2012/05/simplified-vpi-iterators-using-pyhvl-generators.html where the vpi_iterator/ vpi_scan are exposed, then wrapped in a Python generator, so something like def vpi_iterator(handle, type=vpiNet): Then you can define def module_iterator(handle): etc for each type of iterator and you can then use them in a similar way to the*Handle objects and have a decent Pythonic interface for module in module_iterator(SimHandle) One solution would maybe be to expose a gpi_iterator / gpi_scan interface (basically what you have although it's currently limited to gpiNet and add the extra types? |
I'm assuming that most of the iterable types defined in vpi aren't really useful though so the overhead of defining abstract GPI equivalents shouldn't be too bad... Which iterator types have you used / might you use? |
True, there are some pretty obvious ones (Net Module), but for the others It would be good if there was an escape hatch left that would allow for a On Wed, Jul 10, 2013 at 4:36 PM, chiggs notifications@github.com wrote:
Gordon McGregor |
Take a look at 3b7a7c2. I think this does what you want - it's still possible to pass in a value if you know it but the common cases are abstracted. I still need to create different subtypes of SimHandle so that it's possible to filter using isinstance() |
Yes, that looks like it opens things up enough to allow what I need and Gordon On Thu, Jul 11, 2013 at 11:03 AM, chiggs notifications@github.com wrote:
|
Fixes cocotb#40: Don't assume the iterable has a length
Fixes cocotb#40: Don't assume the iterable has a length
Add those defines into simulator Namespace so they can be used from Python code (e.g., simulator.vpiNet)
The longer term plan for this is to expose the vpi_iterator/ vpi_scan methods so that any of the vpi* types can be scanned.
Auto generating the VPI defines to load into the simulator Dictionary helps avoid any mismatch in the simulators with the IEEE standard.
I realise some of these are already in the local vpi_user.h - probably needs to be resolved?
Sending as a pull request but happy to discuss the idea further - this shows the general approach.