Skip to content

Commit

Permalink
[Syntax] Init FSM
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed Mar 21, 2024
1 parent f2ebf2f commit 04b109e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions magma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def set_mantle_target(t):
from magma.debug import magma_helper_function
import magma.mantle
from magma.sum_type import Sum, match, case, Enum2
from magma.syntax.fsm import fsm, FSMState, wait

################################################################################
# BEGIN ALIASES
Expand Down
13 changes: 13 additions & 0 deletions magma/syntax/fsm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import magma as m


class FSMState(m.Enum2):
pass


def fsm(T: m.Kind):
pass


def wait():
pass
31 changes: 31 additions & 0 deletions tests/test_syntax/test_fsm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import magma as m
from magma.testing.utils import check_gold


def test_fsm_wait():
class State(m.FSMState):
INIT = 0
RUN = 1
DONE = 2

class Foo(m.Circuit):
io = m.IO(O=m.Out(m.Bits[16]))
# Must delay elaboration of state register until total number states
# computed (number of wait statements)
# Could use a builder here?
with m.fsm(State) as state:
with m.case(State.INIT):
io.O @= 0xFEED
state.next @= State.RUN
with m.case(State.RUN):
io.O @= 0xDEAD
m.wait()
io.O @= 0xBEEF
state.next @= State.DONE
with m.case(State.DONE):
io.O @= 0xBEEF
state.next @= State.DONE

m.compile("build/test_sum_enum", Foo, output="mlir",
flatten_all_tuples=True)
assert check_gold(__file__, "test_sum_enum.mlir")

0 comments on commit 04b109e

Please sign in to comment.