From de44ee29acb01edfb429eb88d96f0bb904adefd0 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 27 Jul 2021 18:48:08 +0200 Subject: Changed List to Iterable. Parse instantiations. Some SimpleName fixes. --- pyGHDL/dom/Concurrent.py | 118 +++++++++++++++++++++++++++++++++++++++++++++++ pyGHDL/dom/DesignUnit.py | 38 ++++++++------- pyGHDL/dom/_Translate.py | 93 ++++++++++++++++++++++++++++++++++++- 3 files changed, 232 insertions(+), 17 deletions(-) create mode 100644 pyGHDL/dom/Concurrent.py diff --git a/pyGHDL/dom/Concurrent.py b/pyGHDL/dom/Concurrent.py new file mode 100644 index 000000000..80417c07b --- /dev/null +++ b/pyGHDL/dom/Concurrent.py @@ -0,0 +1,118 @@ +# ============================================================================= +# ____ _ _ ____ _ _ +# _ __ _ _ / ___| | | | _ \| | __| | ___ _ __ ___ +# | '_ \| | | | | _| |_| | | | | | / _` |/ _ \| '_ ` _ \ +# | |_) | |_| | |_| | _ | |_| | |___ | (_| | (_) | | | | | | +# | .__/ \__, |\____|_| |_|____/|_____(_)__,_|\___/|_| |_| |_| +# |_| |___/ +# ============================================================================= +# Authors: +# Patrick Lehmann +# +# Package module: DOM: Concurrent statements. +# +# License: +# ============================================================================ +# Copyright (C) 2019-2021 Tristan Gingold +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# SPDX-License-Identifier: GPL-2.0-or-later +# ============================================================================ +from typing import Iterable + +from pydecor import export + +from pyVHDLModel.SyntaxModel import ( + ConcurrentBlockStatement as VHDLModel_ConcurrentBlockStatement, + ComponentInstantiation as VHDLModel_ComponentInstantiation, + EntityInstantiation as VHDLModel_EntityInstantiation, + ConfigurationInstantiation as VHDLModel_ConfigurationInstantiation, + PortInterfaceItem, + ConcurrentStatement, +) + +from pyGHDL.libghdl import Iir +from pyGHDL.libghdl.vhdl import nodes +from pyGHDL.dom import DOMMixin +from pyGHDL.dom.Symbol import EntitySymbol + + +@export +class ComponentInstantiation(VHDLModel_ComponentInstantiation, DOMMixin): + def __init__(self, node: Iir, componentName: str): + super().__init__(componentName) + DOMMixin.__init__(self, node) + + @classmethod + def parse(cls, instantiationNode: Iir) -> "ComponentInstantiation": + componentName = "" + + return cls(instantiationNode, componentName) + + +@export +class EntityInstantiation(VHDLModel_EntityInstantiation, DOMMixin): + def __init__(self, node: Iir, entityName: EntitySymbol): + super().__init__(entityName) + DOMMixin.__init__(self, node) + + @classmethod + def parse(cls, instantiationNode: Iir) -> "EntityInstantiation": + entityName = "" + + return cls(instantiationNode, entityName) + + +@export +class ConfigurationInstantiation(VHDLModel_ConfigurationInstantiation, DOMMixin): + def __init__(self, node: Iir, configurationName: str): + super().__init__(configurationName) + DOMMixin.__init__(self, node) + + @classmethod + def parse(cls, instantiationNode: Iir) -> "ConfigurationInstantiation": + configurationName = "" + + return cls(instantiationNode, configurationName) + + +@export +class ConcurrentBlockStatement(VHDLModel_ConcurrentBlockStatement, DOMMixin): + def __init__( + self, + node: Iir, + label: str, + # portItems: Iterable[PortInterfaceItem] = None, + declaredItems: Iterable = None, + bodyItems: Iterable["ConcurrentStatement"] = None, + ): + super().__init__(label, None, declaredItems, bodyItems) + DOMMixin.__init__(self, node) + + @classmethod + def parse(cls, blockNode: Iir, label: str) -> "ConcurrentBlockStatement": + from pyGHDL.dom._Translate import ( + GetDeclaredItemsFromChainedNodes, + GetStatementsFromChainedNodes, + ) + + declaredItems = GetDeclaredItemsFromChainedNodes( + nodes.Get_Declaration_Chain(blockNode), "block", label + ) + bodyItems = GetStatementsFromChainedNodes( + nodes.Get_Concurrent_Statement_Chain(blockNode), "block", label + ) + + return cls(blockNode, label, declaredItems, bodyItems) diff --git a/pyGHDL/dom/DesignUnit.py b/pyGHDL/dom/DesignUnit.py index 13e197075..d8e816635 100644 --- a/pyGHDL/dom/DesignUnit.py +++ b/pyGHDL/dom/DesignUnit.py @@ -39,7 +39,7 @@ This module contains all DOM classes for VHDL's design units (:class:`context Generator[ConcurrentStatement, None, None]: + for statement in utils.chain_iter(nodeChain): + label = nodes.Get_Label(statement) + if label != nodes.Null_Iir: + label = name_table.Get_Name_Ptr(label) + + pos = Position.parse(statement) + + kind = GetIirKindOfNode(statement) + if kind == nodes.Iir_Kind.Sensitized_Process_Statement: + print( + "[NOT IMPLEMENTED] Process (label: '{label}') with sensitivity list at line {line}".format( + label=label, line=pos.Line + ) + ) + elif kind == nodes.Iir_Kind.Concurrent_Simple_Signal_Assignment: + print( + "[NOT IMPLEMENTED] Concurrent (simple) signal assignment (label: '{label}') at line {line}".format( + label=label, line=pos.Line + ) + ) + elif kind == nodes.Iir_Kind.Component_Instantiation_Statement: + 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) + + print( + "Instance of '{component!s}({architecture})' with label '{label}' at line {line}".format( + component=entityName, + architecture=architectureName, + label=label, + line=pos.Line, + ) + ) + elif instantiatedUnitKind == nodes.Iir_Kind.Entity_Aspect_Configuration: + configurationId = nodes.Get_Configuration_Name(instantiatedUnit) + configurationName = GetNameFromNode(configurationId) + + print( + "Instance of '{configuration}' with label '{label}' at line {line}".format( + configuration=configurationName, label=label, line=pos.Line + ) + ) + elif instantiatedUnitKind in ( + nodes.Iir_Kind.Simple_Name, + nodes.Iir_Kind.Parenthesis_Name, + ): + componentName = GetNameFromNode(instantiatedUnit) + + print( + "Component '{component}' instantiated with label '{label}' at line {line}".format( + component=componentName, label=label, line=pos.Line + ) + ) + else: + raise DOMException( + "Unknown instantiation kind '{kind}' in instantiation of label {label} at {file}:{line}:{column}.".format( + kind=instantiatedUnitKind.name, + label=label, + file=pos.Filename, + line=pos.Line, + column=pos.Column, + ) + ) + + elif kind == nodes.Iir_Kind.Block_Statement: + yield ConcurrentBlockStatement.parse(statement, label) + else: + raise DOMException( + "Unknown statement of kind '{kind}' in {entity} '{name}' at {file}:{line}:{column}.".format( + kind=kind.name, + entity=entity, + name=name, + file=pos.Filename, + line=pos.Line, + column=pos.Column, + ) + ) + + def GetAliasFromNode(aliasNode: Iir): aliasName = GetNameOfNode(aliasNode) -- cgit v1.2.3