mirror of
https://github.com/retroSoC/retroSoC.git
synced 2026-11-06 14:55:14 +00:00
chore: enhance RTL style checks and enforce naming conventions
- Updated to enforce stricter naming rules for new owned RTL. - Expanded documentation on RTL coding style to include detailed naming contracts. - Refactored RTL code to comply with new naming conventions, including: - Renaming typedefs to use suffix for enums and for other types. - Ensuring module names use lower snake case and ports have appropriate direction suffixes. - Adjusting instance names to start with and ensuring state variables use and suffixes. - Modified scripts to include checks for new naming rules and updated tests to validate these changes. - Updated to reflect new naming guidelines and exceptions.
This commit is contained in:
18 files changed
+436
-80
No files matched your search
@@ -8,6 +8,8 @@ tooling.
|
||||
archive, and regression-helper behavior.
|
||||
- `test_rtl_readiness.py` covers the machine-readable RTL maturity and
|
||||
synthesis-intent checks.
|
||||
- `test_rtl_style.py` covers ownership, named connections, and staged naming
|
||||
rules for new owned RTL.
|
||||
|
||||
Add a host C test when changing deterministic runtime or media logic; add a
|
||||
Python test when changing scripts or build policy. Run:
|
||||
|
||||
+44
-2
@@ -10,7 +10,9 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
SCRIPT = ROOT / "scripts/check_rtl_style.py"
|
||||
|
||||
|
||||
def run_style(tmp_path: Path, source: str) -> subprocess.CompletedProcess[str]:
|
||||
def run_style(
|
||||
tmp_path: Path, source: str, *, enforce_naming: bool = False
|
||||
) -> subprocess.CompletedProcess[str]:
|
||||
(tmp_path / "rtl/ip/test.sv").parent.mkdir(parents=True)
|
||||
(tmp_path / "rtl/ip/test.sv").write_text(source, encoding="utf-8")
|
||||
(tmp_path / "rtl/rtl_style_manifest.json").write_text(
|
||||
@@ -31,8 +33,11 @@ def run_style(tmp_path: Path, source: str) -> subprocess.CompletedProcess[str]:
|
||||
)
|
||||
subprocess.run(["git", "init", "-q", str(tmp_path)], check=True)
|
||||
subprocess.run(["git", "-C", str(tmp_path), "add", "."], check=True)
|
||||
command = [sys.executable, str(SCRIPT), "--root", str(tmp_path), "--profile", "owned"]
|
||||
if enforce_naming:
|
||||
command.append("--enforce-naming")
|
||||
return subprocess.run(
|
||||
[sys.executable, str(SCRIPT), "--root", str(tmp_path), "--profile", "owned"],
|
||||
command,
|
||||
text=True,
|
||||
capture_output=True,
|
||||
check=False,
|
||||
@@ -88,3 +93,40 @@ def test_owned_style_rejects_non_ascii_and_long_lines(tmp_path: Path) -> None:
|
||||
assert result.returncode == 1
|
||||
assert "non-ASCII" in result.stderr
|
||||
assert "100 characters" in result.stderr
|
||||
|
||||
|
||||
def test_owned_style_enforces_staged_naming_contract(tmp_path: Path) -> None:
|
||||
result = run_style(
|
||||
tmp_path,
|
||||
"`define BAD_MACRO 1\n"
|
||||
"module badModule(\n"
|
||||
" input logic clk,\n"
|
||||
" output logic data_o\n"
|
||||
");\n"
|
||||
" logic s_state_q;\n"
|
||||
" bad_if if0 ();\n"
|
||||
"endmodule\n",
|
||||
enforce_naming=True,
|
||||
)
|
||||
assert result.returncode == 1
|
||||
assert "module name" in result.stderr
|
||||
assert "port 'clk'" in result.stderr
|
||||
assert "interface instance" in result.stderr
|
||||
assert "macro 'BAD_MACRO'" in result.stderr
|
||||
|
||||
|
||||
def test_owned_style_accepts_project_naming_contract(tmp_path: Path) -> None:
|
||||
result = run_style(
|
||||
tmp_path,
|
||||
"`define RETROSOC_TEST__VALUE 1\n"
|
||||
"module test_module(\n"
|
||||
" input logic clk_i,\n"
|
||||
" output logic data_o\n"
|
||||
");\n"
|
||||
" logic s_state_d;\n"
|
||||
" logic s_state_q;\n"
|
||||
" test_if u_test_if ();\n"
|
||||
"endmodule\n",
|
||||
enforce_naming=True,
|
||||
)
|
||||
assert result.returncode == 0, result.stderr
|
||||
@@ -54,7 +54,7 @@ def test_extensions_generate_isolated_scalar_bindings(tmp_path: Path) -> None:
|
||||
assert core.count("ribp2rib #(") == 6
|
||||
assert core.count(".SYNC_RESET(1'b1)") == 3
|
||||
assert core.count(".SYNC_RESET(1'b0)") == 3
|
||||
assert "rib.cmd_valid = '0;" in core
|
||||
assert "u_user_rib_if.cmd_valid = '0;" in core
|
||||
assert "5'd0: begin" in core
|
||||
assert "5'd4: begin" in core
|
||||
assert "5'd5: begin" in core
|
||||
|
||||
Reference in new issue
Block a user