Skip to content

Commit

Permalink
Moved enumeration VHDLVersion from ProjectModel (former part of pyIPC…
Browse files Browse the repository at this point in the history
…MI) to pyVHDLModel.
  • Loading branch information
Paebbels committed Sep 19, 2021
1 parent d3d22ac commit 2be50d8
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 6 deletions.
Empty file added doc/_extensions/.gitempty
Empty file.
2 changes: 1 addition & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r ../requirements.txt
# Enforce latest version on ReadTheDocs
sphinx>=4.1.2
sphinx>=4.2.0

# Sphinx Extenstions
#sphinx.ext.coverage
Expand Down
86 changes: 85 additions & 1 deletion pyVHDLModel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
:license: Apache License, Version 2.0
"""
from enum import IntEnum, unique, Enum
from typing import List, Iterable, Union, Optional as Nullable
from typing import List, Iterable, Union, Optional as Nullable, Dict

from pydecor import export

Expand Down Expand Up @@ -86,6 +86,90 @@
'ContextReference'
]


@export
@unique
class VHDLVersion(Enum):
"""
An enumeration for all possible version numbers for VHDL.
A version can be given as integer or string and is represented as a unified
enumeration value.
This enumeration supports compare operators.
"""

VHDL87 = 87
VHDL93 = 93
VHDL2002 = 2002
VHDL2008 = 2008
VHDL2019 = 2019

__VERSION_MAPPINGS__: Dict[Union[int, str], Enum] = {
87: VHDL87,
93: VHDL93,
2: VHDL2002,
8: VHDL2008,
19: VHDL2019,
1987: VHDL87,
1993: VHDL93,
2002: VHDL2002,
2008: VHDL2008,
2019: VHDL2019,
"87": VHDL87,
"93": VHDL93,
"02": VHDL2002,
"08": VHDL2008,
"19": VHDL2019,
"1987": VHDL87,
"1993": VHDL93,
"2002": VHDL2002,
"2008": VHDL2008,
"2019": VHDL2019
}

def __init__(self, *_) -> None:
"""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: Union[int, str]) -> 'Enum':
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: Enum) -> bool:
return self.value < other.value

def __le__(self, other: Enum) -> bool:
return self.value <= other.value

def __gt__(self, other: Enum) -> bool:
return self.value > other.value

def __ge__(self, other: Enum) -> bool:
return self.value >= other.value

def __ne__(self, other: Enum) -> bool:
return self.value != other.value

def __eq__(self, other: Enum) -> bool:
if ((self is self.__class__.Any) or (other is self.__class__.Any)):
return True
else:
return (self.value == other.value)


def __str__(self) -> str:
return "VHDL'" + str(self.value)[-2:]

def __repr__(self) -> str:
return str(self.value)


@export
@unique
class Direction(Enum):
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/Instantiate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
#
# Python unittest: Instantiation tests for the language model.
#
# Description:
# ------------------------------------
# TODO:
#
# License:
# ==============================================================================
# Copyright 2017-2021 Patrick Lehmann - Boetzingen, Germany
Expand Down

0 comments on commit 2be50d8

Please sign in to comment.