Skip to content

Commit

Permalink
v0.26.0
Browse files Browse the repository at this point in the history
v0.26.0
  • Loading branch information
Paebbels authored May 16, 2023
2 parents 3776f27 + e7bfb89 commit bf61f56
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 180 deletions.
85 changes: 30 additions & 55 deletions pyVHDLModel/Concurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@

from pyTooling.Decorators import export

from pyVHDLModel.Base import ModelEntity, LabeledEntityMixin, DocumentedEntityMixin, ExpressionUnion, Range, BaseChoice, BaseCase, IfBranchMixin, \
ElsifBranchMixin, ElseBranchMixin, AssertStatementMixin, BlockStatementMixin, WaveformElement
from pyVHDLModel.Namespace import Namespace
from pyVHDLModel.Base import ModelEntity, LabeledEntityMixin, DocumentedEntityMixin, ExpressionUnion, Range, BaseChoice, BaseCase, IfBranchMixin
from pyVHDLModel.Base import ElsifBranchMixin, ElseBranchMixin, AssertStatementMixin, BlockStatementMixin, WaveformElement
from pyVHDLModel.Regions import ConcurrentDeclarationRegionMixin
from pyVHDLModel.Namespace import Namespace
from pyVHDLModel.Symbol import ComponentInstantiationSymbol, EntityInstantiationSymbol, ArchitectureSymbol, ConfigurationInstantiationSymbol
from pyVHDLModel.Association import AssociationItem, ParameterAssociationItem
from pyVHDLModel.Interface import PortInterfaceItem
Expand Down Expand Up @@ -90,26 +91,16 @@ def IterateInstantiations(self) -> Generator['Instantiation', None, None]:
yield from generate.IterateInstantiations()

# TODO: move into _init__
def Index(self):
def IndexStatements(self):
for statement in self._statements:
if isinstance(statement, EntityInstantiation):
if isinstance(statement, (EntityInstantiation, ComponentInstantiation, ConfigurationInstantiation)):
self._instantiations[statement.NormalizedLabel] = statement
elif isinstance(statement, ComponentInstantiation):
self._instantiations[statement.NormalizedLabel] = statement
elif isinstance(statement, ConfigurationInstantiation):
self._instantiations[statement.NormalizedLabel] = statement
elif isinstance(statement, ForGenerateStatement):
self._generates[statement.NormalizedLabel] = statement
statement.Index()
elif isinstance(statement, IfGenerateStatement):
self._generates[statement.NormalizedLabel] = statement
statement.Index()
elif isinstance(statement, CaseGenerateStatement):
elif isinstance(statement, (ForGenerateStatement, IfGenerateStatement, CaseGenerateStatement)):
self._generates[statement.NormalizedLabel] = statement
statement.Index()
statement.IndexStatement()
elif isinstance(statement, ConcurrentBlockStatement):
self._hierarchy[statement.NormalizedLabel] = statement
statement.Index()
statement.IndexStatements()


@export
Expand Down Expand Up @@ -234,26 +225,8 @@ def __init__(self, label: str, procedureName: 'Name', parameterMappings: Iterabl
ProcedureCall.__init__(self, procedureName, parameterMappings)


# FIXME: Why not used in package, package body
@export
class ConcurrentDeclarations:
_declaredItems: List # FIXME: define list prefix type e.g. via Union

def __init__(self, declaredItems: Iterable = None):
# TODO: extract to mixin
self._declaredItems = [] # TODO: convert to dict
if declaredItems is not None:
for item in declaredItems:
self._declaredItems.append(item)
item._parent = self

@property
def DeclaredItems(self) -> List:
return self._declaredItems


@export
class ConcurrentBlockStatement(ConcurrentStatement, BlockStatementMixin, LabeledEntityMixin, ConcurrentDeclarations, ConcurrentStatements, DocumentedEntityMixin):
class ConcurrentBlockStatement(ConcurrentStatement, BlockStatementMixin, LabeledEntityMixin, ConcurrentDeclarationRegionMixin, ConcurrentStatements, DocumentedEntityMixin):
_portItems: List[PortInterfaceItem]

def __init__(
Expand All @@ -267,7 +240,7 @@ def __init__(
super().__init__(label)
BlockStatementMixin.__init__(self)
LabeledEntityMixin.__init__(self, label)
ConcurrentDeclarations.__init__(self, declaredItems)
ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
ConcurrentStatements.__init__(self, statements)
DocumentedEntityMixin.__init__(self, documentation)

Expand All @@ -284,7 +257,7 @@ def PortItems(self) -> List[PortInterfaceItem]:


@export
class GenerateBranch(ModelEntity, ConcurrentDeclarations, ConcurrentStatements):
class GenerateBranch(ModelEntity, ConcurrentDeclarationRegionMixin, ConcurrentStatements):
"""A ``GenerateBranch`` is a base-class for all branches in a generate statements."""

_alternativeLabel: Nullable[str]
Expand All @@ -294,7 +267,7 @@ class GenerateBranch(ModelEntity, ConcurrentDeclarations, ConcurrentStatements):

def __init__(self, declaredItems: Iterable = None, statements: Iterable[ConcurrentStatement] = None, alternativeLabel: str = None):
super().__init__()
ConcurrentDeclarations.__init__(self, declaredItems)
ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
ConcurrentStatements.__init__(self, statements)

self._alternativeLabel = alternativeLabel
Expand Down Expand Up @@ -348,7 +321,7 @@ def IterateInstantiations(self) -> Generator[Instantiation, None, None]:
raise NotImplementedError()

# @mustoverride
def Index(self) -> None:
def IndexStatement(self) -> None:
raise NotImplementedError()


Expand Down Expand Up @@ -395,12 +368,12 @@ def IterateInstantiations(self) -> Generator[Instantiation, None, None]:
if self._elseBranch is not None:
yield from self._ifBranch.IterateInstantiations()

def Index(self) -> None:
self._ifBranch.Index()
def IndexStatement(self) -> None:
self._ifBranch.IndexStatements()
for branch in self._elsifBranches:
branch.Index()
branch.IndexStatements()
if self._elseBranch is not None:
self._elseBranch.Index()
self._elseBranch.IndexStatements()


@export
Expand All @@ -409,11 +382,11 @@ class ConcurrentChoice(BaseChoice):


@export
class ConcurrentCase(BaseCase, LabeledEntityMixin, ConcurrentDeclarations, ConcurrentStatements):
class ConcurrentCase(BaseCase, LabeledEntityMixin, ConcurrentDeclarationRegionMixin, ConcurrentStatements):
def __init__(self, declaredItems: Iterable = None, statements: Iterable[ConcurrentStatement] = None, alternativeLabel: str = None):
super().__init__()
LabeledEntityMixin.__init__(self, alternativeLabel)
ConcurrentDeclarations.__init__(self, declaredItems)
ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
ConcurrentStatements.__init__(self, statements)


Expand Down Expand Up @@ -476,19 +449,19 @@ def IterateInstantiations(self) -> Generator[Instantiation, None, None]:
for case in self._cases:
yield from case.IterateInstantiations()

def Index(self):
def IndexStatement(self):
for case in self._cases:
case.Index()
case.IndexStatements()


@export
class ForGenerateStatement(GenerateStatement, ConcurrentDeclarations, ConcurrentStatements):
class ForGenerateStatement(GenerateStatement, ConcurrentDeclarationRegionMixin, ConcurrentStatements):
_loopIndex: str
_range: Range

def __init__(self, label: str, loopIndex: str, rng: Range, declaredItems: Iterable = None, statements: Iterable[ConcurrentStatement] = None):
super().__init__(label)
ConcurrentDeclarations.__init__(self, declaredItems)
ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
ConcurrentStatements.__init__(self, statements)

self._loopIndex = loopIndex
Expand All @@ -506,13 +479,15 @@ def Range(self) -> Range:

IterateInstantiations = ConcurrentStatements.IterateInstantiations

Index = ConcurrentStatements.Index
# IndexDeclaredItems = ConcurrentStatements.IndexDeclaredItems

def IndexStatement(self) -> None:
self.IndexStatements()

IndexStatements = ConcurrentStatements.IndexStatements

# def IterateInstantiations(self) -> Generator[Instantiation, None, None]:
# return ConcurrentStatements.IterateInstantiations(self)
#
# def Index(self) -> None:
# return ConcurrentStatements.Index(self)


@export
Expand Down
Loading

0 comments on commit bf61f56

Please sign in to comment.