diff --git a/rdlexporter/src/rdlexporter/exporter.py b/rdlexporter/src/rdlexporter/exporter.py index 6502e0c..de3add4 100644 --- a/rdlexporter/src/rdlexporter/exporter.py +++ b/rdlexporter/src/rdlexporter/exporter.py @@ -131,7 +131,7 @@ def _emit_property(self, properties: dict, assign_op: str = "=", endline: str = print(f"Warning: Type {type(obj)} not implemented, skipping it.") def _arrays(self, component: Reg) -> str: - if not component.is_array: + if component.array_dimensions is None: return "" if len(component.array_dimensions) > 1: diff --git a/rdlexporter/tests/snapshots/arrays.rdl b/rdlexporter/tests/snapshots/arrays.rdl new file mode 100644 index 0000000..9525406 --- /dev/null +++ b/rdlexporter/tests/snapshots/arrays.rdl @@ -0,0 +1,22 @@ +`include "user_defined.rdl" + +addrmap arrays { + reg { + field { + desc = "Enable the block."; + sw = rw; + hw = r; + reset = 0x0; + } EN[0:0]; + } CTRL @ 0x0; + + reg { + field { + desc = "Data word."; + sw = rw; + hw = r; + reset = 0x0; + } VAL[31:0]; + } DATA[4] @ 0x4; + +}; diff --git a/rdlexporter/tests/test_exporter.py b/rdlexporter/tests/test_exporter.py index 42a73e9..dd96469 100644 --- a/rdlexporter/tests/test_exporter.py +++ b/rdlexporter/tests/test_exporter.py @@ -51,6 +51,18 @@ def test_cli_lc_ctrl_from_file(tmp_path: Path) -> None: _run_ip_test_from_file(tmp_path, "lc_ctrl") +def test_cli_arrays_from_file(tmp_path: Path) -> None: + """Regression test for register array export. + + Covers both branches of ``RdlExporter._arrays``: a plain register (``CTRL``) + and a register array (``DATA[4]``). Guards against relying on attributes that + only exist on elaborated ``Node`` objects (e.g. ``is_array``, removed from raw + ``Component`` objects in systemrdl-compiler 1.32.2) rather than ``Component`` + ones (``array_dimensions``). + """ + _run_ip_test_from_file(tmp_path, "arrays") + + def test_importer(tmp_path: Path) -> None: """Test with the SystemRDL importer.""" input_rdl = SNAPSHOTS_DIR / "generic.rdl"