hdl.xfrm, back.rtlil: implement and use LHSGroupFilter.
This is a refactoring to simplify reusing the filtering code in simulation, and separate that concern from backends in general.
This commit is contained in:
parent
1c7c75a254
commit
98f554aa08
3 changed files with 59 additions and 36 deletions
|
|
@ -13,7 +13,7 @@ __all__ = ["ValueVisitor", "ValueTransformer",
|
|||
"StatementVisitor", "StatementTransformer",
|
||||
"FragmentTransformer",
|
||||
"DomainRenamer", "DomainLowerer",
|
||||
"SwitchCleaner", "LHSGroupAnalyzer",
|
||||
"SwitchCleaner", "LHSGroupAnalyzer", "LHSGroupFilter",
|
||||
"ResetInserter", "CEInserter"]
|
||||
|
||||
|
||||
|
|
@ -286,7 +286,7 @@ class SwitchCleaner(StatementVisitor):
|
|||
|
||||
def on_Switch(self, stmt):
|
||||
cases = OrderedDict((k, self.on_statement(s)) for k, s in stmt.cases.items())
|
||||
if any(len(s) for s in stmt.cases.values()):
|
||||
if any(len(s) for s in cases.values()):
|
||||
return Switch(stmt.test, cases)
|
||||
|
||||
def on_statements(self, stmts):
|
||||
|
|
@ -341,6 +341,18 @@ class LHSGroupAnalyzer(StatementVisitor):
|
|||
return self.groups()
|
||||
|
||||
|
||||
class LHSGroupFilter(SwitchCleaner):
|
||||
def __init__(self, signals):
|
||||
self.signals = signals
|
||||
|
||||
def on_Assign(self, stmt):
|
||||
# The invariant provided by LHSGroupAnalyzer is that all signals that ever appear together
|
||||
# on LHS are a part of the same group, so it is sufficient to check any of them.
|
||||
any_lhs_signal = next(iter(stmt.lhs._lhs_signals()))
|
||||
if any_lhs_signal in self.signals:
|
||||
return stmt
|
||||
|
||||
|
||||
class _ControlInserter(FragmentTransformer):
|
||||
def __init__(self, controls):
|
||||
if isinstance(controls, Value):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue