aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/dom
diff options
context:
space:
mode:
authorPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-26 10:02:16 +0200
committerPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-07-01 06:39:46 +0200
commit2492b5595c7a61e29096a217e46f9dfe2e0fd6ac (patch)
tree57d296d765b1b66ea5ce4e63d369c9e4ee6009d3 /pyGHDL/dom
parent2b25719bf3a5880f428b5a58b17208b8e71eba8a (diff)
downloadghdl-2492b5595c7a61e29096a217e46f9dfe2e0fd6ac.tar.gz
ghdl-2492b5595c7a61e29096a217e46f9dfe2e0fd6ac.tar.bz2
ghdl-2492b5595c7a61e29096a217e46f9dfe2e0fd6ac.zip
WIP: Handle more generic interface kinds.
(cherry picked from commit 6b5606852371bdd8bdc9c8a3dcd38ef8e7eecbc9)
Diffstat (limited to 'pyGHDL/dom')
-rw-r--r--pyGHDL/dom/InterfaceItem.py92
-rw-r--r--pyGHDL/dom/_Translate.py15
-rw-r--r--pyGHDL/dom/__init__.py8
3 files changed, 97 insertions, 18 deletions
diff --git a/pyGHDL/dom/InterfaceItem.py b/pyGHDL/dom/InterfaceItem.py
index df62c8256..c5955c6aa 100644
--- a/pyGHDL/dom/InterfaceItem.py
+++ b/pyGHDL/dom/InterfaceItem.py
@@ -34,6 +34,10 @@ from pydecor import export
from pyVHDLModel.VHDLModel import (
GenericConstantInterfaceItem as VHDLModel_GenericConstantInterfaceItem,
+ GenericTypeInterfaceItem as VHDLModel_GenericTypeInterfaceItem,
+ GenericPackageInterfaceItem as VHDLModel_GenericPackageInterfaceItem,
+ GenericProcedureInterfaceItem as VHDLModel_GenericProcedureInterfaceItem,
+ GenericFunctionInterfaceItem as VHDLModel_GenericFunctionInterfaceItem,
PortSignalInterfaceItem as VHDLModel_PortSignalInterfaceItem,
ParameterConstantInterfaceItem as VHDLModel_ParameterConstantInterfaceItem,
ParameterVariableInterfaceItem as VHDLModel_ParameterVariableInterfaceItem,
@@ -64,13 +68,9 @@ class GenericConstantInterfaceItem(VHDLModel_GenericConstantInterfaceItem, DOMMi
subType: SubTypeOrSymbol,
defaultExpression: Expression,
):
- super().__init__(name=name, mode=mode)
+ super().__init__(name, mode, subType, defaultExpression)
DOMMixin.__init__(self, node)
- # TODO: move to model
- self._subType = subType
- self._defaultExpression = defaultExpression
-
@classmethod
def parse(cls, genericNode: Iir) -> "GenericConstantInterfaceItem":
name = GetNameOfNode(genericNode)
@@ -83,6 +83,82 @@ class GenericConstantInterfaceItem(VHDLModel_GenericConstantInterfaceItem, DOMMi
@export
+class GenericTypeInterfaceItem(VHDLModel_GenericTypeInterfaceItem, DOMMixin):
+ def __init__(
+ self,
+ node: Iir,
+ name: str,
+ ):
+ super().__init__(name=name)
+ DOMMixin.__init__(self, node)
+
+ @classmethod
+ def parse(cls, genericNode: Iir) -> "GenericTypeInterfaceItem":
+ name = GetNameOfNode(genericNode)
+
+ return cls(genericNode, name)
+
+
+@export
+class GenericPackageInterfaceItem(VHDLModel_GenericPackageInterfaceItem, DOMMixin):
+ def __init__(
+ self,
+ node: Iir,
+ name: str,
+ ):
+ super().__init__(name)
+ DOMMixin.__init__(self, node)
+
+ @classmethod
+ def parse(cls, genericNode: Iir) -> "GenericPackageInterfaceItem":
+ name = GetNameOfNode(genericNode)
+
+ return cls(genericNode, name)
+
+
+@export
+class GenericProcedureInterfaceItem(VHDLModel_GenericProcedureInterfaceItem, DOMMixin):
+ def __init__(
+ self,
+ node: Iir,
+ name: str,
+ ):
+ super().__init__(name)
+ DOMMixin.__init__(self, node)
+
+ @classmethod
+ def parse(cls, genericNode: Iir) -> "GenericProcedureInterfaceItem":
+ name = GetNameOfNode(genericNode)
+ mode = GetModeOfNode(genericNode)
+ subTypeIndication = GetSubTypeIndicationFromNode(genericNode, "generic", name)
+ default = nodes.Get_Default_Value(genericNode)
+ value = GetExpressionFromNode(default) if default else None
+
+ return cls(genericNode, name)
+
+
+@export
+class GenericFunctionInterfaceItem(VHDLModel_GenericFunctionInterfaceItem, DOMMixin):
+ def __init__(
+ self,
+ node: Iir,
+ name: str,
+ ):
+ super().__init__(name)
+ DOMMixin.__init__(self, node)
+
+ @classmethod
+ def parse(cls, genericNode: Iir) -> "GenericFunctionInterfaceItem":
+ name = GetNameOfNode(genericNode)
+ mode = GetModeOfNode(genericNode)
+ subTypeIndication = GetSubTypeIndicationFromNode(genericNode, "generic", name)
+ default = nodes.Get_Default_Value(genericNode)
+ value = GetExpressionFromNode(default) if default else None
+
+ return cls(genericNode, name)
+
+
+@export
class PortSignalInterfaceItem(VHDLModel_PortSignalInterfaceItem, DOMMixin):
def __init__(
self,
@@ -92,13 +168,9 @@ class PortSignalInterfaceItem(VHDLModel_PortSignalInterfaceItem, DOMMixin):
subType: SubTypeOrSymbol,
defaultExpression: Expression = None,
):
- super().__init__(name=name, mode=mode)
+ super().__init__(name, mode, subType, defaultExpression)
DOMMixin.__init__(self, node)
- # TODO: move to model
- self._subType = subType
- self._defaultExpression = defaultExpression
-
@classmethod
def parse(cls, portNode: Iir) -> "PortSignalInterfaceItem":
name = GetNameOfNode(portNode)
diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py
index 502a94ad3..806b6f2fa 100644
--- a/pyGHDL/dom/_Translate.py
+++ b/pyGHDL/dom/_Translate.py
@@ -416,6 +416,13 @@ def GetExpressionFromNode(node: Iir) -> Expression:
def GetGenericsFromChainedNodes(
nodeChain: Iir,
) -> Generator[GenericInterfaceItem, None, None]:
+ from pyGHDL.dom.InterfaceItem import (
+ GenericTypeInterfaceItem,
+ GenericPackageInterfaceItem,
+ GenericProcedureInterfaceItem,
+ GenericFunctionInterfaceItem,
+ )
+
for generic in utils.chain_iter(nodeChain):
kind = GetIirKindOfNode(generic)
if kind == nodes.Iir_Kind.Interface_Constant_Declaration:
@@ -423,13 +430,13 @@ def GetGenericsFromChainedNodes(
yield GenericConstantInterfaceItem.parse(generic)
elif kind == nodes.Iir_Kind.Interface_Type_Declaration:
- print("[NOT IMPLEMENTED] generic type")
+ yield GenericTypeInterfaceItem.parse(generic)
elif kind == nodes.Iir_Kind.Interface_Package_Declaration:
- print("[NOT IMPLEMENTED] generic package")
+ yield GenericPackageInterfaceItem.parse(generic)
elif kind == nodes.Iir_Kind.Interface_Procedure_Declaration:
- print("[NOT IMPLEMENTED] generic procedure")
+ yield GenericProcedureInterfaceItem.parse(generic)
elif kind == nodes.Iir_Kind.Interface_Function_Declaration:
- print("[NOT IMPLEMENTED] generic function")
+ yield GenericFunctionInterfaceItem.parse(generic)
else:
position = Position.parse(generic)
raise DOMException(
diff --git a/pyGHDL/dom/__init__.py b/pyGHDL/dom/__init__.py
index d3dc506f5..143fab1ff 100644
--- a/pyGHDL/dom/__init__.py
+++ b/pyGHDL/dom/__init__.py
@@ -32,13 +32,12 @@
# ============================================================================
from pathlib import Path
-from pyGHDL import GHDLBaseException
-from pyGHDL.libghdl import files_map, name_table
-
-from pyGHDL.libghdl.vhdl import nodes
from pydecor import export
+from pyGHDL import GHDLBaseException
+from pyGHDL.libghdl import files_map, name_table
from pyGHDL.libghdl._types import Iir
+from pyGHDL.libghdl.vhdl import nodes
__all__ = []
@@ -46,6 +45,7 @@ __all__ = []
@export
class Position:
"""Represents the source code position of a IIR node in a source file."""
+
_filename: Path
_line: int
_column: int