@@ -262,20 +262,74 @@ Minimizing Verilog designs
262262 This section is not specific to Yosys, so feel free to use another guide such
263263 as Stack Overflow's `How to create a Minimal, Reproducible Example `_.
264264
265- Unlike RTLIL designs where we can use `bugpoint `, minimizing Verilog designs is
266- a much more manual, iterative process. Be sure to check any errors or warnings
267- for messages that might identify source lines or object names that might be
268- causing the failure, and back up your source code before modifying it. At any
269- point in the process, you can check for anything that is unused or totally
270- disconnected (ports, wires, etc) and remove them too. If you have multiple
271- source files, try to reduce them down to a single file; either by removing files
272- or combining them.
273-
274- .. note ::
275-
276- If a specific module is causing the problem, try to set that as the top
277- module instead. Any parameters should have their default values changed to
278- match the failing usage.
265+ Be sure to check any errors or warnings for messages that might identify source
266+ lines or object names that might be causing the failure, and back up your source
267+ code before modifying it. If you have multiple source files, you should start
268+ by reducing them down to a single file. If a specific file is failing to read,
269+ try removing everything else and just focus on that one. If your source uses
270+ the `include ` directive, replace it with the contents of the file referenced.
271+
272+ Unlike RTLIL designs where we can use `bugpoint `, Yosys does not provide any
273+ tools for minimizing Verilog designs. Instead, you should use an external tool
274+ like `C-Reduce `_ (with the ``--not-c `` flag) or `sv-bugpoint `_.
275+
276+ .. _C-Reduce : https://github.com/csmith-project/creduce
277+ .. _sv-bugpoint : https://github.com/antmicro/sv-bugpoint
278+
279+ C-Reduce
280+ ~~~~~~~~
281+
282+ As a very brief overview for using C-Reduce, you want your failing source design
283+ (``test.v ``), and some shell script which checks for the error being
284+ investigated (``test.sh ``). Below is an :ref: `egtest ` which uses `logger ` and
285+ the ``-expect error "<string>" 1 `` option to perform a similar role to
286+ ``bugpoint -grep ``, along with ``verilator `` to lint the code and make sure it
287+ is still valid.
288+
289+ .. code-block :: bash
290+ :caption: Example test.sh
291+ :name: egtest
292+
293+ #! /bin/bash
294+ verilator --lint-only test.v && /
295+ yosys -p ' logger -expect error "unsupported" 1; read_verilog test.v'
296+
297+ .. code-block :: verilog
298+ :caption: input test.v
299+
300+ module top(input clk, a, b, c, output x, y, z);
301+ always @(posedge clk) begin
302+ if (a == 1'b1)
303+ $stop;
304+ end
305+ assign x = a;
306+ assign y = a ^ b;
307+ assign z = c;
308+ endmodule
309+
310+ In this example ``read_verilog test.v `` is giving an error message that contains
311+ the string "unsupported" because the ``$stop `` system task is only supported in
312+ ``initial `` blocks. By calling ``creduce ./test.sh test.v --not-c `` we can
313+ minimize the design to just the failing code, while still being valid Verilog.
314+
315+ .. code-block :: verilog
316+ :caption: output test.v
317+
318+ module a;
319+ always begin $stop;
320+ end endmodule
321+
322+
323+ Doing it manually
324+ ~~~~~~~~~~~~~~~~~
325+
326+ If for some reason you are unable to use a tool to minimize your code, you can
327+ still do it manually. But it can be a time consuming process and requires a lot
328+ of iteration. At any point in the process, you can check for anything that is
329+ unused or totally disconnected (ports, wires, etc) and remove them. If a
330+ specific module is causing the problem, try to set that as the top module
331+ instead. Any parameters should have their default values changed to match the
332+ failing usage.
279333
280334As a rule of thumb, try to split things roughly in half at each step; similar to
281335a "binary search". If you have 10 cells (instances of modules) in your top
@@ -318,15 +372,6 @@ the error still occurs. Try reducing ``if .. else`` and ``case`` blocks to a
318372single case. Even if that doesn't work, you may still be able to remove some
319373paths; start with cases that appear to be unreachable and go from there.
320374
321- If you're planning to share the minimized code, remember to make sure there is
322- no sensitive or proprietary data in the design. Maybe rename that
323- ``ibex_prefetch_buffer `` module to ``buf ``, and ``very_important_signal_name ``
324- could just as easily be ``sig ``. The point here isn't to make names as small as
325- possible, but rather to remove the context that is no longer necessary. Calling
326- something ``multiplier_output_value `` doesn't mean as much if you no longer have
327- the multiplier being referred to; but if the name does still make sense then
328- it's fine to leave it as-is.
329-
330375.. note ::
331376
332377 When sharing code on the `Yosys GitHub `_, please try to keep things in
0 commit comments