aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/dom/Subprogram.py
diff options
context:
space:
mode:
authorUnai Martinez-Corral <38422348+umarcor@users.noreply.github.com>2021-06-22 12:05:45 +0100
committerGitHub <noreply@github.com>2021-06-22 12:05:45 +0100
commitbf45d9939dc26d0d584dd549923b9962f83360ec (patch)
tree976beef99129705fa8d0e592dfba4fad61b80135 /pyGHDL/dom/Subprogram.py
parent15f447b1270a815748fdbcce46d97abd9eecc21d (diff)
parent0a69901be945dfb6c5372e657332d5e5ddfa10c7 (diff)
downloadghdl-bf45d9939dc26d0d584dd549923b9962f83360ec.tar.gz
ghdl-bf45d9939dc26d0d584dd549923b9962f83360ec.tar.bz2
ghdl-bf45d9939dc26d0d584dd549923b9962f83360ec.zip
More expression kinds and function calls (#1802)
Diffstat (limited to 'pyGHDL/dom/Subprogram.py')
-rw-r--r--pyGHDL/dom/Subprogram.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/pyGHDL/dom/Subprogram.py b/pyGHDL/dom/Subprogram.py
new file mode 100644
index 000000000..b3c47bfe5
--- /dev/null
+++ b/pyGHDL/dom/Subprogram.py
@@ -0,0 +1,99 @@
+# =============================================================================
+# ____ _ _ ____ _ _
+# _ __ _ _ / ___| | | | _ \| | __| | ___ _ __ ___
+# | '_ \| | | | | _| |_| | | | | | / _` |/ _ \| '_ ` _ \
+# | |_) | |_| | |_| | _ | |_| | |___ | (_| | (_) | | | | | |
+# | .__/ \__, |\____|_| |_|____/|_____(_)__,_|\___/|_| |_| |_|
+# |_| |___/
+# =============================================================================
+# 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 <gnu.org/licenses>.
+#
+# 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,
+ SubTypeOrSymbol,
+)
+from pyGHDL.libghdl._types import Iir
+
+
+@export
+class Function(VHDLModel_Function):
+ 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 function
+
+
+@export
+class Procedure(VHDLModel_Procedure):
+ def __init__(self, procedureName: str):
+ super().__init__(procedureName)
+
+ @classmethod
+ def parse(cls, node: Iir):
+ from pyGHDL.dom._Translate import (
+ GetGenericsFromChainedNodes,
+ GetParameterFromChainedNodes,
+ )
+
+ procedureName = GetNameOfNode(node)
+
+ 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