Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hofstee committed Oct 5, 2018
1 parent cd26ee9 commit 0c38342
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
4 changes: 2 additions & 2 deletions silica/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from silica.type_check import TypeChecker
from silica.analysis import CollectInitialWidthsAndTypes
from silica.transformations.promote_widths import PromoteWidths
from silica.transformations.desugar_for_loops import propagate_types, aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
from silica.transformations.desugar_for_loops import propagate_types, get_final_widths

import veriloggen as vg

Expand Down Expand Up @@ -103,7 +103,7 @@ def compile(coroutine, file_name=None, mux_strategy="one-hot", output='verilog',

CollectInitialWidthsAndTypes(width_table, type_table).visit(tree)
PromoteWidths(width_table, type_table).visit(tree)
tree, loopvars = aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(tree, width_table, func_locals, func_globals)
tree, loopvars = get_final_widths(tree, width_table, func_locals, func_globals)

ast_utils.print_ast(tree)

Expand Down
16 changes: 5 additions & 11 deletions silica/transformations/desugar_for_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from .constant_fold import constant_fold
from silica.memory import MemoryType
from copy import deepcopy

# TODO: should probably delete
import astor

counter = itertools.count()
Expand All @@ -19,7 +17,6 @@ def get_call_func(node):
raise NotImplementedError(type(node.value.func)) # pragma: no cover



def desugar_for_loops(tree, type_table):
class ForLoopDesugarer(ast.NodeTransformer):
def __init__(self):
Expand All @@ -36,8 +33,6 @@ def visit_For(self, node):
new_body.append(result)
node.body = new_body



# range() iterator
if is_call(node.iter) and is_name(node.iter.func) and \
node.iter.func.id == "range":
Expand Down Expand Up @@ -91,7 +86,6 @@ def visit_For(self, node):
# TODO: currently just assumes that this is a list
# TODO: maybe this should just reshape the for-loop to use a range()
# iterator and then just call the previous branch
# TODO: index should be an unused identifier
index = '__silica_count_' + str(next(counter))
start = ast.Num(0)
stop = ast.Num(type_table[node.iter.id][1])
Expand Down Expand Up @@ -136,8 +130,8 @@ def visit_Assign(self, node):
propagator.visit(tree)
return tree, propagator.loopvars

def aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(tree, width_table, globals, locals):
class AAAAAA(ast.NodeTransformer):
def get_final_widths(tree, width_table, globals, locals):
class WidthCalculator(ast.NodeTransformer):
def __init__(self):
super().__init__()
self.loopvars = {}
Expand All @@ -158,6 +152,6 @@ def visit_Assign(self, node):

return node

aaaa = AAAAAA()
aaaa.visit(tree)
return tree, aaaa.loopvars
wc = WidthCalculator()
wc.visit(tree)
return tree, wc.loopvars

0 comments on commit 0c38342

Please sign in to comment.