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
53 changes: 46 additions & 7 deletions src/hammer-vlsi/hammer_vlsi/hammer_tool.py
Original file line number Diff line number Diff line change
@@ -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']


@@ -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 = self.get_mode_setting("vlsi.inputs.bumps_mode") #type: ModeType
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
@@ -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 = self.get_mode_setting("par.inputs.gds_map_mode") #type: ModeType

# 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
@@ -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(
@@ -1128,3 +1131,39 @@ def verbose_tcl_append(cmd: str, output_buffer: List[str]) -> None:
"""
output_buffer.append("""puts "{0}" """.format(cmd.replace('"', '\"')))
output_buffer.append(cmd)

def get_mode_setting(self, setting: str) -> ModeType:
"""
Create a ModeType object based on the mode settings.
:param setting: Key of the setting to receive.
:return: ModeType, can be auto, empty, manual or generated.
"""
return ModeType.from_str(self.get_setting(setting))

class ModeType(Enum):
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.Generated,
}

@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]


9 changes: 4 additions & 5 deletions src/hammer-vlsi/hammer_vlsi/hammer_vlsi_impl.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@
from .constraints import *
from .units import VoltageValue


class HierarchicalMode(Enum):
Flat = 1
Leaf = 2
@@ -1323,15 +1322,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 = self.get_mode_setting("par.inputs.gds_map_mode")
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))