From bef613e0d3d1da3226ea460d18211c84a1ba7aac Mon Sep 17 00:00:00 2001 From: Unai Martinez-Corral Date: Fri, 15 Sep 2023 01:00:55 +0200 Subject: [PATCH] test --- mods/pyOSVDE/topwrap.py | 145 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 2 deletions(-) diff --git a/mods/pyOSVDE/topwrap.py b/mods/pyOSVDE/topwrap.py index 311d21f..2bdef7f 100755 --- a/mods/pyOSVDE/topwrap.py +++ b/mods/pyOSVDE/topwrap.py @@ -50,8 +50,7 @@ def __init__(self, dirName): self.Design = Design() self.parseDir(Path(dirName)) resolve_Symbols(self.Design) - #self.loadFileTree() - #self.loadDesignTree() + self.printDesignTree() def parseDir(self, dirName: Path): """ @@ -78,6 +77,148 @@ def parseFile(self, sourceFile: Path, library: str = "lib"): lib = self.Design.GetLibrary(library) self.Design.AddDocument(Document(sourceFile), lib) + def printDesignTree(self, parent=""): + """ + Print the Design Tree with the data from the pyVHDLModel Design. + """ + +# def addTreeItem(parent, text, isOpen, image): +# return dtw.insert(parent, tk.END, text=text, open=isOpen, image=self.Image[image]) +# +# def loadStatementsTree(item, statements): +# for statement in statements: +# +# # Note: the following share the same base class 'Instantiation' +# # ComponentInstantiation, EntityInstantiation, ConfigurationInstantiation +# +# if isinstance(statement, Instantiation): +# addTreeItem(item, "{}: inst".format(statement.Label), False, "inst") +# +# elif isinstance(statement, ConcurrentBlockStatement): +# instItem = addTreeItem(item, "{}: block".format(statement.Label), False, "file") +# innerstatements = statement.Statements +# if len(innerstatements) != 0: +# loadStatementsTree(instItem, innerstatements) +# +# # Note: the following share the same base class 'GenerateStatement' +# # ForGenerateStatement, CaseGenerateStatement, IfGenerateStatement +# +# elif isinstance(statement, IfGenerateStatement): +# instItem = addTreeItem(item, "{}: if .. generate".format(statement.Label), False, "file") +# loadStatementsTree( +# addTreeItem( +# instItem, +# "if: {}".format(statement.IfBranch.Condition), +# False, +# "file", +# ), +# statement.IfBranch.Statements, +# ) +# for elsifbranch in statement.ElsifBranches: +# loadStatementsTree( +# addTreeItem( +# instItem, +# "elsif: {}".format(elsifbranch.Condition), +# False, +# "file", +# ), +# elsifbranch.Statements, +# ) +# if statement.ElseBranch is not None: +# loadStatementsTree( +# addTreeItem(instItem, "else:", False, "file"), +# statement.ElseBranch.Statements, +# ) +# +# elif isinstance(statement, CaseGenerateStatement): +# instItem = addTreeItem(item, "{}: case .. generate".format(statement.Label), False, "file") +# for case in statement.Cases: +# if isinstance(case, GenerateCase): +# loadStatementsTree( +# addTreeItem( +# instItem, +# "case: {}".format(" | ".join([str(c) for c in case.Choises])), +# False, +# "file", +# ), +# case.Statements, +# ) +# elif isinstance(case, OthersGenerateCase): +# loadStatementsTree( +# addTreeItem(instItem, "others:", False, "file"), +# case.Statements, +# ) +# +# elif isinstance(statement, ForGenerateStatement): +# instItem = addTreeItem( +# item, +# "{0}: for {1!s} generate".format(statement.Label, statement.Range), +# False, +# "file", +# ) +# innerstatements = statement.Statements +# if len(innerstatements) != 0: +# loadStatementsTree(instItem, innerstatements) +# +# elif isinstance(statement, ProcessStatement): +# addTreeItem( +# item, +# "{}: process".format(statement.Label or "DefaultLabel"), +# False, +# "file", +# ) + + for libName, lib in self.Design.Libraries.items(): + print(f"Library: {libName}") +# LibItem = addTreeItem(parent, libName, True, "lib") + for entity in lib.Entities: + print(f" Entity: {entity.Identifier}") +# EntityItem = addTreeItem(LibItem, entity.Identifier, False, "ent") +# +# generics = entity.GenericItems +# if len(generics) != 0: +# GenericsItem = addTreeItem(EntityItem, "Generics", False, "generics") +# for generic in generics: +# if isinstance(generic, GenericConstantInterfaceItem): +# addTreeItem( +# GenericsItem, +# "{} [{}]".format(",".join(generic.Identifiers), generic.Subtype), +# False, +# "generic", +# ) +# elif isinstance(generic, GenericTypeInterfaceItem): +# addTreeItem( +# GenericsItem, +# "type: {}".format(generic.Identifier), +# False, +# "generic", +# ) +# else: +# print( +# "[NOT IMPLEMENTED] Generic item class not supported yet: {0}", +# generic.__class__.__name__, +# ) +# +# ports = entity.PortItems +# if len(ports) != 0: +# PortsItem = addTreeItem(EntityItem, "Ports", False, "ports") +# for port in ports: +# addTreeItem( +# PortsItem, +# "{} [{}]".format(",".join(port.Identifiers), port.Subtype), +# False, +# "out" if port.Mode is Mode.Out else "inout" if port.Mode is Mode.InOut else "in", +# ) +# +# architectures = entity.Architectures +# if len(architectures) != 0: +# ArchitecturesItem = addTreeItem(EntityItem, "Architectures", False, "archs") +# for architecture in entity.Architectures: +# loadStatementsTree( +# addTreeItem(ArchitecturesItem, "{}".format(architecture.Identifier), False, "arch"), +# architecture.Statements, +# ) + if __name__ == "__main__": if len(sys_argv) < 2: raise Exception('Needs one argument: the path to a directory containing VHDL sources.')