-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemory.py
More file actions
22 lines (19 loc) · 805 Bytes
/
Memory.py
File metadata and controls
22 lines (19 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import itertools
import CodeGenerator
__author__ = 'sambodanis'
class Memory:
def __init__(self, ir):
self._mem = []
self._pc = 0
self._var_map = {}
# Filter the list of all strings in the IR to only contain temps
# Sort those temps by their number and pick the largest.
top_register = int(
sorted([x for line in self._lines for x in line
if x[0] == '_'], key=lambda t: int(t[2:]))[-1][2:])
# Counter that increments by 1 with every call
count = lambda c=itertools.count(top_register + 1): next(c)
#
self._var_map = {line[0]: ['R' + str(count())]
for line in self._lines if line[0][0] not in ['_', '~', '[']
and line[0] not in self._reserved_words}