diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2020-12-27 23:27:35 +0100 |
---|---|---|
committer | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2020-12-27 23:27:35 +0100 |
commit | 0b16ac19879a49acfe777a922dff182e18574442 (patch) | |
tree | a5f964fef5b5f4f3537c156a8703ebbfb48944b0 /pyGHDL/dom/Common.py | |
parent | a9c0630b8f3cda6b857b915585023afa94771832 (diff) | |
download | ghdl-0b16ac19879a49acfe777a922dff182e18574442.tar.gz ghdl-0b16ac19879a49acfe777a922dff182e18574442.tar.bz2 ghdl-0b16ac19879a49acfe777a922dff182e18574442.zip |
Added first implementation of a document object model (DOM).
Diffstat (limited to 'pyGHDL/dom/Common.py')
-rw-r--r-- | pyGHDL/dom/Common.py | 48 |
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..8baa6537e --- /dev/null +++ b/pyGHDL/dom/Common.py @@ -0,0 +1,48 @@ +from pydecor import export + +from pyVHDLModel.VHDLModel import Modes + +from libghdl.thin import name_table +from libghdl.thin.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.") |