From ca39821dc013a877a8dbdfabbc3b861eb4d4d2e3 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 26 Jul 2021 00:13:11 +0200 Subject: Adjusted to renaming in pyVHDLModel. --- pyGHDL/dom/formatting/prettyprint.py | 78 +++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 23 deletions(-) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 4d6e5dccb..949935b3f 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -1,25 +1,40 @@ +# ============================================================================= +# ____ _ _ ____ _ _ +# _ __ _ _ / ___| | | | _ \| | __| | ___ _ __ ___ +# | '_ \| | | | | _| |_| | | | | | / _` |/ _ \| '_ ` _ \ +# | |_) | |_| | |_| | _ | |_| | |___ | (_| | (_) | | | | | | +# | .__/ \__, |\____|_| |_|____/|_____(_)__,_|\___/|_| |_| |_| +# |_| |___/ +# ============================================================================= +# Authors: +# Patrick Lehmann +# +# Package module: A pretty printer to format the DOM as a tree in text form. +# +# 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 List, Union from pydecor import export -from pyGHDL.dom.Attribute import Attribute, AttributeSpecification -from pyGHDL.dom.Misc import Alias -from pyGHDL.dom.PSL import DefaultClock -from pyGHDL.dom.Subprogram import Procedure -from pyGHDL.dom.Type import ( - IntegerType, - Subtype, - ArrayType, - RecordType, - AccessType, - EnumeratedType, - FileType, - ProtectedType, - ProtectedTypeBody, - PhysicalType, - IncompleteType, -) -from pyVHDLModel.VHDLModel import ( +from pyVHDLModel.SyntaxModel import ( GenericInterfaceItem, NamedEntity, PortInterfaceItem, @@ -42,16 +57,33 @@ from pyGHDL.dom.DesignUnit import ( UseClause, PackageInstantiation, ) -from pyGHDL.dom.Object import Constant, Signal, SharedVariable, File +from pyGHDL.dom.Symbol import ( + SimpleSubtypeSymbol, + ConstrainedCompositeSubtypeSymbol, +) +from pyGHDL.dom.Type import ( + IntegerType, + Subtype, + ArrayType, + RecordType, + AccessType, + EnumeratedType, + FileType, + ProtectedType, + ProtectedTypeBody, + PhysicalType, + IncompleteType, +) from pyGHDL.dom.InterfaceItem import ( GenericConstantInterfaceItem, PortSignalInterfaceItem, GenericTypeInterfaceItem, ) -from pyGHDL.dom.Symbol import ( - SimpleSubtypeSymbol, - ConstrainedCompositeSubtypeSymbol, -) +from pyGHDL.dom.Object import Constant, Signal, SharedVariable, File +from pyGHDL.dom.Attribute import Attribute, AttributeSpecification +from pyGHDL.dom.Subprogram import Procedure +from pyGHDL.dom.Misc import Alias +from pyGHDL.dom.PSL import DefaultClock StringBuffer = List[str] -- cgit v1.2.3 From c9e31a5915ad223d35b19a565539eaa586681938 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 26 Jul 2021 00:42:12 +0200 Subject: Adjust DOM to a change in pyVHDLModel: some Identifiers being now a list of identifiers. --- pyGHDL/dom/formatting/prettyprint.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 949935b3f..524ae9ab9 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -363,10 +363,10 @@ class PrettyPrint: buffer.append( "{prefix} - {name} : {mode!s} {subtypeindication}{initialValue}".format( prefix=prefix, - name=generic.Identifier, + name=", ".join(generic.Identifiers), mode=generic.Mode, subtypeindication=self.formatSubtypeIndication( - generic.Subtype, "generic", generic.Identifier + generic.Subtype, "generic", generic.Identifiers[0] ), initialValue=self.formatInitialValue(generic), ) @@ -398,10 +398,10 @@ class PrettyPrint: buffer.append( "{prefix} - {name} : {mode!s} {subtypeindication}{initialValue}".format( prefix=prefix, - name=port.Identifier, + name=", ".join(port.Identifiers), mode=port.Mode, subtypeindication=self.formatSubtypeIndication( - port.Subtype, "port", port.Identifier + port.Subtype, "port", port.Identifiers[0] ), initialValue=self.formatInitialValue(port), ) @@ -428,9 +428,9 @@ class PrettyPrint: buffer.append( "{prefix}- shared variable {name} : {subtype}".format( prefix=prefix, - name=item.Identifier, + name=", ".join(item.Identifiers), subtype=self.formatSubtypeIndication( - item.Subtype, "shared variable", item.Identifier + item.Subtype, "shared variable", item.Identifiers[0] ), ) ) @@ -438,9 +438,9 @@ class PrettyPrint: buffer.append( "{prefix}- signal {name} : {subtype}{initValue}".format( prefix=prefix, - name=item.Identifier, + name=", ".join(item.Identifiers), subtype=self.formatSubtypeIndication( - item.Subtype, "signal", item.Identifier + item.Subtype, "signal", item.Identifiers[0] ), initValue=" := {expr}".format(expr=str(item.DefaultExpression)) if item.DefaultExpression is not None @@ -451,9 +451,9 @@ class PrettyPrint: buffer.append( "{prefix}- File {name} : {subtype}".format( prefix=prefix, - name=item.Identifier, + name=", ".join(item.Identifiers), subtype=self.formatSubtypeIndication( - item.Subtype, "file", item.Identifier + item.Subtype, "file", item.Identifiers[0] ), ) ) -- cgit v1.2.3 From 5fae449cbac688b5779f0ef2ec2052bb3f9bed00 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 26 Jul 2021 01:21:36 +0200 Subject: Needed for changes in prettyprint for the Identifier(s) change in pyVHDLModel. --- pyGHDL/dom/formatting/prettyprint.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 524ae9ab9..20355db24 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -340,7 +340,7 @@ class PrettyPrint: else: raise PrettyPrintException( "Unhandled generic kind for generic '{name}'.".format( - name=generic.Identifier + name=generic.Identifiers[0] ) ) @@ -351,7 +351,9 @@ class PrettyPrint: return self.formatPortSignal(port, level) else: raise PrettyPrintException( - "Unhandled port kind for port '{name}'.".format(name=port.Identifier) + "Unhandled port kind for port '{name}'.".format( + name=port.Identifiers[0] + ) ) def formatGenericConstant( @@ -417,9 +419,9 @@ class PrettyPrint: buffer.append( "{prefix}- constant {name} : {subtype} := {expr}".format( prefix=prefix, - name=item.Identifier, + name=", ".join(item.Identifiers), subtype=self.formatSubtypeIndication( - item.Subtype, "constant", item.Identifier + item.Subtype, "constant", item.Identifiers[0] ), expr=str(item.DefaultExpression), ) -- cgit v1.2.3 From ee6a244880f2d4fff429118ccbce043b342fae4d Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Fri, 30 Jul 2021 09:00:16 +0200 Subject: PrettyPrint deferred constants. --- pyGHDL/dom/formatting/prettyprint.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 20355db24..8ab854212 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -41,7 +41,7 @@ from pyVHDLModel.SyntaxModel import ( WithDefaultExpressionMixin, Function, BaseType, - FullType, + FullType, BaseConstant, ) from pyGHDL import GHDLBaseException @@ -79,7 +79,7 @@ from pyGHDL.dom.InterfaceItem import ( PortSignalInterfaceItem, GenericTypeInterfaceItem, ) -from pyGHDL.dom.Object import Constant, Signal, SharedVariable, File +from pyGHDL.dom.Object import Constant, Signal, SharedVariable, File, DeferredConstant from pyGHDL.dom.Attribute import Attribute, AttributeSpecification from pyGHDL.dom.Subprogram import Procedure from pyGHDL.dom.Misc import Alias @@ -415,15 +415,20 @@ class PrettyPrint: buffer = [] prefix = " " * level - if isinstance(item, Constant): + if isinstance(item, BaseConstant): + if isinstance(item, Constant): + default = " := {expr}".format(expr=str(item.DefaultExpression)) + else: + default = "" + buffer.append( - "{prefix}- constant {name} : {subtype} := {expr}".format( + "{prefix}- constant {name} : {subtype}{default}".format( prefix=prefix, name=", ".join(item.Identifiers), subtype=self.formatSubtypeIndication( item.Subtype, "constant", item.Identifiers[0] ), - expr=str(item.DefaultExpression), + default=default, ) ) elif isinstance(item, SharedVariable): -- cgit v1.2.3 From 5314281f0b8090f820ae64b652e40c300c2bdec2 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Fri, 30 Jul 2021 23:55:18 +0200 Subject: Fixes. --- pyGHDL/dom/formatting/prettyprint.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 8ab854212..a30258443 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -41,7 +41,8 @@ from pyVHDLModel.SyntaxModel import ( WithDefaultExpressionMixin, Function, BaseType, - FullType, BaseConstant, + FullType, + BaseConstant, ) from pyGHDL import GHDLBaseException -- cgit v1.2.3 From 63cd71d89d9e389299cfb1c2faca35463d6502ee Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Wed, 11 Aug 2021 00:41:28 +0200 Subject: Reworked pretty printing. --- pyGHDL/dom/formatting/prettyprint.py | 71 ++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 27 deletions(-) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index a30258443..4d6fbb19a 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -34,6 +34,7 @@ from typing import List, Union from pydecor import export +from pyGHDL.dom.Concurrent import ConcurrentBlockStatement, ProcessStatement from pyVHDLModel.SyntaxModel import ( GenericInterfaceItem, NamedEntity, @@ -42,7 +43,7 @@ from pyVHDLModel.SyntaxModel import ( Function, BaseType, FullType, - BaseConstant, + BaseConstant, ConcurrentStatement, ) from pyGHDL import GHDLBaseException @@ -107,14 +108,15 @@ class PrettyPrint: prefix = " " * level buffer.append("{prefix}Libraries:".format(prefix=prefix)) for library in design.Libraries.values(): - for line in self.formatLibrary(library, level + 1): + buffer.append("{prefix} - Name: {name}".format(prefix=prefix, name=library.Identifier)) + for line in self.formatLibrary(library, level + 2): buffer.append(line) buffer.append("{prefix}Documents:".format(prefix=prefix)) for document in design.Documents: buffer.append( - "{prefix}- Path: '{doc!s}':".format(doc=document.Path, prefix=prefix) + "{prefix} - Path: '{doc!s}':".format(doc=document.Path, prefix=prefix) ) - for line in self.formatDocument(document, level + 1): + for line in self.formatDocument(document, level + 2): buffer.append(line) return buffer @@ -124,33 +126,19 @@ class PrettyPrint: prefix = " " * level buffer.append("{prefix}Entities:".format(prefix=prefix)) for entity in library.Entities: - for line in self.formatEntity(entity, level + 1): - buffer.append(line) - # buffer.append("{prefix}Architectures:".format(prefix=prefix)) - # for architecture in library.Architectures: - # for line in self.formatArchitecture(architecture, level + 1): - # buffer.append(line) + buffer.append("{prefix} - {name}({architectures})".format(prefix=prefix, name=entity.Identifier, architectures=", ".join([a.Identifier for a in entity.Architectures]))) buffer.append("{prefix}Packages:".format(prefix=prefix)) for package in library.Packages: if isinstance(package, Package): - gen = self.formatPackage - else: - gen = self.formatPackageInstance - - for line in gen(package, level + 1): - buffer.append(line) - # buffer.append("{prefix}PackageBodies:".format(prefix=prefix)) - # for packageBodies in library.PackageBodies: - # for line in self.formatPackageBody(packageBodies, level + 1): - # buffer.append(line) + buffer.append("{prefix} - {name}".format(prefix=prefix, name=package.Identifier)) + elif isinstance(package, PackageInstantiation): + buffer.append("{prefix} - {name} instantiate from {package}".format(prefix=prefix, name=package.Identifier, package=package.PackageReference)) buffer.append("{prefix}Configurations:".format(prefix=prefix)) for configuration in library.Configurations: - for line in self.formatConfiguration(configuration, level + 1): - buffer.append(line) + buffer.append("{prefix} - {name}".format(prefix=prefix, name=configuration.Identifier)) buffer.append("{prefix}Contexts:".format(prefix=prefix)) for context in library.Contexts: - for line in self.formatContext(context, level + 1): - buffer.append(line) + buffer.append("{prefix} - {name}".format(prefix=prefix, name=context.Identifier)) return buffer @@ -193,7 +181,7 @@ class PrettyPrint: buffer = [] prefix = " " * level buffer.append( - "{prefix}- Name: {name} at {file}:{line}:{column}".format( + "{prefix}- Name: {name}\n{prefix} File: {file}\n{prefix} Position: {line}:{column}".format( name=entity.Identifier, prefix=prefix, file=entity.Position.Filename.name, @@ -213,6 +201,12 @@ class PrettyPrint: for item in entity.DeclaredItems: for line in self.formatDeclaredItems(item, level + 1): buffer.append(line) + buffer.append("{prefix} Statements:".format(prefix=prefix)) + for item in entity.Statements: + buffer.append("{prefix} ...".format(prefix=prefix)) + buffer.append("{prefix} Architecures:".format(prefix=prefix)) + for item in entity.Architectures: + buffer.append("{prefix} - {name}".format(prefix=prefix, name=item.Identifier)) return buffer @@ -222,7 +216,7 @@ class PrettyPrint: buffer = [] prefix = " " * level buffer.append( - "{prefix}- Name: {name} at {file}:{line}:{column}".format( + "{prefix}- Name: {name}\n{prefix} File: {file}\n{prefix} Position: {line}:{column}".format( name=architecture.Identifier, prefix=prefix, file=architecture.Position.Filename.name, @@ -239,6 +233,15 @@ class PrettyPrint: for item in architecture.DeclaredItems: for line in self.formatDeclaredItems(item, level + 2): buffer.append(line) + buffer.append("{prefix} Hierarchy:".format(prefix=prefix)) + for item in architecture.Statements: + for line in self.formatHierarchy(item, level + 2): + buffer.append(line) + buffer.append("{prefix} Statements:".format(prefix=prefix)) + for item in architecture.Statements: + buffer.append("{prefix} ...".format(prefix=prefix)) +# for line in self.formatStatements(item, level + 2): +# buffer.append(line) return buffer @@ -265,7 +268,10 @@ class PrettyPrint: buffer = [] prefix = " " * level buffer.append( - "{prefix}- Name: {name}".format(name=package.Identifier, prefix=prefix) + "{prefix}- Name: {name}\n{prefix} File: {file}\n{prefix} Position: {line}:{column}".format(name=package.Identifier, prefix=prefix, + file=package.Position.Filename.name, + line=package.Position.Line, + column=package.Position.Column,) ) buffer.append("{prefix} Declared:".format(prefix=prefix)) for item in package.DeclaredItems: @@ -598,3 +604,14 @@ class PrettyPrint: return "" return " := {expr!s}".format(expr=item.DefaultExpression) + + def formatHierarchy(self, statement: ConcurrentStatement, level: int = 0) -> StringBuffer: + buffer = [] + prefix = " " * level + + if isinstance(statement, ProcessStatement): + buffer.append("{prefix}{label}: process(...)".format(prefix=prefix, label=statement.Label)) + elif isinstance(statement, ConcurrentBlockStatement): + buffer.append("{prefix}{label}: block".format(prefix=prefix, label=statement.Label)) + + return buffer -- cgit v1.2.3 From 3f31acc7304b03996f045f39b9e1130a4ffdc330 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Wed, 11 Aug 2021 02:55:48 +0200 Subject: Improved pretty-printing for hierarchy. --- pyGHDL/dom/formatting/prettyprint.py | 144 +++++++++++++++++++++++++++++++---- 1 file changed, 128 insertions(+), 16 deletions(-) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 4d6fbb19a..1aefb570d 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -34,7 +34,16 @@ from typing import List, Union from pydecor import export -from pyGHDL.dom.Concurrent import ConcurrentBlockStatement, ProcessStatement +from pyGHDL.dom.Concurrent import ( + ConcurrentBlockStatement, + ProcessStatement, + IfGenerateStatement, + CaseGenerateStatement, + ForGenerateStatement, + ComponentInstantiation, + ConfigurationInstantiation, + EntityInstantiation, +) from pyVHDLModel.SyntaxModel import ( GenericInterfaceItem, NamedEntity, @@ -43,7 +52,8 @@ from pyVHDLModel.SyntaxModel import ( Function, BaseType, FullType, - BaseConstant, ConcurrentStatement, + BaseConstant, + ConcurrentStatement, ) from pyGHDL import GHDLBaseException @@ -108,7 +118,11 @@ class PrettyPrint: prefix = " " * level buffer.append("{prefix}Libraries:".format(prefix=prefix)) for library in design.Libraries.values(): - buffer.append("{prefix} - Name: {name}".format(prefix=prefix, name=library.Identifier)) + buffer.append( + "{prefix} - Name: {name}".format( + prefix=prefix, name=library.Identifier + ) + ) for line in self.formatLibrary(library, level + 2): buffer.append(line) buffer.append("{prefix}Documents:".format(prefix=prefix)) @@ -126,19 +140,41 @@ class PrettyPrint: prefix = " " * level buffer.append("{prefix}Entities:".format(prefix=prefix)) for entity in library.Entities: - buffer.append("{prefix} - {name}({architectures})".format(prefix=prefix, name=entity.Identifier, architectures=", ".join([a.Identifier for a in entity.Architectures]))) + buffer.append( + "{prefix} - {name}({architectures})".format( + prefix=prefix, + name=entity.Identifier, + architectures=", ".join( + [a.Identifier for a in entity.Architectures] + ), + ) + ) buffer.append("{prefix}Packages:".format(prefix=prefix)) for package in library.Packages: if isinstance(package, Package): - buffer.append("{prefix} - {name}".format(prefix=prefix, name=package.Identifier)) + buffer.append( + "{prefix} - {name}".format(prefix=prefix, name=package.Identifier) + ) elif isinstance(package, PackageInstantiation): - buffer.append("{prefix} - {name} instantiate from {package}".format(prefix=prefix, name=package.Identifier, package=package.PackageReference)) + buffer.append( + "{prefix} - {name} instantiate from {package}".format( + prefix=prefix, + name=package.Identifier, + package=package.PackageReference, + ) + ) buffer.append("{prefix}Configurations:".format(prefix=prefix)) for configuration in library.Configurations: - buffer.append("{prefix} - {name}".format(prefix=prefix, name=configuration.Identifier)) + buffer.append( + "{prefix} - {name}".format( + prefix=prefix, name=configuration.Identifier + ) + ) buffer.append("{prefix}Contexts:".format(prefix=prefix)) for context in library.Contexts: - buffer.append("{prefix} - {name}".format(prefix=prefix, name=context.Identifier)) + buffer.append( + "{prefix} - {name}".format(prefix=prefix, name=context.Identifier) + ) return buffer @@ -206,7 +242,9 @@ class PrettyPrint: buffer.append("{prefix} ...".format(prefix=prefix)) buffer.append("{prefix} Architecures:".format(prefix=prefix)) for item in entity.Architectures: - buffer.append("{prefix} - {name}".format(prefix=prefix, name=item.Identifier)) + buffer.append( + "{prefix} - {name}".format(prefix=prefix, name=item.Identifier) + ) return buffer @@ -240,8 +278,8 @@ class PrettyPrint: buffer.append("{prefix} Statements:".format(prefix=prefix)) for item in architecture.Statements: buffer.append("{prefix} ...".format(prefix=prefix)) -# for line in self.formatStatements(item, level + 2): -# buffer.append(line) + # for line in self.formatStatements(item, level + 2): + # buffer.append(line) return buffer @@ -268,10 +306,13 @@ class PrettyPrint: buffer = [] prefix = " " * level buffer.append( - "{prefix}- Name: {name}\n{prefix} File: {file}\n{prefix} Position: {line}:{column}".format(name=package.Identifier, prefix=prefix, + "{prefix}- Name: {name}\n{prefix} File: {file}\n{prefix} Position: {line}:{column}".format( + name=package.Identifier, + prefix=prefix, file=package.Position.Filename.name, line=package.Position.Line, - column=package.Position.Column,) + column=package.Position.Column, + ) ) buffer.append("{prefix} Declared:".format(prefix=prefix)) for item in package.DeclaredItems: @@ -605,13 +646,84 @@ class PrettyPrint: return " := {expr!s}".format(expr=item.DefaultExpression) - def formatHierarchy(self, statement: ConcurrentStatement, level: int = 0) -> StringBuffer: + def formatHierarchy( + self, statement: ConcurrentStatement, level: int = 0 + ) -> StringBuffer: buffer = [] prefix = " " * level if isinstance(statement, ProcessStatement): - buffer.append("{prefix}{label}: process(...)".format(prefix=prefix, label=statement.Label)) + buffer.append( + "{prefix}- {label}: process(...)".format( + prefix=prefix, label=statement.Label + ) + ) + elif isinstance(statement, EntityInstantiation): + buffer.append( + "{prefix}- {label}: entity {name}".format( + prefix=prefix, label=statement.Label, name=statement.Entity + ) + ) + elif isinstance(statement, ComponentInstantiation): + buffer.append( + "{prefix}- {label}: component {name}".format( + prefix=prefix, label=statement.Label, name=statement.Component + ) + ) + elif isinstance(statement, ConfigurationInstantiation): + buffer.append( + "{prefix}- {label}: configuration {name}".format( + prefix=prefix, label=statement.Label, name=statement.Configuration + ) + ) elif isinstance(statement, ConcurrentBlockStatement): - buffer.append("{prefix}{label}: block".format(prefix=prefix, label=statement.Label)) + buffer.append( + "{prefix}- {label}: block".format(prefix=prefix, label=statement.Label) + ) + for stmt in statement.Statements: + for line in self.formatHierarchy(stmt, level + 2): + buffer.append(line) + elif isinstance(statement, IfGenerateStatement): + buffer.append( + "{prefix}- {label}: if ... generate".format( + prefix=prefix, label=statement.Label + ) + ) + for stmt in statement.IfBranch.Statements: + for line in self.formatHierarchy(stmt, level + 2): + buffer.append(line) + for elsifBranch in statement.ElsifBranches: + buffer.append( + "{prefix} {label}: elsif ... generate".format( + prefix=prefix, label=statement.Label + ) + ) + for stmt in elsifBranch.Statements: + for line in self.formatHierarchy(stmt, level + 2): + buffer.append(line) + if statement.ElseBranch is not None: + buffer.append( + "{prefix} {label}: else generate".format( + prefix=prefix, label=statement.Label + ) + ) + for stmt in statement.ElseBranch.Statements: + for line in self.formatHierarchy(stmt, level + 2): + buffer.append(line) + elif isinstance(statement, CaseGenerateStatement): + buffer.append( + "{prefix}- {label}: case ... generate".format( + prefix=prefix, label=statement.Label + ) + ) + elif isinstance(statement, ForGenerateStatement): + buffer.append( + "{prefix}- {label}: for ... generate".format( + prefix=prefix, label=statement.Label + ) + ) + for stmt in statement.Statements: + for line in self.formatHierarchy(stmt, level + 2): + buffer.append(line) return buffer -- cgit v1.2.3 From 3abbfe34b529af865d6549bb3e6ed47ea1ab1e37 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Wed, 11 Aug 2021 03:34:54 +0200 Subject: Improved handling of generate statements and pretty-printing of hierarchy. --- pyGHDL/dom/formatting/prettyprint.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 1aefb570d..d7d5af2f9 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -685,8 +685,10 @@ class PrettyPrint: buffer.append(line) elif isinstance(statement, IfGenerateStatement): buffer.append( - "{prefix}- {label}: if ... generate".format( - prefix=prefix, label=statement.Label + "{prefix}- {label}: if {condition} generate".format( + prefix=prefix, + label=statement.Label, + condition=statement.IfBranch.Condition, ) ) for stmt in statement.IfBranch.Statements: @@ -694,8 +696,10 @@ class PrettyPrint: buffer.append(line) for elsifBranch in statement.ElsifBranches: buffer.append( - "{prefix} {label}: elsif ... generate".format( - prefix=prefix, label=statement.Label + "{prefix} {label}: elsif {condition} generate".format( + prefix=prefix, + label=statement.Label, + condition=elsifBranch.Condition, ) ) for stmt in elsifBranch.Statements: @@ -718,8 +722,11 @@ class PrettyPrint: ) elif isinstance(statement, ForGenerateStatement): buffer.append( - "{prefix}- {label}: for ... generate".format( - prefix=prefix, label=statement.Label + "{prefix}- {label}: for {index} in {range} generate".format( + prefix=prefix, + label=statement.Label, + index=statement.LoopIndex, + range=statement.Range, ) ) for stmt in statement.Statements: -- cgit v1.2.3 From b34f3e885407693a2839771fd469af4ce2b40978 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Wed, 11 Aug 2021 11:48:00 +0200 Subject: Improvements for case generate statements. --- pyGHDL/dom/formatting/prettyprint.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index d7d5af2f9..bc6744fe8 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -43,6 +43,7 @@ from pyGHDL.dom.Concurrent import ( ComponentInstantiation, ConfigurationInstantiation, EntityInstantiation, + OthersGenerateCase, ) from pyVHDLModel.SyntaxModel import ( GenericInterfaceItem, @@ -716,10 +717,18 @@ class PrettyPrint: buffer.append(line) elif isinstance(statement, CaseGenerateStatement): buffer.append( - "{prefix}- {label}: case ... generate".format( - prefix=prefix, label=statement.Label + "{prefix}- {label}: case {expression} generate".format( + prefix=prefix, + label=statement.Label, + expression=statement.SelectExpression, ) ) + for case in statement.Cases: + buffer.append( + "{prefix} {case!s}".format( + prefix=prefix, label=case.Label, case=case + ) + ) elif isinstance(statement, ForGenerateStatement): buffer.append( "{prefix}- {label}: for {index} in {range} generate".format( -- cgit v1.2.3 From bc09bbf10599436e1efdb0432886b2bb8b4bf890 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Wed, 11 Aug 2021 15:49:39 +0200 Subject: Support for concurrent procedure call. --- pyGHDL/dom/formatting/prettyprint.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index bc6744fe8..7fa49389d 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -44,6 +44,7 @@ from pyGHDL.dom.Concurrent import ( ConfigurationInstantiation, EntityInstantiation, OthersGenerateCase, + ConcurrentProcedureCall, ) from pyVHDLModel.SyntaxModel import ( GenericInterfaceItem, @@ -741,5 +742,11 @@ class PrettyPrint: for stmt in statement.Statements: for line in self.formatHierarchy(stmt, level + 2): buffer.append(line) + elif isinstance(statement, ConcurrentProcedureCall): + buffer.append( + "{prefix}- {label}: {name!s}(...)".format( + prefix=prefix, label=statement.Label, name=statement.Procedure + ) + ) return buffer -- cgit v1.2.3 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/formatting/prettyprint.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'pyGHDL/dom/formatting/prettyprint.py') 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 From 3f0308a5f807269aa5691fa1c704c0e9147d45f1 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 16 Aug 2021 23:47:04 +0200 Subject: Handle contexts. --- pyGHDL/dom/formatting/prettyprint.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 2f582a5f8..bfb91f3da 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -389,8 +389,8 @@ class PrettyPrint: return self.formatGenericType(generic, level) else: raise PrettyPrintException( - "Unhandled generic kind for generic '{name}'.".format( - name=generic.Identifiers[0] + "Unhandled generic kind '{kind}' for generic '{name}'.".format( + kind=generic.__class__.__name__, name=generic.Identifiers[0] ) ) @@ -401,8 +401,8 @@ class PrettyPrint: return self.formatPortSignal(port, level) else: raise PrettyPrintException( - "Unhandled port kind for port '{name}'.".format( - name=port.Identifiers[0] + "Unhandled port kind '{kind}' for port '{name}'.".format( + kind=port.__class__.__name__, name=port.Identifiers[0] ) ) -- cgit v1.2.3 From ad58c297680fe0256eacd12249d2131b00ff9b66 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 17 Aug 2021 00:51:37 +0200 Subject: Fixed pretty printer after model fix. --- pyGHDL/dom/formatting/prettyprint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index bfb91f3da..9917394da 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -566,7 +566,7 @@ class PrettyPrint: ) elif isinstance(item, UseClause): buffer.append( - "{prefix}- use {name!s}".format(prefix=prefix, name=item.Item) + "{prefix}- use {names}".format(prefix=prefix, names=", ".join([str(n) for n in item.Names])) ) elif isinstance(item, Package): buffer.append( -- cgit v1.2.3 From c34b020a8c1b6aa5083a637e3e9062c7a71b309a Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 17 Aug 2021 10:16:59 +0200 Subject: Some updates. --- pyGHDL/dom/formatting/prettyprint.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 9917394da..6314d37f2 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -566,7 +566,9 @@ class PrettyPrint: ) elif isinstance(item, UseClause): buffer.append( - "{prefix}- use {names}".format(prefix=prefix, names=", ".join([str(n) for n in item.Names])) + "{prefix}- use {names}".format( + prefix=prefix, names=", ".join([str(n) for n in item.Names]) + ) ) elif isinstance(item, Package): buffer.append( -- cgit v1.2.3 From 8fb4da723067b2ff99050f9ef9fc0bbd3c835ef4 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 23 Aug 2021 00:13:43 +0200 Subject: Some fixes. --- pyGHDL/dom/formatting/prettyprint.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'pyGHDL/dom/formatting/prettyprint.py') diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 6314d37f2..6c0f06061 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -43,7 +43,6 @@ from pyGHDL.dom.Concurrent import ( ComponentInstantiation, ConfigurationInstantiation, EntityInstantiation, - OthersGenerateCase, ConcurrentProcedureCall, ) from pyVHDLModel.SyntaxModel import ( @@ -93,7 +92,7 @@ from pyGHDL.dom.InterfaceItem import ( PortSignalInterfaceItem, GenericTypeInterfaceItem, ) -from pyGHDL.dom.Object import Constant, Signal, SharedVariable, File, DeferredConstant +from pyGHDL.dom.Object import Constant, Signal, SharedVariable, File from pyGHDL.dom.Attribute import Attribute, AttributeSpecification from pyGHDL.dom.Subprogram import Procedure from pyGHDL.dom.Misc import Alias -- cgit v1.2.3