4

Is there some way to pass parameters (or command line arguments) to a Yosys script?

I see in this quetion (Can we have variables in a Yosys script?) you can run the Yosys script within a TCL interpreter. Is there some way to pass in an argument?

The reason I am doing this is that I have a script, and I want to be able to call the script with a parameterized path to a Verilog file. Surely this is a common need, and there must be some easy way to do this, but I'm not seeing it.

jgoeders
  • 1,886
  • 19
  • 25

2 Answers2

5

The only way to do that at the moment is using environment variables and TCL scripts. For example, you can write a TCL script test.tcl:

yosys read_verilog $::env(VLOG_FILE_NAME)
yosys synth -top $::env(TOP_MODULE)
yosys write_verilog output.v

And then call if with VLOG_FILE_NAME and TOP_MODULE set in the environment:

VLOG_FILE_NAME=tests/simple/fiedler-cooley.v TOP_MODULE=up3down5 yosys test.tcl

If you are running Yosys from a shell script you can also simply run something like export VLOG_FILE_NAME=... at the top of your script. Similarly you can use the export Makefile statement when you are running Yosys from a Makefile.

CliffordVienna
  • 7,995
  • 1
  • 37
  • 57
0

I was facing a similar case. This question showed up while I was working on a solution. I ended up with a different approach though:

I'm creating a wrapper to my top module, written in m4 language. It's very simple, it overrides the parameters value, and then includes my top module definition.

Then in the Makefile, I process the wrapper.m4 file, to create the resulting wrapper.v file, that will be input to yosys.

I have detailled the solution here.

Alexandre Dumont
  • 123
  • 2
  • 10