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

icebox_vlog: improve module declaration and unit testing #329

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

X-Illuminati
Copy link

Resolves #328

  • icebox_vlog: use proper Verilog-2001 module declarations
  • icebox_vlog: add basic test cases

First commit changes iceblox_vlog to output Verilog-2001 module declarations
by default. An additional command line option (-C) supports output of
Verilog-1995 module declarations for backwards compatibility.

Second commit adds test cases that try out different combinations of
commandline options for iceblox_vlog and ensure they parse correctly with
iverilog and yosys.
I didn't see any other obvious regression tests, so I added these to support
development in the future.

Resolves YosysHQ#328
Summary:
- By default emit Verilog-2001 style module declarations with direction
  and signal type defined in the module prototype and not in the body of
  the module
- Add -C option to output Verilog-1995 module declarations for
  compatibility with older toolchains
- Add some comments to the file to assist future maintainers

Background:
Currently, icebox_vlog outputs a mixed-style module declaration in which
it puts the port direction in the module prototype and later declares
the signals as ports or wires.
```verilog
module chip (input pin1, output pin2);

wire pin1;
reg pin2 = 0;
```

The inclusion of the direction in the module prototype is a feature of
newer Verilog-2001 specification.

It seems probable that older versions of Icarus Verilog had some leeway
in handling this mixed-style of declaration. But, it seems that at least
the version included in newer Ubuntu distributions considers this to be
a syntax error.

In this commit, the module declaration above will be emitted as:
```verilog
module chip (input wire pin1, output reg pin2 = 0);
```

Or if you sepcificy the -C option for Verilog-1995 compatibility:
```verilog
module chip (pin1, pin2);
input pin1;
output pin2;

wire pin1;
reg pin2 = 0;
```
Makefile provides various targets for testing icebox_vlog.
- %_syn.v targets will use icebox_vlog to generate a .v file from
  the blinky.asc file
- %_syntb targets will invoke iverilog on the .v files
- %.json targets will invoke yosys on the .v files
- test target will attempt several combinations of command line options
  for icebox_vlog (all combinations of -s, -l, -p, -c, -C) and will then
  trigger iverilog and yosys targets to attempt parsing the .v files

Output files generated by `make test` can be compared after making code
changes to icebox_vlog.py to identify any regressions.
@X-Illuminati
Copy link
Author

It seems clear to me that icebox_vlog is largely superceded by the yosys "write_verilog" command. This change may be seen mostly as a personal journey in understanding, but it may prove useful for continuing to work with unmaintained scripts in other projects.

@X-Illuminati X-Illuminati marked this pull request as ready for review April 21, 2024 22:36
@X-Illuminati
Copy link
Author

X-Illuminati commented Apr 21, 2024

@gatecat I hope you can review this or assign to a relevant reviewer.

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

Successfully merging this pull request may close these issues.

iceblox_vlog does not(?) generate verilog that is compatible with Icarus Verilog
1 participant