Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mode enum #407

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
41 changes: 34 additions & 7 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 @@ -892,10 +895,10 @@ def get_independent_ground_nets(self) -> List[Supply]:
return list(filter(lambda x: x.tie is None, self.get_all_ground_nets()))

def get_bumps(self) -> Optional[BumpsDefinition]:
bumps_mode = self.get_setting("vlsi.inputs.bumps_mode")
if bumps_mode == "empty":
bumps_mode = ModeType.from_str(self.get_setting("vlsi.inputs.bumps_mode")) #Type: ModeType Enum
Jingyi99 marked this conversation as resolved.
Show resolved Hide resolved
if bumps_mode == ModeType.Empty:
return None
elif bumps_mode != "manual":
elif bumps_mode != ModeType.Manual:
self.logger.error("Invalid bumps_mode:{m}, only empty or manual supported. Assuming empty.".format(
m=bumps_mode))
return None
Expand Down Expand Up @@ -970,7 +973,7 @@ def get_gds_map_file(self) -> Optional[str]:
:return: Fully-resolved path to GDS map file or None.
"""
# Mode can be auto, empty, or manual
gds_map_mode = str(self.get_setting("par.inputs.gds_map_mode")) # type: str
gds_map_mode = ModeType.from_str(str(self.get_setting("par.inputs.gds_map_mode"))) # type: ModeType Enum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


# gds_map_file will only be used in manual mode
# Not including the map_file flag includes all layers but with no specific layer numbers
Expand All @@ -983,11 +986,11 @@ def get_gds_map_file(self) -> Optional[str]:
tech_map_file_raw) if tech_map_file_raw is not None else None # type: Optional[str]
tech_map_file = optional_map(tech_map_file_optional, lambda p: self.technology.prepend_dir_path(p))

if gds_map_mode == "auto":
if gds_map_mode == ModeType.Auto:
map_file = tech_map_file
elif gds_map_mode == "manual":
elif gds_map_mode == ModeType.Manual:
map_file = manual_map_file
elif gds_map_mode == "empty":
elif gds_map_mode == ModeType.Empty:
map_file = None
else:
self.logger.error(
Expand Down Expand Up @@ -1128,3 +1131,27 @@ 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):
Jingyi99 marked this conversation as resolved.
Show resolved Hide resolved
Auto = 1
Empty = 2
Manual = 3
Generated = 4

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

@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]
10 changes: 5 additions & 5 deletions src/hammer-vlsi/hammer_vlsi/hammer_vlsi_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from .constraints import *
from .units import VoltageValue

from .hammer_tool import ModeType

class HierarchicalMode(Enum):
Flat = 1
Expand Down Expand Up @@ -1323,15 +1323,15 @@ def generate_power_spec_commands(self) -> List[str]:
return []

power_spec_contents = "" # type: str
power_spec_mode = str(self.get_setting("vlsi.inputs.power_spec_mode")) # type: str
if power_spec_mode == "empty":
power_spec_mode = ModeType.from_str(str(self.get_setting("vlsi.inputs.power_spec_mode"))) # type: ModeType Enum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

if power_spec_mode == ModeType.Empty:
return []
elif power_spec_mode == "auto":
elif power_spec_mode == ModeType.Auto:
if power_spec_type == "cpf":
power_spec_contents = self.cpf_power_specification
elif power_spec_type == "upf":
power_spec_contents = self.upf_power_specification
elif power_spec_mode == "manual":
elif power_spec_mode == ModeType.Manual:
power_spec_contents = str(self.get_setting("vlsi.inputs.power_spec_contents"))
else:
self.logger.error("Invalid power specification mode '{mode}'; using 'empty'.".format(mode=power_spec_mode))
Expand Down