From 0562c182aba6e99cbdeb302f6efa584d6642267f Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Sat, 14 Aug 2021 21:58:48 +0200 Subject: Handle bodies in case generate statements. --- pyGHDL/dom/Concurrent.py | 52 +++++++++++++++++++----------------- pyGHDL/dom/formatting/prettyprint.py | 3 +++ 2 files changed, 30 insertions(+), 25 deletions(-) (limited to 'pyGHDL/dom') diff --git a/pyGHDL/dom/Concurrent.py b/pyGHDL/dom/Concurrent.py index 3b1f22829..b411553c5 100644 --- a/pyGHDL/dom/Concurrent.py +++ b/pyGHDL/dom/Concurrent.py @@ -384,23 +384,23 @@ class GenerateCase(VHDLModel_GenerateCase, DOMMixin): statements: Iterable[ConcurrentStatement] = None, alternativeLabel: str = None, ): - super().__init__(choices) + super().__init__(choices, declaredItems, statements, alternativeLabel) DOMMixin.__init__(self, node) @classmethod - def parse(cls, caseNode: Iir) -> "GenerateCase": + def parse( + cls, caseNode: Iir, choices: Iterable[ConcurrentChoice] + ) -> "GenerateCase": from pyGHDL.dom._Translate import ( GetDeclaredItemsFromChainedNodes, GetConcurrentStatementsFromChainedNodes, ) - body = nodes.Get_Generate_Statement_Body(caseNode) + body = nodes.Get_Associated_Block(caseNode) alternativeLabelId = nodes.Get_Alternative_Label(body) alternativeLabel = "" - choices = [] - declarationChain = nodes.Get_Declaration_Chain(body) declaredItems = GetDeclaredItemsFromChainedNodes( declarationChain, "generate case", alternativeLabel @@ -433,23 +433,22 @@ class OthersGenerateCase(VHDLModel_OthersGenerateCase, DOMMixin): GetConcurrentStatementsFromChainedNodes, ) - # body = nodes.Get_Generate_Statement_Body(caseNode) - # - # alternativeLabelId = nodes.Get_Alternative_Label(body) - # alternativeLabel = "" - # - # declarationChain = nodes.Get_Declaration_Chain(body) - # declaredItems = GetDeclaredItemsFromChainedNodes( - # declarationChain, "else-generate branch", alternativeLabel - # ) - # - # statementChain = nodes.Get_Concurrent_Statement_Chain(body) - # statements = GetStatementsFromChainedNodes( - # statementChain, "else-generate branch", alternativeLabel - # ) - - # return cls(caseNode, declaredItems, statements, alternativeLabel) - return cls(caseNode, [], [], "") + body = nodes.Get_Associated_Block(caseNode) + + alternativeLabelId = nodes.Get_Alternative_Label(body) + alternativeLabel = "" + + declarationChain = nodes.Get_Declaration_Chain(body) + declaredItems = GetDeclaredItemsFromChainedNodes( + declarationChain, "case-generate others", alternativeLabel + ) + + statementChain = nodes.Get_Concurrent_Statement_Chain(body) + statements = GetConcurrentStatementsFromChainedNodes( + statementChain, "case-generate others", alternativeLabel + ) + + return cls(caseNode, declaredItems, statements, alternativeLabel) @export @@ -480,6 +479,7 @@ class CaseGenerateStatement(VHDLModel_CaseGenerateStatement, DOMMixin): cases = [] choices = None alternative = nodes.Get_Case_Statement_Alternative_Chain(generateNode) + caseNode = alternative while alternative != nodes.Null_Iir: choiceKind = GetIirKindOfNode(alternative) @@ -524,10 +524,11 @@ class CaseGenerateStatement(VHDLModel_CaseGenerateStatement, DOMMixin): continue elif choiceKind is nodes.Iir_Kind.Choice_By_Others: if choices is not None: - cases.append(GenerateCase(alternative, choices)) + cases.append(GenerateCase.parse(caseNode, choices)) choices = None cases.append(OthersGenerateCase.parse(alternative)) alternative = nodes.Get_Chain(alternative) + caseNode = alternative continue else: pos = Position.parse(alternative) @@ -538,8 +539,9 @@ class CaseGenerateStatement(VHDLModel_CaseGenerateStatement, DOMMixin): ) if choices is not None: - cases.append(GenerateCase(alternative, choices)) + cases.append(GenerateCase.parse(caseNode, choices)) + caseNode = alternative choices = [ choice, ] @@ -547,7 +549,7 @@ class CaseGenerateStatement(VHDLModel_CaseGenerateStatement, DOMMixin): alternative = nodes.Get_Chain(alternative) if choices is not None: - cases.append(GenerateCase(alternative, choices)) + cases.append(GenerateCase.parse(caseNode, choices)) return cls(generateNode, label, expression, cases) diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 7fa49389d..2f582a5f8 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -730,6 +730,9 @@ class PrettyPrint: prefix=prefix, label=case.Label, case=case ) ) + for stmt in case.Statements: + for line in self.formatHierarchy(stmt, level + 2): + buffer.append(line) elif isinstance(statement, ForGenerateStatement): buffer.append( "{prefix}- {label}: for {index} in {range} generate".format( -- cgit v1.2.3