From 0c38342089aa8f5bc9ce87e44936119163e5d26e Mon Sep 17 00:00:00 2001 From: Teguh Hofstee Date: Fri, 5 Oct 2018 20:05:20 +0000 Subject: [PATCH] minor cleanup --- silica/compile.py | 4 ++-- silica/transformations/desugar_for_loops.py | 16 +++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/silica/compile.py b/silica/compile.py index 171a316..9073a5b 100644 --- a/silica/compile.py +++ b/silica/compile.py @@ -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 @@ -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) diff --git a/silica/transformations/desugar_for_loops.py b/silica/transformations/desugar_for_loops.py index 2c5f40d..378627d 100644 --- a/silica/transformations/desugar_for_loops.py +++ b/silica/transformations/desugar_for_loops.py @@ -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() @@ -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): @@ -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": @@ -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]) @@ -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 = {} @@ -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