HAL  v4.5.0-299-g9ee015483
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
netlist_factory.cpp
Go to the documentation of this file.
2 
3 namespace hal
4 {
6  {
7  m.def_submodule("NetlistFactory", R"(
8  Functions to create a netlist, either empty or by parsing a netlist file.
9  )")
10  .def(
11  "create_netlist", [](const GateLibrary* gate_library) { return std::shared_ptr<Netlist>(netlist_factory::create_netlist(gate_library)); }, py::arg("gate_library"), R"(
12  Create a new empty netlist using the specified gate library.
13 
14  :param hal_py.GateLibrary gate_library: The gate library.
15  :returns: The netlist on success, ``None`` otherwise.
16  :rtype: hal_py.Netlist or None
17  )")
18 
19  .def(
20  "load_netlist",
21  [](const std::filesystem::path& netlist_file, const std::filesystem::path& gate_library_file) {
22  return std::shared_ptr<Netlist>(netlist_factory::load_netlist(netlist_file, gate_library_file));
23  },
24  py::arg("netlist_file"),
25  // a default of std::filesystem::path() would reach Python as pathlib.Path(""), which is '.', and come back as a non-empty path
26  py::arg("gate_library_file") = "",
27  R"(
28  Create a netlist from the given file using the specified gate library file.
29  Will either deserialize ``.hal`` file or call parser plugin for other formats.
30  In the latter case the specified gate library file is mandatory.
31 
32  :param pathlib.Path netlist_file: Path to the file.
33  :param pathlib.Path gate_library_file: Path to the gate library file. Optional for a ``.hal`` file, which then uses the gate library it names.
34  :returns: The netlist on success, ``None`` otherwise.
35  :rtype: hal_py.Netlist or None
36  )")
37 
38  .def(
39  "load_netlist",
40  [](const std::filesystem::path& netlist_file, GateLibrary* gate_library) { return std::shared_ptr<Netlist>(netlist_factory::load_netlist(netlist_file, gate_library)); },
41  py::arg("netlist_file"),
42  py::arg("gate_library"),
43  R"(
44  Create a netlist from the given file trying to parse it with the specified gate library.
45  Will either deserialize ``.hal`` file or call parser plugin for other formats.
46 
47  :param pathlib.Path netlist_file: Path to the file.
48  :param hal_py.GateLibrary gate_library: The gate library.
49  :returns: The netlist on success, ``None`` otherwise.
50  :rtype: hal_py.Netlist or None
51  )")
52 
53  .def(
54  "load_netlist_from_string",
55  [](const std::string& netlist_string, const std::filesystem::path& gate_library_file) {
56  return std::shared_ptr<Netlist>(netlist_factory::load_netlist_from_string(netlist_string, gate_library_file));
57  },
58  py::arg("netlist_string"),
59  py::arg("gate_library_file") = "",
60  R"(
61  Create a netlist from the given string.
62  The string must contain a netlist in HAL-(JSON)-format.
63 
64  :param str netlist_string: The string containing the netlist.
65  :param pathlib.Path gate_library_file: Path to the gate library file.
66  :returns: The netlist on success, ``None`` otherwise.
67  :rtype: hal_py.Netlist or None
68  )")
69 
70  .def(
71  "load_hal_project", [](const std::filesystem::path& project_dir) { return std::shared_ptr<Netlist>(netlist_factory::load_hal_project(project_dir)); }, py::arg("project_dir"), R"(
72  Create a netlist using information specified in command line arguments on startup.
73  Will either deserialize ``.hal`` file or call parser plugin for other formats.
74 
75  :param pathlib.Path project_dir: Path to the hal project directory.
76  :returns: The netlist on success, ``None`` otherwise.
77  :rtype: hal_py.Netlist or None
78  )")
79 
80  .def(
81  "load_netlists",
82  [](const std::filesystem::path& hal_file) {
83  std::vector<std::shared_ptr<Netlist>> result;
84  for (auto& ptr : netlist_factory::load_netlists(hal_file))
85  {
86  result.emplace_back(std::move(ptr));
87  }
88  return result;
89  },
90  py::arg("netlist_file"),
91  R"(
92  Create a netlist from a given file for each matching pre-loaded gate library.
93 
94  :param pathlib.Path netlist_file: Path to the netlist file.
95  :returns: A list of netlists, one for each suitable gate library.
96  :rtype: list[hal_py.Netlist]
97  )");
98  }
99 } // namespace hal
void netlist_factory_init(py::module &m)
const Module * module(const Gate *g, const NodeBoxes &boxes)
std::unique_ptr< Netlist > load_hal_project(const std::filesystem::path &project_dir)
Create a netlist from the given hal project.
std::vector< std::unique_ptr< Netlist > > load_netlists(const std::filesystem::path &netlist_file)
Create a netlist from a given file for each matching pre-loaded gate library.
std::unique_ptr< Netlist > load_netlist_from_string(const std::string &netlist_string, const std::filesystem::path &gate_library_file=std::filesystem::path())
Create a netlist from the given string.
std::unique_ptr< Netlist > create_netlist(const GateLibrary *gate_library)
Create a new empty netlist using the specified gate library.
std::unique_ptr< Netlist > load_netlist(const std::filesystem::path &netlist_file, const std::filesystem::path &gate_library_file=std::filesystem::path())
Create a netlist from the given file.
Definition: defines.h:45