Skip to content

Commit 6faa933

Browse files
committed
Remove dangerous usage of non-public parts of the systemrdl-compiler API
1 parent 416e2a4 commit 6faa933

File tree

5 files changed

+25
-45
lines changed

5 files changed

+25
-45
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "peakrdl-uvm"
77
dynamic = ["version"]
88
requires-python = ">=3.7"
99
dependencies = [
10-
"systemrdl-compiler ~= 1.30",
10+
"systemrdl-compiler ~= 1.31",
1111
"jinja2 >= 2.9",
1212
]
1313

src/peakrdl_uvm/exporter.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@ def __init__(self, **kwargs):
6262
# value = max accesswidth/memwidth used in node's descendants
6363
self.bus_width_db = {}
6464

65-
# Dictionary of root-level type definitions
66-
# key = definition type name
67-
# value = representative object
68-
# components, this is the original_def (which can be None in some cases)
69-
self.namespace_db = {}
65+
# Set of root-level type definitions
66+
self.namespace_db = set()
7067

7168
self.reuse_class_definitions = True
7269

@@ -184,14 +181,18 @@ def _get_class_name(self, node: Node) -> str:
184181
# Unable to determine a reusable type name. Fall back to hierarchical path
185182
class_name = node.get_rel_path(
186183
self.top.parent,
187-
hier_separator="__", array_suffix="", empty_array_suffix=""
184+
hier_separator="__",
185+
array_suffix="",
186+
empty_array_suffix="",
188187
)
189188
# Add prefix to prevent collision when mixing namespace methods
190189
class_name = "xtern__" + class_name
191190
else:
192191
class_name = node.get_rel_path(
193192
self.top.parent,
194-
hier_separator="__", array_suffix="", empty_array_suffix=""
193+
hier_separator="__",
194+
array_suffix="",
195+
empty_array_suffix="",
195196
)
196197

197198
return class_name
@@ -213,7 +214,7 @@ def _get_class_friendly_name(self, node: Node) -> str:
213214
else:
214215
friendly_name = node.get_rel_path(self.top.parent)
215216

216-
return type(node.inst).__name__ + " - " + friendly_name
217+
return node.component_type_name + " - " + friendly_name
217218

218219

219220
def _get_inst_name(self, node: Node) -> str:
@@ -235,19 +236,12 @@ def _class_needs_definition(self, node: Node) -> bool:
235236
type_name = self._get_class_name(node)
236237

237238
if type_name in self.namespace_db:
238-
obj = self.namespace_db[type_name]
239-
240-
# Sanity-check for collisions
241-
if (obj is None) or (obj is not node.original_def):
242-
raise RuntimeError("Namespace collision! Type-name generation is not robust enough to create unique names!")
243-
244-
# This object likely represents the existing class definition
245239
# Ok to omit the re-definition
246240
return False
247241

248242
# Need to emit a new definition
249243
# First, register it in the namespace
250-
self.namespace_db[type_name] = node.original_def
244+
self.namespace_db.add(type_name)
251245
return True
252246

253247

test/pylint.rc

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ load-plugins=
5050
# Pickle collected data for later comparisons.
5151
persistent=yes
5252

53-
# When enabled, pylint would attempt to guess common misconfiguration and emit
54-
# user-friendly hints instead of false-positive error messages.
55-
suggestion-mode=yes
56-
5753
# Allow loading of arbitrary C extensions. Extensions are imported into the
5854
# active Python interpreter and may run arbitrary code.
5955
unsafe-load-any-extension=no
@@ -98,9 +94,6 @@ disable=
9894
abstract-method,
9995
protected-access,
10096
duplicate-code,
101-
cyclic-import,
102-
103-
# Can't do until py35 support is dropped
10497
consider-using-f-string
10598

10699
# Enable the message, report, category or checker with the given id(s). You can
@@ -144,7 +137,7 @@ max-nested-blocks=5
144137
# inconsistent-return-statements if a never returning function is called then
145138
# it will be considered as an explicit return statement and no message will be
146139
# printed.
147-
never-returning-functions=sys.exit
140+
never-returning-functions=sys.exit,argparse.parse_error
148141

149142

150143
[STRING]
@@ -494,7 +487,7 @@ valid-metaclass-classmethod-first-arg=cls
494487
ignored-parents=
495488

496489
# Maximum number of arguments for function / method.
497-
max-args=8
490+
max-args=16
498491

499492
# Maximum number of attributes for a class (see R0902).
500493
max-attributes=7
@@ -569,5 +562,5 @@ preferred-modules=
569562

570563
# Exceptions that will emit a warning when being caught. Defaults to
571564
# "BaseException, Exception".
572-
overgeneral-exceptions=BaseException,
573-
Exception
565+
overgeneral-exceptions=builtin.BaseException,
566+
builtin.Exception

test/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pylint

test/run.sh

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,34 @@
22

33
set -e
44

5-
this_dir="$( cd "$(dirname "$0")" ; pwd -P )"
5+
cd "$(dirname "$0")"
66

77
exists () {
88
type "$1" >/dev/null 2>/dev/null
99
}
1010

1111
# Initialize venv
12-
venv_bin=$this_dir/.venv/bin
13-
python3 -m venv $this_dir/.venv
14-
15-
#tools
16-
python=$venv_bin/python
17-
pylint=$venv_bin/pylint
12+
#rm -rf .venv
13+
python3.13 -m venv .venv
14+
source .venv/bin/activate
1815

1916

2017
# Install test dependencies
21-
$python -m pip install -U pylint setuptools pip
18+
pip install -r requirements.txt
2219

2320

2421
# Install dut
25-
cd $this_dir/..
26-
$python setup.py install
27-
cd $this_dir
22+
pip install -e "../[cli]"
2823

24+
# Run lint
25+
pylint --rcfile pylint.rc ../src/peakrdl_uvm
2926

3027
# Generate testcase verilog files
31-
$python generate_testcase_data.py basic testcases/basic.rdl
32-
28+
python generate_testcase_data.py basic testcases/basic.rdl
3329

3430
# Run modelsim testcases
3531
if exists vsim; then
3632
./vsim_test.sh testcases/basic_uvm_nofac_reuse_pkg.sv testcases/basic_test.sv
3733
./vsim_test.sh testcases/basic_uvm_fac_reuse_pkg.sv testcases/basic_test.sv
3834
./vsim_test.sh testcases/basic_uvm_nofac_noreuse_pkg.sv testcases/basic_test.sv
3935
fi
40-
41-
42-
# Run lint
43-
$pylint --rcfile $this_dir/pylint.rc ../src/peakrdl_uvm | tee $this_dir/lint.rpt

0 commit comments

Comments
 (0)