HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
python_bindings.cpp
Go to the documentation of this file.
2 
5 #include "pybind11/operators.h"
6 #include "pybind11/pybind11.h"
7 #include "pybind11/stl.h"
8 #include "pybind11/stl_bind.h"
9 
10 namespace py = pybind11;
11 
12 namespace hal
13 {
14 
15  // the name in PYBIND11_MODULE/PYBIND11_PLUGIN *MUST* match the filename of the output library (without extension),
16  // otherwise you will get "ImportError: dynamic module does not define module export function" when importing the module
17 
18 #ifdef PYBIND11_MODULE
19  PYBIND11_MODULE(dot_viewer, m)
20  {
21  m.doc() = "Plugin to visualize .dot graphs within the HAL GUI.";
22 #else
23  PYBIND11_PLUGIN(dot_viewer)
24  {
25  py::module m("dot_viewer", "Plugin to visualize .dot graphs within the HAL GUI.");
26 #endif // ifdef PYBIND11_MODULE
27 
28  py::class_<DotViewerPlugin, RawPtrWrapper<DotViewerPlugin>, BasePluginInterface> py_dotviewer_plugin(
29  m, "DotViewerPlugin", R"(This class provides an interface to integrate a ``.dot`` viewer as a plugin within the HAL framework.)");
30 
31  py_dotviewer_plugin.def_property_readonly("name", &DotViewerPlugin::get_name, R"(
32  The name of the plugin.
33 
34  :type: str
35  )");
36 
37  py_dotviewer_plugin.def("get_name", &DotViewerPlugin::get_name, R"(
38  Get the name of the plugin.
39 
40  :returns: The name of the plugin.
41  :rtype: str
42  )");
43 
44  py_dotviewer_plugin.def_property_readonly("version", &DotViewerPlugin::get_version, R"(
45  The version of the plugin.
46 
47  :type: str
48  )");
49 
50  py_dotviewer_plugin.def("get_version", &DotViewerPlugin::get_version, R"(
51  Get the version of the plugin.
52 
53  :returns: The version of the plugin.
54  :rtype: str
55  )");
56 
57  py_dotviewer_plugin.def_property_readonly("description", &DotViewerPlugin::get_description, R"(
58  The description of the plugin.
59 
60  :type: str
61  )");
62 
63  py_dotviewer_plugin.def("get_description", &DotViewerPlugin::get_description, R"(
64  Get the description of the plugin.
65 
66  :returns: The description of the plugin.
67  :rtype: str
68  )");
69 
70  py_dotviewer_plugin.def_property_readonly("dependencies", &DotViewerPlugin::get_dependencies, R"(
71  A set of plugin names that this plugin depends on.
72 
73  :type: set[str]
74  )");
75 
76  py_dotviewer_plugin.def("get_dependencies", &DotViewerPlugin::get_dependencies, R"(
77  Get a set of plugin names that this plugin depends on.
78 
79  :returns: A set of plugin names that this plugin depends on.
80  :rtype: set[str]
81  )");
82 
83  m.def(
84  "load_dot_file",
85  [](const std::filesystem::path& path, const std::string& creator_plugin = "") -> bool {
86  QString qfilename = QString::fromStdString(path.string());
87  QString qcreator = QString::fromStdString(creator_plugin);
89  if (dv)
90  {
91  return dv->loadDotFile(qfilename, qcreator);
92  }
93  else
94  {
95  log_error("python_context", "Cannot find dot viewer instance.");
96  }
97  return false;
98  },
99  py::arg("path"),
100  py::arg("creator_plugin") = std::string(),
101  R"(
102  Loads a dot file in the graphic viewer provided by dot_viewer plugin.
103 
104  :param pathlib.Path path: The path to the ``.dot`` file.
105  :param str creator_plugin: The name of plugin that created the ``.dot`` file. Will try to detect from content or query by popup if empty.
106  :returns: ``True`` on success, ``False`` otherwise.
107  :rtype: bool
108  )");
109 
110 #ifndef PYBIND11_MODULE
111  return m.ptr();
112 #endif // PYBIND11_MODULE
113  }
114 } // namespace hal
static DotViewer * getDotviewerInstance()
Definition: dot_viewer.cpp:68
bool loadDotFile(const QString &fileName, const QString &creator=QString())
Definition: dot_viewer.cpp:108
std::string get_description() const override
Get a short description of the plugin.
std::string get_name() const override
Get the name of the plugin.
std::string get_version() const override
Get the version of the plugin.
std::set< std::string > get_dependencies() const override
Get the plugin dependencies.
#define log_error(channel,...)
Definition: log.h:78
const Module * module(const Gate *g, const NodeBoxes &boxes)
Definition: defines.h:45
PYBIND11_PLUGIN(hal_py)
QString fromStdString(const std::string &str)