Skip to content

Conversation

@RyanGlScott
Copy link
Contributor

To do so, we parse cell parameter values more generally to accept all possible JSON values, and then we refine the code which parses *_SIGNED parameters to accept both strings (which is what Yosys's write_json command normally produces for parameters) and numbers (which is what is produced when using write_json -compat-int).

Fixes #2846.

@RyanGlScott RyanGlScott self-assigned this Nov 25, 2025
@RyanGlScott RyanGlScott added the subsystem: hardware Issues related to verification of hardware label Nov 25, 2025
Copy link
Contributor

@podhrmic podhrmic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, although I haven't actually ran it.

Just (Aeson.Number n) -> n > 0
Just (Aeson.String t) -> textBinNat t > 0
Just v ->
panic "cellToTerm"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error reports an ill-formed input file and shouldn't be a panic...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, perhaps so. At the same time, this is already an established convention in this module (see existing uses of panic in the connWidthNat and input functions further down), so if we change how errors are reported here, we should also change how they're reported elsewhere.

What would be your preference for how to report these errors?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a YosysError datatype in SAWCentral.Yosys.Utils that has an Exception instance, and some other parts of our Yosys code throw these as exceptions. For consistency it might be nice to do the same, perhaps adding a new constructor to the YosysError type.

Except definitely don't use throw like the existing code does; all such uses need to be changed to throwIO.

These local functions like connSigned with pure types should be changed to monadic types if they are partial.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought would be just to add -- XXX this should not be a panic and I'll fix it when I come through with the new error infrastructure, which hopefully won't be that much longer.

I would rather not introduce any new explicit throwing, even IO-level throwing, because there's an impenetrable mess of unsystematic throw and catch all over everywhere that I don't think can be cleaned up, only removed. This will become clearer as other things move forward...

Copy link
Contributor Author

@RyanGlScott RyanGlScott Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I've settled on leaving XXX-style comments next to each of the panics in this function. See fe4c3e4.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving it for later is fine with me.

@RyanGlScott RyanGlScott force-pushed the rgs/yosys-cell-parameters-ints branch from 4065fd6 to f3d43dd Compare November 25, 2025 21:35
@brianhuffman
Copy link
Contributor

I just merged #2832, which does a bunch of extra refactoring and reformatting of Yosys code. I realized it will probably cause a bunch of merge conflicts for this PR; sorry about that!

To do so, we parse cell parameter values more generally to accept all possible
JSON values, and then we refine the code which parses `*_SIGNED` parameters to
accept both strings (which is what Yosys's `write_json` command normally
produces for parameters) and numbers (which is what is produced when using
`write_json -compat-int`).

Fixes #2846.
@RyanGlScott RyanGlScott force-pushed the rgs/yosys-cell-parameters-ints branch from f3d43dd to fe4c3e4 Compare November 26, 2025 11:06
@RyanGlScott
Copy link
Contributor Author

I've rebased on top of #2832. Surprisingly, there were no merge conflicts!

@RyanGlScott RyanGlScott merged commit 766c039 into master Nov 26, 2025
58 of 59 checks passed
@RyanGlScott RyanGlScott deleted the rgs/yosys-cell-parameters-ints branch November 26, 2025 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

subsystem: hardware Issues related to verification of hardware

Projects

None yet

Development

Successfully merging this pull request may close these issues.

yosys_import doesn't support JSON files written using -compat-int

5 participants