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 an RFC for Print statement and string formatting. #50

Merged
merged 1 commit into from
Mar 4, 2024

Conversation

wanda-phi
Copy link
Member

@whitequark whitequark added meta:nominated Nominated for discussion on the next relevant meeting area:core RFC affecting APIs in amaranth-lang/amaranth labels Mar 1, 2024
@whitequark
Copy link
Member

We have discussed this RFC on the 2024-03-04 weekly meeting. The disposition was to merge, with the following changes:

  • Clarify that the first character of a string is stored in the least significant bits of a string (which is the inverse of what Verilog does).
  • Define __format__ on Value to prevent unintentional misuse of f-strings that will not result in the desired effect (it will insert the AST dump instead of the runtime value into the string).

@whitequark whitequark removed the meta:nominated Nominated for discussion on the next relevant meeting label Mar 4, 2024
@whitequark whitequark merged commit c36f781 into amaranth-lang:main Mar 4, 2024
@wanda-phi wanda-phi deleted the print branch March 4, 2024 18:58
@lekcyjna123
Copy link

Hi,
in "Future possibilities" you have pointed to:

  • Some kind of output redirection or output hook could be implemented in pysim.
  • Likewise, a hook for assertion failure could be desirable.
  • Some way to print the current simulation time could be useful.

Maybe you will be interested in kuznia-rdzeni/coreblocks#595 where we have recently added logging possibility with syntax similar to the python logging library. There is integration with pysim and cocotb simulators. The printing is handled in separate simulation process so we have a possibility to inject custom callable on having error print. There is also simulation time printed.

The code is not very strictly bound to the transactron framework. Only the DependencyContext is used (something like global variable), so I think that it can be possible to integrate our solution with Amaranth if you wish.

@tilk @xThaid please look on this RFC and RFC 58.

@whitequark
Copy link
Member

Note that Print is designed to be synthesizable so that it can also be used with CXXRTL or exported to Verilog for use with Verilator, etc. It is explicitly not desired to introduce features that would only be implementable in a Python simulation but not in these other contexts.

In light of this, I think your logging functionality would probably need to reserve the beginning of the string for metadata, which can be then filtered by means of capturing and processing the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:core RFC affecting APIs in amaranth-lang/amaranth
Development

Successfully merging this pull request may close these issues.

3 participants