Skip to content

Commit

Permalink
This works now
Browse files Browse the repository at this point in the history
  • Loading branch information
jwright6323 committed Mar 17, 2019
1 parent 6c68bad commit 2b6f747
Showing 1 changed file with 40 additions and 16 deletions.
56 changes: 40 additions & 16 deletions src/hammer-vlsi/hammer_vlsi/hammer_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,32 @@
from typing import NamedTuple, Optional, List, Any, Dict, Callable, Union, TextIO
from functools import reduce
import yaml
import copy

# Note: Do not include the top module in the module spec
# e.g. [] = root
# ['inst1'] = inst at first level of hierarchy
class ModuleSpec(NamedTuple('ModuleSpec', [
('path', List[str])
])):
__slots__ = ()

@staticmethod
def from_str(s: str) -> ModuleSpec:
return ModuleSpec(s.split("/"))
def from_str(s: str) -> 'ModuleSpec':
return ModuleSpec(list(filter(lambda x: x != '', s.split("/"))))

@property
def is_top(self) -> bool:
return len(self.path) == 0

class PortSpec(NamedTuple('PortSpec', [
('path', List[str])
])):
__slots__ = ()

@staticmethod
def from_str(s: str) -> PortSpec:
return PortSpec(s.split("/"))
def from_str(s: str) -> 'PortSpec':
return PortSpec(list(filter(lambda x: x != '', s.split("/"))))

# TODO document me
IRType = Dict[str, Union[str, List[str]]]
Expand All @@ -44,7 +52,7 @@ class TimingPathSpec(NamedTuple('TimingPathSpec', [
__slots__ = ()

@staticmethod
def from_ir(ir: IRType) -> TimingPathSpec:
def from_ir(ir: IRType) -> 'TimingPathSpec':
start = ir["start"] if "start" in ir else ""
end = ir["end"] if "end" in ir else ""
through = ir["through"] if "through" in ir else ""
Expand All @@ -66,7 +74,7 @@ class CriticalPathEntry(NamedTuple('CriticalPathEntry', [
__slots__ = ()

@staticmethod
def from_ir(ir: IRType) -> CriticalPathEntry:
def from_ir(ir: IRType) -> 'CriticalPathEntry':
try:
module = ir["module"]
clock = ir["clock"] if "clock" in ir else ""
Expand All @@ -89,7 +97,7 @@ class TimingPathEntry(NamedTuple('TimingPathEntry', [
__slots__ = ()

@staticmethod
def from_ir(ir: IRType) -> TimingPathEntry:
def from_ir(ir: IRType) -> 'TimingPathEntry':
try:
clock = ir["clock"] if "clock" in ir else ""
assert isinstance(clock, str)
Expand All @@ -108,7 +116,7 @@ class ModuleAreaEntry(NamedTuple('ModuleAreaEntry', [
__slots__ = ()

@staticmethod
def from_ir(ir: IRType) -> ModuleAreaEntry:
def from_ir(ir: IRType) -> 'ModuleAreaEntry':
try:
mod = ir["module"]
assert isinstance(mod, str)
Expand Down Expand Up @@ -157,18 +165,23 @@ def _support_map(self) -> SupportMap:
return {}

def _is_supported(self, entry: MetricsDBEntry) -> bool:
return (entry.__class__ in self._support_map)
return (entry.__class__.__name__ in self._support_map)

def create_metrics_db_from_ir(self, ir: Union[str, TextIO]) -> MetricsDB:
# convert to a dict
y = yaml.load(ir)
y = yaml.load(ir) # type: Optional[Dict[Str, Any]]
if y is None:
y = {}
assert(isinstance(y, dict))
# create a db
db = MetricsDB()
if self.namespace in y:
testcases = y[self.namespace]
for testcase in testcases:
key = "{}.{}".format(self.namespace, testcase)
testcase_data = testcases[testcase]
if "type" not in testcase_data:
raise ValueError("Missing \"type\" field in testcase {}".format(testcase))
mtype = testcase_data["type"] # type: str
if mtype in FromIRMap:
entry = FromIRMap[mtype](testcase_data) # type: MetricsDBEntry
Expand Down Expand Up @@ -198,23 +211,34 @@ class HasAreaMetricSupport(HasMetricSupport):

@property
def _support_map(self) -> SupportMap:
x = reduce(add_dicts, [super()._support_map, {
#x = reduce(add_dicts, [super()._support_map, {
# 'ModuleAreaEntry': self.get_module_area
#}]) # type: SupportMap
x = copy.deepcopy(super()._support_map) # type: SupportMap
x.update({
'ModuleAreaEntry': self.get_module_area
}]) # type: SupportMap
})
return x

@abstractmethod
#@abstractmethod
def get_module_area(self, key: str, entry: ModuleAreaEntry) -> List[str]:
pass
print("FUCK THIS IS BAD")
return []
#pass

class HasTimingPathMetricSupport(HasMetricSupport):

@property
def _support_map(self) -> SupportMap:
x = reduce(add_dicts, [super()._support_map, {
#x = reduce(add_dicts, [super()._support_map, {
# 'CriticalPathEntry': self.get_critical_path,
# 'TimingPathEntry': self.get_timing_path
#}]) # type: SupportMap
x = copy.deepcopy(super()._support_map) # type: SupportMap
x.update({
'CriticalPathEntry': self.get_critical_path,
'TimingPathEntry': self.get_timing_path
}]) # type: SupportMap
})
return x

@abstractmethod
Expand Down

0 comments on commit 2b6f747

Please sign in to comment.