31 #include "pybind11/pybind11.h"
33 #include <igraph/igraph.h>
34 #include <pybind11/detail/descr.h>
35 #include <pybind11/pytypes.h>
42 class BasePluginInterface;
58 #ifdef PYBIND11_MODULE
59 PYBIND11_MODULE( clock_tree_extractor, m )
68 py::class_<ClockTreeExtractorPlugin, RawPtrWrapper<ClockTreeExtractorPlugin>,
BasePluginInterface>
69 py_clock_tree_extractor_plugin( m,
"ClockTreeExtractorPlugin",
"" );
72 The name of the plugin.
78 Get the name of the plugin.
80 :returns: The name of the plugin.
85 The version of the plugin.
91 Get the version of the plugin.
93 :returns: The version of the plugin.
97 py_clock_tree_extractor_plugin.def_property_readonly(
99 The description of the plugin.
105 Get the description of the plugin.
107 :returns: The description of the plugin.
111 py_clock_tree_extractor_plugin.def_property_readonly(
113 A set of plugin names that this plugin depends on.
119 Get a set of plugin names that this plugin depends on.
121 :returns: A set of plugin names that this plugin depends on.
125 py::class_<cte::ClockTree>( m, "ClockTree", R
"(
126 The clock distribution network of a netlist as a directed graph whose vertices are gates and nets.
130 [](
const Netlist *netlist ) -> std::unique_ptr<cte::ClockTree> {
137 log_error(
"clock_tree_extractor",
"{}", result.get_error().get() );
140 py::arg(
"netlist" ),
141 py::return_value_policy::move,
142 py::keep_alive<0, 1>(),
144 Extract the clock tree of a netlist.
146 Starting at the clock pin of every flip-flop, the extraction walks against the signal direction through buffers, inverters, delay gates, clock gates and toggle flip-flops up to the global input nets that drive them.
148 :param hal_py.Netlist netlist: The netlist.
149 :returns: The clock tree on success, ``None`` otherwise.
150 :rtype: clock_tree_extractor.ClockTree or None
154 [](
const cte::ClockTree &
self,
const std::string &pathname ) ->
bool {
155 auto result =
self.export_dot( pathname );
161 log_error(
"clock_tree_extractor",
"{}", result.get_error().get() );
164 py::arg(
"pathname" ),
166 Write the clock tree to a DOT file.
168 :param str pathname: The path of the file to write.
169 :returns: ``True`` on success, ``False`` otherwise.
176 const bool parent ) -> std::unique_ptr<cte::ClockTree> {
177 auto result =
self.get_subtree( ptr, parent );
183 log_error(
"clock_tree_extractor",
"{}", result.get_error().get() );
187 py::arg(
"parent" ) =
false,
188 py::return_value_policy::move,
189 py::keep_alive<0, 1>(),
191 Get the clock tree below a gate or net as a clock tree of its own.
193 :param ptr: The gate or net.
194 :type ptr: hal_py.Gate or hal_py.Net
195 :param bool parent: Set ``True`` to start one level up, at the parent of the given object, if it has exactly one. Defaults to ``False``.
196 :returns: The subtree on success, ``None`` otherwise.
197 :rtype: clock_tree_extractor.ClockTree or None
203 const auto &map =
self.get_all();
204 for(
auto &[ptr,
type] : map )
208 result.append( py::cast( (
const Gate *) ptr ) );
212 result.append( py::cast( (
const Net *) ptr ) );
219 Get all gates and nets of the clock tree.
221 :returns: A list of gates and nets.
222 :rtype: list[hal_py.Gate or hal_py.Net]
225 "get_vertex_from_ptr",
227 auto result =
self.get_vertex_from_ptr( ptr );
230 return py::int_( result.get() );
232 log_error(
"clock_tree_extractor",
"{}", result.get_error().get() );
237 Get the igraph vertex ID of a gate or net of the clock tree.
239 :param ptr: The gate or net.
240 :type ptr: hal_py.Gate or hal_py.Net
241 :returns: The vertex ID on success, ``None`` otherwise.
245 "get_ptr_from_vertex",
246 [](
const cte::ClockTree &
self,
const igraph_integer_t vertex ) -> py::object {
247 auto result =
self.get_ptr_from_vertex( vertex );
250 auto [ptr,
type] = result.get();
253 return py::cast( (
const Gate *) ptr );
257 return py::cast( (
const Net *) ptr );
261 log_error(
"clock_tree_extractor",
"{}", result.get_error().get() );
267 Get the gate or net behind an igraph vertex ID of the clock tree.
269 :param int vertex: The vertex ID.
270 :returns: The gate or net on success, ``None`` otherwise.
271 :rtype: hal_py.Gate or hal_py.Net or None
274 "get_vertices_from_ptrs",
275 [](
const cte::ClockTree &
self,
const std::vector<const void *> &ptrs ) -> py::list {
276 auto result =
self.get_vertices_from_ptrs( ptrs );
279 return py::cast( result.get() );
281 log_error(
"clock_tree_extractor",
"{}", result.get_error().get() );
286 Get the igraph vertex IDs of gates and nets of the clock tree.
288 :param list[hal_py.Gate or hal_py.Net] ptrs: The gates and nets.
289 :returns: The vertex IDs on success, ``None`` otherwise.
290 :rtype: list[int] or None
293 "get_ptrs_from_vertices",
294 [](
const cte::ClockTree &
self,
const std::vector<igraph_integer_t> &vertices ) -> py::list {
295 auto res =
self.get_ptrs_from_vertices( vertices );
299 for(
const auto &[ptr,
type] : res.get() )
303 result.append( py::cast( (
const Gate *) ptr ) );
307 result.append( py::cast( (
const Net *) ptr ) );
311 log_error(
"clock_tree_extractor",
"unknown ptr type" );
317 log_error(
"clock_tree_extractor",
"{}", res.get_error().get() );
320 py::arg(
"vertices" ),
323 Get the gates and nets behind igraph vertex IDs of the clock tree.
325 :param list[int] vertices: The vertex IDs.
326 :returns: The gates and nets on success, ``None`` otherwise.
327 :rtype: list[hal_py.Gate or hal_py.Net] or None
332 auto res =
self.get_neighbors( ptr, IGRAPH_IN );
336 for(
const auto &[ptr,
type] : res.get() )
340 result.append( py::cast( (
const Gate *) ptr ) );
344 result.append( py::cast( (
const Net *) ptr ) );
348 log_error(
"clock_tree_extractor",
"unknown ptr type" );
354 log_error(
"clock_tree_extractor",
"{}", res.get_error().get() );
360 Get the gates and nets directly upstream of a gate or net in the clock tree.
362 :param ptr: The gate or net.
363 :type ptr: hal_py.Gate or hal_py.Net
364 :returns: The neighbors on success, ``None`` otherwise.
365 :rtype: list[hal_py.Gate or hal_py.Net] or None
370 auto res =
self.get_neighbors( ptr, IGRAPH_OUT );
374 for(
const auto &[ptr,
type] : res.get() )
378 result.append( py::cast( (
const Gate *) ptr ) );
382 result.append( py::cast( (
const Net *) ptr ) );
386 log_error(
"clock_tree_extractor",
"unknown ptr type" );
392 log_error(
"clock_tree_extractor",
"{}", res.get_error().get() );
398 Get the gates and nets directly downstream of a gate or net in the clock tree.
400 :param ptr: The gate or net.
401 :type ptr: hal_py.Gate or hal_py.Net
402 :returns: The neighbors on success, ``None`` otherwise.
403 :rtype: list[hal_py.Gate or hal_py.Net] or None
406 Get all gates of the clock tree.
409 :rtype: list[hal_py.Gate]
412 Get all nets of the clock tree.
415 :rtype: list[hal_py.Net]
418 Get the netlist the clock tree was extracted from.
420 :returns: The netlist.
421 :rtype: hal_py.Netlist
424 #ifndef PYBIND11_MODULE
const Netlist * get_netlist() const
const std::vector< const Gate * > get_gates() const
const std::vector< const Net * > get_nets() const
static Result< std::unique_ptr< ClockTree > > from_netlist(const Netlist *netlist)
#define log_error(channel,...)
const Module * module(const Gate *g, const NodeBoxes &boxes)