Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 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
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We may want to create a static helper method called ModeType.from_setting that takes the HammerTool object and the setting string as args and returns a ModeType. e.g.

class ModeType:
  @staticmethod
  def from_setting(tool: HammerTool, setting: str) -> ModeType:
    return ModeType.from_str(str(tool.get_setting(setting)))

which would then allow the following change (no need for type hint, either):

Suggested change
gds_map_mode = ModeType.from_str(str(self.get_setting("par.inputs.gds_map_mode"))) # type: ModeType
gds_map_mode = ModeType.from_setting(self, "par.inputs.gds_map_mode")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not to nitpick too much - at that point I would prefer almost gds_map_mode = self.get_mode_setting("par.inputs.gds_map_mode") to avoid a dependency from ModeType -> HammerTool

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I also like that, perhaps more.


# 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,28 @@ 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):
Comment thread
Jingyi99 marked this conversation as 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.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]
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
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