From 0986cd818c34a207f4822e3a7f0e6cdc1a9d6f74 Mon Sep 17 00:00:00 2001 From: Franck Jullien Date: Mon, 20 Jun 2022 08:59:30 +0200 Subject: [PATCH] gen: override FSM to add filter file generation --- litex/gen/genlib/__init__.py | 0 litex/gen/genlib/fsm.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 litex/gen/genlib/__init__.py create mode 100644 litex/gen/genlib/fsm.py diff --git a/litex/gen/genlib/__init__.py b/litex/gen/genlib/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/litex/gen/genlib/fsm.py b/litex/gen/genlib/fsm.py new file mode 100644 index 000000000..2036f2b29 --- /dev/null +++ b/litex/gen/genlib/fsm.py @@ -0,0 +1,19 @@ +from migen import * + +class nFSM(FSM): + def __init__(self, reset_state=None, name=None, with_filter=True): + super().__init__(reset_state) + self.name = name + self.with_filter = with_filter + + def _finalize_sync(self, ls): + if self.with_filter and self.name: + self.generate_fsm_filter() + super()._finalize_sync(ls) + + def generate_fsm_filter(self): + with open(f"filter_{self.name}.txt", "w") as f: + for i, state in enumerate(self.actions): + f.write("{} {}\n".format(i, state)) + + self.state.name_override = self.name \ No newline at end of file