Skip to content

Commit

Permalink
add Mode Enum class #400
Browse files Browse the repository at this point in the history
  • Loading branch information
Jingyi99 committed May 22, 2019
1 parent cdad2aa commit 46b4868
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/hammer-vlsi/hammer_vlsi/hammer_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
from .submit_command import HammerSubmitCommand
from .units import TemperatureValue, TimeValue, VoltageValue

from enum import Enum
from hammer_utils import reverse_dict

__all__ = ['HammerTool']


Expand Down Expand Up @@ -1128,3 +1131,34 @@ def verbose_tcl_append(cmd: str, output_buffer: List[str]) -> None:
"""
output_buffer.append("""puts "{0}" """.format(cmd.replace('"', '\"')))
output_buffer.append(cmd)
class ModeType(Enum):
Auto = 1
Empty = 2
Manual = 3
Generate = 4
Generated = 5
Append = 6
Prepend = 7

@classmethod
def __mapping(cls) -> Dict[str, "ModeType"]:
return {
"auto": ModeType.Auto,
"empty": ModeType.Empty,
"manual": ModeType.Manual,
"generate": ModeType.Generated,
"generated": ModeType.Generate,
"append": ModeType.Append,
"prepend": ModeType.Prepend
}

@staticmethod
def from_str(input_str: str) -> "ModeType":
try:
return ModeType.__mapping()[input_str]
except KeyError:
raise ValueError("Invalid mode type: " + str(input_str))

def __str__(self) -> str:
return reverse_dict(ModeType.__mapping())[self]

0 comments on commit 46b4868

Please sign in to comment.