librelane 2.4.0__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.

Files changed (170) hide show
  1. librelane/__init__.py +38 -0
  2. librelane/__main__.py +479 -0
  3. librelane/__version__.py +43 -0
  4. librelane/common/__init__.py +63 -0
  5. librelane/common/cli.py +75 -0
  6. librelane/common/drc.py +246 -0
  7. librelane/common/generic_dict.py +319 -0
  8. librelane/common/metrics/__init__.py +35 -0
  9. librelane/common/metrics/__main__.py +413 -0
  10. librelane/common/metrics/library.py +354 -0
  11. librelane/common/metrics/metric.py +186 -0
  12. librelane/common/metrics/util.py +279 -0
  13. librelane/common/misc.py +456 -0
  14. librelane/common/ring_buffer.py +63 -0
  15. librelane/common/tcl.py +80 -0
  16. librelane/common/toolbox.py +549 -0
  17. librelane/common/tpe.py +41 -0
  18. librelane/common/types.py +116 -0
  19. librelane/config/__init__.py +32 -0
  20. librelane/config/__main__.py +155 -0
  21. librelane/config/config.py +1025 -0
  22. librelane/config/flow.py +490 -0
  23. librelane/config/pdk_compat.py +255 -0
  24. librelane/config/preprocessor.py +464 -0
  25. librelane/config/removals.py +45 -0
  26. librelane/config/variable.py +743 -0
  27. librelane/container.py +285 -0
  28. librelane/env_info.py +320 -0
  29. librelane/examples/spm/config.yaml +33 -0
  30. librelane/examples/spm/pin_order.cfg +14 -0
  31. librelane/examples/spm/src/impl.sdc +73 -0
  32. librelane/examples/spm/src/signoff.sdc +68 -0
  33. librelane/examples/spm/src/spm.v +73 -0
  34. librelane/examples/spm/verify/spm_tb.v +106 -0
  35. librelane/examples/spm-user_project_wrapper/SPM_example.v +286 -0
  36. librelane/examples/spm-user_project_wrapper/base_sdc_file.sdc +145 -0
  37. librelane/examples/spm-user_project_wrapper/config-tut.json +12 -0
  38. librelane/examples/spm-user_project_wrapper/config.json +13 -0
  39. librelane/examples/spm-user_project_wrapper/defines.v +66 -0
  40. librelane/examples/spm-user_project_wrapper/template.def +7656 -0
  41. librelane/examples/spm-user_project_wrapper/user_project_wrapper.v +123 -0
  42. librelane/flows/__init__.py +24 -0
  43. librelane/flows/builtins.py +18 -0
  44. librelane/flows/classic.py +327 -0
  45. librelane/flows/cli.py +463 -0
  46. librelane/flows/flow.py +1049 -0
  47. librelane/flows/misc.py +71 -0
  48. librelane/flows/optimizing.py +179 -0
  49. librelane/flows/sequential.py +367 -0
  50. librelane/flows/synth_explore.py +173 -0
  51. librelane/help/__main__.py +39 -0
  52. librelane/logging/__init__.py +40 -0
  53. librelane/logging/logger.py +323 -0
  54. librelane/open_pdks_rev +1 -0
  55. librelane/plugins.py +21 -0
  56. librelane/py.typed +0 -0
  57. librelane/scripts/base.sdc +80 -0
  58. librelane/scripts/klayout/Readme.md +2 -0
  59. librelane/scripts/klayout/open_design.py +63 -0
  60. librelane/scripts/klayout/render.py +121 -0
  61. librelane/scripts/klayout/stream_out.py +176 -0
  62. librelane/scripts/klayout/xml_drc_report_to_json.py +45 -0
  63. librelane/scripts/klayout/xor.drc +120 -0
  64. librelane/scripts/magic/Readme.md +1 -0
  65. librelane/scripts/magic/common/read.tcl +114 -0
  66. librelane/scripts/magic/def/antenna_check.tcl +35 -0
  67. librelane/scripts/magic/def/mag.tcl +19 -0
  68. librelane/scripts/magic/def/mag_gds.tcl +79 -0
  69. librelane/scripts/magic/drc.tcl +78 -0
  70. librelane/scripts/magic/extract_spice.tcl +98 -0
  71. librelane/scripts/magic/gds/drc_batch.tcl +74 -0
  72. librelane/scripts/magic/gds/erase_box.tcl +32 -0
  73. librelane/scripts/magic/gds/extras_mag.tcl +45 -0
  74. librelane/scripts/magic/gds/mag_with_pointers.tcl +31 -0
  75. librelane/scripts/magic/get_bbox.tcl +11 -0
  76. librelane/scripts/magic/lef/extras_maglef.tcl +61 -0
  77. librelane/scripts/magic/lef/maglef.tcl +26 -0
  78. librelane/scripts/magic/lef.tcl +57 -0
  79. librelane/scripts/magic/open.tcl +28 -0
  80. librelane/scripts/magic/wrapper.tcl +21 -0
  81. librelane/scripts/netgen/setup.tcl +28 -0
  82. librelane/scripts/odbpy/apply_def_template.py +49 -0
  83. librelane/scripts/odbpy/cell_frequency.py +107 -0
  84. librelane/scripts/odbpy/check_antenna_properties.py +116 -0
  85. librelane/scripts/odbpy/contextualize.py +109 -0
  86. librelane/scripts/odbpy/defutil.py +573 -0
  87. librelane/scripts/odbpy/diodes.py +373 -0
  88. librelane/scripts/odbpy/disconnected_pins.py +305 -0
  89. librelane/scripts/odbpy/eco_buffer.py +181 -0
  90. librelane/scripts/odbpy/eco_diode.py +139 -0
  91. librelane/scripts/odbpy/filter_unannotated.py +100 -0
  92. librelane/scripts/odbpy/io_place.py +482 -0
  93. librelane/scripts/odbpy/ioplace_parser/__init__.py +23 -0
  94. librelane/scripts/odbpy/ioplace_parser/parse.py +147 -0
  95. librelane/scripts/odbpy/label_macro_pins.py +277 -0
  96. librelane/scripts/odbpy/lefutil.py +97 -0
  97. librelane/scripts/odbpy/placers.py +162 -0
  98. librelane/scripts/odbpy/power_utils.py +397 -0
  99. librelane/scripts/odbpy/random_place.py +57 -0
  100. librelane/scripts/odbpy/reader.py +250 -0
  101. librelane/scripts/odbpy/remove_buffers.py +173 -0
  102. librelane/scripts/odbpy/snap_to_grid.py +57 -0
  103. librelane/scripts/odbpy/wire_lengths.py +93 -0
  104. librelane/scripts/openroad/antenna_check.tcl +20 -0
  105. librelane/scripts/openroad/antenna_repair.tcl +31 -0
  106. librelane/scripts/openroad/basic_mp.tcl +24 -0
  107. librelane/scripts/openroad/buffer_list.tcl +10 -0
  108. librelane/scripts/openroad/common/dpl.tcl +24 -0
  109. librelane/scripts/openroad/common/dpl_cell_pad.tcl +26 -0
  110. librelane/scripts/openroad/common/grt.tcl +32 -0
  111. librelane/scripts/openroad/common/io.tcl +540 -0
  112. librelane/scripts/openroad/common/pdn_cfg.tcl +135 -0
  113. librelane/scripts/openroad/common/resizer.tcl +103 -0
  114. librelane/scripts/openroad/common/set_global_connections.tcl +78 -0
  115. librelane/scripts/openroad/common/set_layer_adjustments.tcl +31 -0
  116. librelane/scripts/openroad/common/set_power_nets.tcl +30 -0
  117. librelane/scripts/openroad/common/set_rc.tcl +75 -0
  118. librelane/scripts/openroad/common/set_routing_layers.tcl +30 -0
  119. librelane/scripts/openroad/cts.tcl +80 -0
  120. librelane/scripts/openroad/cut_rows.tcl +24 -0
  121. librelane/scripts/openroad/dpl.tcl +24 -0
  122. librelane/scripts/openroad/drt.tcl +37 -0
  123. librelane/scripts/openroad/fill.tcl +30 -0
  124. librelane/scripts/openroad/floorplan.tcl +145 -0
  125. librelane/scripts/openroad/gpl.tcl +88 -0
  126. librelane/scripts/openroad/grt.tcl +30 -0
  127. librelane/scripts/openroad/gui.tcl +37 -0
  128. librelane/scripts/openroad/insert_buffer.tcl +127 -0
  129. librelane/scripts/openroad/ioplacer.tcl +67 -0
  130. librelane/scripts/openroad/irdrop.tcl +51 -0
  131. librelane/scripts/openroad/pdn.tcl +52 -0
  132. librelane/scripts/openroad/rcx.tcl +32 -0
  133. librelane/scripts/openroad/repair_design.tcl +70 -0
  134. librelane/scripts/openroad/repair_design_postgrt.tcl +48 -0
  135. librelane/scripts/openroad/rsz_timing_postcts.tcl +68 -0
  136. librelane/scripts/openroad/rsz_timing_postgrt.tcl +70 -0
  137. librelane/scripts/openroad/sta/check_macro_instances.tcl +53 -0
  138. librelane/scripts/openroad/sta/corner.tcl +393 -0
  139. librelane/scripts/openroad/tapcell.tcl +25 -0
  140. librelane/scripts/openroad/write_views.tcl +27 -0
  141. librelane/scripts/pyosys/construct_abc_script.py +177 -0
  142. librelane/scripts/pyosys/json_header.py +84 -0
  143. librelane/scripts/pyosys/synthesize.py +493 -0
  144. librelane/scripts/pyosys/ys_common.py +153 -0
  145. librelane/scripts/tclsh/hello.tcl +1 -0
  146. librelane/state/__init__.py +24 -0
  147. librelane/state/__main__.py +61 -0
  148. librelane/state/design_format.py +195 -0
  149. librelane/state/state.py +359 -0
  150. librelane/steps/__init__.py +61 -0
  151. librelane/steps/__main__.py +510 -0
  152. librelane/steps/checker.py +637 -0
  153. librelane/steps/common_variables.py +340 -0
  154. librelane/steps/cvc_rv.py +169 -0
  155. librelane/steps/klayout.py +509 -0
  156. librelane/steps/magic.py +576 -0
  157. librelane/steps/misc.py +160 -0
  158. librelane/steps/netgen.py +253 -0
  159. librelane/steps/odb.py +1088 -0
  160. librelane/steps/openroad.py +2460 -0
  161. librelane/steps/openroad_alerts.py +102 -0
  162. librelane/steps/pyosys.py +640 -0
  163. librelane/steps/step.py +1571 -0
  164. librelane/steps/tclstep.py +288 -0
  165. librelane/steps/verilator.py +222 -0
  166. librelane/steps/yosys.py +371 -0
  167. librelane-2.4.0.dist-info/METADATA +169 -0
  168. librelane-2.4.0.dist-info/RECORD +170 -0
  169. librelane-2.4.0.dist-info/WHEEL +4 -0
  170. librelane-2.4.0.dist-info/entry_points.txt +9 -0
@@ -0,0 +1,160 @@
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
+ from typing import Tuple
16
+
17
+ from .step import ViewsUpdate, MetricsUpdate, Step
18
+ from ..common import Path
19
+ from ..state import State, DesignFormat
20
+ from ..steps import Netgen, Magic, KLayout, OpenROAD
21
+ from ..logging import options
22
+
23
+
24
+ @Step.factory.register()
25
+ class LoadBaseSDC(Step):
26
+ """
27
+ Loads an SDC file specified as a configuration variable into the state
28
+ object unaltered.
29
+
30
+ This Step exists for legacy compatibility and should not be used
31
+ in new flows.
32
+ """
33
+
34
+ id = "Misc.LoadBaseSDC"
35
+ name = "Load Base SDC"
36
+ long_name = "Load Base Design Constraints File"
37
+
38
+ inputs = []
39
+ outputs = [DesignFormat.SDC]
40
+
41
+ def run(self, state_in: State, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
42
+ path = self.config["FALLBACK_SDC_FILE"]
43
+
44
+ target = os.path.join(self.step_dir, f"{self.config['DESIGN_NAME']}.sdc")
45
+
46
+ # Otherwise, you'll end up with weird permissions and may have to chmod
47
+ with open(target, "w", encoding="utf8") as out:
48
+ for line in open(path, "r", encoding="utf8"):
49
+ out.write(line)
50
+
51
+ return {DesignFormat.SDC: Path(target)}, {}
52
+
53
+
54
+ @Step.factory.register()
55
+ class ReportManufacturability(Step):
56
+ id = "Misc.ReportManufacturability"
57
+ name = "Report Manufacturability"
58
+ long_name = "Report Manufacturability (DRC, LVS, Antenna)"
59
+ inputs = []
60
+ outputs = []
61
+
62
+ def __get_lvs_report(self, state_in):
63
+ lvs_step = Netgen.LVS.id
64
+ report = []
65
+ report.append("* LVS")
66
+ try:
67
+ total = state_in.metrics["design__lvs_error__count"]
68
+ unmatched_pins = state_in.metrics["design__lvs_unmatched_pin__count"]
69
+ unmatched_nets = state_in.metrics["design__lvs_unmatched_net__count"]
70
+ if total == 0:
71
+ report.append("Passed ✅")
72
+ else:
73
+ report.append("Failed 𐄂")
74
+ report.append(f"Total Errors: {total}")
75
+ report.append(f"Unmatched Pins: {unmatched_pins}")
76
+ report.append(f"Unmatched Nets: {unmatched_nets}")
77
+ report.append(f"Check the report directory of {lvs_step}.")
78
+ except KeyError as key:
79
+ self.warn(f"{key} not reported. {lvs_step} may have been skipped.")
80
+ report.append("N/A")
81
+
82
+ report.append("")
83
+
84
+ return "\n".join(report)
85
+
86
+ def __get_drc_report(self, state_in):
87
+ klayout_step = KLayout.DRC.id
88
+ magic_step = Magic.DRC.id
89
+ klayout_failed = False
90
+ magic_failed = False
91
+ report = []
92
+
93
+ report.append("* DRC")
94
+
95
+ klayout = state_in.metrics.get("klayout__drc_error__count", "N/A")
96
+ if klayout == "N/A":
97
+ self.warn(
98
+ f"klayout__drc_error__count not reported. {klayout_step} may have been skipped."
99
+ )
100
+ elif klayout > 0:
101
+ klayout_failed = True
102
+
103
+ magic = state_in.metrics.get("magic__drc_error__count", "N/A")
104
+ if magic == "N/A":
105
+ self.warn(
106
+ f"magic__drc_error__count not reported. {magic_step} may have been skipped."
107
+ )
108
+ elif magic > 0:
109
+ magic_failed = True
110
+
111
+ if magic == "N/A" and klayout == "N/A":
112
+ report.append("N/A")
113
+ elif magic_failed or klayout_failed:
114
+ report.append("Failed 𐄂")
115
+ report.append(f"KLayout DRC errors: {klayout}")
116
+ report.append(f"Magic DRC errors: {magic}")
117
+ report.append(
118
+ f"Check the report directories of {klayout_step} and {magic_step}."
119
+ )
120
+ else:
121
+ report.append("Passed ✅")
122
+
123
+ report.append("")
124
+
125
+ return "\n".join(report)
126
+
127
+ def __get_antenna_report(self, state_in):
128
+ antenna_step = OpenROAD.CheckAntennas.id
129
+ report = []
130
+ report.append("* Antenna")
131
+
132
+ try:
133
+ nets = state_in.metrics["antenna__violating__nets"]
134
+ pins = state_in.metrics["antenna__violating__pins"]
135
+ if pins + nets == 0:
136
+ report.append("Passed ✅")
137
+ else:
138
+ report.append("Failed 𐄂")
139
+ report.append(f"Pin violations: {pins}")
140
+ report.append(f"Net violations: {nets}")
141
+ report.append(f"Check the report directory of {antenna_step}.")
142
+ except KeyError as key:
143
+ self.warn(f"{key} not reported. {antenna_step} may have been skipped.")
144
+ report.append("N/A")
145
+
146
+ report.append("")
147
+
148
+ return "\n".join(report)
149
+
150
+ def run(self, state_in: State, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
151
+ report_file = os.path.join(self.step_dir, "manufacturability.rpt")
152
+ lvs_report = self.__get_lvs_report(state_in)
153
+ drc_report = self.__get_drc_report(state_in)
154
+ antenna_report = self.__get_antenna_report(state_in)
155
+ if not options.get_condensed_mode():
156
+ print(f"{antenna_report}\n{lvs_report}\n{drc_report}")
157
+
158
+ with open(report_file, "w") as f:
159
+ print(f"{antenna_report}\n{lvs_report}\n{drc_report}", file=f)
160
+ return {}, {}
@@ -0,0 +1,253 @@
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
+ import json
17
+ import textwrap
18
+ from decimal import Decimal
19
+ from abc import abstractmethod
20
+ from typing import List, Dict, Tuple, Optional
21
+
22
+ from .step import ViewsUpdate, MetricsUpdate, Step
23
+ from .tclstep import TclStep
24
+
25
+ from ..common import Path, mkdirp, get_script_dir, TclUtils
26
+ from ..config import Variable
27
+ from ..state import DesignFormat, State
28
+
29
+
30
+ def get_metrics(stats: Dict) -> Dict:
31
+ metrics: Dict = {}
32
+ if not stats:
33
+ return metrics
34
+
35
+ pin_fails = 0
36
+ property_fails = 0
37
+ net_differences = 0
38
+ device_differences = 0
39
+ top_cell = stats[-1]
40
+
41
+ def filter_list_dict(list, element):
42
+ return [i[element] for i in list if i.get(element)]
43
+
44
+ def flatten(list):
45
+ return [item for sublist in list for item in sublist]
46
+
47
+ property_fails += len(flatten(filter_list_dict(stats, "properties")))
48
+ net_fails = len(top_cell.get("badnets", []))
49
+ device_fails = len(top_cell.get("badelements", []))
50
+
51
+ nets = top_cell.get("nets", [0, 0])
52
+ net_differences = abs(nets[0] - nets[1])
53
+
54
+ if "devices" in top_cell:
55
+ devices = top_cell["devices"]
56
+ devlist = [val for pair in zip(devices[0], devices[1]) for val in pair]
57
+ devpair = list(devlist[p : p + 2] for p in range(0, len(devlist), 2))
58
+ for dev in devpair:
59
+ c1dev = dev[0]
60
+ c2dev = dev[1]
61
+ device_differences += abs(c1dev[1] - c2dev[1])
62
+
63
+ if "pins" in top_cell:
64
+ pins = top_cell["pins"]
65
+ pinlist = [val for pair in zip(pins[0], pins[1]) for val in pair]
66
+ pinpair = list(pinlist[p : p + 2] for p in range(0, len(pinlist), 2))
67
+ for pin in pinpair:
68
+ # Avoid flagging global vs. local names, e.g., "gnd" vs. "gnd!,"
69
+ # and ignore case when comparing pins.
70
+ pin0 = re.sub("!$", "", pin[0].lower())
71
+ pin1 = re.sub("!$", "", pin[1].lower())
72
+ if pin0 != pin1:
73
+ # The text "(no pin)" indicates a missing pin that can be
74
+ # ignored because the pin in the other netlist is a no-connect
75
+ if pin0 != "(no pin)" and pin1 != "(no pin)":
76
+ pin_fails += 1
77
+
78
+ total_errors = (
79
+ device_differences
80
+ + net_differences
81
+ + property_fails
82
+ + device_fails
83
+ + net_fails
84
+ + pin_fails
85
+ )
86
+ metrics = {}
87
+ metrics["design__lvs_device_difference__count"] = device_differences
88
+ metrics["design__lvs_net_difference__count"] = net_differences
89
+ metrics["design__lvs_property_fail__count"] = property_fails
90
+ metrics["design__lvs_error__count"] = total_errors
91
+ metrics["design__lvs_unmatched_device__count"] = device_fails
92
+ metrics["design__lvs_unmatched_net__count"] = net_fails
93
+ metrics["design__lvs_unmatched_pin__count"] = pin_fails
94
+
95
+ return metrics
96
+
97
+
98
+ class NetgenStep(TclStep):
99
+ inputs = []
100
+ outputs = []
101
+
102
+ config_vars = [
103
+ Variable(
104
+ "MAGIC_EXT_USE_GDS",
105
+ bool,
106
+ "A flag to choose whether to use GDS for spice extraction or not. If not, then the extraction will be done using the DEF/LEF, which is faster.",
107
+ default=False,
108
+ ),
109
+ Variable(
110
+ "NETGEN_SETUP",
111
+ Path,
112
+ "A path to the setup file for Netgen used to configure LVS. If set to None, this PDK will not support Netgen-based steps.",
113
+ deprecated_names=["NETGEN_SETUP_FILE"],
114
+ pdk=True,
115
+ ),
116
+ ]
117
+
118
+ @abstractmethod
119
+ def get_script_path(self) -> str:
120
+ pass
121
+
122
+ def get_command(self) -> List[str]:
123
+ return ["netgen", "-batch", "source"]
124
+
125
+
126
+ @Step.factory.register()
127
+ class LVS(NetgenStep):
128
+ """
129
+ Performs `Layout vs. Schematic <https://en.wikipedia.org/wiki/Layout_Versus_Schematic>`_ checks on the extracted SPICE netlist versus.
130
+ a Verilog netlist with power connections.
131
+
132
+ This verifies the following:
133
+ * There are no unexpected shorts in the final layout.
134
+ * There are no unexpected opens in the final layout.
135
+ * All signals are connected correctly.
136
+ """
137
+
138
+ id = "Netgen.LVS"
139
+ name = "Netgen LVS"
140
+ inputs = [DesignFormat.SPICE, DesignFormat.POWERED_NETLIST]
141
+ config_vars = NetgenStep.config_vars + [
142
+ Variable(
143
+ "LVS_INCLUDE_MARCO_NETLISTS",
144
+ bool,
145
+ "A flag that enables including the gate-level netlist of macros while running Netgen",
146
+ default=False,
147
+ ),
148
+ Variable(
149
+ "LVS_FLATTEN_CELLS",
150
+ Optional[List[str]],
151
+ "A list of cell names to be flattened while running LVS",
152
+ ),
153
+ ]
154
+
155
+ def get_command(self) -> List[str]:
156
+ return super().get_command() + [self.get_script_path()]
157
+
158
+ def get_script_path(self):
159
+ return os.path.join(self.step_dir, "lvs_script.lvs")
160
+
161
+ def run(self, state_in: State, **kwargs) -> Tuple[ViewsUpdate, MetricsUpdate]:
162
+ spice_files = []
163
+ if self.config["CELL_SPICE_MODELS"] is None:
164
+ self.warn(
165
+ "This PDK does not appear to define any SPICE models. LVS will still run, but all cells will be black-boxed and the result may be inaccurate."
166
+ )
167
+ else:
168
+ spice_files = self.config["CELL_SPICE_MODELS"].copy()
169
+
170
+ if pdk_spice_files := self.config.get("SPICE_MODELS"):
171
+ spice_files = pdk_spice_files.copy()
172
+
173
+ if extra_spice_files := self.config.get("EXTRA_SPICE_MODELS"):
174
+ spice_files += extra_spice_files
175
+
176
+ design_name = self.config["DESIGN_NAME"]
177
+ reports_dir = os.path.join(self.step_dir, "reports")
178
+ stats_file = os.path.join(reports_dir, "lvs.netgen.rpt")
179
+ stats_file_json = os.path.join(reports_dir, "lvs.netgen.json")
180
+ mkdirp(reports_dir)
181
+
182
+ with open(self.get_script_path(), "w") as f:
183
+ for lib in spice_files:
184
+ print(
185
+ f"puts \"Reading SPICE netlist file '{lib}'...\"",
186
+ file=f,
187
+ )
188
+ print(
189
+ f"readnet spice {lib} 1",
190
+ file=f,
191
+ )
192
+ netgen_setup_script = os.path.join(get_script_dir(), "netgen", "setup.tcl")
193
+ mkdirp(reports_dir)
194
+
195
+ spice_files_commands = []
196
+ for lib in spice_files:
197
+ spice_files_commands.append(
198
+ f"puts \"Reading SPICE netlist file '{lib}'...\""
199
+ )
200
+ spice_files_commands.append(f"readnet spice {lib} $circuit2")
201
+
202
+ macros_commands = []
203
+ macros_commands += [
204
+ f"readnet verilog {state_in[DesignFormat.POWERED_NETLIST]} $circuit2"
205
+ ]
206
+
207
+ format_list = [
208
+ DesignFormat.POWERED_NETLIST,
209
+ DesignFormat.NETLIST,
210
+ DesignFormat.VERILOG_HEADER,
211
+ ]
212
+
213
+ if self.config["LVS_INCLUDE_MARCO_NETLISTS"]:
214
+ macros_views = []
215
+ for view, _ in self.toolbox.get_macro_views_by_priority(
216
+ self.config, format_list
217
+ ):
218
+ macros_views.append(TclUtils.escape(str(view)))
219
+
220
+ for netlist in macros_views:
221
+ macros_commands.append(
222
+ f"puts \"Reading Verilog netlist file '{str(netlist)}'...\""
223
+ )
224
+ macros_commands.append(f"readnet verilog {str(netlist)} $circuit2")
225
+
226
+ netgen_commands = (
227
+ (
228
+ textwrap.dedent(
229
+ f"""
230
+ set circuit1 [readnet spice {state_in[DesignFormat.SPICE]}]
231
+ set circuit2 [readnet verilog /dev/null]"""
232
+ )
233
+ )
234
+ .lstrip()
235
+ .rstrip()
236
+ .split("\n")
237
+ )
238
+ netgen_commands += spice_files_commands
239
+ netgen_commands += macros_commands
240
+ netgen_commands += f'lvs "$circuit1 {design_name}" "$circuit2 {design_name}" {netgen_setup_script} {stats_file} -blackbox -json'.split(
241
+ "\n"
242
+ )
243
+ with open(self.get_script_path(), "w") as f:
244
+ print(
245
+ "\n".join(netgen_commands),
246
+ file=f,
247
+ )
248
+ views_updates, metrics_updates = super().run(state_in, **kwargs)
249
+ stats_string = open(stats_file_json).read()
250
+ lvs_metrics = get_metrics(json.loads(stats_string, parse_float=Decimal))
251
+ metrics_updates.update(lvs_metrics)
252
+
253
+ return (views_updates, metrics_updates)