Synthesis¶
See Verilog and Yosys for how synthesis is used.
Synthesis
¶
Synthesis(
verilog_files: VerilogFiles,
verilog_top_module: str,
functional: bool = False,
parameters: Parameters | None = None,
includes: IncludeFolders | None = None,
defines: Defines | None = None,
keep_signals: bool = False,
)
Synthesizes Verilog into a netlist with Yosys, which a YosysComponent can be built from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verilog_files
|
VerilogFiles
|
One Verilog file, or a list of them. |
required |
verilog_top_module
|
str
|
The name of the module to synthesize. |
required |
functional
|
bool
|
Synthesize into functional blocks, like adders, multiplexers and registers, instead of gates and one-bit flip-flops. The netlist has far fewer cells, so it simulates faster. |
False
|
parameters
|
Parameters | None
|
Values for parameters of the top module, by name, instead of their defaults, like {"WIDTH": 16}. The values are integers. |
None
|
includes
|
IncludeFolders | None
|
Folders to find the files of `include in, after the folder of the including file. |
None
|
defines
|
Defines | None
|
Macros for the Verilog files, like `define, by name: {"WIDTH": 8}, or {"DEBUG": None} for a macro without a value. A value is the text of the macro, like '"file.txt"' for a string. |
None
|
keep_signals
|
bool
|
Keep the named wires and registers, also of the submodules, and the logic that drives them, also when no output depends on them. Synthesis removes those, which hides them from a simulation that shows the signals inside the design, like the tests of cocotb. A signal that is the same net as another one (assign b = a, not a constant) gets a buffer, so that it has a cell of its own. The netlist gets bigger. |
False
|
Raises:
| Type | Description |
|---|---|
SynthesisException
|
If a parameter name is not a Verilog identifier, or its value not an integer. A parameter that the module doesn't have is an error of the synthesis. A macro name that is not a Verilog identifier, a macro value with a line break, or an include folder with a space or a quote. |
list_modules
classmethod
¶
list_modules(
verilog_files: VerilogFiles,
log: list[str] | None = None,
) -> list[str]
The names of the modules in Verilog files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verilog_files
|
VerilogFiles
|
One Verilog file, or a list of them. |
required |
log
|
list[str] | None
|
A list to add the Yosys log to. |
None
|
Raises:
| Type | Description |
|---|---|
SynthesisException
|
If Yosys reports an error, like a syntax error. |
list_parameters
classmethod
¶
list_parameters(
verilog_files: VerilogFiles,
module: str,
log: list[str] | None = None,
) -> dict[str, int | str]
The parameters of a module and their defaults, in the order of the Verilog. A default is an integer, or text if it isn't one (like a string parameter).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verilog_files
|
VerilogFiles
|
One Verilog file, or a list of them. |
required |
module
|
str
|
The name of the module. |
required |
log
|
list[str] | None
|
A list to add the Yosys log to. |
None
|
Raises:
| Type | Description |
|---|---|
SynthesisException
|
If Yosys reports an error, like a syntax error, or the files have no such module. |
module_hierarchy
classmethod
¶
module_hierarchy(
verilog_files: VerilogFiles,
log: list[str] | None = None,
) -> dict[str, list[str]]
The modules of Verilog files, in the order of the Verilog, each with the modules of the files that it instantiates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verilog_files
|
VerilogFiles
|
One Verilog file, or a list of them. |
required |
log
|
list[str] | None
|
A list to add the Yosys log to. |
None
|
Raises:
| Type | Description |
|---|---|
SynthesisException
|
If Yosys reports an error, like a syntax error. |
top_modules
staticmethod
¶
top_modules(
hierarchy: Mapping[str, Sequence[str]],
) -> list[str]
The modules of a module_hierarchy() that no other module instantiates
list_module_parameters
classmethod
¶
list_module_parameters(
verilog_files: VerilogFiles,
log: list[str] | None = None,
) -> dict[str, dict[str, int | str]]
The parameters of every module in Verilog files and their defaults, by module, see list_parameters(). A module without parameters has an empty dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verilog_files
|
VerilogFiles
|
One Verilog file, or a list of them. |
required |
log
|
list[str] | None
|
A list to add the Yosys log to. |
None
|
Raises:
| Type | Description |
|---|---|
SynthesisException
|
If Yosys reports an error, like a syntax error. |
synth_to_json
¶
synth_to_json(silent: bool = False) -> str
Synthesize, and return the netlist as JSON text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
silent
|
bool
|
Don't print the Yosys log. |
False
|
Raises:
| Type | Description |
|---|---|
SynthesisException
|
If Yosys reports an error, like a syntax error. |
synth_to_dict
¶
synth_to_dict(silent: bool = False) -> dict[str, Any]
Synthesize, and return the netlist as a dict, for YosysNetlist(**netlist_dict).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
silent
|
bool
|
Don't print the Yosys log. |
False
|
Raises:
| Type | Description |
|---|---|
SynthesisException
|
If Yosys reports an error, like a syntax error. |
synth_to_json_file
¶
synth_to_json_file(
filename: str | Path, silent: bool = False
) -> None
Synthesize, and write the netlist to a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | Path
|
The netlist file to write. |
required |
silent
|
bool
|
Don't print the Yosys log. |
False
|
Raises:
| Type | Description |
|---|---|
SynthesisException
|
If Yosys reports an error, like a syntax error. |
get_messages
¶
get_messages() -> list[YosysMessage]
The errors and warnings of the last synthesis, see parse_messages()
SynthesisException
¶
SynthesisException(message: str, log: Sequence[str] = ())
Bases: DigsimException
Yosys could not synthesize the Verilog, the message is the Yosys error.
Attributes:
| Name | Type | Description |
|---|---|---|
log |
The Yosys log, empty if Yosys didn't write one. |
|
messages |
The errors and warnings in the log, see parse_messages(). An error that isn't in the log is the only message. |
YosysMessage
dataclass
¶
YosysMessage(
kind: Literal["error", "warning"],
text: str,
file: str | None = None,
line: int | None = None,
)
An error or a warning in the Yosys log.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
Literal['error', 'warning']
|
"error" or "warning". |
required |
text
|
str
|
The message, without the file, line and kind. |
required |
file
|
str | None
|
The file the message is about, None if it doesn't say. |
None
|
line
|
int | None
|
The line in the file, from 1, None if it doesn't say. |
None
|
parse_messages
¶
parse_messages(log: Sequence[str]) -> list[YosysMessage]
The errors and warnings in a Yosys log, each once, in the order of the log
yosys_path_problem
¶
yosys_path_problem(path: str | PathLike[str]) -> str | None
Why the Yosys of DigSim can't read a file, None if it can. The WebAssembly Yosys (YoWASP) can't read files in /tmp on Linux, in /share, or directly in /, and not network paths on Windows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
The path of a Verilog file. |
required |