Skip to content

Commit 8d871f9

Browse files
committed
[rdl2ot] Make the tool a peak rdl pluggin
Signed-off-by: Douglas Reis <[email protected]>
1 parent c379f1f commit 8d871f9

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
lines changed

rdl2ot/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# rdl2ot cli tool
22
A PeakRDL extension to generate Opentitan style source files from SystemRDL files.
33

4-
## How to generate the Opentitan register interfaces from a RDL file
4+
## Using as a standalone tool
5+
### How to generate the Opentitan register interfaces from a RDL file
56
```sh
67
rdl2ot export-rtl <input_rdl> <output_dir>
78
```
@@ -12,6 +13,17 @@ mkdir -p /tmp/lc_ctrl
1213
rdl2ot export-rtl tests/snapshots/lc_ctrl.rdl /tmp/lc_ctrl/
1314
```
1415

16+
## Using as a Peakrdl pluggin
17+
### Installing
18+
```sh
19+
pip install peakrdl rdl2ot
20+
```
21+
### Running
22+
```sh
23+
mkdir -p /tmp/lc_ctrl
24+
peakrdl rdl2ot tests/snapshots/lc_ctrl.rdl -o /tmp/lc_ctrl/
25+
```
26+
1527
## Contributing
1628
### How to run tests
1729
```sh

rdl2ot/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Homepage = "https://github.com/lowrisc/benevisrdl"
2323
Issues = "https://github.com/lowrisc/benevisrdl/issues"
2424
Documentation = "https://github.com/lowrisc/benevisrdl"
2525

26+
[project.entry-points."peakrdl.exporters"]
27+
rdl2ot = "rdl2ot.__peakrdl__:Exporter"
28+
2629
[build-system]
2730
requires = ["hatchling"]
2831
build-backend = "hatchling.build"
@@ -38,3 +41,4 @@ executionEnvironments = [
3841

3942
[tool.hatch.build.targets.wheel]
4043
packages = ["src/rdl2ot", "src/templates"]
44+

rdl2ot/src/rdl2ot/__peakrdl__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
# Copyright lowRISC contributors.
3+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
"""Generates Opentitan regblock RTL."""
7+
8+
from pathlib import Path
9+
from typing import TYPE_CHECKING
10+
11+
from peakrdl.plugins.exporter import ExporterSubcommandPlugin # pylint: disable=import-error
12+
13+
from rdl2ot import rtl_exporter
14+
15+
if TYPE_CHECKING:
16+
import argparse
17+
18+
from systemrdl.node import AddrmapNode
19+
20+
21+
class Exporter(ExporterSubcommandPlugin):
22+
"""Generates Opentitan regblock RTL."""
23+
24+
short_desc = "Generates Opentitan register block RTL."
25+
26+
def add_exporter_arguments(self, arg_group: "argparse.ArgumentParser") -> None:
27+
"""No extra arguments."""
28+
29+
def do_export(self, top_node: "AddrmapNode", options: "argparse.Namespace") -> None:
30+
"""Plugin entry function."""
31+
rtl_exporter.run(top_node, Path(options.output))

rdl2ot/src/rdl2ot/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ def export_rtl(input_file: str, out_dir: str) -> None:
4141
rdlc.compile_file(input_file)
4242
root = rdlc.elaborate()
4343

44-
rtl_exporter.run(root, Path(out_dir))
44+
rtl_exporter.run(root.top, Path(out_dir))
4545

4646
print("Successfully finished!\n")

rdl2ot/src/rdl2ot/rtl_exporter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
DEFAULT_INTERFACE_NAME = "regs"
1818

1919

20-
def run(obj: node.RootNode, out_dir: Path) -> None:
20+
def run(root_node: node.AddrmapNode, out_dir: Path) -> None:
2121
"""Export RDL to opentitan RTL."""
2222
factory = OtInterfaceBuilder()
23-
data = factory.parse_root(obj.top)
23+
data = factory.parse_root(root_node)
2424

2525
Path(out_dir / "rdl.json").write_text(json.dumps(data, indent=2), encoding="utf-8")
2626

rdl2ot/tests/test_rdl2ot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ def _run_cli_tool(input_file_path: Path, output_dir_path: Path) -> subprocess.Co
2424
]
2525
return subprocess.run(command, capture_output=True, text=True, check=False) # noqa: S603
2626

27+
2728
test_ips = ["lc_ctrl", "uart"]
29+
30+
2831
@pytest.mark.parametrize("ip_block", test_ips)
2932
def test_export_ip(tmp_path: Path, ip_block: str) -> None:
3033
"""Test an given ip block."""

0 commit comments

Comments
 (0)