-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged VerilogVersion and SystemVerilogVersion.
- Loading branch information
Showing
2 changed files
with
173 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ | |
:copyright: Copyright 2021-2023 Patrick Lehmann - Bötzingen, Germany | ||
:license: Apache License, Version 2.0 | ||
""" | ||
from enum import unique, Enum | ||
from enum import unique, Enum | ||
from typing import Dict, Union | ||
|
||
from pyTooling.Decorators import export | ||
|
@@ -44,97 +44,50 @@ | |
__email__ = "[email protected]" | ||
__copyright__ = "2021-2023, Patrick Lehmann" | ||
__license__ = "Apache License, Version 2.0" | ||
__version__ = "0.3.6" | ||
|
||
|
||
@export | ||
@unique | ||
class VerilogVersion(Enum): | ||
Any = -1 | ||
Verilog95 = 95 | ||
Verilog2001 = 2001 | ||
Verilog2005 = 2005 | ||
|
||
__VERSION_MAPPINGS__: Dict[Union[int, str], Enum] = { | ||
95: Verilog95, | ||
1: Verilog2001, | ||
5: Verilog2005, | ||
1995: Verilog95, | ||
2001: Verilog2001, | ||
2005: Verilog2005, | ||
"Any": Any, | ||
"95": Verilog95, | ||
"01": Verilog2001, | ||
"05": Verilog2005, | ||
"1995": Verilog95, | ||
"2001": Verilog2001, | ||
"2005": Verilog2005, | ||
} | ||
|
||
def __init__(self, *_): | ||
"""Patch the embedded MAP dictionary""" | ||
for k, v in self.__class__.__VERSION_MAPPINGS__.items(): | ||
if (not isinstance(v, self.__class__)) and (v == self.value): | ||
self.__class__.__VERSION_MAPPINGS__[k] = self | ||
|
||
@classmethod | ||
def Parse(cls, value): | ||
try: | ||
return cls.__VERSION_MAPPINGS__[value] | ||
except KeyError: | ||
ValueError("Value '{0!s}' cannot be parsed to member of {1}.".format(value, cls.__name__)) | ||
|
||
def __lt__(self, other): | ||
return self.value < other.value | ||
|
||
def __le__(self, other): | ||
return self.value <= other.value | ||
|
||
def __gt__(self, other): | ||
return self.value > other.value | ||
|
||
def __ge__(self, other): | ||
return self.value >= other.value | ||
|
||
def __ne__(self, other): | ||
return self.value != other.value | ||
|
||
def __eq__(self, other): | ||
if (self is self.__class__.Any) or (other is self.__class__.Any): | ||
return True | ||
else: | ||
return self.value == other.value | ||
|
||
def __str__(self): | ||
return "Verilog'" + str(self.value)[-2:] | ||
|
||
def __repr__(self): | ||
return str(self.value) | ||
__version__ = "0.4.0" | ||
|
||
|
||
@export | ||
@unique | ||
class SystemVerilogVersion(Enum): | ||
Any = -1 | ||
|
||
Verilog95 = 95 | ||
Verilog2001 = 1 | ||
Verilog2005 = 5 | ||
|
||
SystemVerilog2005 = 2005 | ||
SystemVerilog2009 = 2009 | ||
SystemVerilog2012 = 2012 | ||
SystemVerilog2017 = 2017 | ||
|
||
__VERSION_MAPPINGS__: Dict[Union[int, str], Enum] = { | ||
5: SystemVerilog2005, | ||
-1: Any, | ||
95: Verilog95, | ||
1: Verilog2001, | ||
5: Verilog2005, | ||
# 5: SystemVerilog2005, # prefer Verilog on numbers below 2000 | ||
9: SystemVerilog2009, | ||
12: SystemVerilog2012, | ||
17: SystemVerilog2017, | ||
1995: Verilog95, | ||
2001: Verilog2001, | ||
# 2005: Verilog2005, # prefer SystemVerilog on numbers above 2000 | ||
2005: SystemVerilog2005, | ||
2009: SystemVerilog2009, | ||
2012: SystemVerilog2012, | ||
2017: SystemVerilog2017, | ||
"Any": Any, | ||
"05": SystemVerilog2005, | ||
"95": Verilog95, | ||
"01": Verilog2001, | ||
"05": Verilog2005, | ||
# "05": SystemVerilog2005, # prefer Verilog on numbers below 2000 | ||
"09": SystemVerilog2009, | ||
"12": SystemVerilog2012, | ||
"17": SystemVerilog2017, | ||
"1995": Verilog95, | ||
"2001": Verilog2001, | ||
# "2005": Verilog2005, # prefer SystemVerilog on numbers above 2000 | ||
"2005": SystemVerilog2005, | ||
"2009": SystemVerilog2009, | ||
"2012": SystemVerilog2012, | ||
|
@@ -148,35 +101,43 @@ def __init__(self, *_): | |
self.__class__.__VERSION_MAPPINGS__[k] = self | ||
|
||
@classmethod | ||
def Parse(cls, value): | ||
def Parse(cls, value: Union[int, str]) -> "SystemVerilogVersion": | ||
try: | ||
return cls.__VERSION_MAPPINGS__[value] | ||
except KeyError: | ||
ValueError("Value '{0!s}' cannot be parsed to member of {1}.".format(value, cls.__name__)) | ||
raise ValueError("Value '{0!s}' cannot be parsed to member of {1}.".format(value, cls.__name__)) | ||
|
||
def __lt__(self, other): | ||
def __lt__(self, other) -> bool: | ||
return self.value < other.value | ||
|
||
def __le__(self, other): | ||
def __le__(self, other) -> bool: | ||
return self.value <= other.value | ||
|
||
def __gt__(self, other): | ||
def __gt__(self, other) -> bool: | ||
return self.value > other.value | ||
|
||
def __ge__(self, other): | ||
def __ge__(self, other) -> bool: | ||
return self.value >= other.value | ||
|
||
def __ne__(self, other): | ||
def __ne__(self, other) -> bool: | ||
return self.value != other.value | ||
|
||
def __eq__(self, other): | ||
def __eq__(self, other) -> bool: | ||
if (self is self.__class__.Any) or (other is self.__class__.Any): | ||
return True | ||
else: | ||
return self.value == other.value | ||
|
||
def __str__(self): | ||
return "SV'" + str(self.value)[-2:] | ||
def __str__(self) -> str: | ||
if self.value == -1: | ||
return "SV'Any" | ||
elif self.value < self.SystemVerilog2005.value: | ||
return "Verilog'" + str(self.value)[-2:] | ||
else: | ||
return "SV'" + str(self.value)[-2:] | ||
|
||
def __repr__(self): | ||
return str(self.value) | ||
def __repr__(self) -> str: | ||
if self.value == -1: | ||
return "Any" | ||
else: | ||
return str(self.value) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters