aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/dom/Common.py
diff options
context:
space:
mode:
authortgingold <tgingold@users.noreply.github.com>2020-12-29 17:19:09 +0100
committerGitHub <noreply@github.com>2020-12-29 17:19:09 +0100
commit7ca54117b8f757396ba5ef04c83ff1228ca94384 (patch)
treecc5f7f4166cc0570bda5cf2047d3ef7abbc36e37 /pyGHDL/dom/Common.py
parent340fc792bba2ffdb4f930bc427a39ea3a1b659b2 (diff)
parent50adcf884c3cfa4e33ca45769295f163baa63a3e (diff)
downloadghdl-7ca54117b8f757396ba5ef04c83ff1228ca94384.tar.gz
ghdl-7ca54117b8f757396ba5ef04c83ff1228ca94384.tar.bz2
ghdl-7ca54117b8f757396ba5ef04c83ff1228ca94384.zip
Merge pull request #1556 from Paebbels/paebbels/pyGHDL
Cleanup and Restructuring of pyGHDL
Diffstat (limited to 'pyGHDL/dom/Common.py')
-rw-r--r--pyGHDL/dom/Common.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/pyGHDL/dom/Common.py b/pyGHDL/dom/Common.py
new file mode 100644
index 000000000..0cd41c99e
--- /dev/null
+++ b/pyGHDL/dom/Common.py
@@ -0,0 +1,48 @@
+from pydecor import export
+
+from pyVHDLModel.VHDLModel import Modes
+
+from pyGHDL.libghdl import name_table
+from pyGHDL.libghdl.vhdl import nodes
+
+__all__ = []
+__api__ = __all__
+
+
+@export
+class GHDLBaseException(Exception):
+ pass
+
+
+@export
+class LibGHDLException(GHDLBaseException):
+ pass
+
+
+@export
+class GHDLException(GHDLBaseException):
+ pass
+
+
+@export
+class GHDLMixin:
+ _MODE_TRANSLATION = {
+ nodes.Iir_Mode.In_Mode: Modes.In,
+ nodes.Iir_Mode.Out_Mode: Modes.Out,
+ nodes.Iir_Mode.Inout_Mode: Modes.InOut,
+ nodes.Iir_Mode.Buffer_Mode: Modes.Buffer,
+ nodes.Iir_Mode.Linkage_Mode: Modes.Linkage
+ }
+
+ @classmethod
+ def _ghdlNodeToName(cls, node):
+ """Return the python string from node :param:`node` identifier"""
+ return name_table.Get_Name_Ptr(nodes.Get_Identifier(node)).decode("utf-8")
+
+ @classmethod
+ def _ghdlPortToMode(cls, port):
+ """Return the mode of a port."""
+ try:
+ return cls._MODE_TRANSLATION[nodes.Get_Mode(port)]
+ except KeyError:
+ raise LibGHDLException("Unknown mode.")