Skip to content

netlist_carpentry.scripts.script_builder

Module for generation and execution of synthesis scripts with Yosys, creating generic JSON netlists.

Functions:

build_script

build_script(
    script_path: Path,
    input_file_paths: List[Path],
    output_file_path: Path,
    top: str = "",
    insbuf: bool = True,
    process_memory: bool = True,
    techmap_paths: List[Path] = [],
    source_paths: Optional[List[str]] = None,
    no_hierarchy: bool = False,
) -> None

Build a Yosys script for synthesis.

This function generates a Yosys script that reads the paths to the input Verilog files, performs hierarchy management (in Yosys), procedural transformations, memory processing, techmap application, optimization, and writes the output in JSON format. This function does not run the generated script. Run the script in the terminal, e.g. via sh <script_name>.

Parameters:

  • script_path

    (Path) –

    Desired path to the output script file.

  • input_file_paths

    (List[Path]) –

    List of paths to input Verilog files.

  • output_file_path

    (Path) –

    Path to the output JSON file.

  • top

    (str, default: '' ) –

    Name of the top module. Defaults to ''.

  • insbuf

    (bool, default: True ) –

    Whether to insert buffers whenever wires are directly assigned to other wires. Defaults to True.

  • process_memory

    (bool, default: True ) –

    Whether to process memory (split into primitive cells). Defaults to True.

  • techmap_paths

    (List[Path], default: [] ) –

    List of paths to techmap files. Defaults to [].

  • source_paths

    (Optional[List[str]], default: None ) –

    A list of paths to files to source before running Yosys. Can be used to enable plugins or activate environments, e.g. the OSS CAD SUITE. Defaults to None, in which case no additional files are sourced.

  • no_hierarchy

    (bool, default: False ) –

    Whether to resolve the hierarchy of the given circuit or not. If True, the yosys "hierarchy" path is skipped. Defaults to False.

build_and_execute

Build a Yosys script and execute it.

This function builds a Yosys script using the provided parameters and then executes it using the subprocess library. It can optionally control output verbosity.

Parameters:

  • script_path

    (Path) –

    Path to the script file to be executed.

  • input_file_paths

    (List[Path]) –

    List of paths to input Verilog files.

  • output_file_path

    (Path) –

    Path to the output JSON file.

  • verbose

    (bool, default: False ) –

    If True, print output to stdout. Defaults to False, which suppresses output and only prints errors.

  • **kwargs

    (Any, default: {} ) –

    Additional arguments passed to build_script.

Returns:

  • CompletedProcess[bytes]

    subprocess.CompletedProcess[bytes]: The result of the subprocess execution.