From ed99fae7f13db8d5c3e95e935e32db825313b56a Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 21 Jun 2021 15:48:35 +0200 Subject: Prepared handling of functions, types, subtypes and aliases. --- pyGHDL/dom/Subprogram.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pyGHDL/dom/Subprogram.py (limited to 'pyGHDL/dom/Subprogram.py') diff --git a/pyGHDL/dom/Subprogram.py b/pyGHDL/dom/Subprogram.py new file mode 100644 index 000000000..70645df6f --- /dev/null +++ b/pyGHDL/dom/Subprogram.py @@ -0,0 +1,44 @@ +# ============================================================================= +# ____ _ _ ____ _ _ +# _ __ _ _ / ___| | | | _ \| | __| | ___ _ __ ___ +# | '_ \| | | | | _| |_| | | | | | / _` |/ _ \| '_ ` _ \ +# | |_) | |_| | |_| | _ | |_| | |___ | (_| | (_) | | | | | | +# | .__/ \__, |\____|_| |_|____/|_____(_)__,_|\___/|_| |_| |_| +# |_| |___/ +# ============================================================================= +# Authors: +# Patrick Lehmann +# +# Package module: DOM: Interface items (e.g. generic or port) +# +# 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 pydecor import export + +from pyVHDLModel.VHDLModel import ( + Function as VHDLModel_Function, + Expression, +) + + +@export +class Function(VHDLModel_Function): + def __init__(self, functionName: str): + super().__init__(functionName) -- cgit v1.2.3 From ad34fac3f4e30f0ff13e1630b42373f31b2918a4 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 21 Jun 2021 21:44:31 +0200 Subject: Fixed function call parameters. Fixed physical literal units. Added basic Procedure detection. --- pyGHDL/dom/Subprogram.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'pyGHDL/dom/Subprogram.py') diff --git a/pyGHDL/dom/Subprogram.py b/pyGHDL/dom/Subprogram.py index 70645df6f..4fa6b3e6a 100644 --- a/pyGHDL/dom/Subprogram.py +++ b/pyGHDL/dom/Subprogram.py @@ -34,6 +34,7 @@ from pydecor import export from pyVHDLModel.VHDLModel import ( Function as VHDLModel_Function, + Procedure as VHDLModel_Procedure, Expression, ) @@ -42,3 +43,9 @@ from pyVHDLModel.VHDLModel import ( class Function(VHDLModel_Function): def __init__(self, functionName: str): super().__init__(functionName) + + +@export +class Procedure(VHDLModel_Procedure): + def __init__(self, procedureName: str): + super().__init__(procedureName) -- cgit v1.2.3 From 11bd75f611a892af0e20e913a9580d43c23e610b Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 21 Jun 2021 22:36:07 +0200 Subject: Print position where exception happened. --- pyGHDL/dom/Subprogram.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'pyGHDL/dom/Subprogram.py') diff --git a/pyGHDL/dom/Subprogram.py b/pyGHDL/dom/Subprogram.py index 4fa6b3e6a..420041a52 100644 --- a/pyGHDL/dom/Subprogram.py +++ b/pyGHDL/dom/Subprogram.py @@ -32,11 +32,13 @@ # ============================================================================ from pydecor import export +from pyGHDL.dom._Utils import GetNameOfNode from pyVHDLModel.VHDLModel import ( Function as VHDLModel_Function, Procedure as VHDLModel_Procedure, Expression, ) +from pyGHDL.libghdl._types import Iir @export @@ -44,8 +46,20 @@ class Function(VHDLModel_Function): def __init__(self, functionName: str): super().__init__(functionName) + @classmethod + def parse(cls, node: Iir): + functionName = GetNameOfNode(node) + + return cls(functionName) + @export class Procedure(VHDLModel_Procedure): def __init__(self, procedureName: str): super().__init__(procedureName) + + @classmethod + def parse(cls, node: Iir): + procedureName = GetNameOfNode(node) + + return cls(procedureName) -- cgit v1.2.3 From f956044c3045992f37f23d88d9e51a1de8593948 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 21 Jun 2021 23:18:29 +0200 Subject: Implemented handling of generic parameters to subprograms. --- pyGHDL/dom/Subprogram.py | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'pyGHDL/dom/Subprogram.py') diff --git a/pyGHDL/dom/Subprogram.py b/pyGHDL/dom/Subprogram.py index 420041a52..b3c47bfe5 100644 --- a/pyGHDL/dom/Subprogram.py +++ b/pyGHDL/dom/Subprogram.py @@ -30,27 +30,47 @@ # # SPDX-License-Identifier: GPL-2.0-or-later # ============================================================================ +from pyGHDL.dom.Symbol import SimpleSubTypeSymbol +from pyGHDL.libghdl.vhdl import nodes from pydecor import export from pyGHDL.dom._Utils import GetNameOfNode from pyVHDLModel.VHDLModel import ( Function as VHDLModel_Function, Procedure as VHDLModel_Procedure, - Expression, + SubTypeOrSymbol, ) from pyGHDL.libghdl._types import Iir @export class Function(VHDLModel_Function): - def __init__(self, functionName: str): + def __init__(self, functionName: str, returnType: SubTypeOrSymbol): super().__init__(functionName) + self._returnType = returnType @classmethod def parse(cls, node: Iir): + from pyGHDL.dom._Translate import ( + GetGenericsFromChainedNodes, + GetParameterFromChainedNodes, + ) + functionName = GetNameOfNode(node) + returnType = nodes.Get_Return_Type_Mark(node) + returnTypeName = GetNameOfNode(returnType) + + returnTypeSymbol = SimpleSubTypeSymbol(returnTypeName) + function = cls(functionName, returnTypeSymbol) + + for generic in GetGenericsFromChainedNodes(nodes.Get_Generic_Chain(node)): + function.GenericItems.append(generic) + for port in GetParameterFromChainedNodes( + nodes.Get_Interface_Declaration_Chain(node) + ): + function.ParameterItems.append(port) - return cls(functionName) + return function @export @@ -60,6 +80,20 @@ class Procedure(VHDLModel_Procedure): @classmethod def parse(cls, node: Iir): + from pyGHDL.dom._Translate import ( + GetGenericsFromChainedNodes, + GetParameterFromChainedNodes, + ) + procedureName = GetNameOfNode(node) - return cls(procedureName) + procedure = cls(procedureName) + + for generic in GetGenericsFromChainedNodes(nodes.Get_Generic_Chain(node)): + procedure.GenericItems.append(generic) + for port in GetParameterFromChainedNodes( + nodes.Get_Interface_Declaration_Chain(node) + ): + procedure.ParameterItems.append(port) + + return procedure -- cgit v1.2.3