Skip to content

Commit

Permalink
Improve error handling for yosys component
Browse files Browse the repository at this point in the history
  • Loading branch information
freand76 committed Dec 9, 2023
1 parent c4bcab3 commit 47ca408
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## vx.x.x
* Fix bug when detecting number of modules with yosys 0.9
* Improve error handling for yosys component

## v0.0.1 - First Release
* Simulation of a digital circuit using a python
Expand Down
7 changes: 6 additions & 1 deletion src/digsim/app/gui_objects/_yosys_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from PySide6.QtGui import QAction

from digsim.circuit.components.atoms import DigsimException

from ._image_objects import ImageObject


Expand All @@ -23,5 +25,8 @@ def add_context_menu_action(self, menu, parent):
reloadAction.triggered.connect(self._reload)

def _reload(self):
self.component.reload_file()
try:
self.component.reload_file()
except DigsimException as exc:
self._app_model.sig_warning_log.emit("Reload Yosys Warning", str(exc))
self._app_model.model_reset()
4 changes: 2 additions & 2 deletions src/digsim/circuit/components/_yosys_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def _synth_verilog(self):
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
filename = tmp_file.name
synthesis = Synthesis(self._path, filename, toplevel)
if not synthesis.execute():
raise YosysComponentException("Yosys synthesis error")
if not synthesis.execute(silent=True):
raise YosysComponentException(f"Yosys synthesis error {self._path}")
return filename

def _load_netlist_dict(self):
Expand Down
2 changes: 1 addition & 1 deletion src/digsim/synth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

""" All classes within digsim.synth namespace """

from ._synthesis import Synthesis # noqa: F401
from ._synthesis import Synthesis, SynthesisException # noqa: F401
11 changes: 9 additions & 2 deletions src/digsim/synth/_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import tempfile
from pathlib import Path

from digsim.circuit.components.atoms import DigsimException

class SynthesisException(Exception):

class SynthesisException(DigsimException):
"""Exception class for yosys synthesis"""


Expand Down Expand Up @@ -52,7 +54,12 @@ def list_modules(cls, verilog_files):
success = process.returncode == 0
Path(script_file).unlink()
if not success:
raise SynthesisException("Yosys execution failed...")
files_str = ""
for verilog_file in verilog_files:
if len(files_str) > 0:
files_str += ", "
files_str += Path(verilog_file).name
raise SynthesisException(f"Yosys error for {files_str}")
return modules

def __init__(self, verilog_files, json_output_file, verilog_top_module):
Expand Down

0 comments on commit 47ca408

Please sign in to comment.