HAL  v4.5.0-124-g47ab54673
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
gate_library_manager.cpp
Go to the documentation of this file.
2 
3 namespace hal
4 {
6  {
7  auto py_gate_library_manager = m.def_submodule("GateLibraryManager", R"(
8  The gate library manager keeps track of all gate libraries that are used within HAL. Further, it takes care of loading and saving gate libraries on demnand.
9  )");
10 
11  py_gate_library_manager.def(
12  "load",
13  [](std::filesystem::path file_path, bool reload) { return gate_library_manager::get_owning(gate_library_manager::load(file_path, reload)); },
14  py::arg("file_path"),
15  py::arg("reload") = false,
16  R"(
17  Load a gate library from file.
18 
19  :param pathlib.Path file_path: The path to the gate library file.
20  :param bool reload: If ``True``, reloads the library in case it is already loaded.
21  :returns: The gate library on success, ``None`` otherwise.
22  :rtype: hal_py.GateLibrary or None
23  )");
24 
25  py_gate_library_manager.def("load_all", &gate_library_manager::load_all, py::arg("reload") = false, R"(
26  Load all gate libraries available in standard gate library directories.
27 
28  :param bool reload: If ``True``, reloads all libraries that have already been loaded.
29  )");
30 
31  py_gate_library_manager.def("save", &gate_library_manager::save, py::arg("file_path"), py::arg("gate_lib"), py::arg("overwrite") = false, R"(
32  Save a gate library to file.
33 
34  :param pathlib.Path file_path: The output path.
35  :param hal_py.GateLibrary gate_lib: The gate library.
36  :param bool overwrite: If ``True``, overwrites already existing files.
37  :returns: ``True`` on success, ``False`` otherwise.
38  :rtype: bool
39  )");
40 
41  py_gate_library_manager.def(
42  "get_gate_library", [](const std::string& file_name) { return gate_library_manager::get_owning(gate_library_manager::get_gate_library(file_name)); }, py::arg("file_path"), R"(
43  Get a gate library by file path. If no library with the given name is loaded, loading the gate library from file will be attempted.
44 
45  :param str file_path: The input path.
46  :returns: The gate library on success, ``None`` otherwise.
47  :rtype: hal_py.GateLibrary or None
48  )");
49 
50  py_gate_library_manager.def(
51  "get_gate_library_by_name",
52  [](const std::string& lib_name) { return gate_library_manager::get_owning(gate_library_manager::get_gate_library_by_name(lib_name)); },
53  py::arg("lib_name"),
54  R"(
55  Get a gate library by name. If no library with the given name is loaded, ``None`` will be returned.
56 
57  :param str lib_name: The name of the gate library.
58  :returns: The gate library on success, ``None`` otherwise.
59  :rtype: hal_py.GateLibrary or None
60  )");
61 
62  py_gate_library_manager.def(
63  "get_gate_libraries",
64  [] {
65  // get_gate_libraries hands out borrowed pointers, so ask the manager for the owning
66  // pointer of each. Constructing a shared_ptr from the borrowed one instead would
67  // open a second, independent ownership group over a library the manager already
68  // owns, and the library would be freed twice.
69  std::vector<std::shared_ptr<GateLibrary>> result;
70  for (const auto* lib : gate_library_manager::get_gate_libraries())
71  {
72  result.emplace_back(gate_library_manager::get_owning(lib));
73  }
74  return result;
75  },
76  R"(
77  Get all loaded gate libraries.
78 
79  :returns: A list of gate libraries.
80  :rtype: list[hal_py.GateLibrary]
81  )");
82  }
83 } // namespace hal
void gate_library_manager_init(py::module &m)
const Module * module(const Gate *g, const NodeBoxes &boxes)
GateLibrary * load(std::filesystem::path file_path, bool reload=false)
std::shared_ptr< GateLibrary > get_owning(const GateLibrary *gate_lib)
std::vector< GateLibrary * > get_gate_libraries()
GateLibrary * get_gate_library_by_name(const std::string &lib_name)
void load_all(bool reload=false)
bool save(std::filesystem::path file_path, GateLibrary *gate_lib, bool overwrite=false)
GateLibrary * get_gate_library(const std::string &file_path)
Definition: defines.h:45