From cfd625ab0a3d4df24bae77ed6143c44a53f26f49 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Thu, 29 Jul 2021 09:00:11 +0200 Subject: Moved parsing into IfGenerateBranch. --- pyGHDL/dom/Concurrent.py | 50 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/pyGHDL/dom/Concurrent.py b/pyGHDL/dom/Concurrent.py index d4e7cf6ff..c9a67f1e1 100644 --- a/pyGHDL/dom/Concurrent.py +++ b/pyGHDL/dom/Concurrent.py @@ -48,6 +48,7 @@ from pyVHDLModel.SyntaxModel import ( Name, SequentialStatement, IfGenerateBranch, + Expression, ) from pyGHDL.libghdl import Iir @@ -199,13 +200,40 @@ class IfGenerateBranch(VHDLModel_IfGenerateBranch): def __init__( self, branchNode: Iir, + condition: Expression, alternativeLabel: str = None, declaredItems: Iterable = None, statements: Iterable[ConcurrentStatement] = None, ): - super().__init__(declaredItems, statements) + super().__init__(condition, declaredItems, statements) DOMMixin.__init__(self, branchNode) + @classmethod + def parse(cls, generateNode: Iir) -> "IfGenerateBranch": + from pyGHDL.dom._Translate import ( + GetDeclaredItemsFromChainedNodes, + GetStatementsFromChainedNodes, + GetExpressionFromNode, + ) + + condition = GetExpressionFromNode(nodes.Get_Condition(generateNode)) + body = nodes.Get_Generate_Statement_Body(generateNode) + + alternativeLabelId = nodes.Get_Alternative_Label(body) + alternativeLabel = "" + + declarationChain = nodes.Get_Declaration_Chain(body) + declaredItems = GetDeclaredItemsFromChainedNodes( + declarationChain, "if-generate branch", alternativeLabel + ) + + statementChain = nodes.Get_Concurrent_Statement_Chain(body) + statements = GetStatementsFromChainedNodes( + statementChain, "if-generate branch", alternativeLabel + ) + + return cls(body, condition, alternativeLabel, declaredItems, statements) + @export class IfGenerateStatement(VHDLModel_IfGenerateStatement, DOMMixin): @@ -218,25 +246,21 @@ class IfGenerateStatement(VHDLModel_IfGenerateStatement, DOMMixin): from pyGHDL.dom._Translate import ( GetDeclaredItemsFromChainedNodes, GetStatementsFromChainedNodes, + GetExpressionFromNode, ) # TODO: get branches # TODO: get declared items # TODO: get concurrent statements - body = nodes.Get_Generate_Statement_Body(generateNode) - alternativeLabelId = nodes.Get_Alternative_Label(body) - alternativeLabel = "" - - declarationChain = nodes.Get_Declaration_Chain(body) - declaredItems = GetDeclaredItemsFromChainedNodes( - declarationChain, "if-generate", label - ) - - statementChain = nodes.Get_Concurrent_Statement_Chain(body) - statements = GetStatementsFromChainedNodes(statementChain, "if-generate", label) + print(generateNode, GetIirKindOfNode(generateNode)) + ifBranch = IfGenerateBranch.parse(generateNode) - ifBranch = IfGenerateBranch(body, alternativeLabel, declaredItems, statements) + elseClause = generateNode + while ( + elseClause := nodes.Get_Generate_Else_Clause(elseClause) + ) != nodes.Null_Iir: + print(elseClause, GetIirKindOfNode(elseClause)) return cls(generateNode, label, ifBranch) -- cgit v1.2.3