Mercurial > lcfOS
view python/ppci/layout.py @ 382:0c44e494ef58
Made lexer more generic
author | Windel Bouwman |
---|---|
date | Sun, 27 Apr 2014 12:24:21 +0200 |
parents | |
children | 173e20a47fda |
line wrap: on
line source
class Layout: def __init__(self): self.mems = [] def __eq__(self, other): return self.mems == other.mems class Memory: def __init__(self, address=0x0): self.inputs = [] self.address = address self.size = 0x0 def add_input(self, inp): assert isinstance(inp, Input) self.inputs.append(inp) class Input: pass class SectionInput(Input): def __init__(self, section_name): self.section_name = section_name def load_layout(f): return deserialize(json.load(f)) def make_int(txt): if txt.startswith('0x'): return int(txt[2:], 16) else: return int(txt) class LayoutParser: def __init__(self): toks = ['ID', '{', '}', 'MEMORY', 'ALIGN', '.', pyyacc.EPS, pyyacc.EOF] g = pyyacc.Grammar(toks) g.add_production('layout', ['MEMORY', '{', 'input_list', '}']) g.add_production('input_list', ['MEMORY', '{', 'input_list', '}']) def deserialize(d): layout = Layout() for mem_node in d['memories']: m = Memory() m.address = make_int(mem_node['address']) m.size = make_int(mem_node['size']) for input_node in mem_node['inputs']: pass return layout