librelane 2.4.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of librelane might be problematic. Click here for more details.
- librelane/__init__.py +38 -0
- librelane/__main__.py +470 -0
- librelane/__version__.py +43 -0
- librelane/common/__init__.py +61 -0
- librelane/common/cli.py +75 -0
- librelane/common/drc.py +245 -0
- librelane/common/generic_dict.py +319 -0
- librelane/common/metrics/__init__.py +35 -0
- librelane/common/metrics/__main__.py +413 -0
- librelane/common/metrics/library.py +354 -0
- librelane/common/metrics/metric.py +186 -0
- librelane/common/metrics/util.py +279 -0
- librelane/common/misc.py +402 -0
- librelane/common/ring_buffer.py +63 -0
- librelane/common/tcl.py +80 -0
- librelane/common/toolbox.py +549 -0
- librelane/common/tpe.py +41 -0
- librelane/common/types.py +117 -0
- librelane/config/__init__.py +32 -0
- librelane/config/__main__.py +158 -0
- librelane/config/config.py +1025 -0
- librelane/config/flow.py +490 -0
- librelane/config/pdk_compat.py +255 -0
- librelane/config/preprocessor.py +464 -0
- librelane/config/removals.py +45 -0
- librelane/config/variable.py +722 -0
- librelane/container.py +264 -0
- librelane/env_info.py +306 -0
- librelane/examples/spm/config.yaml +33 -0
- librelane/examples/spm/pin_order.cfg +14 -0
- librelane/examples/spm/src/impl.sdc +73 -0
- librelane/examples/spm/src/signoff.sdc +68 -0
- librelane/examples/spm/src/spm.v +73 -0
- librelane/examples/spm/verify/spm_tb.v +106 -0
- librelane/examples/spm-user_project_wrapper/SPM_example.v +286 -0
- librelane/examples/spm-user_project_wrapper/base_sdc_file.sdc +145 -0
- librelane/examples/spm-user_project_wrapper/config-tut.json +12 -0
- librelane/examples/spm-user_project_wrapper/config.json +13 -0
- librelane/examples/spm-user_project_wrapper/defines.v +66 -0
- librelane/examples/spm-user_project_wrapper/template.def +7656 -0
- librelane/examples/spm-user_project_wrapper/user_project_wrapper.v +123 -0
- librelane/flows/__init__.py +24 -0
- librelane/flows/builtins.py +18 -0
- librelane/flows/classic.py +330 -0
- librelane/flows/cli.py +463 -0
- librelane/flows/flow.py +985 -0
- librelane/flows/misc.py +71 -0
- librelane/flows/optimizing.py +179 -0
- librelane/flows/sequential.py +367 -0
- librelane/flows/synth_explore.py +173 -0
- librelane/logging/__init__.py +40 -0
- librelane/logging/logger.py +323 -0
- librelane/open_pdks_rev +1 -0
- librelane/plugins.py +21 -0
- librelane/py.typed +0 -0
- librelane/scripts/base.sdc +80 -0
- librelane/scripts/klayout/Readme.md +2 -0
- librelane/scripts/klayout/open_design.py +63 -0
- librelane/scripts/klayout/render.py +121 -0
- librelane/scripts/klayout/stream_out.py +176 -0
- librelane/scripts/klayout/xml_drc_report_to_json.py +45 -0
- librelane/scripts/klayout/xor.drc +120 -0
- librelane/scripts/magic/Readme.md +1 -0
- librelane/scripts/magic/common/read.tcl +114 -0
- librelane/scripts/magic/def/antenna_check.tcl +35 -0
- librelane/scripts/magic/def/mag.tcl +19 -0
- librelane/scripts/magic/def/mag_gds.tcl +81 -0
- librelane/scripts/magic/drc.tcl +79 -0
- librelane/scripts/magic/extract_spice.tcl +98 -0
- librelane/scripts/magic/gds/drc_batch.tcl +74 -0
- librelane/scripts/magic/gds/erase_box.tcl +32 -0
- librelane/scripts/magic/gds/extras_mag.tcl +47 -0
- librelane/scripts/magic/gds/mag_with_pointers.tcl +32 -0
- librelane/scripts/magic/get_bbox.tcl +11 -0
- librelane/scripts/magic/lef/extras_maglef.tcl +63 -0
- librelane/scripts/magic/lef/maglef.tcl +27 -0
- librelane/scripts/magic/lef.tcl +57 -0
- librelane/scripts/magic/open.tcl +28 -0
- librelane/scripts/magic/wrapper.tcl +19 -0
- librelane/scripts/netgen/setup.tcl +28 -0
- librelane/scripts/odbpy/apply_def_template.py +49 -0
- librelane/scripts/odbpy/cell_frequency.py +107 -0
- librelane/scripts/odbpy/check_antenna_properties.py +116 -0
- librelane/scripts/odbpy/contextualize.py +109 -0
- librelane/scripts/odbpy/defutil.py +574 -0
- librelane/scripts/odbpy/diodes.py +373 -0
- librelane/scripts/odbpy/disconnected_pins.py +305 -0
- librelane/scripts/odbpy/exception_codes.py +17 -0
- librelane/scripts/odbpy/filter_unannotated.py +100 -0
- librelane/scripts/odbpy/io_place.py +482 -0
- librelane/scripts/odbpy/label_macro_pins.py +277 -0
- librelane/scripts/odbpy/lefutil.py +97 -0
- librelane/scripts/odbpy/placers.py +162 -0
- librelane/scripts/odbpy/power_utils.py +395 -0
- librelane/scripts/odbpy/random_place.py +57 -0
- librelane/scripts/odbpy/reader.py +246 -0
- librelane/scripts/odbpy/remove_buffers.py +173 -0
- librelane/scripts/odbpy/snap_to_grid.py +57 -0
- librelane/scripts/odbpy/wire_lengths.py +93 -0
- librelane/scripts/openroad/antenna_check.tcl +20 -0
- librelane/scripts/openroad/antenna_repair.tcl +31 -0
- librelane/scripts/openroad/basic_mp.tcl +24 -0
- librelane/scripts/openroad/buffer_list.tcl +10 -0
- librelane/scripts/openroad/common/dpl.tcl +24 -0
- librelane/scripts/openroad/common/dpl_cell_pad.tcl +26 -0
- librelane/scripts/openroad/common/grt.tcl +32 -0
- librelane/scripts/openroad/common/io.tcl +476 -0
- librelane/scripts/openroad/common/pdn_cfg.tcl +135 -0
- librelane/scripts/openroad/common/resizer.tcl +103 -0
- librelane/scripts/openroad/common/set_global_connections.tcl +78 -0
- librelane/scripts/openroad/common/set_layer_adjustments.tcl +31 -0
- librelane/scripts/openroad/common/set_power_nets.tcl +30 -0
- librelane/scripts/openroad/common/set_rc.tcl +75 -0
- librelane/scripts/openroad/common/set_routing_layers.tcl +30 -0
- librelane/scripts/openroad/cts.tcl +80 -0
- librelane/scripts/openroad/cut_rows.tcl +24 -0
- librelane/scripts/openroad/dpl.tcl +24 -0
- librelane/scripts/openroad/drt.tcl +37 -0
- librelane/scripts/openroad/fill.tcl +30 -0
- librelane/scripts/openroad/floorplan.tcl +145 -0
- librelane/scripts/openroad/gpl.tcl +88 -0
- librelane/scripts/openroad/grt.tcl +30 -0
- librelane/scripts/openroad/gui.tcl +15 -0
- librelane/scripts/openroad/insert_buffer.tcl +127 -0
- librelane/scripts/openroad/ioplacer.tcl +67 -0
- librelane/scripts/openroad/irdrop.tcl +51 -0
- librelane/scripts/openroad/pdn.tcl +52 -0
- librelane/scripts/openroad/rcx.tcl +32 -0
- librelane/scripts/openroad/repair_design.tcl +70 -0
- librelane/scripts/openroad/repair_design_postgrt.tcl +48 -0
- librelane/scripts/openroad/rsz_timing_postcts.tcl +68 -0
- librelane/scripts/openroad/rsz_timing_postgrt.tcl +70 -0
- librelane/scripts/openroad/sta/check_macro_instances.tcl +53 -0
- librelane/scripts/openroad/sta/corner.tcl +393 -0
- librelane/scripts/openroad/tapcell.tcl +25 -0
- librelane/scripts/openroad/write_views.tcl +27 -0
- librelane/scripts/pyosys/construct_abc_script.py +177 -0
- librelane/scripts/pyosys/json_header.py +84 -0
- librelane/scripts/pyosys/synthesize.py +493 -0
- librelane/scripts/pyosys/ys_common.py +153 -0
- librelane/scripts/tclsh/hello.tcl +1 -0
- librelane/state/__init__.py +24 -0
- librelane/state/__main__.py +61 -0
- librelane/state/design_format.py +180 -0
- librelane/state/state.py +351 -0
- librelane/steps/__init__.py +61 -0
- librelane/steps/__main__.py +511 -0
- librelane/steps/checker.py +637 -0
- librelane/steps/common_variables.py +340 -0
- librelane/steps/cvc_rv.py +169 -0
- librelane/steps/klayout.py +509 -0
- librelane/steps/magic.py +566 -0
- librelane/steps/misc.py +160 -0
- librelane/steps/netgen.py +253 -0
- librelane/steps/odb.py +955 -0
- librelane/steps/openroad.py +2433 -0
- librelane/steps/openroad_alerts.py +102 -0
- librelane/steps/pyosys.py +629 -0
- librelane/steps/step.py +1547 -0
- librelane/steps/tclstep.py +288 -0
- librelane/steps/verilator.py +222 -0
- librelane/steps/yosys.py +371 -0
- librelane-2.4.0.dev0.dist-info/METADATA +151 -0
- librelane-2.4.0.dev0.dist-info/RECORD +166 -0
- librelane-2.4.0.dev0.dist-info/WHEEL +4 -0
- librelane-2.4.0.dev0.dist-info/entry_points.txt +8 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
# Copyright 2023 Efabless Corporation
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import os
|
|
17
|
+
import threading
|
|
18
|
+
from enum import Enum
|
|
19
|
+
from decimal import Decimal
|
|
20
|
+
from abc import abstractmethod
|
|
21
|
+
from dataclasses import is_dataclass, asdict
|
|
22
|
+
from typing import (
|
|
23
|
+
Any,
|
|
24
|
+
ClassVar,
|
|
25
|
+
Iterable,
|
|
26
|
+
List,
|
|
27
|
+
Mapping,
|
|
28
|
+
Optional,
|
|
29
|
+
Sequence,
|
|
30
|
+
Tuple,
|
|
31
|
+
Dict,
|
|
32
|
+
Union,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
from .step import ViewsUpdate, MetricsUpdate, Step, StepException
|
|
36
|
+
|
|
37
|
+
from ..state import State, DesignFormat
|
|
38
|
+
from ..common import (
|
|
39
|
+
Path,
|
|
40
|
+
TclUtils,
|
|
41
|
+
get_script_dir,
|
|
42
|
+
protected,
|
|
43
|
+
is_string,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class TclStep(Step):
|
|
48
|
+
"""
|
|
49
|
+
A subclass of :class:`Step` that primarily deals with running Tcl-based utilities,
|
|
50
|
+
such as Yosys, OpenROAD and Magic.
|
|
51
|
+
|
|
52
|
+
A TclStep Step should ideally correspond to running one Tcl script with such
|
|
53
|
+
a utility.
|
|
54
|
+
|
|
55
|
+
:cvar reproducibles_allowed: Whether this class can generate reproducibles.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
reproducibles_allowed: ClassVar[bool] = True
|
|
59
|
+
|
|
60
|
+
@staticmethod
|
|
61
|
+
def value_to_tcl(value: Any) -> str:
|
|
62
|
+
"""
|
|
63
|
+
Converts an arbitrary Python value to Tcl as follows:
|
|
64
|
+
|
|
65
|
+
* If the value is an instance of a dataclass, it is serialized as a JSON object.
|
|
66
|
+
* If the value is a list, it is joined using :meth:`TclUtils.join`.
|
|
67
|
+
* If the value is a dict, the keys and values are escaped recursively using:
|
|
68
|
+
joined using :meth:`TclUtils.join`.
|
|
69
|
+
* If the value is an Enum, its name is returned.
|
|
70
|
+
* If the value is Boolean, "1" is returned for True and "0" for False.
|
|
71
|
+
* If the value is numeric, it is converted to a string.
|
|
72
|
+
* Otherwise, the value is passed to ``str()``.
|
|
73
|
+
"""
|
|
74
|
+
if not isinstance(value, type) and is_dataclass(value):
|
|
75
|
+
return TclStep.value_to_tcl(asdict(value))
|
|
76
|
+
elif isinstance(value, Mapping):
|
|
77
|
+
result = []
|
|
78
|
+
for v_key, v_value in value.items():
|
|
79
|
+
result.append(TclStep.value_to_tcl(v_key))
|
|
80
|
+
result.append(TclStep.value_to_tcl(v_value))
|
|
81
|
+
return TclUtils.join(result)
|
|
82
|
+
elif isinstance(value, Iterable) and not is_string(value):
|
|
83
|
+
result = []
|
|
84
|
+
for item in value:
|
|
85
|
+
result.append(TclStep.value_to_tcl(item))
|
|
86
|
+
return TclUtils.join(result)
|
|
87
|
+
elif isinstance(value, Enum):
|
|
88
|
+
return value.name
|
|
89
|
+
elif isinstance(value, bool):
|
|
90
|
+
return "1" if value else "0"
|
|
91
|
+
elif isinstance(value, Decimal) or isinstance(value, int):
|
|
92
|
+
return str(value)
|
|
93
|
+
else:
|
|
94
|
+
return str(value)
|
|
95
|
+
|
|
96
|
+
@protected
|
|
97
|
+
@abstractmethod
|
|
98
|
+
def get_script_path(self) -> str:
|
|
99
|
+
"""
|
|
100
|
+
:returns: A path to the Tcl script to be run by this step.
|
|
101
|
+
"""
|
|
102
|
+
pass
|
|
103
|
+
|
|
104
|
+
@protected
|
|
105
|
+
def get_command(self) -> List[str]:
|
|
106
|
+
"""
|
|
107
|
+
This command should be overridden by subclasses and replaced with a
|
|
108
|
+
command incorporating the appropriate tool: e.g. ``openroad``,
|
|
109
|
+
``yosys``, et cetera.
|
|
110
|
+
|
|
111
|
+
:returns: A list of strings representing the command used to run the script,
|
|
112
|
+
including the result of :meth:`get_script_path`.
|
|
113
|
+
"""
|
|
114
|
+
return ["tclsh", self.get_script_path()]
|
|
115
|
+
|
|
116
|
+
@protected
|
|
117
|
+
def prepare_env(self, env: dict, state: State) -> dict:
|
|
118
|
+
"""
|
|
119
|
+
Creates a copy of an environment dictionary, then converts all accessible
|
|
120
|
+
``self.config`` variables and state inputs to environment variables so
|
|
121
|
+
they may be used as inputs to the scripts.
|
|
122
|
+
|
|
123
|
+
Inputs are assigned the keys ``CURRENT_{ID}`` where ID is
|
|
124
|
+
the relevant :class:`DesignFormat`'s enum name.
|
|
125
|
+
|
|
126
|
+
Outputs are assigned the keys ``CURRENT_{ID}`` where ID is
|
|
127
|
+
the relevant :class:`DesignFormat`'s enum name, although outputs with
|
|
128
|
+
multiple values (SPEF, etc) will be skipped and a step is expected to
|
|
129
|
+
handle creating variables for them on its own.
|
|
130
|
+
|
|
131
|
+
The values are converted to strings as per :meth:`value_to_tcl`.
|
|
132
|
+
|
|
133
|
+
:param env: The input environment dictionary
|
|
134
|
+
:param state: The input state
|
|
135
|
+
:returns: a copy of the environment dictionary where ``self.config`` variables
|
|
136
|
+
"""
|
|
137
|
+
env = env.copy()
|
|
138
|
+
|
|
139
|
+
env["STEP_ID"] = self.get_implementation_id()
|
|
140
|
+
env["SCRIPTS_DIR"] = os.path.abspath(get_script_dir())
|
|
141
|
+
env["STEP_DIR"] = os.path.abspath(self.step_dir)
|
|
142
|
+
|
|
143
|
+
tech_lefs = self.toolbox.filter_views(self.config, self.config["TECH_LEFS"])
|
|
144
|
+
if len(tech_lefs) != 1:
|
|
145
|
+
raise StepException(
|
|
146
|
+
"Misconfigured SCL: 'TECH_LEFS' must return exactly one Tech LEF for its default timing corner."
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
env["TECH_LEF"] = tech_lefs[0]
|
|
150
|
+
|
|
151
|
+
macro_lefs = self.toolbox.get_macro_views(self.config, DesignFormat.LEF)
|
|
152
|
+
env["MACRO_LEFS"] = TclUtils.join([str(lef) for lef in macro_lefs])
|
|
153
|
+
|
|
154
|
+
for element in self.config.keys():
|
|
155
|
+
value = self.config[element]
|
|
156
|
+
if value is None:
|
|
157
|
+
continue
|
|
158
|
+
env[element] = TclStep.value_to_tcl(value)
|
|
159
|
+
|
|
160
|
+
for input in self.inputs:
|
|
161
|
+
key = f"CURRENT_{input.name}"
|
|
162
|
+
env[key] = TclStep.value_to_tcl(state[input])
|
|
163
|
+
|
|
164
|
+
for output in self.outputs:
|
|
165
|
+
if output.value.multiple:
|
|
166
|
+
# Too step-specific.
|
|
167
|
+
continue
|
|
168
|
+
filename = f"{self.config['DESIGN_NAME']}.{output.value.extension}"
|
|
169
|
+
env[f"SAVE_{output.name}"] = os.path.join(self.step_dir, filename)
|
|
170
|
+
|
|
171
|
+
return env
|
|
172
|
+
|
|
173
|
+
@protected
|
|
174
|
+
def run(self, state_in: State, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
|
|
175
|
+
"""
|
|
176
|
+
This overridden :meth:`run` function prepares configuration variables and
|
|
177
|
+
inputs for use with Tcl: specifically, it converts them all to
|
|
178
|
+
environment variables so they may be used by the Tcl scripts being called.
|
|
179
|
+
See :meth:`prepare_env` for more info.
|
|
180
|
+
|
|
181
|
+
Additionally, it logs the output to a ``.log`` file named after the script.
|
|
182
|
+
|
|
183
|
+
When overriding in a subclass, you may find it useful to use this pattern:
|
|
184
|
+
|
|
185
|
+
.. code-block:: python
|
|
186
|
+
|
|
187
|
+
kwargs, env = self.extract_env(kwargs)
|
|
188
|
+
env["CUSTOM_ENV_VARIABLE"] = "1"
|
|
189
|
+
return super().run(state_in, env=env, **kwargs)
|
|
190
|
+
|
|
191
|
+
This will allow you to add further custom environment variables to a call
|
|
192
|
+
while still respecting an ``env`` argument further up the call-stack.
|
|
193
|
+
|
|
194
|
+
:param state_in: See superclass.
|
|
195
|
+
:param \\*\\*kwargs: Passed on to subprocess execution: useful if you want to
|
|
196
|
+
redirect stdin, stdout, etc.
|
|
197
|
+
:returns: see superclass
|
|
198
|
+
"""
|
|
199
|
+
command = self.get_command()
|
|
200
|
+
|
|
201
|
+
kwargs, env = self.extract_env(kwargs)
|
|
202
|
+
|
|
203
|
+
env = self.prepare_env(env, state_in)
|
|
204
|
+
|
|
205
|
+
subprocess_result = self.run_subprocess(
|
|
206
|
+
command,
|
|
207
|
+
env=env,
|
|
208
|
+
**kwargs,
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
overrides: ViewsUpdate = {}
|
|
212
|
+
for output in self.outputs:
|
|
213
|
+
if output.value.multiple:
|
|
214
|
+
# Too step-specific.
|
|
215
|
+
continue
|
|
216
|
+
path = Path(env[f"SAVE_{output.name}"])
|
|
217
|
+
if not path.exists():
|
|
218
|
+
continue
|
|
219
|
+
overrides[output] = path
|
|
220
|
+
|
|
221
|
+
return overrides, subprocess_result["generated_metrics"]
|
|
222
|
+
|
|
223
|
+
def _reroute_env(
|
|
224
|
+
self,
|
|
225
|
+
env: Dict[str, str],
|
|
226
|
+
report_dir: Optional[Union[str, os.PathLike]] = None,
|
|
227
|
+
):
|
|
228
|
+
thread_postfix = f"_{threading.current_thread().name}"
|
|
229
|
+
if threading.current_thread() is threading.main_thread():
|
|
230
|
+
thread_postfix = ""
|
|
231
|
+
|
|
232
|
+
env_in_dir = report_dir or self.step_dir
|
|
233
|
+
env_in_file = os.path.join(env_in_dir, f"_env{thread_postfix}.tcl")
|
|
234
|
+
|
|
235
|
+
ENV_ALLOWLIST = [
|
|
236
|
+
"PATH",
|
|
237
|
+
"PYTHONPATH",
|
|
238
|
+
"SCRIPTS_DIR",
|
|
239
|
+
"DESIGN_DIR",
|
|
240
|
+
"STEP_DIR",
|
|
241
|
+
"PDK_ROOT",
|
|
242
|
+
"PDK",
|
|
243
|
+
"_TCL_ENV_IN",
|
|
244
|
+
]
|
|
245
|
+
env_in: List[Tuple[str, str]] = list(env.items())
|
|
246
|
+
|
|
247
|
+
# Create new "blank" env dict
|
|
248
|
+
#
|
|
249
|
+
# For all values:
|
|
250
|
+
# If a value is unchanged: keep as is
|
|
251
|
+
# If a value is changed and is in ENV_ALLOWLIST: emplace in dict
|
|
252
|
+
# If a value is changed and is not in ENV_ALLOWLIST: write to file
|
|
253
|
+
#
|
|
254
|
+
# Emplace file to be sourced in dict with key ``_TCL_ENV_IN``
|
|
255
|
+
env = os.environ.copy()
|
|
256
|
+
with open(env_in_file, "a+") as f:
|
|
257
|
+
for key, value in env_in:
|
|
258
|
+
if key in env and env[key] == value:
|
|
259
|
+
continue
|
|
260
|
+
if key in ENV_ALLOWLIST or key.startswith("_"):
|
|
261
|
+
env[key] = value
|
|
262
|
+
else:
|
|
263
|
+
f.write(
|
|
264
|
+
f"set ::env({key}) {TclUtils.escape(TclStep.value_to_tcl(value))}\n"
|
|
265
|
+
)
|
|
266
|
+
env["_TCL_ENV_IN"] = env_in_file
|
|
267
|
+
return env
|
|
268
|
+
|
|
269
|
+
@protected
|
|
270
|
+
def run_subprocess(
|
|
271
|
+
self,
|
|
272
|
+
cmd: Sequence[Union[str, os.PathLike]],
|
|
273
|
+
log_to: Optional[Union[str, os.PathLike]] = None,
|
|
274
|
+
silent: bool = False,
|
|
275
|
+
report_dir: Optional[Union[str, os.PathLike]] = None,
|
|
276
|
+
env: Optional[Dict[str, str]] = None,
|
|
277
|
+
**kwargs,
|
|
278
|
+
) -> Dict[str, Any]:
|
|
279
|
+
if env is not None:
|
|
280
|
+
env = self._reroute_env(env, report_dir=report_dir)
|
|
281
|
+
return super().run_subprocess(
|
|
282
|
+
cmd=cmd,
|
|
283
|
+
log_to=log_to,
|
|
284
|
+
silent=silent,
|
|
285
|
+
report_dir=report_dir,
|
|
286
|
+
env=env,
|
|
287
|
+
**kwargs,
|
|
288
|
+
)
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# Copyright 2023 Efabless Corporation
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
import os
|
|
15
|
+
import re
|
|
16
|
+
from typing import List, Optional, Set, Tuple
|
|
17
|
+
|
|
18
|
+
from .step import Step, StepException, ViewsUpdate, MetricsUpdate
|
|
19
|
+
from ..config import Variable
|
|
20
|
+
from ..state import DesignFormat, State
|
|
21
|
+
from ..common import Path
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@Step.factory.register()
|
|
25
|
+
class Lint(Step):
|
|
26
|
+
"""
|
|
27
|
+
Lints inputs RTL Verilog files.
|
|
28
|
+
|
|
29
|
+
The linting is done with the defines for power and ground inputs on, as more
|
|
30
|
+
macros are available with powered netlists than unpowered netlists.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
id = "Verilator.Lint"
|
|
34
|
+
name = "Verilator Lint"
|
|
35
|
+
long_name = "Verilator Lint"
|
|
36
|
+
inputs = [] # The input RTL is part of the configuration
|
|
37
|
+
outputs = []
|
|
38
|
+
|
|
39
|
+
config_vars = [
|
|
40
|
+
Variable(
|
|
41
|
+
"VERILOG_FILES",
|
|
42
|
+
List[Path],
|
|
43
|
+
"The paths of the design's Verilog files.",
|
|
44
|
+
),
|
|
45
|
+
Variable(
|
|
46
|
+
"VERILOG_INCLUDE_DIRS",
|
|
47
|
+
Optional[List[Path]],
|
|
48
|
+
"Specifies the Verilog `include` directories.",
|
|
49
|
+
),
|
|
50
|
+
Variable(
|
|
51
|
+
"VERILOG_POWER_DEFINE",
|
|
52
|
+
Optional[str],
|
|
53
|
+
"Specifies the name of the define used to guard power and ground connections in the input RTL.",
|
|
54
|
+
deprecated_names=["SYNTH_USE_PG_PINS_DEFINES", "SYNTH_POWER_DEFINE"],
|
|
55
|
+
default="USE_POWER_PINS",
|
|
56
|
+
),
|
|
57
|
+
Variable(
|
|
58
|
+
"LINTER_INCLUDE_PDK_MODELS",
|
|
59
|
+
bool,
|
|
60
|
+
"Include Verilog models of the PDK",
|
|
61
|
+
default=False,
|
|
62
|
+
),
|
|
63
|
+
Variable(
|
|
64
|
+
"LINTER_RELATIVE_INCLUDES",
|
|
65
|
+
bool,
|
|
66
|
+
"When a file references an include file, resolve the filename relative to the path of the referencing file, instead of relative to the current directory.",
|
|
67
|
+
default=True,
|
|
68
|
+
deprecated_names=["VERILATOR_RELATIVE_INCLUDES"],
|
|
69
|
+
),
|
|
70
|
+
Variable(
|
|
71
|
+
"LINTER_ERROR_ON_LATCH",
|
|
72
|
+
bool,
|
|
73
|
+
"When a latch is inferred by an `always` block that is not explicitly marked as `always_latch`, report this as a linter error.",
|
|
74
|
+
default=True,
|
|
75
|
+
),
|
|
76
|
+
Variable(
|
|
77
|
+
"VERILOG_DEFINES",
|
|
78
|
+
Optional[List[str]],
|
|
79
|
+
"Preprocessor defines for input Verilog files",
|
|
80
|
+
deprecated_names=["SYNTH_DEFINES"],
|
|
81
|
+
),
|
|
82
|
+
Variable(
|
|
83
|
+
"LINTER_DEFINES",
|
|
84
|
+
Optional[List[str]],
|
|
85
|
+
"Linter-specific preprocessor definitions; overrides VERILOG_DEFINES for the lint step if exists",
|
|
86
|
+
),
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
def run(self, state_in: State, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
|
|
90
|
+
kwargs, env = self.extract_env(kwargs)
|
|
91
|
+
views_updates: ViewsUpdate = {}
|
|
92
|
+
metrics_updates: MetricsUpdate = {}
|
|
93
|
+
extra_args = []
|
|
94
|
+
|
|
95
|
+
blackboxes = []
|
|
96
|
+
|
|
97
|
+
model_list: List[str] = []
|
|
98
|
+
model_set: Set[str] = set()
|
|
99
|
+
|
|
100
|
+
if cell_verilog_models := self.config["CELL_VERILOG_MODELS"]:
|
|
101
|
+
blackboxes.append(
|
|
102
|
+
self.toolbox.create_blackbox_model(
|
|
103
|
+
frozenset(cell_verilog_models),
|
|
104
|
+
frozenset(["USE_POWER_PINS"]),
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
macro_views = self.toolbox.get_macro_views_by_priority(
|
|
109
|
+
self.config,
|
|
110
|
+
[
|
|
111
|
+
DesignFormat.VERILOG_HEADER,
|
|
112
|
+
DesignFormat.POWERED_NETLIST,
|
|
113
|
+
DesignFormat.NETLIST,
|
|
114
|
+
],
|
|
115
|
+
)
|
|
116
|
+
for view, format in macro_views:
|
|
117
|
+
if format == DesignFormat.VERILOG_HEADER:
|
|
118
|
+
blackboxes.append(str(view))
|
|
119
|
+
else:
|
|
120
|
+
str_view = str(view)
|
|
121
|
+
if str_view not in model_set:
|
|
122
|
+
model_set.add(str_view)
|
|
123
|
+
model_list.append(str_view)
|
|
124
|
+
|
|
125
|
+
if extra_verilog_models := self.config["EXTRA_VERILOG_MODELS"]:
|
|
126
|
+
for model in extra_verilog_models:
|
|
127
|
+
str_model = str(model)
|
|
128
|
+
if str_model not in model_set:
|
|
129
|
+
model_set.add(str_model)
|
|
130
|
+
model_list.append(str_model)
|
|
131
|
+
defines = [
|
|
132
|
+
f"PDK_{self.config['PDK']}",
|
|
133
|
+
f"SCL_{self.config['STD_CELL_LIBRARY']}",
|
|
134
|
+
"__librelane__",
|
|
135
|
+
"__pnr__",
|
|
136
|
+
]
|
|
137
|
+
if verilog_power_define := self.config.get("VERILOG_POWER_DEFINE"):
|
|
138
|
+
defines += [verilog_power_define]
|
|
139
|
+
|
|
140
|
+
defines += self.config["LINTER_DEFINES"] or self.config["VERILOG_DEFINES"] or []
|
|
141
|
+
|
|
142
|
+
if len(model_list):
|
|
143
|
+
bb_path = self.toolbox.create_blackbox_model(
|
|
144
|
+
tuple(model_list),
|
|
145
|
+
frozenset(defines),
|
|
146
|
+
)
|
|
147
|
+
blackboxes.append(bb_path)
|
|
148
|
+
|
|
149
|
+
vlt_file = os.path.join(self.step_dir, "_deps.vlt")
|
|
150
|
+
with open(vlt_file, "w") as f:
|
|
151
|
+
f.write("`verilator_config\n")
|
|
152
|
+
f.write("lint_off -rule DECLFILENAME\n")
|
|
153
|
+
f.write("lint_off -rule EOFNEWLINE\n")
|
|
154
|
+
for blackbox in blackboxes:
|
|
155
|
+
f.write(f'lint_off -rule UNDRIVEN -file "{blackbox}"\n')
|
|
156
|
+
f.write(f'lint_off -rule UNUSEDSIGNAL -file "{blackbox}"\n')
|
|
157
|
+
|
|
158
|
+
extra_args.append("--Wno-fatal")
|
|
159
|
+
|
|
160
|
+
if self.config["LINTER_RELATIVE_INCLUDES"]:
|
|
161
|
+
extra_args.append("--relative-includes")
|
|
162
|
+
|
|
163
|
+
if self.config["LINTER_ERROR_ON_LATCH"]:
|
|
164
|
+
extra_args.append("--Werror-LATCH")
|
|
165
|
+
|
|
166
|
+
if include_dirs := self.config["VERILOG_INCLUDE_DIRS"]:
|
|
167
|
+
extra_args.extend([f"-I{dir}" for dir in include_dirs])
|
|
168
|
+
|
|
169
|
+
for define in defines:
|
|
170
|
+
extra_args.append(f"+define+{define}")
|
|
171
|
+
|
|
172
|
+
result = self.run_subprocess(
|
|
173
|
+
[
|
|
174
|
+
"verilator",
|
|
175
|
+
"--lint-only",
|
|
176
|
+
"--Wall",
|
|
177
|
+
"--Wno-DECLFILENAME",
|
|
178
|
+
"--Wno-EOFNEWLINE",
|
|
179
|
+
"--top-module",
|
|
180
|
+
self.config["DESIGN_NAME"],
|
|
181
|
+
vlt_file,
|
|
182
|
+
]
|
|
183
|
+
+ blackboxes
|
|
184
|
+
+ self.config["VERILOG_FILES"]
|
|
185
|
+
+ extra_args,
|
|
186
|
+
env=env,
|
|
187
|
+
check=False,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
warnings_count = 0
|
|
191
|
+
errors_count = 0
|
|
192
|
+
latch_count = 0
|
|
193
|
+
timing_constructs = 0
|
|
194
|
+
|
|
195
|
+
exiting_rx = re.compile(r"^\s*%Error: Exiting due to (\d+) error\(s\)")
|
|
196
|
+
with open(self.get_log_path(), "r", encoding="utf8") as f:
|
|
197
|
+
for line in f:
|
|
198
|
+
line = line.strip()
|
|
199
|
+
if r"%Warning-" in line:
|
|
200
|
+
warnings_count += 1
|
|
201
|
+
if r"%Error-LATCH" in line or r"%Warning-LATCH" in line:
|
|
202
|
+
latch_count += 1
|
|
203
|
+
if r"%Error-NEEDTIMINGOPT" in line:
|
|
204
|
+
timing_constructs += 1
|
|
205
|
+
if match := exiting_rx.search(line):
|
|
206
|
+
errors_count = int(match[1])
|
|
207
|
+
|
|
208
|
+
if result["returncode"] != 0 and errors_count == 0:
|
|
209
|
+
raise StepException(
|
|
210
|
+
f"Verilator exited unexpectedly with return code {result['returncode']}"
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
metrics_updates.update({"design__lint_error__count": errors_count})
|
|
214
|
+
metrics_updates.update(
|
|
215
|
+
{"design__lint_timing_construct__count": timing_constructs}
|
|
216
|
+
)
|
|
217
|
+
metrics_updates.update({"design__lint_warning__count": warnings_count})
|
|
218
|
+
metrics_updates.update({"design__inferred_latch__count": latch_count})
|
|
219
|
+
return views_updates, metrics_updates
|
|
220
|
+
|
|
221
|
+
def layout_preview(self) -> Optional[str]:
|
|
222
|
+
return None
|