Description
We currently have several warts in the very core of the language: the way .matches()
works (by masking and comparing) which is different from the way with m.Case():
works (by emitting decision trees), and which duplicate most of their logic, which sometimes gets out of sync. Also, Case()
emits Switch()
statements, which are undocumented and extremely fragile.
Instead of this mess, we should emit a new (internal) Match
AST node from Value.matches()
, replace Switch
with an (internal) decision tree statement Decision
that will also absorb StatementList
, and have Switch
lower to a simple priority mux where if the condition is one or more Matches
nodes, then the masking is absorbed into the RTLIL decision tree, and otherwise it's treated as a single bit pattern.
The Decision
statement should conceptually contain a list of pairs (condition, statements)
, which are evaluated in order. The condition
is an arbitrary expression that is reduced to a boolean. The first branch that evaluates to true is the one that becomes active.