tsfpga.yosys package
Submodules
tsfpga.yosys.build_result module
- class tsfpga.yosys.build_result.YosysBuildResult(name: str)
Bases:
BuildResultThe result of a Yosys netlist build.
Yosys builds are synthesis-only, so there are no implementation metrics and no timing information. Only
BuildResult.synthesis_sizeis available.
tsfpga.yosys.common module
- tsfpga.yosys.common.get_ghdl_library_prefix(ghdl_path: Path | None = None) Path | None
Try to automatically find the GHDL “library prefix”, i.e. the location where the
std/ieeestandard libraries are installed, by parsing the output ofghdl --disp-config.GHDL can normally find this on its own, by looking at the path of its own executable. This does however not work when GHDL is used as a library, e.g. via the
ghdl-yosys-pluginmodule loaded into Yosys (seerun_yosys()), since there is noghdlexecutable path to derive the prefix from in that case. Calling this function against the standaloneghdlexecutable lets us find the prefix anyway, so it can be forwarded explicitly.- Parameters:
ghdl_path – Path to the GHDL executable. Can be set to
Noneto use whatever version is inPATH.- Returns:
The library prefix, or
Noneif it could not be determined.
- tsfpga.yosys.common.get_ghdl_path(ghdl_path: Path | None = None) Path
Wrapper to get a path to the GHDL executable.
- Parameters:
ghdl_path – Path to the GHDL executable. Leave as
Noneto use whatever is available in the systemPATH.
- tsfpga.yosys.common.get_yosys_path(yosys_path: Path | None = None) Path
Wrapper to get a path to the Yosys executable.
- Parameters:
yosys_path – Path to the Yosys executable. Leave as
Noneto use whatever is available in the systemPATH.
- tsfpga.yosys.common.run_ghdl(ghdl_path: Path | None, arguments: list[str], cwd: Path) bool
Run GHDL with the given arguments. Used for analyzing VHDL source files into an on-disk library, which can later be picked up by the
ghdl-yosys-pluginwhen runningrun_yosys().Setting
cwdensures that any files produced (e.g. GHDL library files) end up in a well-known location.- Parameters:
ghdl_path – Path to the GHDL executable. Can be set to
Noneto use whatever version is inPATH.arguments – Arguments that shall be passed on to GHDL.
cwd – The GHDL process will be executed with this as the working directory.
- Returns:
True if everything went well.
- tsfpga.yosys.common.run_yosys(script_file: Path, cwd: Path, yosys_path: Path | None = None, ghdl_plugin_path: Path | None = None, ghdl_path: Path | None = None, ghdl_prefix: Path | None = None) bool
Run Yosys with the given script.
Setting
cwdensures that any files produced (e.g. reports, netlists) end up in a well-known location.- Parameters:
script_file – Path to a file containing the Yosys commands that shall be executed.
cwd – The Yosys process will be executed with this as the working directory.
yosys_path – Path to the Yosys executable. Can be set to
Noneto use whatever version is inPATH.ghdl_plugin_path – Path to the
ghdl-yosys-pluginmodule (typically namedghdl.so). Can be set toNoneif the plugin is already available to Yosys without explicitly loading it (e.g. if it has been installed in the Yosys plugin directory).ghdl_path – Path to the GHDL executable, used only to auto-detect ‘ghdl_prefix’ below when it is not given explicitly. Can be set to
Noneto use whatever version is inPATH.ghdl_prefix – Value to set the
GHDL_PREFIXenvironment variable to for this process. Theghdl-yosys-pluginmodule is loaded as part of the Yosys process, and hence can not find the GHDL standard libraries (std,ieee, …) on its own the way the standaloneghdlexecutable can. Corresponds to the “library prefix” printed byghdl --disp-config. If left asNone, this method will try to find a value automatically by callingghdl --disp-config(see ‘ghdl_path’ above) and parsing its output. Set explicitly to override the auto-detected value, or if auto-detection fails.
- Returns:
True if everything went well.
tsfpga.yosys.project module
- class tsfpga.yosys.project.YosysIntelNetlistBuild(family: str | None = None, **kwargs: Any)
Bases:
YosysNetlistBuildUsed for handling a Yosys netlist build that targets Intel (Altera) primitives (
*_lcell_comb,dffeas,altsyncram, …), using the Yosyssynth_intelcommand.Note
Targets the MAX10, Cyclone IV, Cyclone IV E and Cyclone 10 LP families. For ALM-based Intel devices (Cyclone V, Cyclone 10 GX) the
synth_intel_almcommand shall be used instead, which is not covered by this class. SubclassYosysNetlistBuildand set its_synth_commandto"synth_intel_alm"for that, though note that no aggregated resource counts will be available in that case.Since the produced utilization report uses the resource names
"Total LUTs","FFs","Block RAMs"and"DSP Blocks", the corresponding checkers invivado.build_result_checkercan be used directly.
- class tsfpga.yosys.project.YosysMicrochipNetlistBuild(family: str | None = None, discard_ffinit: bool = False, **kwargs: Any)
Bases:
YosysNetlistBuildUsed for handling a Yosys netlist build that targets Microchip primitives (
CFG*,SLE,RAM1K20,MACC_PA, …), using the Yosyssynth_microchipcommand.Note
Targets the PolarFire family, which is the only one currently supported by the Yosys
synth_microchipcommand.Since the produced utilization report uses the resource names
"Total LUTs","FFs","Block RAMs"and"DSP Blocks", the corresponding checkers invivado.build_result_checkercan be used directly.- __init__(family: str | None = None, discard_ffinit: bool = False, **kwargs: Any) None
- Parameters:
family – Optionally target a specific Microchip device family. See the Yosys
synth_microchipcommand documentation for valid values.discard_ffinit – The Yosys
synth_microchipcommand will raise an error if the design contains a flip-flop with an initial value that can not be legalized to a supported flip-flop type (which is a common occurrence, since e.g. VHDL signals initialized to a default value result in flip-flops with an initial value). Set this toTrueto instead discard the initial value and let synthesis proceed. Corresponds to the Yosys-discard-ffinitflag.kwargs – Further arguments accepted by
YosysNetlistBuild.__init__().
- class tsfpga.yosys.project.YosysNetlistBuild(name: str, modules: ModuleList, top: str | None = None, vhdl_entities: list[str] | None = None, generics: GenericValues | None = None, build_result_checkers: list[SizeChecker] | None = None, vhdl_standard: str = '08', ghdl_path: Path | None = None, yosys_path: Path | None = None, ghdl_plugin_path: Path | None = None, ghdl_prefix: Path | None = None, defined_at: Path | None = None, **other_arguments: Any)
Bases:
objectUsed for handling a synthesis-only (netlist) build of a design, using Yosys with the
ghdl-yosys-pluginas the VHDL front end.Since this is a netlist build, there is no implementation (place & route) step, and hence no bitstream is produced. This is a great tool for getting quick feedback on the resource utilization of a design, or a sub-component of a design, during development.
The
topis typically a VHDL entity, in which case all of its VHDL dependencies are found automatically via the compile order. It can also be a Verilog/SystemVerilog module (or the design can have no VHDL at all), in which case any VHDL entities that shall be instantiated from it (or from other VHDL entities) must be explicitly listed using thevhdl_entitiesargument.Note
Requires GHDL, Yosys, and the
ghdl-yosys-pluginmodule to be installed and available. See the ghdl-yosys-plugin documentation for installation instructions.- __init__(name: str, modules: ModuleList, top: str | None = None, vhdl_entities: list[str] | None = None, generics: GenericValues | None = None, build_result_checkers: list[SizeChecker] | None = None, vhdl_standard: str = '08', ghdl_path: Path | None = None, yosys_path: Path | None = None, ghdl_plugin_path: Path | None = None, ghdl_prefix: Path | None = None, defined_at: Path | None = None, **other_arguments: Any) None
Class constructor. Performs a shallow copy of the mutable arguments, so that the user can e.g. append items to their list after creating an object.
- Parameters:
name – Project name.
modules – Modules that shall be included in the build. Only VHDL source files are considered, since the build uses the GHDL front end.
top – Name of top level entity. If left out, the top level name will be inferred from the
name. Is typically a VHDL entity, but can also be a Verilog/SystemVerilog module – seevhdl_entitiesbelow.vhdl_entities – Only used if
topis not a VHDL entity (i.e. if it is a Verilog/SystemVerilog module, or if the design has no VHDL at all). A list of the names of the VHDL entities that shall be made available for instantiation from the non-VHDL top level (or from other VHDL entities), since there is in that case no single VHDL top level to automatically find these dependencies from. Not used, and shall be left asNone, iftopis a VHDL entity, since in that case all of its VHDL dependencies are found automatically via the compile order.generics –
A dict with generics values (name: value). Use this parameter for “static” generics that do not change between multiple builds of this project.
Compare to the build-time generic argument in
build().The generic value shall be of type
GenericValue.build_result_checkers – Checkers that will be executed after a successful build. Is used to automatically check that e.g. resource utilization is not greater than expected.
vhdl_standard – The VHDL standard that shall be used by GHDL when analyzing the source files (e.g.
"93"or"08").ghdl_path – Path to the GHDL executable. If omitted, the default location from the system PATH will be used.
yosys_path – Path to the Yosys executable. If omitted, the default location from the system PATH will be used.
ghdl_plugin_path – Path to the
ghdl-yosys-pluginmodule (typically namedghdl.so). Can be left out if the plugin is already available to Yosys without explicitly loading it (e.g. if it has been installed in the Yosys plugin directory).ghdl_prefix – Value to set the
GHDL_PREFIXenvironment variable to when running Yosys with theghdl-yosys-plugin. The plugin is loaded as part of the Yosys process, and can not find the GHDL standard libraries (std,ieee, …) on its own the way the standaloneghdlexecutable can. Corresponds to the “library prefix” printed byghdl --disp-config. If left out, this is auto-detected by callingghdl --disp-configagainst the executable given byghdl_pathabove. Set explicitly to override the auto-detected value, or if auto-detection fails.defined_at – Optional path to the file where you defined this project. To get a useful
build_fpga.py --listmessage. Is useful when you have many projects set up.other_arguments –
Optional further arguments. Will not be used by tsfpga, but will instead be passed on to
along with further arguments supplied at build-time to
create()andbuild().Note
This is a “kwargs” style argument. You can pass any number of named arguments.
- build(project_path: Path, output_path: Path | None = None, generics: dict[str, bool | int | float | StringGenericValue | BitVectorGenericValue] | None = None, **pre_and_post_build_parameters: Any) YosysBuildResult
Synthesize the design with Yosys.
- Parameters:
project_path – A path containing the result of a call to
create().output_path – The utilization report, and any other artifacts, will be placed here. Will default to
project_pathif not set.generics – A dict with generics values (dict(name: value)). Use for run-time generics, i.e. values that can change between each build of this project. Compare to the create-time generics argument in
__init__(). The generic value types follow the same rules as for__init__().pre_and_post_build_parameters –
Optional further arguments. Will not be used by tsfpga, but will instead be sent to
along with further
other_argumentssupplied to__init__().Note
This is a “kwargs” style argument. You can pass any number of named arguments.
- Returns:
Result object with build information.
- create(project_path: Path, **other_arguments: Any) bool
Analyze all the VHDL source files with GHDL, so that the design is ready to be elaborated and synthesized by
build().- Parameters:
project_path – Path where the GHDL analysis result shall be placed.
other_arguments –
Optional further arguments. Will not be used by tsfpga, but will instead be sent to
along with further
other_argumentssupplied to__init__().
- Returns:
True if everything went well.
- is_netlist_build = True
Will always be
Truefor this class, since it is a netlist build.
- post_build(**kwargs: Any) bool
Override this function in a subclass if you wish to do something useful with it. Will be called from
build()right after the call to Yosys.Note
This default method does nothing. Shall be overridden by project that utilize this mechanism.
- Parameters:
kwargs – Will have all the
build()parameters in it. Including additional parameters from the user. Will also includebuild_result.- Returns:
True if everything went well.
- pre_build(**kwargs: Any) bool
Override this function in a subclass if you wish to do something useful with it. Will be called from
build()right before the call to Yosys.- Parameters:
kwargs – Will have all the
build()parameters in it. Including additional parameters from the user.- Returns:
True if everything went well.
- pre_create(**kwargs: Any) bool
Override this function in a subclass if you wish to do something useful with it. Will be called from
create()right before the GHDL analysis is started.Note
This default method does nothing. Shall be overridden by project that utilize this mechanism.
- Parameters:
kwargs – Will have all the
create()parameters in it, as well as everything in theother_argumentsargument toYosysNetlistBuild.__init__().- Returns:
True if everything went well.
- class tsfpga.yosys.project.YosysXilinxNetlistBuild(family: str | None = None, **kwargs: Any)
Bases:
YosysNetlistBuildUsed for handling a Yosys netlist build that targets Xilinx primitives (LUTs, FDs, RAMBs, DSP48s, …), using the Yosys
synth_xilinxcommand.Since the produced utilization report uses the same resource naming convention as the Vivado utilization report, the checkers in
vivado.build_result_checkercan be used directly to check e.g. the LUT or RAMB count of the design.
tsfpga.yosys.utilization_parser module
- class tsfpga.yosys.utilization_parser.YosysIntelUtilizationParser
Bases:
YosysUtilizationParserUtilization parser for a design synthesized with the Yosys
synth_intelcommand, i.e. targeting the MAX10, Cyclone IV, Cyclone IV E or Cyclone 10 LP families.Note
The
"DSP Blocks"count is only meaningful for the MAX10 family. Of the families supported bysynth_intel, only that one maps multiplications to DSP cells. The others implement them in soft logic, so their reports contain no DSP cells at all and the count is always zero. Observed with Yosys 0.68, on a design with a single 18x18 multiplication.- resource_name_patterns: ClassVar[dict[str, str]] = {'Block RAMs': 'altsyncram$', 'DSP Blocks': '.*_mac_mult$', 'FFs': 'dffeas$', 'Total LUTs': '.*_lcell_comb$'}
Mapping of aggregated resource name (e.g.
"Total LUTs") to a regular expression that is matched, usingre.match(), against the raw primitive cell names to decide which cells shall be summed up to get that number. Shall be set by subclasses. The aggregated names are chosen to match the ones used in the Vivado utilization report (seevivado.build_result_checker) where applicable, so that the same build result checkers can be reused for Yosys builds.
- class tsfpga.yosys.utilization_parser.YosysMicrochipUtilizationParser
Bases:
YosysUtilizationParserUtilization parser for a design synthesized with the Yosys
synth_microchipcommand, i.e. targeting the PolarFire family.- resource_name_patterns: ClassVar[dict[str, str]] = {'Block RAMs': 'RAM(1K20|64[xX]12)$', 'DSP Blocks': 'MACC_PA$', 'FFs': 'SLE$', 'Total LUTs': 'CFG\\d$'}
Mapping of aggregated resource name (e.g.
"Total LUTs") to a regular expression that is matched, usingre.match(), against the raw primitive cell names to decide which cells shall be summed up to get that number. Shall be set by subclasses. The aggregated names are chosen to match the ones used in the Vivado utilization report (seevivado.build_result_checker) where applicable, so that the same build result checkers can be reused for Yosys builds.
- class tsfpga.yosys.utilization_parser.YosysUtilizationParser
Bases:
objectUsed for parsing the resource utilization report produced by the Yosys
statcommand.This base class reports only the raw Yosys primitive cell counts, which depend entirely on which
synth_*command was used. Use one of the architecture-specific subclasses to also get aggregated, architecture-independent resource counts (e.g."Total LUTs").- classmethod get_size(report: str) dict[str, int]
- Parameters:
report – The text printed to the console (or a log file) by the Yosys
statcommand.- Returns:
A dictionary with the resource utilization of the design. Contains the raw count of each cell primitive used in the design, as well as the aggregated counts (e.g.
"Total LUTs") given byresource_name_patterns, if any.
- resource_name_patterns: ClassVar[dict[str, str]] = {}
Mapping of aggregated resource name (e.g.
"Total LUTs") to a regular expression that is matched, usingre.match(), against the raw primitive cell names to decide which cells shall be summed up to get that number. Shall be set by subclasses. The aggregated names are chosen to match the ones used in the Vivado utilization report (seevivado.build_result_checker) where applicable, so that the same build result checkers can be reused for Yosys builds.
- class tsfpga.yosys.utilization_parser.YosysXilinxUtilizationParser
Bases:
YosysUtilizationParserUtilization parser for a design synthesized with the Yosys
synth_xilinxcommand.- resource_name_patterns: ClassVar[dict[str, str]] = {'Block RAMs': 'RAMB', 'DSP Blocks': 'DSP', 'FFs': 'FD', 'RAMB18': 'RAMB18', 'RAMB36': 'RAMB36', 'SRLs': 'SRL', 'Total LUTs': 'LUT'}
Mapping of aggregated resource name (e.g.
"Total LUTs") to a regular expression that is matched, usingre.match(), against the raw primitive cell names to decide which cells shall be summed up to get that number. Shall be set by subclasses. The aggregated names are chosen to match the ones used in the Vivado utilization report (seevivado.build_result_checker) where applicable, so that the same build result checkers can be reused for Yosys builds.