-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMemory.py
More file actions
58 lines (47 loc) · 1.74 KB
/
Memory.py
File metadata and controls
58 lines (47 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Memory:
TYPE_NONE = 0
TYPE_DRAM = 1
TYPE_LPM = 2
def __init__(self, capacity, wcet_scale, power_active, power_idle):
self.type = None
self.capacity = capacity
self.wcet_scale = wcet_scale
self.power_active = power_active
self.power_idle = power_idle
def get_type_str(self) -> str:
if self.type == Memory.TYPE_DRAM:
return "DRAM"
elif self.type == Memory.TYPE_NONE:
return "None"
else:
return "LPM"
class LPM(Memory):
def __init__(self, capacity, wcet_scale, power_active, power_idle):
super().__init__(capacity, wcet_scale, power_active, power_idle)
self.type = Memory.TYPE_LPM
class DRAM(Memory):
def __init__(self, capacity, wcet_scale, power_active, power_idle):
super().__init__(capacity, wcet_scale, power_active, power_idle)
self.type = Memory.TYPE_DRAM
class Memories:
def __init__(self):
self.list = []
self.n_mem_types = 0
self.total_capacity = 0
def get_memory_by_type(self, memory_type):
for memory in self.list:
if memory.type == memory_type:
return memory
return None
def get_memory(self, index):
return self.list[index]
def insert_memory(self, memory_str: str, capacity, wcet_scale, power_active, power_idle) -> bool:
if memory_str.lower() == "lpm":
self.list.append(LPM(capacity, wcet_scale, power_active, power_idle))
elif memory_str.lower() == "dram":
self.list.append(DRAM(capacity, wcet_scale, power_active, power_idle))
else:
return False
self.n_mem_types += 1
self.total_capacity += capacity
return True