diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-07-28 09:00:03 +0200 |
---|---|---|
committer | umarcor <unai.martinezcorral@ehu.eus> | 2021-08-23 16:35:32 +0200 |
commit | 20b636decb9c502891fbf5f9a15cf8e7126904a5 (patch) | |
tree | c429b7f0026cc032c18fbb8b92b26484e75120f7 /pyGHDL/dom | |
parent | ee933a5fc78353e7a87fe64616b25387fdc12b2b (diff) | |
download | ghdl-20b636decb9c502891fbf5f9a15cf8e7126904a5.tar.gz ghdl-20b636decb9c502891fbf5f9a15cf8e7126904a5.tar.bz2 ghdl-20b636decb9c502891fbf5f9a15cf8e7126904a5.zip |
Handle instantiations 1/2.
Diffstat (limited to 'pyGHDL/dom')
-rw-r--r-- | pyGHDL/dom/Concurrent.py | 48 | ||||
-rw-r--r-- | pyGHDL/dom/_Translate.py | 34 |
2 files changed, 42 insertions, 40 deletions
diff --git a/pyGHDL/dom/Concurrent.py b/pyGHDL/dom/Concurrent.py index 80417c07b..2698054e5 100644 --- a/pyGHDL/dom/Concurrent.py +++ b/pyGHDL/dom/Concurrent.py @@ -39,53 +39,65 @@ from pyVHDLModel.SyntaxModel import ( ComponentInstantiation as VHDLModel_ComponentInstantiation, EntityInstantiation as VHDLModel_EntityInstantiation, ConfigurationInstantiation as VHDLModel_ConfigurationInstantiation, - PortInterfaceItem, - ConcurrentStatement, + ConcurrentStatement, Name, ) from pyGHDL.libghdl import Iir from pyGHDL.libghdl.vhdl import nodes from pyGHDL.dom import DOMMixin -from pyGHDL.dom.Symbol import EntitySymbol +from pyGHDL.dom._Utils import GetNameOfNode @export class ComponentInstantiation(VHDLModel_ComponentInstantiation, DOMMixin): - def __init__(self, node: Iir, componentName: str): - super().__init__(componentName) + def __init__(self, node: Iir, label: str, componentName: Name): + super().__init__(label, componentName) DOMMixin.__init__(self, node) @classmethod - def parse(cls, instantiationNode: Iir) -> "ComponentInstantiation": - componentName = "" + def parse(cls, instantiationNode: Iir, instantiatedUnit: Iir, label: str) -> "ComponentInstantiation": + from pyGHDL.dom._Translate import GetNameFromNode - return cls(instantiationNode, componentName) + componentName = GetNameFromNode(instantiatedUnit) + + return cls(instantiationNode, label, componentName) @export class EntityInstantiation(VHDLModel_EntityInstantiation, DOMMixin): - def __init__(self, node: Iir, entityName: EntitySymbol): - super().__init__(entityName) + def __init__(self, node: Iir, label: str, entityName: Name, architectureName: Name = None): + super().__init__(label, entityName, architectureName) DOMMixin.__init__(self, node) @classmethod - def parse(cls, instantiationNode: Iir) -> "EntityInstantiation": - entityName = "" + def parse(cls, instantiationNode: Iir, instantiatedUnit: Iir, label: str) -> "EntityInstantiation": + from pyGHDL.dom._Translate import GetNameFromNode + + entityId = nodes.Get_Entity_Name(instantiatedUnit) + entityName = GetNameFromNode(entityId) - return cls(instantiationNode, entityName) + architectureName = None + architectureId = nodes.Get_Architecture(instantiatedUnit) + if architectureId != nodes.Null_Iir: + architectureName = GetNameOfNode(architectureId) + + return cls(instantiationNode, label, entityName, architectureName) @export class ConfigurationInstantiation(VHDLModel_ConfigurationInstantiation, DOMMixin): - def __init__(self, node: Iir, configurationName: str): - super().__init__(configurationName) + def __init__(self, node: Iir, label: str, configurationName: Name): + super().__init__(label, configurationName) DOMMixin.__init__(self, node) @classmethod - def parse(cls, instantiationNode: Iir) -> "ConfigurationInstantiation": - configurationName = "" + def parse(cls, instantiationNode: Iir, instantiatedUnit: Iir, label: str) -> "ConfigurationInstantiation": + from pyGHDL.dom._Translate import GetNameFromNode + + configurationId = nodes.Get_Configuration_Name(instantiatedUnit) + configurationName = GetNameFromNode(configurationId) - return cls(instantiationNode, configurationName) + return cls(instantiationNode, label, configurationName) @export diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py index 84b99a4a3..b7e8f5ab9 100644 --- a/pyGHDL/dom/_Translate.py +++ b/pyGHDL/dom/_Translate.py @@ -138,7 +138,7 @@ from pyGHDL.dom.Expression import ( MatchingLessEqualExpression, MatchingGreaterThanExpression, ) -from pyGHDL.dom.Concurrent import ConcurrentBlockStatement +from pyGHDL.dom.Concurrent import ConcurrentBlockStatement, EntityInstantiation, ConfigurationInstantiation, ComponentInstantiation from pyGHDL.dom.Subprogram import Function, Procedure from pyGHDL.dom.Misc import Alias from pyGHDL.dom.PSL import DefaultClock @@ -796,40 +796,30 @@ def GetStatementsFromChainedNodes( instantiatedUnit = nodes.Get_Instantiated_Unit(statement) instantiatedUnitKind = GetIirKindOfNode(instantiatedUnit) if instantiatedUnitKind == nodes.Iir_Kind.Entity_Aspect_Entity: - entityId = nodes.Get_Entity_Name(instantiatedUnit) - entityName = GetNameFromNode(entityId) - - architectureName = "" - architectureId = nodes.Get_Architecture(instantiatedUnit) - if architectureId != nodes.Null_Iir: - architectureName = GetNameOfNode(architectureId) + entityInstance = EntityInstantiation.parse(statement, instantiatedUnit, label) print( - "Instance of '{component!s}({architecture})' with label '{label}' at line {line}".format( - component=entityName, - architecture=architectureName, - label=label, + "Entity '{entity!s}({architecture})' instantiated with label '{label}' at line {line}".format( + entity=entityInstance.Entity, + architecture=entityInstance.Architecture, + label=entityInstance.Label, line=pos.Line, ) ) elif instantiatedUnitKind == nodes.Iir_Kind.Entity_Aspect_Configuration: - configurationId = nodes.Get_Configuration_Name(instantiatedUnit) - configurationName = GetNameFromNode(configurationId) + configurationInstance = ConfigurationInstantiation.parse(statement, instantiatedUnit, label) print( - "Instance of '{configuration}' with label '{label}' at line {line}".format( - configuration=configurationName, label=label, line=pos.Line + "Configuration '{configuration}' instantiated with label '{label}' at line {line}".format( + configuration=configurationInstance.Configuration, label=configurationInstance.Label, line=pos.Line ) ) - elif instantiatedUnitKind in ( - nodes.Iir_Kind.Simple_Name, - nodes.Iir_Kind.Parenthesis_Name, - ): - componentName = GetNameFromNode(instantiatedUnit) + elif instantiatedUnitKind == nodes.Iir_Kind.Simple_Name: + configurationInstance = ComponentInstantiation.parse(statement, instantiatedUnit, label) print( "Component '{component}' instantiated with label '{label}' at line {line}".format( - component=componentName, label=label, line=pos.Line + component=configurationInstance.Component, label=label, line=pos.Line ) ) else: |