Re: [myhdl-list] Global state and multiple instances
Brought to you by:
jandecaluwe
From: Henry G. <he...@ca...> - 2015-05-07 14:10:28
|
On 06/05/15 09:18, Henry Gomersall wrote: > In light of a PR I submitted last week, I have an idea to try... I'll > try to get some code later on... I've implemented a partial solution... https://github.com/hgomersall/myhdl/tree/globals_free_sim It's fairly clean and shouldn't break _too_ much. Most of the changes are in _simulator.py. It works by creating a context which can be used to store all the current simulation variables. So whenever access to the simulation variables is required, the context manager is used: with _simulator.simulation_context(some_hashable): do the simulation stuff here There is a default context which it falls back to when not inside the context manager. All the core tests pass except two, in the tracing stuff. The issue here is that the simulation now uses its own context which the tracing code doesn't know about, so the variables are not shared. This is just an API issue so I haven't tried to fix it (i.e. what are peoples opinion, assuming the general approach is good). The other problem is the state on a Signal object is not being handled properly. I tried to implement the solution for this (currently commented out in _simulator.py) in which on each context switch, the signals are stashed (using _Signal._stash_state) to the context that is being departed, and then the signal state is reloaded when it is reentered (susing _Signal._recall_state). The tests begin to work and then one gets into an infinite loop because some waiter or other is missing. I'm not sure quite what I've missed. This is hard to bug isolate because the tests all run in isolation or indeed, in their respective test classes. Also, the signal code really hits performance, so it needs a bit of a reassessment from that perspective too. I'd appreciate feedback on this approach. Cheers, Henry |