Skip to content

Add an amaranth.hdl._ast.Match node, use it for Value.matches, and delegate from Case() to Value.matches #1074

Open
@whitequark

Description

@whitequark

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions