Yosys & Netlistsvg Quick Reference
For turning Verilog/SystemVerilog code into logic schematics.
Installation
Linux (Ubuntu/Debian)
Basic Workflow
-
Write your Verilog file(s), e.g.
design.v. -
Synthesize and export a
JSONnetlist withYosys. -
Render an
SVGschematic with netlistsvg.
One-liner (combines steps 2 and 3):
yosys -p "read_verilog design.v; proc; synth -top top_module; write_json output.json" && netlistsvg output.json -o schematic.svg
-
-p "..."passes a sequence of Yosys commands directly on the command line (no script file needed). -
synthperforms generic synthesis (converts always blocks to gate-level logic). -
netlistsvgreads the JSON and draws an SVG.
Specifying the Top Module
If your file contains multiple modules, explicitly choose the top-level one:
Without -top, netlistsvg may pick the first module it finds, often a submodule.
Flattening the Schematic (remove hierarchy)
To see all gates in one flat diagram (no sub‑module boxes), insert the flatten command after synth:
yosys -p "read_verilog design.v; proc; synth -top my_top; flatten; write_json output.json" && netlistsvg output.json -o flat_schematic.svg
Caution: For large designs, a flattened schematic can become very cluttered.
Yosys Built‑in show Command (Quick Preview)
Yosys can also produce a schematic directly (needs Graphviz dot):
-format svg (or png) sets the output format.
-prefix my_design sets the output filename (e.g. my_design.svg).
This skips netlistsvg entirely, but the visual style is different (bubble shapes).
SVG Background Color
The SVG from netlistsvg has a transparent background. To add a white background:
Option A: Insert a white rectangle right after the <svg> tag:
Option B: Convert to PNG with a background using rsvg-convert:
IEC (Rectangular) Logic Symbols
netlistsvg supports custom skin files to change gate appearances (e.g., from bubble to rectangular IEC 60617 symbols).
Copy the default skin from netlistsvg:
(Path may differ; find withnpm list -g netlistsvg or check /usr/local/lib/... on Linux.)
Edit iec_skin.svg:
Replace gate shapes and labels with rectangular templates and IEC qualifying symbols.
Use the custom skin:
Creating a full IEC skin is non‑trivial, but this approach gives you full control.
Printing Synthesis Statistics
In Yosys, use the stat command to see cell counts and hierarchy:
Or interactively:
This shows how many cells, wires, and processes remain, and helps confirm no latches were inferred (look for Number of processes: 0 after synthesis).
Useful Tips
-
No latches = all
always @(*)/always_combblocks converted to combinational logic. In stat, Number of processes should become0after synth. -
If you see unexpected submodule boxes, check your
-topsetting or consider flatten. -
Combine
write_jsonwithflattenfor a fully flat gate‑level view. -
Add
$dumpfileand$dumpvarsin your testbench and usevvpto generate VCD files. Then view them with GTKWave for timing diagrams (separate from schematic). -
For more advanced synthesis, explore Yosys commands like
abc -g gatesto map to a specific gate library.