From d557b50e78e74801bf296b18a004a468555921be Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 6 Dec 2022 00:36:29 +0100 Subject: Updated for latest pyVHDLModel v0.17.x (cherry picked from commit fb6e98b119cc1bb94ba5ecca88d7533a00a2e3f6) --- pyGHDL/dom/InterfaceItem.py | 44 +++++++++++++++++++++++++++++++------------- pyGHDL/dom/Object.py | 12 ++++++------ pyGHDL/dom/_Translate.py | 33 ++++++++++++++++++++------------- 3 files changed, 57 insertions(+), 32 deletions(-) (limited to 'pyGHDL') diff --git a/pyGHDL/dom/InterfaceItem.py b/pyGHDL/dom/InterfaceItem.py index fb8a1b320..aa63f3094 100644 --- a/pyGHDL/dom/InterfaceItem.py +++ b/pyGHDL/dom/InterfaceItem.py @@ -30,7 +30,7 @@ # # SPDX-License-Identifier: GPL-2.0-or-later # ============================================================================ -from typing import List +from typing import List, Iterable from pyTooling.Decorators import export @@ -75,15 +75,18 @@ class GenericConstantInterfaceItem(VHDLModel_GenericConstantInterfaceItem, DOMMi DOMMixin.__init__(self, node) @classmethod - def parse(cls, genericNode: Iir) -> "GenericConstantInterfaceItem": + def parse(cls, genericNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "GenericConstantInterfaceItem": name = GetNameOfNode(genericNode) documentation = GetDocumentationOfNode(genericNode) + identifiers = [name] + if furtherIdentifiers is not None: + identifiers.extend(furtherIdentifiers) 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], mode, subtypeIndication, value, documentation) + return cls(genericNode, identifiers, mode, subtypeIndication, value, documentation) @export @@ -157,16 +160,19 @@ class PortSignalInterfaceItem(VHDLModel_PortSignalInterfaceItem, DOMMixin): DOMMixin.__init__(self, node) @classmethod - def parse(cls, portNode: Iir) -> "PortSignalInterfaceItem": + def parse(cls, portNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "PortSignalInterfaceItem": name = GetNameOfNode(portNode) documentation = GetDocumentationOfNode(portNode) + identifiers = [name] + if furtherIdentifiers is not None: + identifiers.extend(furtherIdentifiers) mode = GetModeOfNode(portNode) subtypeIndication = GetSubtypeIndicationFromNode(portNode, "port", name) defaultValue = nodes.Get_Default_Value(portNode) value = GetExpressionFromNode(defaultValue) if defaultValue != nodes.Null_Iir else None - return cls(portNode, [name], mode, subtypeIndication, value, documentation) + return cls(portNode, identifiers, mode, subtypeIndication, value, documentation) @export @@ -184,16 +190,19 @@ class ParameterConstantInterfaceItem(VHDLModel_ParameterConstantInterfaceItem, D DOMMixin.__init__(self, node) @classmethod - def parse(cls, parameterNode: Iir) -> "ParameterConstantInterfaceItem": + def parse(cls, parameterNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "ParameterConstantInterfaceItem": name = GetNameOfNode(parameterNode) documentation = GetDocumentationOfNode(parameterNode) + identifiers = [name] + if furtherIdentifiers is not None: + identifiers.extend(furtherIdentifiers) mode = GetModeOfNode(parameterNode) subtypeIndication = GetSubtypeIndicationFromNode(parameterNode, "parameter", name) defaultValue = nodes.Get_Default_Value(parameterNode) value = GetExpressionFromNode(defaultValue) if defaultValue != nodes.Null_Iir else None - return cls(parameterNode, [name], mode, subtypeIndication, value, documentation) + return cls(parameterNode, identifiers, mode, subtypeIndication, value, documentation) @export @@ -211,16 +220,19 @@ class ParameterVariableInterfaceItem(VHDLModel_ParameterVariableInterfaceItem, D DOMMixin.__init__(self, node) @classmethod - def parse(cls, parameterNode: Iir) -> "ParameterVariableInterfaceItem": + def parse(cls, parameterNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "ParameterVariableInterfaceItem": name = GetNameOfNode(parameterNode) documentation = GetDocumentationOfNode(parameterNode) + identifiers = [name] + if furtherIdentifiers is not None: + identifiers.extend(furtherIdentifiers) mode = GetModeOfNode(parameterNode) subtypeIndication = GetSubtypeIndicationFromNode(parameterNode, "parameter", name) defaultValue = nodes.Get_Default_Value(parameterNode) value = GetExpressionFromNode(defaultValue) if defaultValue != nodes.Null_Iir else None - return cls(parameterNode, [name], mode, subtypeIndication, value, documentation) + return cls(parameterNode, identifiers, mode, subtypeIndication, value, documentation) @export @@ -238,16 +250,19 @@ class ParameterSignalInterfaceItem(VHDLModel_ParameterSignalInterfaceItem, DOMMi DOMMixin.__init__(self, node) @classmethod - def parse(cls, parameterNode: Iir) -> "ParameterSignalInterfaceItem": + def parse(cls, parameterNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "ParameterSignalInterfaceItem": name = GetNameOfNode(parameterNode) documentation = GetDocumentationOfNode(parameterNode) + identifiers = [name] + if furtherIdentifiers is not None: + identifiers.extend(furtherIdentifiers) mode = GetModeOfNode(parameterNode) subtypeIndication = GetSubtypeIndicationFromNode(parameterNode, "parameter", name) defaultValue = nodes.Get_Default_Value(parameterNode) value = GetExpressionFromNode(defaultValue) if defaultValue != nodes.Null_Iir else None - return cls(parameterNode, [name], mode, subtypeIndication, value, documentation) + return cls(parameterNode, identifiers, mode, subtypeIndication, value, documentation) @export @@ -257,9 +272,12 @@ class ParameterFileInterfaceItem(VHDLModel_ParameterFileInterfaceItem, DOMMixin) DOMMixin.__init__(self, node) @classmethod - def parse(cls, parameterNode: Iir) -> "ParameterFileInterfaceItem": + def parse(cls, parameterNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "ParameterFileInterfaceItem": name = GetNameOfNode(parameterNode) documentation = GetDocumentationOfNode(parameterNode) + identifiers = [name] + if furtherIdentifiers is not None: + identifiers.extend(furtherIdentifiers) subtypeIndication = GetSubtypeIndicationFromNode(parameterNode, "parameter", name) - return cls(parameterNode, [name], subtypeIndication, documentation) + return cls(parameterNode, identifiers, subtypeIndication, documentation) diff --git a/pyGHDL/dom/Object.py b/pyGHDL/dom/Object.py index e3528c9db..1079eae4a 100644 --- a/pyGHDL/dom/Object.py +++ b/pyGHDL/dom/Object.py @@ -76,10 +76,10 @@ class Constant(VHDLModel_Constant, DOMMixin): ) name = GetNameOfNode(constantNode) + documentation = GetDocumentationOfNode(constantNode) identifiers = [name] if furtherIdentifiers is not None: identifiers.extend(furtherIdentifiers) - documentation = GetDocumentationOfNode(constantNode) subtypeIndication = GetSubtypeIndicationFromNode(constantNode, "constant", name) defaultValue = nodes.Get_Default_Value(constantNode) if defaultValue != nodes.Null_Iir: @@ -101,10 +101,10 @@ class DeferredConstant(VHDLModel_DeferredConstant, DOMMixin): from pyGHDL.dom._Translate import GetSubtypeIndicationFromNode name = GetNameOfNode(constantNode) + documentation = GetDocumentationOfNode(constantNode) identifiers = [name] if furtherIdentifiers is not None: identifiers.extend(furtherIdentifiers) - documentation = GetDocumentationOfNode(constantNode) subtypeIndication = GetSubtypeIndicationFromNode(constantNode, "deferred constant", name) return cls(constantNode, identifiers, subtypeIndication, documentation) @@ -131,10 +131,10 @@ class Variable(VHDLModel_Variable, DOMMixin): ) name = GetNameOfNode(variableNode) + documentation = GetDocumentationOfNode(variableNode) identifiers = [name] if furtherIdentifiers is not None: identifiers.extend(furtherIdentifiers) - documentation = GetDocumentationOfNode(variableNode) subtypeIndication = GetSubtypeIndicationFromNode(variableNode, "variable", name) defaultValue = nodes.Get_Default_Value(variableNode) defaultExpression = None @@ -155,10 +155,10 @@ class SharedVariable(VHDLModel_SharedVariable, DOMMixin): from pyGHDL.dom._Translate import GetSubtypeIndicationFromNode name = GetNameOfNode(variableNode) + documentation = GetDocumentationOfNode(variableNode) identifiers = [name] if furtherIdentifiers is not None: identifiers.extend(furtherIdentifiers) - documentation = GetDocumentationOfNode(variableNode) subtypeIndication = GetSubtypeIndicationFromNode(variableNode, "variable", name) return cls(variableNode, identifiers, subtypeIndication, documentation) @@ -185,10 +185,10 @@ class Signal(VHDLModel_Signal, DOMMixin): ) name = GetNameOfNode(signalNode) + documentation = GetDocumentationOfNode(signalNode) identifiers = [name] if furtherIdentifiers is not None: identifiers.extend(furtherIdentifiers) - documentation = GetDocumentationOfNode(signalNode) subtypeIndication = GetSubtypeIndicationFromNode(signalNode, "signal", name) default = nodes.Get_Default_Value(signalNode) defaultExpression = GetExpressionFromNode(default) if default else None @@ -207,10 +207,10 @@ class File(VHDLModel_File, DOMMixin): from pyGHDL.dom._Translate import GetSubtypeIndicationFromNode name = GetNameOfNode(fileNode) + documentation = GetDocumentationOfNode(fileNode) identifiers = [name] if furtherIdentifiers is not None: identifiers.extend(furtherIdentifiers) - documentation = GetDocumentationOfNode(fileNode) subtypeIndication = GetSubtypeIndicationFromNode(fileNode, "file", name) # FIXME: handle file open stuff diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py index ef8656e52..d39b14765 100644 --- a/pyGHDL/dom/_Translate.py +++ b/pyGHDL/dom/_Translate.py @@ -464,21 +464,20 @@ def GetGenericsFromChainedNodes( GenericFunctionInterfaceItem, ) + furtherIdentifiers = [] generic = nodeChain while generic != nodes.Null_Iir: kind = GetIirKindOfNode(generic) if kind == nodes.Iir_Kind.Interface_Constant_Declaration: from pyGHDL.dom.InterfaceItem import GenericConstantInterfaceItem - genericConstant = GenericConstantInterfaceItem.parse(generic) - # Lookahead for generics with multiple identifiers at once if nodes.Get_Has_Identifier_List(generic): nextNode = nodes.Get_Chain(generic) for nextGeneric in utils.chain_iter(nextNode): # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication(nextGeneric) == nodes.Null_Iir: - genericConstant.Identifiers.append(GetNameOfNode(nextGeneric)) + furtherIdentifiers.append(GetNameOfNode(nextGeneric)) else: generic = nextGeneric break @@ -492,7 +491,8 @@ def GetGenericsFromChainedNodes( else: generic = nodes.Get_Chain(generic) - yield genericConstant + yield GenericConstantInterfaceItem.parse(generic, furtherIdentifiers) + furtherIdentifiers.clear() continue else: if kind == nodes.Iir_Kind.Interface_Type_Declaration: @@ -517,13 +517,14 @@ def GetPortsFromChainedNodes( nodeChain: Iir, ) -> Generator[PortInterfaceItem, None, None]: + furtherIdentifiers = [] port = nodeChain while port != nodes.Null_Iir: kind = GetIirKindOfNode(port) if kind == nodes.Iir_Kind.Interface_Signal_Declaration: from pyGHDL.dom.InterfaceItem import PortSignalInterfaceItem - portSignal = PortSignalInterfaceItem.parse(port) + portToParse = port # Lookahead for ports with multiple identifiers at once if nodes.Get_Has_Identifier_List(port): @@ -531,7 +532,7 @@ def GetPortsFromChainedNodes( for nextPort in utils.chain_iter(nextNode): # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication(nextPort) == nodes.Null_Iir: - portSignal.Identifiers.append(GetNameOfNode(nextPort)) + furtherIdentifiers.append(GetNameOfNode(nextPort)) else: port = nextPort break @@ -545,7 +546,8 @@ def GetPortsFromChainedNodes( else: port = nodes.Get_Chain(port) - yield portSignal + yield PortSignalInterfaceItem.parse(portToParse, furtherIdentifiers) + furtherIdentifiers.clear() continue else: position = Position.parse(port) @@ -559,25 +561,30 @@ def GetParameterFromChainedNodes( nodeChain: Iir, ) -> Generator[ParameterInterfaceItem, None, None]: + identifiers = [] parameter = nodeChain while parameter != nodes.Null_Iir: kind = GetIirKindOfNode(parameter) if kind == nodes.Iir_Kind.Interface_Constant_Declaration: from pyGHDL.dom.InterfaceItem import ParameterConstantInterfaceItem - param = ParameterConstantInterfaceItem.parse(parameter) + parseMethod = ParameterConstantInterfaceItem.parse + parseNode = parameter elif kind == nodes.Iir_Kind.Interface_Variable_Declaration: from pyGHDL.dom.InterfaceItem import ParameterVariableInterfaceItem - param = ParameterVariableInterfaceItem.parse(parameter) + parseMethod = ParameterVariableInterfaceItem.parse + parseNode = parameter elif kind == nodes.Iir_Kind.Interface_Signal_Declaration: from pyGHDL.dom.InterfaceItem import ParameterSignalInterfaceItem - param = ParameterSignalInterfaceItem.parse(parameter) + parseMethod = ParameterSignalInterfaceItem.parse + parseNode = parameter elif kind == nodes.Iir_Kind.Interface_File_Declaration: from pyGHDL.dom.InterfaceItem import ParameterFileInterfaceItem - param = ParameterFileInterfaceItem.parse(parameter) + parseMethod = ParameterFileInterfaceItem.parse + parseNode = parameter else: position = Position.parse(parameter) raise DOMException( @@ -590,7 +597,7 @@ def GetParameterFromChainedNodes( for nextParameter in utils.chain_iter(nextNode): # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication(nextParameter) == nodes.Null_Iir: - param.Identifiers.append(GetNameOfNode(nextParameter)) + identifiers.append(GetNameOfNode(nextParameter)) else: parameter = nextParameter break @@ -604,7 +611,7 @@ def GetParameterFromChainedNodes( else: parameter = nodes.Get_Chain(parameter) - yield param + yield parseMethod(parseNode, identifiers) def GetMapAspect(mapAspect: Iir, cls: Type, entity: str) -> Generator[AssociationItem, None, None]: -- cgit v1.2.3