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

Cannot specify a command file for Icarus from compile_args - Needed for setting timescale #95

Closed
gretzteam opened this issue Sep 12, 2020 · 4 comments

Comments

@gretzteam
Copy link
Contributor

gretzteam commented Sep 12, 2020

To set the icarus timescale, a cmds.f file with the following content is created:

+timescale+1ns/1ns

Then compile_args is set to:
compile_args = ["-f /home/cmds.f"]

However, icarus complains that the file cannot be read:

INFO cocotb: Running command: iverilog -o /home/sim_build/toplevel.vvp -D COCOTB_SIM=1 -s toplevel -g2012 -f /home/cmds.f  /home/toplevel.sv 
INFO cocotb: iverilog: cannot open command file  /home/cmds.f for reading.
ERROR cocotb: Command terminated with error 1
AssertionError: Simulation terminated abnormally. Results file not found.

Interestingly, if I then manually go in /sim_build and type the exact same command, there are no errors and subsequent run work fine...
iverilog -o /home/sim_build/toplevel.vvp -D COCOTB_SIM=1 -s toplevel -g2012 -f /home/cmds.f /home/toplevel.sv

@themperek
Copy link
Owner

Try :
compile_args = ["-f", "/home/cmds.f"]

Should probably split this in code before passing to subprocess.

@gretzteam
Copy link
Contributor Author

This worked fine, thanks!

Related to this, would it make sense to add a default cmds.f file with decent timescale directive? I believe Icarus is mostly not usable as it is for most people and they will all have to figure out the funny way to set the timescale...

Something along those lines, but I'm sure there is a better way.

class icarus_custom(Icarus):
    def compile_command(self):
        if '-f' in self.compile_args:
            print('A command file is already provided.')
        else:
            print('Override default icarus timescale to 1ns/1ns. Create cmds.f file and add to compile_args')
            with open(self.sim_dir+"/cmds.f", 'w') as f:
                f.write("+timescale+1ns/1ns")  
            self.compile_args.extend(["-f", self.sim_dir+"/cmds.f"])

        cmd_compile = (
            ["iverilog", "-o", self.sim_file, "-D", "COCOTB_SIM=1", "-s", self.toplevel, "-g2012"]
            + self.get_define_commands(self.defines)
            + self.get_include_commands(self.includes)
            + self.compile_args
            + self.verilog_sources
        )

        return cmd_compile

@themperek
Copy link
Owner

I am closing it.
In case it is still an issue please reopen.

@shuckc
Copy link
Contributor

shuckc commented Nov 19, 2022

This is one of the things I imagine every Icarus user has to solve when moving from cocotb to cocotb-test - why is Icarus now complaining about timescales?

The Cocotb Makefile takes care of writing a default timescale to cmds.f file and including it here: https://github.com/cocotb/cocotb/blob/master/cocotb/share/makefiles/simulators/Makefile.icarus#L69
When cocotb-test invokes icarus it has no equivalent to set timescale https://github.com/themperek/cocotb-test/blob/master/cocotb_test/simulator.py#L421

Setting compile_args on every test is clunky, and it's not obvious how to replace SIM=icarus pytest . with a custom Icarus subclass (like icarus_custom above) without losing the ability to switch simulators from the command line. Here is one way:

from cocotb_test.simulator import run, Icarus
from cocotb_test import simulator

class IcarusAutoTimescale(Icarus):
    def compile_command(self):
        with open(self.sim_dir+"/cmds.f", 'w') as f:
            f.write("+timescale+1ns/1ns\n")
        self.compile_args.extend(["-f", self.sim_dir+"/cmds.f"])
        return super().compile_command()

simulator.Icarus = IcarusAutoTimescale

def test_fen_decode():
    run(
        verilog_sources=["hw/fen_decode.sv", "hw/ascii_int_to_bin.sv", "hw/onehot_to_bin.v"],
        toplevel="fen_decode",
        module="cocotb_fen_decode"
    )

It's especially odd given all the support to handle Icarus.waves = True which writes a custom modules and adds a new top level.

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

No branches or pull requests

3 participants