Skip to content

Commit

Permalink
rename inputs and see what breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
hofstee authored and THofstee committed Jan 12, 2019
1 parent e9be689 commit 2cae041
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
4 changes: 3 additions & 1 deletion magma/ssa/ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ def visit_Assign(self, node):
return node

def visit_FunctionDef(self, node):
for a in node.args.args:
a.arg = f"{a.arg}_0"
node.body = flatten([self.visit(s) for s in node.body])
return node

def visit_Name(self, node):
if node.id not in self.last_name:
self.last_name[node.id] = node.id
self.last_name[node.id] = f"{node.id}_0"
if isinstance(node.ctx, ast.Store):
self.write_name(node.id)
node.id = f"{self.last_name[node.id]}"
Expand Down
42 changes: 20 additions & 22 deletions tests/test_ssa/test_ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def basic_if(I: m.Bits(2), S: m.Bit) -> m.Bit:
return x

assert inspect.getsource(basic_if) == """\
def basic_if(I: m.Bits(2), S: m.Bit) ->m.Bit:
x_0 = I[0]
x_1 = I[1]
x_2 = phi([x_1, x_0], S)
def basic_if(I_0: m.Bits(2), S_0: m.Bit) ->m.Bit:
x_0 = I_0[0]
x_1 = I_0[1]
x_2 = phi([x_1, x_0], S_0)
return x_2
"""

Expand All @@ -32,11 +32,11 @@ def basic_if(I: m.Bit, S: m.Bit) -> m.Bit:
return x

assert inspect.getsource(basic_if) == """\
def basic_if(I: m.Bit, S: m.Bit) ->m.Bit:
x_0 = I
def basic_if(I_0: m.Bit, S_0: m.Bit) ->m.Bit:
x_0 = I_0
x_1 = x_0
x_2 = x_0
x_3 = phi([x_2, x_1], S)
x_3 = phi([x_2, x_1], S_0)
return x_3
"""

Expand All @@ -50,10 +50,10 @@ def default(I: m.Bits(2), S: m.Bit) -> m.Bit:
return x

assert inspect.getsource(default) == """\
def default(I: m.Bits(2), S: m.Bit) ->m.Bit:
x_0 = I[1]
x_1 = I[0]
x_2 = phi([x_0, x_1], S)
def default(I_0: m.Bits(2), S_0: m.Bit) ->m.Bit:
x_0 = I_0[1]
x_1 = I_0[0]
x_2 = phi([x_0, x_1], S_0)
return x_2
"""

Expand All @@ -74,14 +74,14 @@ def nested(I: m.Bits(4), S: m.Bits(2)) -> m.Bit:
return x

assert inspect.getsource(nested) == """\
def nested(I: m.Bits(4), S: m.Bits(2)) ->m.Bit:
x_0 = I[0]
x_1 = I[1]
x_2 = phi([x_1, x_0], S[1])
x_3 = I[2]
x_4 = I[3]
x_5 = phi([x_4, x_3], S[1])
x_6 = phi([x_5, x_2], S[0])
def nested(I_0: m.Bits(4), S_0: m.Bits(2)) ->m.Bit:
x_0 = I_0[0]
x_1 = I_0[1]
x_2 = phi([x_1, x_0], S_0[1])
x_3 = I_0[2]
x_4 = I_0[3]
x_5 = phi([x_4, x_3], S_0[1])
x_6 = phi([x_5, x_2], S_0[0])
return x_6
"""

Expand All @@ -93,10 +93,8 @@ def default(I: m.Bits(2), x_0: m.Bit) -> m.Bit:
x = I[0]
return x

print(inspect.getsource(default))
assert inspect.getsource(default) == """\
def default(I: m.Bits(2), x_0: m.Bit) ->m.Bit:
I_0, x_0_0 = I, x_0
def default(I_0: m.Bits(2), x_0_0: m.Bit) ->m.Bit:
x_0 = I_0[1]
x_1 = I_0[0]
x_2 = phi([x_0, x_1], x_0_0)
Expand Down

0 comments on commit 2cae041

Please sign in to comment.