aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xpyGHDL/cli/DOM.py35
1 files changed, 26 insertions, 9 deletions
diff --git a/pyGHDL/cli/DOM.py b/pyGHDL/cli/DOM.py
index 1ab3d4321..2feb6aecd 100755
--- a/pyGHDL/cli/DOM.py
+++ b/pyGHDL/cli/DOM.py
@@ -7,15 +7,15 @@ from pathlib import Path
from pydecor import export
+from pyGHDL import GHDLBaseException
+from pyGHDL.libghdl import LibGHDLException
from pyGHDL.dom import NonStandard
+from pyGHDL.dom.Common import DOMException
+from pyGHDL.dom.formatting.prettyprint import PrettyPrint, PrettyPrintException
__all__ = []
__api__ = __all__
-from pyGHDL.dom.Common import DOMException
-
-from pyGHDL.dom.formatting.prettyprint import PrettyPrint, PrettyPrintException
-
@export
class Application:
@@ -40,6 +40,26 @@ class Application:
print("\n".join(buffer))
+def handleException(ex):
+ if isinstance(ex, PrettyPrintException):
+ print("PP:", ex)
+ return 5
+ elif isinstance(ex, DOMException):
+ print("DOM:", ex)
+ return 4
+ elif isinstance(ex, LibGHDLException):
+ print("LIB:", ex)
+ return 3
+ elif isinstance(ex, GHDLBaseException):
+ print("GHDL:", ex)
+ return 2
+ else:
+ print(
+ "Fatal: An unhandled exception has reached to the top-most exception handler."
+ )
+ return 1
+
+
def main(items=argv[1:]):
_exitcode = 0
@@ -53,11 +73,8 @@ def main(items=argv[1:]):
app = Application()
app.addFile(Path(item), "default_lib")
app.prettyPrint()
- except DOMException as ex:
- print("DOM:", ex)
- except PrettyPrintException as ex:
- print("PP:", ex)
- _exitcode = 1
+ except Exception as ex:
+ _exitcode = handleException(ex)
return _exitcode