pytholith: add register muxes
This commit is contained in:
parent
18758d87f6
commit
9c182c47d1
|
@ -33,7 +33,8 @@ class _Register:
|
||||||
if not self.finalized:
|
if not self.finalized:
|
||||||
raise FinalizeError
|
raise FinalizeError
|
||||||
# do nothing when sel == 0
|
# do nothing when sel == 0
|
||||||
cases = [(v, self.storage.eq(k)) for k, v in self.source_encoding.items()]
|
cases = [(Constant(v, self.sel.bv),
|
||||||
|
self.storage.eq(k)) for k, v in self.source_encoding.items()]
|
||||||
sync = [Case(self.sel, *cases)]
|
sync = [Case(self.sel, *cases)]
|
||||||
return Fragment(sync=sync)
|
return Fragment(sync=sync)
|
||||||
|
|
||||||
|
@ -53,13 +54,15 @@ class _Compiler:
|
||||||
|
|
||||||
# blocks and statements
|
# blocks and statements
|
||||||
def visit_block(self, statements):
|
def visit_block(self, statements):
|
||||||
r = []
|
states = []
|
||||||
for statement in statements:
|
for statement in statements:
|
||||||
if isinstance(statement, ast.Assign):
|
if isinstance(statement, ast.Assign):
|
||||||
r += self.visit_assign(statement)
|
op = self.visit_assign(statement)
|
||||||
|
if op:
|
||||||
|
states.append(op)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
return r
|
return states
|
||||||
|
|
||||||
def visit_assign(self, node):
|
def visit_assign(self, node):
|
||||||
if isinstance(node.targets[0], ast.Name):
|
if isinstance(node.targets[0], ast.Name):
|
||||||
|
@ -155,9 +158,10 @@ def make_pytholite(func):
|
||||||
symdict = func.__globals__.copy()
|
symdict = func.__globals__.copy()
|
||||||
registers = []
|
registers = []
|
||||||
|
|
||||||
c = _Compiler(symdict, registers)
|
states = _Compiler(symdict, registers).visit_top(tree)
|
||||||
|
|
||||||
print("compilation result:")
|
print("compilation result:")
|
||||||
print(c.visit_top(tree))
|
print(states)
|
||||||
|
|
||||||
print("registers:")
|
print("registers:")
|
||||||
print(registers)
|
print(registers)
|
||||||
|
@ -166,3 +170,9 @@ def make_pytholite(func):
|
||||||
|
|
||||||
print("ast:")
|
print("ast:")
|
||||||
print(ast.dump(tree))
|
print(ast.dump(tree))
|
||||||
|
|
||||||
|
regf = Fragment()
|
||||||
|
for register in registers:
|
||||||
|
register.finalize()
|
||||||
|
regf += register.get_fragment()
|
||||||
|
return regf
|
||||||
|
|
Loading…
Reference in New Issue