HAL  v4.5.0-83-g30c8f0afc
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 = std::filesystem::path()) {
22  return std::shared_ptr<Netlist>(netlist_factory::load_netlist(netlist_file, gate_library_file));
23  },
24  py::arg("netlist_file"),
25  py::arg("gate_library_file") = std::filesystem::path(),
26  R"(
27  Create a netlist from the given file using the specified gate library file.
28  Will either deserialize ``.hal`` file or call parser plugin for other formats.
29  In the latter case the specified gate library file is mandatory.
30 
31  :param pathlib.Path netlist_file: Path to the file.
32  :param pathlib.Path gate_library_file: Path to the gate library file.
33  :returns: The netlist on success, ``None`` otherwise.
34  :rtype: hal_py.Netlist or None
35  )")
36 
37  .def(
38  "load_netlist",
39  [](const std::filesystem::path& netlist_file, GateLibrary* gate_library) { return std::shared_ptr<Netlist>(netlist_factory::load_netlist(netlist_file, gate_library)); },
40  py::arg("netlist_file"),
41  py::arg("gate_library"),
42  R"(
43  Create a netlist from the given file trying to parse it with the specified gate library.
44  Will either deserialize ``.hal`` file or call parser plugin for other formats.
45 
46  :param pathlib.Path netlist_file: Path to the file.
47  :param hal_py.GateLibrary gate_library: The gate library.
48  :returns: The netlist on success, ``None`` otherwise.
49  :rtype: hal_py.Netlist or None
50  )")
51 
52  .def(
53  "load_netlist_from_string",
54  [](const std::string& netlist_string, const std::filesystem::path& gate_library_file) {
55  return std::shared_ptr<Netlist>(netlist_factory::load_netlist_from_string(netlist_string, gate_library_file));
56  },
57  py::arg("netlist_string"),
58  py::arg("gate_library_file") = "",
59  R"(
60  Create a netlist from the given string.
61  The string must contain a netlist in HAL-(JSON)-format.
62 
63  :param str netlist_string: The string containing the netlist.
64  :param pathlib.Path gate_library_file: Path to the gate library file.
65  :returns: The netlist on success, ``None`` otherwise.
66  :rtype: hal_py.Netlist or None
67  )")
68 
69  .def(
70  "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"(
71  Create a netlist using information specified in command line arguments on startup.
72  Will either deserialize ``.hal`` file or call parser plugin for other formats.
73 
74  :param pathlib.Path project_dir: Path to the hal project directory.
75  :returns: The netlist on success, ``None`` otherwise.
76  :rtype: hal_py.Netlist or None
77  )")
78 
79  .def(
80  "load_netlists",
81  [](const std::filesystem::path& hal_file) {
82  std::vector<std::shared_ptr<Netlist>> result;
83  for (auto& ptr : netlist_factory::load_netlists(hal_file))
84  {
85  result.emplace_back(std::move(ptr));
86  }
87  return result;
88  },
89  py::arg("netlist_file"),
90  R"(
91  Create a netlist from a given file for each matching pre-loaded gate library.
92 
93  :param pathlib.Path netlist_file: Path to the netlist file.
94  :returns: A list of netlists, one for each suitable gate library.
95  :rtype: list[hal_py.Netlist]
96  )");
97  }
98 } // 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