Skip to content

Commit 5f9acfc

Browse files
authored
Merge pull request #9 from lowRISC/develop
Tidy up the repository to be published to Pypi
2 parents a5f3c14 + 0c0f196 commit 5f9acfc

File tree

18 files changed

+483
-781
lines changed

18 files changed

+483
-781
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ jobs:
3333
run: uv run pytest
3434
working-directory: rdlexporter
3535

36-
- name: Build rdlexporter package
37-
run: uv run python -m build
38-
working-directory: rdlexporter
36+
- name: Build packages
37+
run: uv build --all

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ nix develop
1818
## rdl2ot cli tool
1919
A PeakRDL extension to generate Opentitan style source files from SystemRDL files.
2020

21+
For more details, refer to [rdl2ot](./rdl2ot)
22+
2123
### How to run tests
2224
```sh
2325
cd rdl2ot
@@ -33,6 +35,8 @@ python src/rdl2ot export-rtl tests/snapshots/lc_ctrl.rdl /tmp/
3335
## Rdl-exporter
3436
A library to generate SystemRDL files from the Hierarchical Register Model.
3537

38+
For more details, refer to [rdlexporter](./rdlexporter)
39+
3640
### How to run tests
3741
```sh
3842
cd rdl-exporter
@@ -46,8 +50,7 @@ uv sync --all-extras
4650
```
4751
Build package
4852
```sh
49-
cd rdl-exporter
50-
uv run python -m build
53+
uv build --all
5154
```
5255
Install the package locally
5356
```sh

pyproject.toml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
[project]
22
name = "benevisrdl"
3-
version = "0.0.0"
3+
version = "0.1.0"
44
description = "Houses PeakRDL pluggins."
55
requires-python = ">=3.10"
6-
readme = "README.md" # Path to your README file
7-
license = { file = "LICENSE" } # Path to your LICENSE file
6+
readme = "README.md"
7+
license = { file = "LICENSE" }
88
dependencies = [
9-
"uv==0.6.1",
10-
"isort==5.10.1",
11-
"yapf==0.32.0",
12-
"click>=8.2.1",
13-
"jinja2>=3.1.6",
14-
"peakrdl>=1.4.0",
159
]
10+
1611
[project.optional-dependencies]
1712
linting = [
13+
"pyright>=1.1.403",
1814
"ruff>=0.9.6",
19-
"mypy==0.971",
20-
"flake8 ~= 7.1",
2115
]
2216
dev = [
2317
"pytest>=8.4.1",
24-
"hatch>=1.4.1",
2518
"twine>=6.1.0",
26-
"build>=1.2.2",
19+
"uv-build>=0.8.4",
2720
]
2821
ci = ["benevisrdl[linting,dev]"]
2922

@@ -33,11 +26,25 @@ py-modules = []
3326
[tool.ruff]
3427
target-version = "py310"
3528
line-length = 100
29+
extend-exclude = [
30+
]
3631

3732
[tool.ruff.lint]
3833
preview = true
3934
explicit-preview-rules = true
40-
extend-select = ["E", "E303", "W391"]
35+
select = ["ALL"]
36+
extend-select = ["W391", "E303"]
37+
allowed-confusables = [""]
38+
ignore = [
39+
"D203", "D213", "COM812", "ISC001", "FIX", "TD", "T201", "S101", "C901", "D401",
40+
"PLR0911", "PLR0915", "INP001", "RUF012", "EXE001", "S701"
41+
]
4142

4243
[tool.uv.workspace]
4344
members = [ "rdl2ot", "rdlexporter"]
45+
46+
[[tool.uv.index]]
47+
name = "testpypi"
48+
url = "https://test.pypi.org/simple/"
49+
publish-url = "https://test.pypi.org/legacy/"
50+
explicit = true

rdl2ot/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# rdl2ot cli tool
2+
A PeakRDL extension to generate Opentitan style source files from SystemRDL files.
3+
4+
## How to generate the Opentitan register interfaces from a RDL file
5+
```sh
6+
rdl2ot export-rtl <input_rdl> <output_dir>
7+
```
8+
9+
Example:
10+
```sh
11+
mkdir -p /tmp/lc_ctrl
12+
rdl2ot export-rtl tests/snapshots/lc_ctrl.rdl /tmp/lc_ctrl/
13+
```
14+
15+
## Contributing
16+
### How to run tests
17+
```sh
18+
cd rdl2ot
19+
pytest
20+
```
21+

rdl2ot/pyproject.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,38 @@ name = "rdl2ot"
33
version = "0.1.0"
44
description = "An extension of PeakRDL to generate Opentitan RTL."
55
requires-python = ">=3.10"
6+
keywords = ["SystemRDL", "Opentitan", "Codegen"]
7+
readme = "README.md"
68
dependencies = [
9+
"click>=8.2.1",
10+
"jinja2>=3.1.6",
11+
"peakrdl>=1.4.0",
712
]
813

14+
authors = [
15+
{ name = "lowRISC contributors"},
16+
]
17+
18+
[project.scripts]
19+
rdl2ot = "rdl2ot.cli:main"
20+
21+
[project.urls]
22+
Homepage = "https://github.com/lowrisc/benevisrdl"
23+
Issues = "https://github.com/lowrisc/benevisrdl/issues"
24+
Documentation = "https://github.com/lowrisc/benevisrdl"
25+
926
[build-system]
1027
requires = ["hatchling"]
1128
build-backend = "hatchling.build"
29+
30+
[tool.pyright]
31+
include = ["src"]
32+
reportMissingImports = "error"
33+
reportMissingTypeStubs = false
34+
venv = ".venv"
35+
executionEnvironments = [
36+
{ root = "src" },
37+
]
38+
39+
[tool.hatch.build.targets.wheel]
40+
packages = ["src/rdl2ot", "src/templates"]

rdl2ot/src/rdl2ot/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Copyright lowRISC contributors (OpenTitan project).
22
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
# SPDX-License-Identifier: Apache-2.0
4+
5+
"""Init."""

rdl2ot/src/rdl2ot/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
# SPDX-License-Identifier: Apache-2.0
44

5+
"""Main."""
6+
57
from cli import main
68

79
if __name__ == "__main__":

rdl2ot/src/rdl2ot/cli.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,44 @@
33
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
44
# SPDX-License-Identifier: Apache-2.0
55

6-
import click
6+
7+
"""Cli."""
8+
79
from pathlib import Path
810

11+
import click
12+
from systemrdl import RDLCompiler
13+
14+
from rdl2ot import rtl_exporter
15+
916

1017
@click.group()
11-
def main():
12-
pass
18+
def main() -> None:
19+
"""Cli."""
1320

1421

1522
@main.command()
1623
@click.argument(
1724
"input_file",
1825
type=click.Path(writable=True),
19-
# help="The input RDL.",
2026
)
2127
@click.argument(
2228
"out_dir",
2329
default="./result",
2430
type=click.Path(writable=True),
25-
# help="The destination dir to generate the output.",
2631
)
27-
def export_rtl(input_file: str, out_dir: str):
28-
from systemrdl import RDLCompiler
32+
def export_rtl(input_file: str, out_dir: str) -> None:
33+
"""Export opentitan rtl.
2934
35+
INPUT_FILE: The input RDL
36+
OUT_DIR: The destination dir to generate the output
37+
38+
"""
39+
print("Compiling file: {input_file}...")
3040
rdlc = RDLCompiler()
31-
try:
32-
rdlc.compile_file(input_file)
33-
root = rdlc.elaborate()
34-
except Exception as e:
35-
raise RuntimeError(f"In file {input_file}") from e
36-
37-
import export_rtl
38-
39-
try:
40-
export_rtl.run(rdlc, root, Path(out_dir))
41-
except Exception as e:
42-
raise RuntimeError(f"In file {input_file}") from e
41+
rdlc.compile_file(input_file)
42+
root = rdlc.elaborate()
43+
44+
rtl_exporter.run(rdlc, root, Path(out_dir))
4345

4446
print("Successfully finished!\n")

rdl2ot/src/rdl2ot/opentitan.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@
22
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
# SPDX-License-Identifier: Apache-2.0
44

5-
from systemrdl.rdltypes import OnReadType, OnWriteType, AccessType
6-
from systemrdl import node
5+
"""Functions with opentitan specific logic."""
6+
77
import re
88

9+
from systemrdl import node
10+
from systemrdl.rdltypes import AccessType, OnReadType, OnWriteType
11+
912

1013
def register_permit_mask(reg: dict) -> int:
11-
"""
12-
One bit presents one byte in the register, so in total 4 bits are used.
13-
"""
14+
"""One bit presents one byte in the register, so in total 4 bits are used."""
1415
w = reg["msb"] + 1
15-
if w > 24:
16+
if w > 24: # noqa: PLR2004
1617
return 0b1111
17-
if w > 16:
18+
if w > 16: # noqa: PLR2004
1819
return 0b0111
19-
if w > 8:
20+
if w > 8: # noqa: PLR2004
2021
return 0b0011
2122
return 0b0001
2223

2324

24-
def needs_read_en(reg: dict()) -> bool:
25-
"""Return true if at least one field needs a read-enable
25+
def needs_read_en(reg: dict) -> bool:
26+
"""Return true if at least one field needs a read-enable.
2627
2728
This is true if any of the following are true:
2829
@@ -40,43 +41,42 @@ def needs_read_en(reg: dict()) -> bool:
4041
side might need the re signal)
4142
"""
4243
return reg["shadowed"] or any(
43-
[
44-
(field["clear_onread"] or (reg["external"] and field["sw_readable"]))
45-
for field in reg["fields"]
46-
]
44+
(field["clear_onread"] or (reg["external"] and field["sw_readable"]))
45+
for field in reg["fields"]
4746
)
4847

4948

50-
def needs_write_en(reg: dict()) -> bool:
51-
"""Should the register for this field have a write-enable signal?
49+
def needs_write_en(reg: dict) -> bool:
50+
"""Return register for this field should have a write-enable signal.
5251
5352
This is almost the same as allows_write(), but doesn't return true for
5453
RC registers, which should use a read-enable signal (connected to their
5554
prim_subreg's we port).
5655
"""
57-
return any([(not field["clear_onread"] and field["sw_writable"]) for field in reg["fields"]])
56+
return any((not field["clear_onread"] and field["sw_writable"]) for field in reg["fields"])
57+
5858

59+
def needs_qe(reg: dict) -> bool:
60+
"""Return true if the register or at least one field needs a q-enable."""
61+
return any(field["swmod"] for field in reg["fields"])
5962

60-
def needs_qe(reg: dict()) -> bool:
61-
"""Return true if the register or at least one field needs a q-enable"""
62-
return any([field["swmod"] for field in reg["fields"]])
6363

64+
def needs_int_qe(reg: dict) -> bool:
65+
"""Return true if the register or at least one field needs an internal q-enable.
6466
65-
def needs_int_qe(reg: dict()) -> bool:
66-
"""Return true if the register or at least one field needs an
67-
internal q-enable. An internal q-enable means the net
68-
may be consumed by other reg logic but will not be exposed
69-
in the package file."""
67+
An internal q-enable means the net may be consumed by other reg logic but will
68+
not be exposed in the package file.
69+
"""
7070
return (bool(reg["async_clk"]) and reg["hw_writable"]) or needs_qe(reg)
7171

7272

7373
def get_bit_width(offset: int) -> int:
74-
"""Calculate the number of bits to address every byte of the block"""
74+
"""Calculate the number of bits to address every byte of the block."""
7575
return (offset - 1).bit_length()
7676

7777

7878
def get_sw_access_enum(field: node.FieldNode) -> str:
79-
"""Map the rdl access permissions to reggen SwAccess enum"""
79+
"""Map the rdl access permissions to reggen SwAccess enum."""
8080
sw = field.get_property("sw")
8181
onwrite = field.get_property("onwrite")
8282
onread = field.get_property("onread")
@@ -98,15 +98,17 @@ def get_sw_access_enum(field: node.FieldNode) -> str:
9898
return "NONE"
9999

100100

101-
def fields_no_write_en(reg: dict()) -> int:
101+
def fields_no_write_en(reg: dict) -> int:
102+
"""Count how many fields has write enable."""
102103
res = 0
103104
for idx, field in enumerate(reg["fields"]):
104105
res |= (not needs_we(field)) << idx
105106
return res
106107

107108

108109
def needs_we(field: dict) -> bool:
109-
"""Should the register for this field have a write-enable signal?
110+
"""True if the register for this field should have a write-enable signal.
111+
110112
This is almost the same as allows_write(), but doesn't return true for
111113
RC registers, which should use a read-enable signal (connected to their
112114
prim_subreg's we port).
@@ -115,8 +117,9 @@ def needs_we(field: dict) -> bool:
115117

116118

117119
def is_homogeneous(reg: dict) -> bool:
118-
"""Return true if all fields of a register are equal. The offset are excluded from
119-
the comparison.
120+
"""Return true if all fields of a register are equal.
121+
122+
The offset are excluded from the comparison.
120123
"""
121124
exclude = ["name", "msb", "lsb", "bitmask", "type"]
122125
unamed_fields = [

0 commit comments

Comments
 (0)