382
|
1
|
|
2 class Layout:
|
|
3 def __init__(self):
|
|
4 self.mems = []
|
|
5
|
|
6 def __eq__(self, other):
|
|
7 return self.mems == other.mems
|
|
8
|
|
9
|
|
10 class Memory:
|
|
11 def __init__(self, address=0x0):
|
|
12 self.inputs = []
|
|
13 self.address = address
|
|
14 self.size = 0x0
|
|
15
|
|
16 def add_input(self, inp):
|
|
17 assert isinstance(inp, Input)
|
|
18 self.inputs.append(inp)
|
|
19
|
|
20
|
|
21 class Input:
|
|
22 pass
|
|
23
|
|
24
|
|
25 class SectionInput(Input):
|
|
26 def __init__(self, section_name):
|
|
27 self.section_name = section_name
|
|
28
|
|
29
|
|
30 def load_layout(f):
|
|
31 return deserialize(json.load(f))
|
|
32
|
|
33
|
|
34 def make_int(txt):
|
|
35 if txt.startswith('0x'):
|
|
36 return int(txt[2:], 16)
|
|
37 else:
|
|
38 return int(txt)
|
|
39
|
|
40
|
|
41 class LayoutParser:
|
|
42 def __init__(self):
|
|
43 toks = ['ID', '{', '}', 'MEMORY', 'ALIGN', '.', pyyacc.EPS, pyyacc.EOF]
|
|
44 g = pyyacc.Grammar(toks)
|
|
45 g.add_production('layout', ['MEMORY', '{', 'input_list', '}'])
|
|
46 g.add_production('input_list', ['MEMORY', '{', 'input_list', '}'])
|
|
47
|
|
48
|
|
49 def deserialize(d):
|
|
50 layout = Layout()
|
|
51 for mem_node in d['memories']:
|
|
52 m = Memory()
|
|
53 m.address = make_int(mem_node['address'])
|
|
54 m.size = make_int(mem_node['size'])
|
|
55 for input_node in mem_node['inputs']:
|
|
56 pass
|
|
57 return layout
|
|
58
|