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