mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
Add get_signals function (w/ optional recursion) for litescope usage
This commit is contained in:
parent
6e42082128
commit
592f6a10dc
1 changed files with 26 additions and 0 deletions
26
litex/gen/fhdl/utils.py
Normal file
26
litex/gen/fhdl/utils.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#
|
||||||
|
# This file is part of LiteX.
|
||||||
|
#
|
||||||
|
# Copyright (c) 2022 Jevin Sweval <jevinsweval@gmail.com>
|
||||||
|
# SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
|
from migen.genlib.record import Record
|
||||||
|
from migen.fhdl.module import Module
|
||||||
|
from migen.fhdl.structure import Signal
|
||||||
|
|
||||||
|
def get_signals(obj, recurse=False):
|
||||||
|
signals = set()
|
||||||
|
for attr_name in dir(obj):
|
||||||
|
if attr_name[:2] == "__" and attr_name[-2:] == "__":
|
||||||
|
continue
|
||||||
|
attr = getattr(obj, attr_name)
|
||||||
|
if isinstance(attr, Signal):
|
||||||
|
signals.add(attr)
|
||||||
|
elif isinstance(attr, Record):
|
||||||
|
for robj in attr.flatten():
|
||||||
|
if isinstance(robj, Signal):
|
||||||
|
signals.add(robj)
|
||||||
|
elif recurse and isinstance(attr, Module):
|
||||||
|
signals |= get_signals(attr, recurse=True)
|
||||||
|
|
||||||
|
return signals
|
Loading…
Reference in a new issue