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

@programmerjake programmerjake commented Jul 22, 2020

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

@whitequark whitequark commented Jul 22, 2020

Sounds reasonable.

@programmerjake
Copy link
Contributor Author

@programmerjake programmerjake commented Jul 22, 2020

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

@whitequark whitequark commented Nov 7, 2020

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

@whitequark whitequark commented Nov 7, 2020

I filed #535 to track the time representation issue.

@programmerjake
Copy link
Contributor Author

@programmerjake programmerjake commented Nov 8, 2020

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

@whitequark whitequark commented Nov 8, 2020

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

@whitequark whitequark commented Nov 24, 2020

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.

@whitequark whitequark closed this Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants