# Workaround for https://github.com/YosysHQ/yosys/issues/4349.
#
# Signal renaming in Yosys sometimes causes name conflicts when both signals foo and foo[0] exist in the original design, which happens when we use data.ArrayLayout.
# We can work around this by monkeypatching Format.Array to generate struct suffixes for array fields, i.e. foo.0 instead of foo[0].

from amaranth import Format

def Array(value, /, fields):
    return Format.Struct(value, {str(i): f for i, f in enumerate(fields)})

Format.Array = Array