aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortgingold <tgingold@users.noreply.github.com>2021-06-22 18:36:24 +0200
committerGitHub <noreply@github.com>2021-06-22 18:36:24 +0200
commit70120662ef44e5906e0c6f104a4f2af4bf5895e0 (patch)
tree914dda852c9b662b07ebcc9249edee92334a9ae2
parentbf45d9939dc26d0d584dd549923b9962f83360ec (diff)
parent38571ce4ce5e1d594a7c55f5bb6f1514f1402329 (diff)
downloadghdl-70120662ef44e5906e0c6f104a4f2af4bf5895e0.tar.gz
ghdl-70120662ef44e5906e0c6f104a4f2af4bf5895e0.tar.bz2
ghdl-70120662ef44e5906e0c6f104a4f2af4bf5895e0.zip
Merge pull request #1801 from umarcor/py-dom-entrypoint
pyGHDL: add ghdl-dom entrypoint
-rwxr-xr-xpyGHDL/cli/DOM.py39
-rw-r--r--setup.py3
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())
diff --git a/setup.py b/setup.py
index db08a2296..75e04bb3a 100644
--- a/setup.py
+++ b/setup.py
@@ -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"
]
},