diff options
-rwxr-xr-x | pyGHDL/cli/DOM.py | 39 | ||||
-rw-r--r-- | setup.py | 3 |
2 files changed, 30 insertions, 12 deletions
diff --git a/pyGHDL/cli/DOM.py b/pyGHDL/cli/DOM.py index 2b846edde..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,7 +40,27 @@ class Application: print("\n".join(buffer)) -def main(items): +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 if len(items) < 1: @@ -53,14 +73,11 @@ def main(items): 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 if __name__ == "__main__": - sysexit(main(argv[1:])) + sysexit(main()) @@ -93,7 +93,8 @@ setuptools_setup( packages=setuptools_find_packages(exclude=("tests",)), entry_points={ 'console_scripts': [ - "ghdl-ls = pyGHDL.cli.lsp:main" + "ghdl-ls = pyGHDL.cli.lsp:main", + "ghdl-dom = pyGHDL.cli.DOM:main" ] }, |