ICE40 primitives with slang plugin

Hi all,

I don’t seem to be able to refer to vendor primitives (like SB_IO or PLL instances) directly in a SystemVerilog file read with read_slang. I found a workaround by including a wrapping module with read_verilog first, then use read_slang for the .sv file that include the Verilog module. What am I doing wrong or missing?

When using the synth_ice40 pass, the blackbox definitions of the vendor primitives are implicitly added to the file list before elaborating the design:

    begin:
        read_verilog -D ICE40_HX -lib -specify +/ice40/cells_sim.v
        hierarchy -check -top <top>
        proc

Since that’s done with read_verilog the slang frontend doesn’t know about those. You would have to also read that file with the slang frontend to make the primitive definitions available (ideally read as blackboxes if there’s that feature available in yosys-slang), and then after import they need to be overwritten by the read_verilog command with the whitebox models.

I’m not sure off the top of my head the exact rules for when overwriting is allowed or not by default, IIRC it allows it with a warning if the module is a blackbox but gives an error if there are contents? If you do encounter an error you would have to run the above section manually, adding -overwrite, before launching the rest of synth_ice40:

read_verilog -D ICE40_HX -lib -specify -overwrite +/ice40/cells_sim.v
hierarchy -check -top foo
proc
synth_ice40 -run flatten: