Skip to content
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

add API to get simulation time for debugging #443

Closed
programmerjake opened this issue Jul 22, 2020 · 7 comments
Closed

add API to get simulation time for debugging #443

programmerjake opened this issue Jul 22, 2020 · 7 comments

Comments

@programmerjake
Copy link
Contributor

currently, sim._state.timeline.now must be used for pysim. It would be nice to have an official public API entrypoint for that instead.

@whitequark
Copy link
Member

Sounds reasonable.

@programmerjake
Copy link
Contributor Author

API suggestion:

m = Module()
m.d.sync += Signal().eq(0)
sim = Simulator(m)

def process():
    yield Delay(12345e-6)
    now = sim.now # for use inside or outside processes
    print("current time:", now)
    now = (yield GetTime()) # for use inside processes -- useful when sim is not visible
    print("current time:", now)

sim.add_sync_process(process)
sim.add_clock(1e-6)
with sim.write_vcd("out.vcd", "out.gtkw", traces=[]):
    sim.run()

@whitequark
Copy link
Member

There's a good reason to not expose sim._state.timeline.now as it is: we shouldn't be representing time as floating point in the first place (I don't know what I was thinking when implementing that...) but we really shouldn't be exposing it to consumers.

Regarding GetTime: do you need to programmatically access the time, or do you just want to print it? In the latter case, would yield Display("format...") where the format language includes a substitution for the current time (like in Verilog) work for you?

@whitequark
Copy link
Member

I filed #535 to track the time representation issue.

@programmerjake
Copy link
Contributor Author

Regarding GetTime: do you need to programmatically access the time, or do you just want to print it? In the latter case, would yield Display("format...") where the format language includes a substitution for the current time (like in Verilog) work for you?

We're currently just printing it, though it would be handy to have it (or a formatted version) available in case you want to have the output go somewhere other than stdout, e.g. json output for easy parsing.

@whitequark
Copy link
Member

though it would be handy to have it (or a formatted version) available in case you want to have the output go somewhere other than stdout, e.g. json output for easy parsing.

I was thinking that Simulator would have an API to capture Display statements (as well as Assert, etc) from PySim as well as CXXSim.

@whitequark
Copy link
Member

Closing in favor of being able to print time via Display (including with custom formats), which will be shipped as a part of the Display feature itself, and being able to redirect Display output, which will be likely shipped later.

If new use cases arise we can reconsider this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants