Skip to content

Commit fade0c9

Browse files
authored
v0.30.0
2 parents 9791e0b + 4a27c47 commit fade0c9

File tree

3 files changed

+228
-38
lines changed

3 files changed

+228
-38
lines changed

pyVHDLModel/IEEE.py

+162-31
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@
3030
# ==================================================================================================================== #
3131
#
3232
"""This module contains library and package declarations for VHDL library ``IEEE``."""
33-
from pyTooling.Decorators import export
3433

34+
from typing import Optional as Nullable
35+
36+
from pyTooling.Decorators import export, readonly
37+
38+
from pyVHDLModel import IEEEFlavor
39+
from pyVHDLModel.Exception import VHDLModelException
3540
from pyVHDLModel.Expression import EnumerationLiteral
3641
from pyVHDLModel.Name import SimpleName
3742
from pyVHDLModel.Predefined import PredefinedLibrary, PredefinedPackage, PredefinedPackageBody
@@ -55,7 +60,6 @@ class Ieee(PredefinedLibrary):
5560
5661
* :class:`~pyVHDLModel.IEEE.Std_Logic_1164`
5762
* :class:`~pyVHDLModel.IEEE.Std_Logic_TextIO`
58-
* :class:`~pyVHDLModel.IEEE.Std_Logic_Misc`
5963
6064
* Numeric
6165
@@ -72,18 +76,57 @@ class Ieee(PredefinedLibrary):
7276
* :class:`~pyVHDLModel.IEEE.Float_Generic_Pkg`
7377
* :class:`~pyVHDLModel.IEEE.Float_Pkg`
7478
79+
* Mentor Graphics packages
80+
81+
* :class:`~pyVHDLModel.IEEE.Std_logic_arith`
82+
83+
* Synopsys packages
84+
85+
* :class:`~pyVHDLModel.IEEE.Std_logic_arith`
86+
* :class:`~pyVHDLModel.IEEE.Std_logic_misc`
87+
* :class:`~pyVHDLModel.IEEE.Std_logic_signed`
88+
* :class:`~pyVHDLModel.IEEE.Std_logic_textio`
89+
* :class:`~pyVHDLModel.IEEE.Std_logic_unsigned`
90+
7591
.. seealso::
7692
7793
Other predefined libraries:
7894
* Library :class:`~pyVHDLModel.STD.Std`
7995
"""
8096

81-
def __init__(self) -> None:
97+
_flavor: IEEEFlavor
98+
99+
def __init__(self, flavor: Nullable[IEEEFlavor] = None) -> None:
82100
super().__init__(PACKAGES)
83101

102+
self._flavor = IEEEFlavor.IEEE
103+
if flavor is None or flavor is IEEEFlavor.IEEE:
104+
pass
105+
elif flavor is IEEEFlavor.MentorGraphics:
106+
self.LoadMentorGraphicsPackages()
107+
elif flavor is IEEEFlavor.Synopsys:
108+
self.LoadSynopsysPackages()
109+
else:
110+
raise VHDLModelException(f"Unknown IEEE library flavor '{flavor}'.")
111+
self._flavor = flavor
112+
113+
@readonly
114+
def Flavor(self) -> IEEEFlavor:
115+
return self._flavor
116+
117+
def LoadMentorGraphicsPackages(self) -> None:
118+
if self._flavor is not IEEEFlavor.IEEE:
119+
raise VHDLModelException(f"IEEE library flavor is '{self._flavor}' and can't be changed to '{IEEEFlavor.MentorGraphics}'.")
120+
121+
self._flavor = IEEEFlavor.MentorGraphics
122+
self.AddPackages(MENTOR_GRAPHICS_PACKAGES)
123+
84124
def LoadSynopsysPackages(self) -> None:
85-
self.AddPackages(PACKAGES_SYNOPSYS)
125+
if self._flavor is not IEEEFlavor.IEEE:
126+
raise VHDLModelException(f"IEEE library flavor is '{self._flavor}' and can't be changed to '{IEEEFlavor.MentorGraphics}'.")
86127

128+
self._flavor = IEEEFlavor.Synopsys
129+
self.AddPackages(SYNOPSYS_PACKAGES)
87130

88131

89132
@export
@@ -125,7 +168,7 @@ def __init__(self) -> None:
125168

126169

127170
@export
128-
class Std_logic_1164(PredefinedPackage):
171+
class Std_Logic_1164(PredefinedPackage):
129172
"""
130173
Predefined package ``ieee.std_logic_1164``.
131174
@@ -170,14 +213,14 @@ def __init__(self) -> None:
170213

171214

172215
@export
173-
class Std_logic_1164_Body(PredefinedPackageBody):
216+
class Std_Logic_1164_Body(PredefinedPackageBody):
174217
"""
175218
Predefined package body of package ``ieee.std_logic_1164``.
176219
"""
177220

178221

179222
@export
180-
class std_logic_textio(PredefinedPackage):
223+
class Std_Logic_TextIO(PredefinedPackage):
181224
"""
182225
Predefined package ``ieee.std_logic_textio``.
183226
"""
@@ -190,26 +233,6 @@ def __init__(self) -> None:
190233
self._AddPackageClause(("IEEE.std_logic_1164.all", ))
191234

192235

193-
@export
194-
class Std_logic_misc(PredefinedPackage):
195-
"""
196-
Predefined package ``ieee.std_logic_misc``.
197-
"""
198-
199-
def __init__(self) -> None:
200-
super().__init__()
201-
202-
self._AddLibraryClause(("IEEE", ))
203-
self._AddPackageClause(("IEEE.std_logic_1164.all", ))
204-
205-
206-
@export
207-
class Std_logic_misc_Body(PredefinedPackageBody):
208-
"""
209-
Predefined package body of package ``ieee.std_logic_misc``.
210-
"""
211-
212-
213236
@export
214237
class Numeric_Bit(PredefinedPackage):
215238
"""
@@ -404,8 +427,8 @@ def __init__(self) -> None:
404427
PACKAGES = (
405428
(Math_Real, Math_Real_Body),
406429
(Math_Complex, Math_Complex_Body),
407-
(Std_logic_1164, Std_logic_1164_Body),
408-
(std_logic_textio, None),
430+
(Std_Logic_1164, Std_Logic_1164_Body),
431+
(Std_Logic_TextIO, None),
409432
(Numeric_Bit, Numeric_Bit_Body),
410433
(Numeric_Bit_Unsigned, Numeric_Bit_Unsigned_Body),
411434
(Numeric_Std, Numeric_Std_Body),
@@ -417,6 +440,114 @@ def __init__(self) -> None:
417440
(Float_Pkg, None),
418441
)
419442

420-
PACKAGES_SYNOPSYS = (
421-
(Std_logic_misc, Std_logic_misc_Body),
443+
444+
@export
445+
class Std_Logic_Arith(PredefinedPackage):
446+
"""
447+
Predefined Mentor Graphics package ``ieee.std_logic_arith``.
448+
"""
449+
450+
def __init__(self) -> None:
451+
super().__init__()
452+
453+
self._AddLibraryClause(("IEEE", ))
454+
455+
# used inside of package
456+
# self._AddPackageClause(("IEEE.std_logic_1164.all", ))
457+
458+
459+
@export
460+
class Std_Logic_Arith_Body(PredefinedPackageBody):
461+
"""
462+
Predefined package body of Mentor Graphics package ``ieee.std_logic_arith``.
463+
"""
464+
465+
466+
MENTOR_GRAPHICS_PACKAGES = (
467+
(Std_Logic_Arith, Std_Logic_Arith_Body),
468+
)
469+
470+
471+
@export
472+
class Std_Logic_Arith(PredefinedPackage):
473+
"""
474+
Predefined Synopsys package ``ieee.std_logic_arith``.
475+
"""
476+
477+
def __init__(self) -> None:
478+
super().__init__()
479+
480+
self._AddLibraryClause(("IEEE", ))
481+
self._AddPackageClause(("IEEE.std_logic_1164.all", ))
482+
483+
484+
@export
485+
class Std_Logic_Misc(PredefinedPackage):
486+
"""
487+
Predefined Synopsys package ``ieee.std_logic_misc``.
488+
"""
489+
490+
def __init__(self) -> None:
491+
super().__init__()
492+
493+
self._AddLibraryClause(("IEEE", ))
494+
self._AddPackageClause(("IEEE.std_logic_1164.all", ))
495+
496+
497+
@export
498+
class Std_Logic_Misc_Body(PredefinedPackageBody):
499+
"""
500+
Predefined package body of Synopsys package ``ieee.std_logic_misc``.
501+
"""
502+
503+
504+
@export
505+
class Std_Logic_Signed(PredefinedPackage):
506+
"""
507+
Predefined Synopsys package ``ieee.std_logic_signed``.
508+
"""
509+
510+
def __init__(self) -> None:
511+
super().__init__()
512+
513+
self._AddLibraryClause(("IEEE", ))
514+
self._AddPackageClause(("IEEE.std_logic_1164.all", ))
515+
self._AddPackageClause(("IEEE.std_logic_arith.all", ))
516+
517+
518+
@export
519+
class Std_Logic_TextIO(PredefinedPackage):
520+
"""
521+
Predefined Synopsys package ``ieee.std_logic_textio``.
522+
"""
523+
524+
def __init__(self) -> None:
525+
super().__init__()
526+
527+
self._AddPackageClause(("STD.textio.all", ))
528+
529+
self._AddLibraryClause(("IEEE", ))
530+
self._AddPackageClause(("IEEE.std_logic_1164.all", ))
531+
532+
533+
@export
534+
class Std_Logic_Unsigned(PredefinedPackage):
535+
"""
536+
Predefined Synopsys package ``ieee.std_logic_unsigned``.
537+
"""
538+
539+
def __init__(self) -> None:
540+
super().__init__()
541+
542+
self._AddLibraryClause(("IEEE", ))
543+
self._AddPackageClause(("IEEE.std_logic_1164.all", ))
544+
self._AddPackageClause(("IEEE.std_logic_arith.all", ))
545+
546+
547+
SYNOPSYS_PACKAGES = (
548+
(Std_Logic_Arith, None),
549+
(Std_Logic_Misc, Std_Logic_Misc_Body),
550+
(Std_Logic_Signed, None),
551+
(Std_Logic_TextIO, None),
552+
(Std_Logic_Unsigned, None),
422553
)

pyVHDLModel/__init__.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
__email__ = "[email protected]"
4949
__copyright__ = "2016-2025, Patrick Lehmann"
5050
__license__ = "Apache License, Version 2.0"
51-
__version__ = "0.29.4"
51+
__version__ = "0.30.0"
5252

5353

5454
from enum import unique, Enum, Flag, auto
@@ -294,6 +294,13 @@ def __repr__(self) -> str:
294294
return str(self.value)
295295

296296

297+
@export
298+
class IEEEFlavor(Enum):
299+
IEEE = 0
300+
Synopsys = 1
301+
MentorGraphics = 2
302+
303+
297304
@export
298305
@unique
299306
class ObjectClass(Enum):
@@ -574,19 +581,20 @@ def LoadStdLibrary(self) -> 'Library':
574581

575582
return library
576583

577-
def LoadIEEELibrary(self) -> 'Library':
584+
def LoadIEEELibrary(self, flavor: IEEEFlavor = IEEEFlavor.IEEE) -> 'Library':
578585
"""
579586
Load the predefined VHDL library ``ieee`` into the design.
580587
581588
This will create a virtual source code file ``ieee.vhdl`` and register VHDL design units of library ``ieee`` to that file.
582589
583-
:returns: The library object of library ``ieee``.
590+
:param flavor: Select the IEEE library flavor: IEEE, Synopsys, MentorGraphics.
591+
:returns: The library object of library ``ieee``.
584592
"""
585593
from pyVHDLModel.IEEE import Ieee
586594

587595
doc = Document(Path("ieee.vhdl"), parent=self)
588596

589-
library = Ieee()
597+
library = Ieee(flavor)
590598
for designUnit in library.IterateDesignUnits():
591599
doc._AddDesignUnit(designUnit)
592600

@@ -1528,6 +1536,12 @@ def LinkComponents(self) -> None:
15281536
# QUESTION: Add link in dependency graph as dashed line from component to entity?
15291537
# Currently, component has no _dependencyVertex field
15301538

1539+
# FIXME: also link components in architectures (and nested structures like generate statements and block statements
1540+
# for architecture in self.IterateDesignUnits(DesignUnitKind.Architecture):
1541+
# library = architecture._parent
1542+
# for component in architecture._components.values():
1543+
# pass
1544+
15311545
def LinkInstantiations(self) -> None:
15321546
for architecture in self.IterateDesignUnits(DesignUnitKind.Architecture): # type: Architecture
15331547
for instance in architecture.IterateInstantiations():

0 commit comments

Comments
 (0)