From 1e4bb87979261ac550e1642ead1fafed331682d9 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Thu, 12 Aug 2021 10:09:25 +0200 Subject: [PATCH 01/13] Bump version to v0.11.4. --- doc/conf.py | 2 +- pyVHDLModel/SyntaxModel.py | 2 +- pyVHDLModel/__init__.py | 8 ++++---- setup.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index b084b32d8..e4d467e4e 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -37,7 +37,7 @@ def _LatestTagName(): # The full version, including alpha/beta/rc tags version = "0.11" # The short X.Y version. -release = "0.11.3" # The full version, including alpha/beta/rc tags. +release = "0.11.4" # The full version, including alpha/beta/rc tags. try: if _IsUnderGitControl: latestTagName = _LatestTagName()[1:] # remove prefix "v" diff --git a/pyVHDLModel/SyntaxModel.py b/pyVHDLModel/SyntaxModel.py index 21a8b3df1..d33220ba7 100644 --- a/pyVHDLModel/SyntaxModel.py +++ b/pyVHDLModel/SyntaxModel.py @@ -42,7 +42,7 @@ """ # load dependencies from pathlib import Path -from typing import List, Tuple, Union, Dict, Iterator, Optional, Any, Iterable +from typing import List, Tuple, Union, Dict, Iterator, Optional, Any, Iterable from pydecor.decorators import export diff --git a/pyVHDLModel/__init__.py b/pyVHDLModel/__init__.py index b4f88e5b5..191a3689c 100644 --- a/pyVHDLModel/__init__.py +++ b/pyVHDLModel/__init__.py @@ -40,13 +40,13 @@ :copyright: Copyright 2007-2021 Patrick Lehmann - Bötzingen, Germany :license: Apache License, Version 2.0 """ -from enum import IntEnum, unique, Enum -from typing import List +from enum import IntEnum, unique, Enum +from typing import List -from pydecor import export +from pydecor import export -__version__ = "0.11.3" +__version__ = "0.11.4" @export diff --git a/setup.py b/setup.py index 2951a1ea0..e74b69c1e 100644 --- a/setup.py +++ b/setup.py @@ -53,7 +53,7 @@ # Assemble all package information setuptools_setup( name=projectName, - version="0.11.3", + version="0.11.4", author="Patrick Lehmann", author_email="Paebbels@gmail.com", From ce07673640dd3a0587bc8c72e90254e4d398a12a Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Thu, 12 Aug 2021 12:04:48 +0200 Subject: [PATCH 02/13] Fixed typing issues. --- pyVHDLModel/SyntaxModel.py | 39 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/pyVHDLModel/SyntaxModel.py b/pyVHDLModel/SyntaxModel.py index d33220ba7..23ac65486 100644 --- a/pyVHDLModel/SyntaxModel.py +++ b/pyVHDLModel/SyntaxModel.py @@ -2396,7 +2396,7 @@ def DeclaredItems(self) -> List: class SequentialStatements: _statements: List[SequentialStatement] - def __init__(self, statements: Iterable[SequentialStatement]): + def __init__(self, statements: Iterable[SequentialStatement] = None): self._statements = [] if statements is None else [s for s in statements] @property @@ -2411,7 +2411,7 @@ class Instantiation(ConcurrentStatement): @export class ComponentInstantiation(Instantiation): - _component: Component + _component: Name def __init__(self, label: str, componentName: Name): super().__init__(label) @@ -2419,14 +2419,14 @@ def __init__(self, label: str, componentName: Name): self._component = componentName @property - def Component(self) -> Component: + def Component(self) -> Name: return self._component @export class EntityInstantiation(Instantiation): - _entity: Entity - _architecture: Architecture + _entity: Name + _architecture: Name def __init__(self, label: str, entityName: Name, architectureName: Name = None): super().__init__(label) @@ -2435,17 +2435,17 @@ def __init__(self, label: str, entityName: Name, architectureName: Name = None): self._architecture = architectureName @property - def Entity(self) -> Entity: + def Entity(self) -> Name: return self._entity @property - def Architecture(self) -> Entity: + def Architecture(self) -> Name: return self._architecture @export class ConfigurationInstantiation(Instantiation): - _configuration: Configuration + _configuration: Name def __init__(self, label: str, configurationName: Name): super().__init__(label) @@ -2453,13 +2453,13 @@ def __init__(self, label: str, configurationName: Name): self._configuration = configurationName @property - def Configuration(self) -> Entity: + def Configuration(self) -> Name: return self._configuration @export class ProcessStatement(ConcurrentStatement, SequentialDeclarations, SequentialStatements): - _sensitivityList: List[Signal] = None + _sensitivityList: List[Name] = None def __init__(self, label: str = None, declaredItems: Iterable = None, statements: Iterable[SequentialStatement] = None, sensitivityList: Iterable[Name] = None): super().__init__(label) @@ -2470,7 +2470,7 @@ def __init__(self, label: str = None, declaredItems: Iterable = None, statements self._sensitivityList = [s for s in sensitivityList] @property - def SensitivityList(self) -> List[Signal]: + def SensitivityList(self) -> List[Name]: return self._sensitivityList @@ -2552,7 +2552,7 @@ class MixinConditional: """ _condition: Expression - def __init__(self, condition: Expression): + def __init__(self, condition: Expression = None): self._condition = condition @property @@ -2891,14 +2891,14 @@ def Waveform(self) -> List[WaveformElement]: class ConcurrentSelectedSignalAssignment(ConcurrentSignalAssignment): def __init__(self, label: str, target: Name, expression: Expression): super().__init__(label, target) - expression + @export class ConcurrentConditionalSignalAssignment(ConcurrentSignalAssignment): def __init__(self, label: str, target: Name, expression: Expression): super().__init__(label, target) - expression + @export @@ -3009,9 +3009,6 @@ class CompoundStatement(SequentialStatement): A ``CompoundStatement`` is a base-class for all compound statements. """ - def __init__(self): - super().__init__() - @export class IfStatement(CompoundStatement): @@ -3069,14 +3066,14 @@ class EndlessLoopStatement(LoopStatement): @export class ForLoopStatement(LoopStatement): - _loopIndex: Constant + _loopIndex: str _range: Range def __init__(self): super().__init__() @property - def LoopIndex(self) -> Constant: + def LoopIndex(self) -> str: return self._loopIndex @property @@ -3119,7 +3116,7 @@ class ExitStatement(LoopControlStatement): @export class WaitStatement(SequentialStatement, MixinConditional): - _sensitivityList: List[Signal] + _sensitivityList: List[Name] _timeout: Expression def __init__(self): @@ -3127,7 +3124,7 @@ def __init__(self): MixinConditional.__init__(self) @property - def SensitivityList(self) -> List[Signal]: + def SensitivityList(self) -> List[Name]: return self._sensitivityList @property From fd4d21f857ae9bfc3842205f44f5db0a8f5e4d21 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Thu, 12 Aug 2021 12:05:03 +0200 Subject: [PATCH 03/13] Prepared for sequential statements. --- pyVHDLModel/SyntaxModel.py | 91 +++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 35 deletions(-) diff --git a/pyVHDLModel/SyntaxModel.py b/pyVHDLModel/SyntaxModel.py index 23ac65486..d979b61db 100644 --- a/pyVHDLModel/SyntaxModel.py +++ b/pyVHDLModel/SyntaxModel.py @@ -2844,6 +2844,16 @@ class VariableAssignment(Assignment): """ An ``VariableAssignment`` is a base-class for all variable assignment statements. """ + _expression: Expression + + def __init__(self, target: Name, expression: Expression): + super().__init__(target) + + self._expression = expression + + @property + def Expression(self) -> Expression: + return self._expression @export @@ -2904,15 +2914,15 @@ def __init__(self, label: str, target: Name, expression: Expression): @export class SequentialSignalAssignment(SequentialStatement, SignalAssignment): def __init__(self, target: Name, expression: Expression, label: str = None): - super().__init__() - SignalAssignment.__init__(self, target, expression) + super().__init__(label) + SignalAssignment.__init__(self, target) @export class SequentialVariableAssignment(SequentialStatement, VariableAssignment): - def __init__(self): - super().__init__() - VariableAssignment.__init__(self) + def __init__(self, target: Name, expression: Expression, label: str = None): + super().__init__(label) + VariableAssignment.__init__(self, target, expression) @export @@ -2974,32 +2984,32 @@ def __init__(self): @export class Branch(ModelEntity, SequentialStatements): """ - A ``Branch`` is a base-class for all branches. + A ``Branch`` is a base-class for all branches in a if statement. """ - def __init__(self): + def __init__(self, statements: Iterable[ConcurrentStatement] = None): super().__init__() - SequentialStatements.__init__(self) + SequentialStatements.__init__(self, statements) @export class IfBranch(Branch, MixinIfBranch): - def __init__(self): - super().__init__() - MixinIfBranch.__init__(self) + def __init__(self, condition: Expression, statements: Iterable[ConcurrentStatement] = None): + super().__init__(statements) + MixinIfBranch.__init__(self, condition) @export class ElsifBranch(Branch, MixinElsifBranch): - def __init__(self): - super().__init__() - MixinElsifBranch.__init__(self) + def __init__(self, condition: Expression, statements: Iterable[ConcurrentStatement] = None): + super().__init__(statements) + MixinElsifBranch.__init__(self, condition) @export class ElseBranch(Branch, MixinElseBranch): - def __init__(self): - super().__init__() + def __init__(self, statements: Iterable[ConcurrentStatement] = None): + super().__init__(statements) MixinElseBranch.__init__(self) @@ -3016,10 +3026,12 @@ class IfStatement(CompoundStatement): _elsifBranches: List['ElsifBranch'] _elseBranch: ElseBranch - def __init__(self): - super().__init__() + def __init__(self, ifBranch: IfBranch, elsifBranches: Iterable[ElsifBranch] = None, elseBranch: ElseBranch = None, label: str = None): + super().__init__(label) - self._elsifBranches = [] + self._ifBranch = ifBranch + self._elsifBranches = [] if elsifBranches is None else [b for b in elsifBranches] + self._elseBranch = elseBranch @property def IfBranch(self) -> IfBranch: @@ -3036,15 +3048,21 @@ def ElseBranch(self) -> ElseBranch: @export class CaseStatement(CompoundStatement): - _selectExpression: Expression - _cases: List[SequentialCase] + _expression: Expression + _cases: List[Case] + + def __init__(self, expression: Expression, cases: Iterable[GenerateCase], label: str = None): + super().__init__(label) + + self._expression = expression + self._cases = [] if cases is None else [c for c in cases] @property def SelectExpression(self) -> Expression: - return self._selectExpression + return self._expression @property - def Cases(self) -> List[SequentialCase]: + def Cases(self) -> List[Case]: return self._cases @@ -3054,9 +3072,9 @@ class LoopStatement(CompoundStatement, SequentialStatements): A ``LoopStatement`` is a base-class for all loop statements. """ - def __init__(self): - super().__init__() - SequentialStatements.__init__(self) + def __init__(self, statements: Iterable[ConcurrentStatement] = None, label: str = None): + super().__init__(label) + SequentialStatements.__init__(self, statements) @export @@ -3069,8 +3087,11 @@ class ForLoopStatement(LoopStatement): _loopIndex: str _range: Range - def __init__(self): - super().__init__() + def __init__(self, loopIndex: str, range: Range, statements: Iterable[ConcurrentStatement] = None, label: str = None): + super().__init__(label, statements) + + self._loopIndex = loopIndex + self._range = range @property def LoopIndex(self) -> str: @@ -3083,9 +3104,9 @@ def Range(self) -> Range: @export class WhileLoopStatement(LoopStatement, MixinConditional): - def __init__(self): - super().__init__() - MixinConditional.__init__(self) + def __init__(self, condition: Expression, statements: Iterable[ConcurrentStatement] = None, label: str = None): + super().__init__(label, statements) + MixinConditional.__init__(self, condition) @export @@ -3095,9 +3116,9 @@ class LoopControlStatement(SequentialStatement, MixinConditional): """ _loopReference: LoopStatement - def __init__(self): + def __init__(self, condition: Expression = None, loopLabel: str = None): # TODO: is this label (currently str) a Name or a Label class? super().__init__() - MixinConditional.__init__(self) + MixinConditional.__init__(self, condition) @property def LoopReference(self) -> LoopStatement: @@ -3136,9 +3157,9 @@ def Timeout(self) -> Expression: class ReturnStatement(SequentialStatement, MixinConditional): _returnValue: Expression - def __init__(self): + def __init__(self, returnValue: Expression = None): super().__init__() - MixinConditional.__init__(self) + MixinConditional.__init__(self, returnValue) @property def ReturnValue(self) -> Expression: From e09ceb0fe80bac882428336749f6d818c6dd1e74 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Thu, 12 Aug 2021 13:03:10 +0200 Subject: [PATCH 04/13] More improvements to sequential statements. --- pyVHDLModel/SyntaxModel.py | 121 ++++++++++++++++++++++++++++++------- 1 file changed, 100 insertions(+), 21 deletions(-) diff --git a/pyVHDLModel/SyntaxModel.py b/pyVHDLModel/SyntaxModel.py index d979b61db..070ada437 100644 --- a/pyVHDLModel/SyntaxModel.py +++ b/pyVHDLModel/SyntaxModel.py @@ -2684,19 +2684,27 @@ class Choice(ModelEntity): class ConcurrentChoice(Choice): """ A ``ConcurrentChoice`` is a base-class for all concurrent choices - (in for...generate statements). + (in case...generate statements). """ @export -class Case(ModelEntity): +class SequentialChoice(Choice): + """ + A ``SequentialChoice`` is a base-class for all sequential choices + (in case statements). + """ + + +@export +class BaseCase(ModelEntity): """ A ``Case`` is a base-class for all cases. """ @export -class ConcurrentCase(Case, LabeledEntity, ConcurrentDeclarations, ConcurrentStatements): +class ConcurrentCase(BaseCase, LabeledEntity, ConcurrentDeclarations, ConcurrentStatements): def __init__(self, declaredItems: Iterable = None, statements: Iterable[ConcurrentStatement] = None, alternativeLabel: str = None): super().__init__() LabeledEntity.__init__(self, alternativeLabel) @@ -2704,6 +2712,19 @@ def __init__(self, declaredItems: Iterable = None, statements: Iterable[Concurre ConcurrentStatements.__init__(self, statements) +@export +class SequentialCase(BaseCase, SequentialStatements): + _choices: List + + def __init__(self, statements: Iterable[SequentialStatement] = None): + super().__init__() + SequentialStatements.__init__(self, statements) + + @property + def Choises(self) -> List[Choice]: + return self._choices + + @export class GenerateCase(ConcurrentCase): _choices: List[ConcurrentChoice] @@ -2727,19 +2748,6 @@ def __str__(self) -> str: return "when others =>" -@export -class SequentialCase(Case, SequentialStatements): - _choices: List - - def __init__(self): - super().__init__() - SequentialStatements.__init__(self) - - @property - def Choises(self) -> List[Choice]: - return self._choices - - @export class IndexedGenerateChoice(ConcurrentChoice): _expression: Expression @@ -2779,7 +2787,7 @@ class CaseGenerateStatement(GenerateStatement): _expression: Expression _cases: List[GenerateCase] - def __init__(self, label: str, expression: Expression, cases: Iterable[GenerateCase]): + def __init__(self, label: str, expression: Expression, cases: Iterable[ConcurrentCase]): super().__init__(label) self._expression = expression @@ -2913,11 +2921,25 @@ def __init__(self, label: str, target: Name, expression: Expression): @export class SequentialSignalAssignment(SequentialStatement, SignalAssignment): - def __init__(self, target: Name, expression: Expression, label: str = None): + def __init__(self, target: Name, label: str = None): super().__init__(label) SignalAssignment.__init__(self, target) +@export +class SequentialSimpleSignalAssignment(SequentialSignalAssignment): + _waveform: List[WaveformElement] + + def __init__(self, target: Name, waveform: Iterable[WaveformElement], label: str = None): + super().__init__(target, label) + + self._waveform = [e for e in waveform] + + @property + def Waveform(self) -> List[WaveformElement]: + return self._waveform + + @export class SequentialVariableAssignment(SequentialStatement, VariableAssignment): def __init__(self, target: Name, expression: Expression, label: str = None): @@ -3046,12 +3068,69 @@ def ElseBranch(self) -> ElseBranch: return self._elseBranch +@export +class Case(SequentialCase): + _choices: List[SequentialChoice] + + def __init__(self, choices: Iterable[SequentialChoice], statements: Iterable[SequentialStatement] = None): + super().__init__(statements) + + self._choices = [c for c in choices] + + @property + def Choises(self) -> List[SequentialChoice]: + return self._choices + + def __str__(self) -> str: + return "when {choices} =>".format(choices=" | ".join([str(c) for c in self._choices])) + + +@export +class OthersCase(SequentialCase): + def __str__(self) -> str: + return "when others =>" + + +@export +class IndexedChoice(SequentialChoice): + _expression: Expression + + def __init__(self, expression: Expression): + super().__init__() + + self._expression = expression + + @property + def Expression(self) -> Expression: + return self._expression + + def __str__(self) -> str: + return "{expression!s}".format(expression=self._expression) + + +@export +class RangedChoice(SequentialChoice): + _range: 'Range' + + def __init__(self, rng: 'Range'): + super().__init__() + + self._range = rng + + @property + def Range(self) -> 'Range': + return self._range + + def __str__(self) -> str: + return "{range!s}".format(range=self._range) + + @export class CaseStatement(CompoundStatement): _expression: Expression - _cases: List[Case] + _cases: List[SequentialCase] - def __init__(self, expression: Expression, cases: Iterable[GenerateCase], label: str = None): + def __init__(self, expression: Expression, cases: Iterable[SequentialCase], label: str = None): super().__init__(label) self._expression = expression @@ -3062,7 +3141,7 @@ def SelectExpression(self) -> Expression: return self._expression @property - def Cases(self) -> List[Case]: + def Cases(self) -> List[SequentialCase]: return self._cases From 9e8f81a27e71bf163adf18335918f8d900b9b469 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 16 Aug 2021 23:45:48 +0200 Subject: [PATCH 05/13] Handle contexts. --- doc/LanguageModel/DesignUnits.rst | 8 +-- doc/LanguageModel/Miscellaneous.rst | 12 ++--- pyVHDLModel/SyntaxModel.py | 75 ++++++++++++----------------- pyVHDLModel/__init__.py | 11 ++++- 4 files changed, 51 insertions(+), 55 deletions(-) diff --git a/doc/LanguageModel/DesignUnits.rst b/doc/LanguageModel/DesignUnits.rst index e9ab04d13..fba6298ce 100644 --- a/doc/LanguageModel/DesignUnits.rst +++ b/doc/LanguageModel/DesignUnits.rst @@ -80,7 +80,7 @@ types). An entity's list of statements is called body items. # inherited from MixinDesignUnitWithContext @property - def LibraryReferences(self) -> List[LibraryStatement]: + def LibraryReferences(self) -> List[LibraryClause]: @property def PackageReferences(self) -> List[UseClause]: @@ -128,7 +128,7 @@ Package # inherited from MixinDesignUnitWithContext @property - def LibraryReferences(self) -> List[LibraryStatement]: + def LibraryReferences(self) -> List[LibraryClause]: @property def PackageReferences(self) -> List[UseClause]: @@ -175,7 +175,7 @@ Architeture # inherited from MixinDesignUnitWithContext @property - def LibraryReferences(self) -> List[LibraryStatement]: + def LibraryReferences(self) -> List[LibraryClause]: @property def PackageReferences(self) -> List[UseClause]: @@ -220,7 +220,7 @@ Package Body # inherited from MixinDesignUnitWithContext @property - def LibraryReferences(self) -> List[LibraryStatement]: + def LibraryReferences(self) -> List[LibraryClause]: @property def PackageReferences(self) -> List[UseClause]: diff --git a/doc/LanguageModel/Miscellaneous.rst b/doc/LanguageModel/Miscellaneous.rst index 25764c60d..4bb24d728 100644 --- a/doc/LanguageModel/Miscellaneous.rst +++ b/doc/LanguageModel/Miscellaneous.rst @@ -36,7 +36,7 @@ a design has the two child nodes: ``Libraries`` and ``Documents``. Each is a # from Design @property - def Libraries(self) -> List[LibraryStatement]: + def Libraries(self) -> List[LibraryClause]: @property def Documents(self) -> List[Document]: @@ -45,24 +45,24 @@ a design has the two child nodes: ``Libraries`` and ``Documents``. Each is a .. _vhdlmodel-library: -LibraryStatement -================ +LibraryClause +============= A library contains multiple *design units*. Each design unit listed in a library is a *primary* design unit like: ``configuration``, ``entity``, ``package`` or ``context``. -**Condensed definition of class** :class:`~pyVHDLModel.VHDLModel.LibraryStatement`: +**Condensed definition of class** :class:`~pyVHDLModel.VHDLModel.LibraryClause`: .. code-block:: Python @export - class LibraryStatement(ModelEntity): + class LibraryClause(ModelEntity): # inherited from ModelEntity @property def Parent(self) -> ModelEntity: - # from LibraryStatement + # from LibraryClause @property def Contexts(self) -> List[Context]: diff --git a/pyVHDLModel/SyntaxModel.py b/pyVHDLModel/SyntaxModel.py index 070ada437..19c2d47ec 100644 --- a/pyVHDLModel/SyntaxModel.py +++ b/pyVHDLModel/SyntaxModel.py @@ -93,6 +93,11 @@ class Protocol: 'Literal', ] +Context = Union[ + 'LibraryClause' + 'UseClause' + 'ContextReference' +] @export class Name: @@ -203,7 +208,7 @@ def __init__(self, prefix: Name): super().__init__("all", prefix) def __str__(self): - return "all" + return str(self._prefix) + "." + "all" @export @@ -1985,23 +1990,6 @@ def __init__(self, identifiers: Iterable[str], subtype: SubtypeOrSymbol): super().__init__(identifiers, subtype) ParameterInterfaceItem.__init__(self) -# class GenericItem(ModelEntity): -# def __init__(self): -# super().__init__() -# self._name = None -# self._subtype = None -# self._init = None -# -# -# class PortItem(ModelEntity): -# def __init__(self): -# super().__init__() -# self._name = None -# self._subtype = None -# self._init = None -# self._mode = None -# self._class = None - @export class Reference(ModelEntity): @@ -2009,12 +1997,13 @@ class Reference(ModelEntity): @export -class LibraryStatement(Reference): - _library: Union[None, LibraryOrSymbol] +class LibraryClause(Reference): + _names: List[Name] - def __init__(self): + def __init__(self, names: Iterable[Name]): super().__init__() - self._library = None + + self._names = [n for n in names] @property def Library(self) -> Union[None, LibraryOrSymbol]: @@ -2023,25 +2012,24 @@ def Library(self) -> Union[None, LibraryOrSymbol]: @export class UseClause(Reference): - _library: Union[None, LibraryOrSymbol] - _package: 'Package' - _item: str + _names: List[Name] - def __init__(self, name: Name): + def __init__(self, names: Iterable[Name]): super().__init__() - self._item = str(name) # FIXME: should the name be splitted? + + self._names = [n for n in names] @property def Library(self) -> Union[None, LibraryOrSymbol]: - return self._library + return "" # self._library @property def Package(self) -> 'Package': - return self._package + return "" # self._package @property def Item(self) -> str: - return self._item + return "" # self._item @export @@ -2066,7 +2054,7 @@ class MixinDesignUnitWithContext: """ A ``DesignUnitWithReferences`` is a base-class for all design units with contexts. """ - _libraryReferences: List[LibraryStatement] + _libraryReferences: List[LibraryClause] _packageReferences: List[UseClause] _contextReferences: List['Context'] @@ -2076,7 +2064,7 @@ def __init__(self): self._contextReferences = [] @property - def LibraryReferences(self) -> List[LibraryStatement]: + def LibraryReferences(self) -> List[LibraryClause]: return self._libraryReferences @property @@ -2090,17 +2078,17 @@ def ContextReferences(self) -> List['Context']: @export class Context(PrimaryUnit): - _libraryReferences: List[LibraryStatement] + _libraryReferences: List[LibraryClause] _packageReferences: List[UseClause] - def __init__(self, identifier): + def __init__(self, identifier: str, libraryReferences: Iterable[LibraryClause] = None, packageReferences: Iterable[UseClause] = None): super().__init__(identifier) - self._libraryReferences = [] - self._packageReferences = [] + self._libraryReferences = [] if libraryReferences is None else [l for l in libraryReferences] + self._packageReferences = [] if packageReferences is None else [p for p in packageReferences] @property - def LibraryReferences(self) -> List[LibraryStatement]: + def LibraryReferences(self) -> List[LibraryClause]: return self._libraryReferences @property @@ -2119,6 +2107,7 @@ class Entity(PrimaryUnit, MixinDesignUnitWithContext): def __init__( self, identifier: str, + contextItems: Iterable[Context] = None, genericItems: Iterable[GenericInterfaceItem] = None, portItems: Iterable[PortInterfaceItem] = None, declaredItems: Iterable = None, @@ -2161,7 +2150,7 @@ class Architecture(SecondaryUnit, MixinDesignUnitWithContext): _declaredItems: List # FIXME: define list prefix type e.g. via Union _statements: List['ConcurrentStatement'] - def __init__(self, identifier: str, entity: Name, declaredItems: Iterable = None, statements: Iterable['ConcurrentStatement'] = None): + def __init__(self, identifier: str, entity: Name, contextItems: Iterable[Context] = None, declaredItems: Iterable = None, statements: Iterable['ConcurrentStatement'] = None): super().__init__(identifier) MixinDesignUnitWithContext.__init__(self) @@ -2212,7 +2201,7 @@ def PortItems(self) -> List[PortInterfaceItem]: @export class Configuration(PrimaryUnit, MixinDesignUnitWithContext): - def __init__(self, identifier: str): + def __init__(self, identifier: str, contextItems: Iterable[Context] = None): super().__init__(identifier) MixinDesignUnitWithContext.__init__(self) @@ -2278,8 +2267,8 @@ class Package(PrimaryUnit, MixinDesignUnitWithContext): _genericItems: List[GenericInterfaceItem] _declaredItems: List - def __init__(self, identifier: str, genericItems: Iterable[GenericInterfaceItem] = None, declaredItems: Iterable = None): - super().__init__(identifier) + def __init__(self, identifier: str, contextItems: Iterable[Context] = None,genericItems: Iterable[GenericInterfaceItem] = None, declaredItems: Iterable = None): + super().__init__(identifier, contextItems) MixinDesignUnitWithContext.__init__(self) self._genericItems = [] if genericItems is None else [g for g in genericItems] @@ -2299,8 +2288,8 @@ class PackageBody(SecondaryUnit, MixinDesignUnitWithContext): _package: Package _declaredItems: List - def __init__(self, identifier: str, declaredItems: Iterable = None): - super().__init__(identifier) + def __init__(self, identifier: str, contextItems: Iterable[Context] = None, declaredItems: Iterable = None): + super().__init__(identifier, contextItems) MixinDesignUnitWithContext.__init__(self) self._declaredItems = [] if declaredItems is None else [i for i in declaredItems] diff --git a/pyVHDLModel/__init__.py b/pyVHDLModel/__init__.py index 191a3689c..89976d30f 100644 --- a/pyVHDLModel/__init__.py +++ b/pyVHDLModel/__init__.py @@ -41,7 +41,7 @@ :license: Apache License, Version 2.0 """ from enum import IntEnum, unique, Enum -from typing import List +from typing import List, Iterable from pydecor import export @@ -262,11 +262,18 @@ class DesignUnit(ModelEntity, NamedEntity): """ A ``DesignUnit`` is a base-class for all design units. """ + _contextItems: List['Context'] - def __init__(self, identifier: str): + def __init__(self, identifier: str, contextItems: Iterable['Context'] = None): super().__init__() NamedEntity.__init__(self, identifier) + self._contextItems = [] if contextItems is None else [c for c in contextItems] + + @property + def ContextItems(self) -> List['Context']: + return self._contextItems + @export class PrimaryUnit(DesignUnit): From 2500dc5bf8fec1f24bd55e0b21b4a378fed061b6 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 16 Aug 2021 23:55:38 +0200 Subject: [PATCH 06/13] Added ContextReference. --- pyVHDLModel/SyntaxModel.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pyVHDLModel/SyntaxModel.py b/pyVHDLModel/SyntaxModel.py index 19c2d47ec..7f3c873bf 100644 --- a/pyVHDLModel/SyntaxModel.py +++ b/pyVHDLModel/SyntaxModel.py @@ -2033,20 +2033,21 @@ def Item(self) -> str: @export -class ContextStatement(Reference): - _library: Union[None, LibraryOrSymbol] - _context: 'Context' +class ContextReference(Reference): + _names: List[Name] - def __init__(self): + def __init__(self, names: Iterable[Name]): super().__init__() + self._names = [n for n in names] + @property def Library(self) -> Union[None, LibraryOrSymbol]: - return self._library + return "" # self._library @property def Context(self) -> 'Context': - return self._context + return "" # self._context @export From bb6810847d3969a0644fbcaa8bc1bda71d560172 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 17 Aug 2021 00:49:02 +0200 Subject: [PATCH 07/13] Fixed model for context items. --- pyVHDLModel/SyntaxModel.py | 46 +++++++------------------------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/pyVHDLModel/SyntaxModel.py b/pyVHDLModel/SyntaxModel.py index 7f3c873bf..873e9e29a 100644 --- a/pyVHDLModel/SyntaxModel.py +++ b/pyVHDLModel/SyntaxModel.py @@ -1993,11 +1993,6 @@ def __init__(self, identifiers: Iterable[str], subtype: SubtypeOrSymbol): @export class Reference(ModelEntity): - pass - - -@export -class LibraryClause(Reference): _names: List[Name] def __init__(self, names: Iterable[Name]): @@ -2006,48 +2001,23 @@ def __init__(self, names: Iterable[Name]): self._names = [n for n in names] @property - def Library(self) -> Union[None, LibraryOrSymbol]: - return self._library + def Names(self) -> List[Name]: + return self._names @export -class UseClause(Reference): - _names: List[Name] - - def __init__(self, names: Iterable[Name]): - super().__init__() - - self._names = [n for n in names] - - @property - def Library(self) -> Union[None, LibraryOrSymbol]: - return "" # self._library +class LibraryClause(Reference): + pass - @property - def Package(self) -> 'Package': - return "" # self._package - @property - def Item(self) -> str: - return "" # self._item +@export +class UseClause(Reference): + pass @export class ContextReference(Reference): - _names: List[Name] - - def __init__(self, names: Iterable[Name]): - super().__init__() - - self._names = [n for n in names] - - @property - def Library(self) -> Union[None, LibraryOrSymbol]: - return "" # self._library - - @property - def Context(self) -> 'Context': - return "" # self._context + pass @export From d5539b434510bbafed5eb29e2ae05c6b7acfaac3 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 17 Aug 2021 10:12:48 +0200 Subject: [PATCH 08/13] Reworked report and assert statements. --- pyVHDLModel/SyntaxModel.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/pyVHDLModel/SyntaxModel.py b/pyVHDLModel/SyntaxModel.py index 873e9e29a..ae6c908ec 100644 --- a/pyVHDLModel/SyntaxModel.py +++ b/pyVHDLModel/SyntaxModel.py @@ -2915,8 +2915,9 @@ class MixinReportStatement: _message: Expression _severity: Expression - def __init__(self): - pass + def __init__(self, message: Expression, severity: Expression = None): + self._message = message + self._severity = severity @property def Message(self) -> Expression: @@ -2934,8 +2935,10 @@ class MixinAssertStatement(MixinReportStatement): """ _condition: Expression - def __init__(self): - super().__init__() + def __init__(self, condition: Expression, message: Expression, severity: Expression = None): + super().__init__(message, severity) + + self._condition = condition @property def Condition(self) -> Expression: @@ -2944,23 +2947,23 @@ def Condition(self) -> Expression: @export class ConcurrentAssertStatement(ConcurrentStatement, MixinAssertStatement): - def __init__(self, label: str = None): + def __init__(self, condition: Expression, message: Expression, severity: Expression = None, label: str = None): super().__init__(label) - MixinAssertStatement.__init__(self) + MixinAssertStatement.__init__(self, condition, message, severity) @export class SequentialReportStatement(SequentialStatement, MixinReportStatement): - def __init__(self): - super().__init__() - MixinReportStatement.__init__(self) + def __init__(self, message: Expression, severity: Expression = None, label: str = None): + super().__init__(label) + MixinReportStatement.__init__(self, message, severity) @export class SequentialAssertStatement(SequentialStatement, MixinAssertStatement): - def __init__(self): - super().__init__() - MixinAssertStatement.__init__(self) + def __init__(self, condition: Expression, message: Expression, severity: Expression = None, label: str = None): + super().__init__(label) + MixinAssertStatement.__init__(self, condition, message, severity) @export From 4ff7da982627f321bcf999907ffd66722a52739b Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 17 Aug 2021 12:16:55 +0200 Subject: [PATCH 09/13] Reworked wait statement. --- pyVHDLModel/SyntaxModel.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pyVHDLModel/SyntaxModel.py b/pyVHDLModel/SyntaxModel.py index ae6c908ec..f323ba2e0 100644 --- a/pyVHDLModel/SyntaxModel.py +++ b/pyVHDLModel/SyntaxModel.py @@ -3182,9 +3182,16 @@ class WaitStatement(SequentialStatement, MixinConditional): _sensitivityList: List[Name] _timeout: Expression - def __init__(self): - super().__init__() - MixinConditional.__init__(self) + def __init__(self, sensitivityList: Iterable[Name] = None, condition: Expression = None, timeout: Expression = None, label: str = None): + super().__init__(label) + MixinConditional.__init__(self, condition) + + if sensitivityList is None: + self._sensitivityList = None + else: + self._sensitivityList = [i for i in sensitivityList] + + self._timeout = timeout @property def SensitivityList(self) -> List[Name]: From ddaf2b203fc1f9cc7520d85231c5fcc2647c0f58 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 17 Aug 2021 20:13:21 +0200 Subject: [PATCH 10/13] Reworked associations. --- pyVHDLModel/SyntaxModel.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/pyVHDLModel/SyntaxModel.py b/pyVHDLModel/SyntaxModel.py index f323ba2e0..ee9a09769 100644 --- a/pyVHDLModel/SyntaxModel.py +++ b/pyVHDLModel/SyntaxModel.py @@ -2179,20 +2179,29 @@ def __init__(self, identifier: str, contextItems: Iterable[Context] = None): @export class AssociationItem(ModelEntity): - _formal: str # FIXME: defined type + _formal: Name _actual: Expression - def __init__(self): + def __init__(self, actual: Expression, formal: Name = None): super().__init__() + self._formal = formal + self._actual = actual + @property - def Formal(self): # FIXME: defined return type + def Formal(self) -> Name: return self._formal @property def Actual(self) -> Expression: return self._actual + def __str__(self): + if self._formal is None: + return str(self._actual) + else: + return "{formal!s} => {actual!s}".format(formal=self._formal, actual=self._actual) + @export class GenericAssociationItem(AssociationItem): @@ -2366,15 +2375,22 @@ def Statements(self) -> List[SequentialStatement]: @export class Instantiation(ConcurrentStatement): - pass + _genericAssociations: List[AssociationItem] + _portAssociations: List[AssociationItem] + + def __init__(self, label: str, genericAssociations: Iterable[AssociationItem] = None, portAssociations: Iterable[AssociationItem] = None): + super().__init__(label) + + self._genericAssociations = [] if genericAssociations is None else [g for g in genericAssociations] + self._portAssociations = [] if portAssociations is None else [p for p in portAssociations] @export class ComponentInstantiation(Instantiation): _component: Name - def __init__(self, label: str, componentName: Name): - super().__init__(label) + def __init__(self, label: str, componentName: Name, genericAssociations: Iterable[AssociationItem] = None, portAssociations: Iterable[AssociationItem] = None): + super().__init__(label, genericAssociations, portAssociations) self._component = componentName @@ -2388,8 +2404,8 @@ class EntityInstantiation(Instantiation): _entity: Name _architecture: Name - def __init__(self, label: str, entityName: Name, architectureName: Name = None): - super().__init__(label) + def __init__(self, label: str, entityName: Name, architectureName: Name = None, genericAssociations: Iterable[AssociationItem] = None, portAssociations: Iterable[AssociationItem] = None): + super().__init__(label, genericAssociations, portAssociations) self._entity = entityName self._architecture = architectureName @@ -2407,8 +2423,8 @@ def Architecture(self) -> Name: class ConfigurationInstantiation(Instantiation): _configuration: Name - def __init__(self, label: str, configurationName: Name): - super().__init__(label) + def __init__(self, label: str, configurationName: Name, genericAssociations: Iterable[AssociationItem] = None, portAssociations: Iterable[AssociationItem] = None): + super().__init__(label, genericAssociations, portAssociations) self._configuration = configurationName @@ -2442,6 +2458,7 @@ class ProcedureCall: def __init__(self, procedureName: Name, parameterMappings: Iterable = None): self._procedure = procedureName self._parameterMappings = [] if procedureName is None else [m for m in parameterMappings] + pass @property def Procedure(self) -> Name: From ad85b3da7e812d8bef1bc0ff716b8902382d14a8 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 17 Aug 2021 20:19:25 +0200 Subject: [PATCH 11/13] Fixed typo. Added list element type for parameter mappings. --- pyVHDLModel/SyntaxModel.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pyVHDLModel/SyntaxModel.py b/pyVHDLModel/SyntaxModel.py index ee9a09769..6f687691e 100644 --- a/pyVHDLModel/SyntaxModel.py +++ b/pyVHDLModel/SyntaxModel.py @@ -2453,32 +2453,31 @@ def SensitivityList(self) -> List[Name]: @export class ProcedureCall: _procedure: Name - _parameterMappings: List + _parameterMappings: List[ParameterAssociationItem] - def __init__(self, procedureName: Name, parameterMappings: Iterable = None): + def __init__(self, procedureName: Name, parameterMappings: Iterable[ParameterAssociationItem] = None): self._procedure = procedureName - self._parameterMappings = [] if procedureName is None else [m for m in parameterMappings] - pass + self._parameterMappings = [] if parameterMappings is None else [m for m in parameterMappings] @property def Procedure(self) -> Name: return self._procedure @property - def ParameterMappings(self) -> List: + def ParameterMappings(self) -> List[ParameterAssociationItem]: return self._parameterMappings @export class ConcurrentProcedureCall(ConcurrentStatement, ProcedureCall): - def __init__(self, label: str, procedureName: Name, parameterMappings: Iterable = None): + def __init__(self, label: str, procedureName: Name, parameterMappings: Iterable[ParameterAssociationItem] = None): super().__init__(label) ProcedureCall.__init__(self, procedureName, parameterMappings) @export class SequentialProcedureCall(SequentialStatement, ProcedureCall): - def __init__(self, label: str, procedureName: Name, parameterMappings: Iterable = None): + def __init__(self, label: str, procedureName: Name, parameterMappings: Iterable[ParameterAssociationItem] = None): super().__init__(label) ProcedureCall.__init__(self, procedureName, parameterMappings) From a51d0dff0ac061dd5b17d0f9d2d94cab0f3f4978 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Wed, 18 Aug 2021 00:46:48 +0200 Subject: [PATCH 12/13] assertion messages are optional in assert statements. --- pyVHDLModel/SyntaxModel.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyVHDLModel/SyntaxModel.py b/pyVHDLModel/SyntaxModel.py index 6f687691e..bb5745e10 100644 --- a/pyVHDLModel/SyntaxModel.py +++ b/pyVHDLModel/SyntaxModel.py @@ -2931,7 +2931,7 @@ class MixinReportStatement: _message: Expression _severity: Expression - def __init__(self, message: Expression, severity: Expression = None): + def __init__(self, message: Expression = None, severity: Expression = None): self._message = message self._severity = severity @@ -2951,7 +2951,7 @@ class MixinAssertStatement(MixinReportStatement): """ _condition: Expression - def __init__(self, condition: Expression, message: Expression, severity: Expression = None): + def __init__(self, condition: Expression, message: Expression = None, severity: Expression = None): super().__init__(message, severity) self._condition = condition @@ -2977,7 +2977,7 @@ def __init__(self, message: Expression, severity: Expression = None, label: str @export class SequentialAssertStatement(SequentialStatement, MixinAssertStatement): - def __init__(self, condition: Expression, message: Expression, severity: Expression = None, label: str = None): + def __init__(self, condition: Expression, message: Expression = None, severity: Expression = None, label: str = None): super().__init__(label) MixinAssertStatement.__init__(self, condition, message, severity) From 99077328e663a76bb1571848c8edb4c6b3c6822a Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Wed, 18 Aug 2021 08:18:58 +0200 Subject: [PATCH 13/13] Added OpenName. --- pyVHDLModel/SyntaxModel.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/pyVHDLModel/SyntaxModel.py b/pyVHDLModel/SyntaxModel.py index bb5745e10..3568a3ec5 100644 --- a/pyVHDLModel/SyntaxModel.py +++ b/pyVHDLModel/SyntaxModel.py @@ -111,8 +111,12 @@ class Name: def __init__(self, identifier: str, prefix: 'Name' = None): self._identifier = identifier - self._prefix = prefix - self._root = prefix._root + if prefix is None: + self._prefix = self + self._root = None + else: + self._prefix = prefix + self._root = prefix._root @property def Identifier(self) -> str: @@ -133,25 +137,8 @@ def Has_Prefix(self) -> bool: @export class SimpleName(Name): - def __init__(self, identifier: str): - self._name = identifier - self._root = self - self._prefix = None - - @property - def Root(self) -> 'Name': - return self - - @property - def Prefix(self) -> Nullable['Name']: - return None - - @property - def Has_Prefix(self) -> bool: - return False - def __str__(self): - return self._name + return self._identifier @export @@ -211,6 +198,15 @@ def __str__(self): return str(self._prefix) + "." + "all" +@export +class OpenName(Name): + def __init__(self): + super().__init__("open") + + def __str__(self): + return "open" + + @export class Symbol(ModelEntity): _symbolName: Name