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 
11 
12 namespace py = pybind11;
13 namespace hal
14 {
15 
16 #ifdef PYBIND11_MODULE
17  PYBIND11_MODULE(module_identification, m)
18  {
19  m.doc() = "Plugin for module classification against a library of predefined types.";
20 #else
21  PYBIND11_PLUGIN(module_identification)
22  {
23  py::module m("module_identification", "Plugin for module classification against a library of predefined types.");
24 #endif // ifdef PYBIND11_MODULE
25 
26  py::class_<ModuleIdentificationPlugin, RawPtrWrapper<ModuleIdentificationPlugin>, BasePluginInterface> py_module_identification_plugin(
27  m, "ModuleIdentificationPlugin", R"(This class provides an interface to integrate the module identification tool as a plugin within the HAL framework.)");
28 
29  py_module_identification_plugin.def_property_readonly("name", &ModuleIdentificationPlugin::get_name, R"(
30  The name of the plugin.
31 
32  :type: str
33  )");
34 
35  py_module_identification_plugin.def("get_name", &ModuleIdentificationPlugin::get_name, R"(
36  Get the name of the plugin.
37 
38  :returns: The name of the plugin.
39  :rtype: str
40  )");
41 
42  py_module_identification_plugin.def_property_readonly("version", &ModuleIdentificationPlugin::get_version, R"(
43  The version of the plugin.
44 
45  :type: str
46  )");
47 
48  py_module_identification_plugin.def("get_version", &ModuleIdentificationPlugin::get_version, R"(
49  Get the version of the plugin.
50 
51  :returns: The version of the plugin.
52  :rtype: str
53  )");
54 
55  py_module_identification_plugin.def_property_readonly("description", &ModuleIdentificationPlugin::get_description, R"(
56  The description of the plugin.
57 
58  :type: str
59  )");
60 
61  py_module_identification_plugin.def("get_description", &ModuleIdentificationPlugin::get_description, R"(
62  Get the description of the plugin.
63 
64  :returns: The description of the plugin.
65  :rtype: str
66  )");
67 
68  py_module_identification_plugin.def_property_readonly("dependencies", &ModuleIdentificationPlugin::get_dependencies, R"(
69  A set of plugin names that this plugin depends on.
70 
71  :type: set[str]
72  )");
73 
74  py_module_identification_plugin.def("get_dependencies", &ModuleIdentificationPlugin::get_dependencies, R"(
75  Get a set of plugin names that this plugin depends on.
76 
77  :returns: A set of plugin names that this plugin depends on.
78  :rtype: set[str]
79  )");
80 
81  // Define Configuration class
82  py::class_<module_identification::Configuration> py_configuration(m, "Configuration", R"(
83  Configuration for the module identification analysis.
84  This struct holds important parameters that configure the module identification analysis, including netlist to analyze, known registers, candidate types to check, threading options, etc.
85  )");
86 
87  py_configuration.def(py::init<hal::Netlist*>(), py::arg("nl"), R"(
88  Constructs a new ModuleIdentification analysis configuration for the given netlist.
89 
90  :param hal_py.Netlist nl: The netlist to be analyzed.
91  )");
92 
93  py_configuration.def(py::init<>(), R"(
94  Constructs an empty configuration.
95  )");
96 
97  py_configuration.def_readwrite("netlist", &module_identification::Configuration::m_netlist, R"(
98  The netlist to be analyzed.
99 
100  :type: hal_py.Netlist
101  )");
102 
103  py_configuration.def_readwrite("known_registers", &module_identification::Configuration::m_known_registers, R"(
104  A vector handling possibly known registers.
105 
106  :type: list[list[hal_py.Gate]]
107  )");
108 
109  py_configuration.def_readwrite("types_to_check", &module_identification::Configuration::m_types_to_check, R"(
110  CandidateTypes that shall be checked. Defaults to all checkable candidate types.
111 
112  :type: list[module_identification.CandidateType]
113  )");
114 
115  py_configuration.def_readwrite("max_thread_count", &module_identification::Configuration::m_max_thread_count, R"(
116  Maximum number of concurrent threads created during execution. Defaults to 1.
117 
118  :type: int
119  )");
120 
121  py_configuration.def_readwrite("max_control_signals", &module_identification::Configuration::m_max_control_signals, R"(
122  Maximum number of control signals to be tested. Defaults to 3.
123 
124  :type: int
125  )");
126 
127  py_configuration.def_readwrite("already_classified_candidates", &module_identification::Configuration::m_already_classified_candidates, R"(
128  Gates to ignore during processing.
129 
130  :type: list[list[hal_py.Gate]]
131  )");
132 
133  py_configuration.def_readwrite("blocked_base_candidates", &module_identification::Configuration::m_blocked_base_candidates, R"(
134  Base candidates to block during analysis.
135 
136  :type: list[set[hal_py.Gate]]
137  )");
138 
139  py_configuration.def_readwrite("multithreading_priority", &module_identification::Configuration::m_multithreading_priority, R"(
140  Choose which `MultithreadingPriority` to use for the analysis. Defaults to memory priority
141 
142  :type: module_identification.MultithreadingPriority
143  )");
144 
145  py_configuration.def("with_known_registers", &module_identification::Configuration::with_known_registers, py::arg("registers"), R"(
146  Set the known registers for prioritization.
147 
148  :param list[list[hal_py.Gate]] registers: The groups provided by a dana run.
149  :returns: The updated module identification configuration.
150  :rtype: module_identification.Configuration
151  )");
152 
153  py_configuration.def("with_max_thread_count", &module_identification::Configuration::with_max_thread_count, py::arg("max_thread_count"), R"(
154  Set the maximum number of threads.
155 
156  :param int max_thread_count: The number of threads to be started at max.
157  :returns: The updated module identification configuration.
158  :rtype: module_identification.Configuration
159  )");
160 
161  py_configuration.def("with_max_control_signals", &module_identification::Configuration::with_max_control_signals, py::arg("max_control_signals"), R"(
162  Set the maximum number of control signals to be tested.
163 
164  :param int max_control_signals: The number of control signals checked.
165  :returns: The updated module identification configuration.
166  :rtype: module_identification.Configuration
167  )");
168 
169  py_configuration.def("with_multithreading_priority", &module_identification::Configuration::with_multithreading_priority, py::arg("priority"), R"(
170  Set the multithreading priority type.
171 
172  :param module_identification.MultithreadingPriority priority: The type of multithreading used during execution.
173  :returns: The updated module identification configuration.
174  :rtype: module_identification.Configuration
175  )");
176 
177  py_configuration.def("with_types_to_check", &module_identification::Configuration::with_types_to_check, py::arg("types_to_check"), R"(
178  Set the candidate types to be checked.
179 
180  :param list[module_identification.CandidateType] types_to_check: A list of candidate types to be checked for.
181  :returns: The updated module identification configuration.
182  :rtype: module_identification.Configuration
183  )");
184 
185  py_configuration.def("with_already_classified_candidates", &module_identification::Configuration::with_already_classified_candidates, py::arg("already_classified_candidates"), R"(
186  Add gates to be ignored during processing.
187 
188  All candidates that are build during the module identification run that contain any gates that overlap with any already classified candidate are discarded to avoid conflicts.
189 
190  :param list[list[hal_py.Gate]] already_classified_candidates: Candidates to be ignored.
191  :returns: The updated module identification configuration.
192  :rtype: module_identification.Configuration
193  )");
194 
195  py_configuration.def("with_blocked_base_candidates", &module_identification::Configuration::with_blocked_base_candidates, py::arg("blocked_base_candidates"), R"(
196  Add base candidates to be blocked during analysis.
197 
198  :param list[set[hal_py.Gate]] blocked_base_candidates: Base candidates to be ignored.
199  :returns: The updated module identification configuration.
200  :rtype: module_identification.Configuration
201  )");
202 
203  // Define Result class
204  py::class_<module_identification::Result> py_result(m, "Result", R"(
205  The result of a module identification run containing the candidates.
206  )");
207 
208  py_result.def(py::init<hal::Netlist*, const std::vector<std::pair<module_identification::BaseCandidate, module_identification::VerifiedCandidate>>&, const std::string&>(),
209  py::arg("nl"),
210  py::arg("result"),
211  py::arg("timing_stats_json") = "",
212  R"(
213  Constructor for `Result`.
214 
215  :param hal_py.Netlist nl: The netlist on which module identification has been performed.
216  :param list[tuple(module_identification.BaseCandidate, module_identification.VerifiedCandidate)] result: A vector of pairs containing base candidates and their verified candidates.
217  :param str timing_stats_json: A JSON string containing timing statistics. Defaults to an empty string.
218  )");
219 
220  py_result.def("get_netlist", &module_identification::Result::get_netlist, R"(
221  Get the netlist on which module identification has been performed.
222 
223  :returns: The netlist.
224  :rtype: hal_py.Netlist
225  )");
226 
227  py_result.def("get_verified_candidate_gates", &module_identification::Result::get_verified_candidate_gates, R"(
228  Get a map of the candidate IDs to the gates contained inside the verified candidates.
229 
230  This map only contains verified candidates that are fully verified.
231  The ID is only unique for this result.
232 
233  :returns: A map of candidate IDs to a vector of gates.
234  :rtype: dict[int, list[hal_py.Gate]]
235  )");
236 
237  py_result.def("get_verified_candidates", &module_identification::Result::get_verified_candidates, R"(
238  Get a map of the candidate IDs to the verified candidates.
239 
240  This map only contains verified candidates that are fully verified.
241  The ID is only unique for this result.
242 
243  :returns: A map of candidate IDs to verified candidates.
244  :rtype: dict[int, module_identification.VerifiedCandidate]
245  )");
246 
247  py_result.def("get_candidate_gates", &module_identification::Result::get_candidate_gates, R"(
248  Get a map of the candidate IDs to the gates contained inside the candidate.
249 
250  This map contains all checked candidates, even the ones not verified.
251  The ID is only unique for this result.
252 
253  :returns: A map of candidate IDs to a vector of gates.
254  :rtype: dict[int, list[hal_py.Gate]]
255  )");
256 
257  py_result.def("get_candidates", &module_identification::Result::get_candidates, R"(
258  Get a map of the candidate IDs to the candidates.
259 
260  This map contains all checked candidates, even the ones not verified.
261  The ID is only unique for this result.
262 
263  :returns: A map of candidate IDs to candidates.
264  :rtype: dict[int, module_identification.VerifiedCandidate]
265  )");
266 
267  py_result.def(
268  "get_candidate_gates_by_id",
269  [](module_identification::Result& self, const u32 id) -> std::optional<std::vector<Gate*>> {
270  const auto res = self.get_candidate_gates_by_id(id);
271  if (res.is_ok())
272  {
273  return res.get();
274  }
275  else
276  {
277  log_error("python_context", "error encountered while getting gates of candidate:\n{}", res.get_error().get());
278  return std::nullopt;
279  }
280  },
281  py::arg("id"),
282  R"(
283  Get the gates of the candidate with the corresponding ID.
284 
285  :param int id: The ID of the requested candidate.
286  :returns: The gates of the candidate on success, ``None`` otherwise.
287  :rtype: list[hal_py.Gate] or None
288  )");
289 
290  py_result.def(
291  "get_candidate_by_id",
292  [](module_identification::Result& self, const u32 id) -> std::optional<module_identification::VerifiedCandidate> {
293  const auto res = self.get_candidate_by_id(id);
294  if (res.is_ok())
295  {
296  return res.get();
297  }
298  else
299  {
300  log_error("python_context", "error encountered while getting candidate:\n{}", res.get_error().get());
301  return std::nullopt;
302  }
303  },
304  py::arg("id"),
305  R"(
306  Get the candidate with the corresponding ID.
307 
308  :param int id: The ID of the requested candidate.
309  :returns: The verified candidate on success, ``None`` otherwise.
310  :rtype: module_identification.VerifiedCandidate or None
311  )");
312 
313  py_result.def("get_all_gates", &module_identification::Result::get_all_gates, R"(
314  Get all gates contained in any of the candidates.
315 
316  :returns: A set of gates.
317  :rtype: set[hal_py.Gate]
318  )");
319 
320  py_result.def("get_all_verified_gates", &module_identification::Result::get_all_verified_gates, R"(
321  Get all gates contained in any of the verified candidates.
322 
323  :returns: A set of gates.
324  :rtype: set[hal_py.Gate]
325  )");
326 
327  py_result.def(
328  "create_modules_in_netlist",
329  [](module_identification::Result& self) -> std::optional<bool> {
330  const auto res = self.create_modules_in_netlist();
331 
332  if (res.is_ok())
333  {
334  return true;
335  }
336  else
337  {
338  log_error("python_context", "error encountered while merging results:\n{}", res.get_error().get());
339  return std::nullopt;
340  }
341  },
342  R"(
343  Creates a HAL module for each candidate of the result.
344 
345  :returns: ```True``` on success, ```False``` otherwise.
346  :rtype: bool
347  )");
348 
349  py_result.def("get_timing_stats", &module_identification::Result::get_timing_stats, R"(
350  Get the collected timing information formatted as a JSON string.
351 
352  :returns: A JSON formatted string.
353  :rtype: str
354  )");
355 
356  py_result.def(
357  "merge",
358  [](module_identification::Result& self, const module_identification::Result& other, const std::vector<std::vector<Gate*>>& registers) -> std::optional<module_identification::Result> {
359  const auto res = self.merge(other, registers);
360  if (res.is_ok())
361  {
362  return res.get();
363  }
364  else
365  {
366  log_error("python_context", "error encountered while merging results:\n{}", res.get_error().get());
367  return std::nullopt;
368  }
369  },
370  py::arg("other"),
371  py::arg("registers"),
372  R"(
373  Merges two results by combining the found verified candidates.
374 
375  When both results contain a verified candidate for the same base candidate, the better one is chosen via the same post-processing used in the original module identification process.
376  This requires that the base candidates are identical and that all gates of all candidates still exist in the netlist!
377 
378  :param module_identification.Result other: Another module identification result that is merged with this one.
379  :param list[list[hal_py.Gate]] registers: A list of previously identified register groupings that is used in the post-processing.
380  :returns: The merged module identification result on success, ``None`` otherwise.
381  :rtype: module_identification.Result or None
382  )");
383 
384  py_result.def_static(
385  "assign_base_candidates_to_iterations", &module_identification::Result::assign_base_candidates_to_iterations, py::arg("iteration_results"), py::arg("create_block_lists") = false, R"(
386  For different runs of the plugin figure out in which iteration the plugin found the highest quality result for each candidate.
387 
388  This is used to compare the results of different runs of the plugin and afterwards get a list of base candidates for each execution for which this execution gave the best results.
389 
390  :param list[module_identification.Result] iteration_results: A vector of all the execution results.
391  :param bool create_block_lists: A parameter to determine whether to create allow or block lists.
392  :returns: A vector of allow or block lists for each plugin execution iteration.
393  :rtype: list[list[set[hal_py.Gate]]]
394  )");
395 
396  // Define execute function
397  m.def(
398  "execute",
399  [](const module_identification::Configuration& config) -> std::optional<module_identification::Result> {
400  const auto res = module_identification::execute(config);
401  if (res.is_ok())
402  {
403  return res.get();
404  }
405  else
406  {
407  log_error("python_context", "error encountered while executing module identification:\n{}", res.get_error().get());
408  return std::nullopt;
409  }
410  },
411  py::arg("config"),
412  R"(
413  Perform a full run of the module identification process on the given netlist with the provided configuration.
414 
415  This function executes the complete module identification process on the specified netlist. It uses the provided configuration to guide the identification process and returns a result object containing information about all analyzed candidates.
416 
417  :param module_identification.Configuration config: The configuration to guide the identification process.
418  :returns: The result of the run containing all computed results and options for further processing on success, ``None`` otherwise.
419  :rtype: module_identification.Result or None
420  )");
421 
422  m.def(
423  "execute_on_gates",
424  [](const std::vector<hal::Gate*>& gates, const module_identification::Configuration& config) -> std::optional<module_identification::Result> {
425  const auto res = module_identification::execute_on_gates(gates, config);
426  if (res.is_ok())
427  {
428  return res.get();
429  }
430  else
431  {
432  log_error("python_context", "error encountered while executing module identification on gates:\n{}", res.get_error().get());
433  return std::nullopt;
434  }
435  },
436  py::arg("gates"),
437  py::arg("config"),
438  R"(
439  Perform a module identification run on the specified gates with the provided configuration.
440 
441  This function executes the module identification process on a specific set of gates. It uses the provided configuration to guide the identification process and returns a result object containing information about all analyzed candidates.
442 
443  :param list[hal_py.Gate] gates: The gates to be analyzed.
444  :param module_identification.Configuration config: The configuration to guide the identification process.
445  :returns: The result of the run containing all computed results and options for further processing on success, ``None`` otherwise.
446  :rtype: module_identification.Result or None
447  )");
448 
449  // Define Architecture enum
450  py::enum_<module_identification::Architecture> py_architecture(m, "Architecture", R"(
451  Defines supported FPGA architectures.
452  This enum specifies the FPGA architectures that are supported by the module identification plugin.
453  )");
454 
455  py_architecture.value("lattice_ice40", module_identification::Architecture::lattice_ice40, R"(Lattice iCE40 FPGA architecture.)")
456  .value("xilinx_unisim", module_identification::Architecture::xilinx_unisim, R"(Xilinx Unisim FPGA architecture.)")
457  .export_values();
458 
459  // Define CandidateType enum
460  py::enum_<module_identification::CandidateType> py_candidate_type(m, "CandidateType", R"(
461  Enumeration of the different candidate types for module identification.
462  This enum specifies the types of operations that the module identification process can recognize and verify, such as arithmetic operations and comparisons.
463  )");
464 
465  py_candidate_type.value("addition", module_identification::CandidateType::addition, R"(Addition operation.)")
466  .value("addition_offset", module_identification::CandidateType::addition, R"(Addition with constant offset operation.)")
467  .value("subtraction", module_identification::CandidateType::subtraction, R"(Subtraction operation.)")
468  .value("counter", module_identification::CandidateType::counter, R"(Counter operation.)")
469  .value("negation", module_identification::CandidateType::negation, R"(Negation operation.)")
470  .value("absolute", module_identification::CandidateType::absolute, R"(Absolute value operation.)")
471  .value("constant_multiplication", module_identification::CandidateType::constant_multiplication, R"(Constant multiplication operation.)")
472  .value("constant_multiplication_offset", module_identification::CandidateType::constant_multiplication_offset, R"(Constant multiplication with constant offset operation.)")
473  .value("equal", module_identification::CandidateType::equal, R"(Equality comparison.)")
474  .value("less_than", module_identification::CandidateType::less_than, R"(Less-than comparison.)")
475  .value("less_equal", module_identification::CandidateType::less_equal, R"(Less-than-or-equal comparison.)")
476  .value("signed_less_than", module_identification::CandidateType::signed_less_than, R"(Signed less-than comparison.)")
477  .value("signed_less_equal", module_identification::CandidateType::signed_less_equal, R"(Signed less-than-or-equal comparison.)")
478  .value("value_check", module_identification::CandidateType::value_check, R"(Value check against a constant operation.)")
479  .value("none", module_identification::CandidateType::none, R"(No operation.)")
480  .value("mixed", module_identification::CandidateType::mixed, R"(Mixed operation, for merged `VerifiedCandidates` that contain multiple candidate types.)")
481  .export_values();
482 
483  // Define MultithreadingPriority enum
484  py::enum_<module_identification::MultithreadingPriority> py_multithreading_priority(m, "MultithreadingPriority", R"(
485  Specifies the strategy for multithreading in the module identification process.
486  This enum class defines the strategies for managing multithreading in the module identification plugin.
487  The strategies determine how resources are allocated and prioritized when performing multithreaded operations.
488  )");
489 
490  py_multithreading_priority
492  Prioritize time efficiency in multithreading.
493  This option specifies that multithreading should be handled with a priority on time efficiency,
494  aiming to complete tasks as quickly as possible.
495  )")
497  Prioritize memory efficiency in multithreading.
498  This option specifies that multithreading should be handled with a priority on memory efficiency,
499  aiming to minimize memory usage even if it results in longer execution times.
500  )")
501  .export_values();
502 
503  // Define WordLevelOperation struct
504  py::class_<module_identification::WordLevelOperation> py_word_level_operation(m, "WordLevelOperation", R"(
505  Represents a word-level operation with its operands, control signals, and the operation implemented as a HAL Boolean function.
506  This struct is used to store the information related to a word-level operation, which includes the operands, control signals, and the Boolean function representing the operation.
507  )");
508 
509  py_word_level_operation.def(py::init<>());
510 
511  py_word_level_operation.def_readwrite("operands", &module_identification::WordLevelOperation::operands, R"(
512  A map of operand names to their corresponding Boolean functions.
513 
514  :type: dict[str, hal_py.BooleanFunction]
515  )");
516 
517  py_word_level_operation.def_readwrite("ctrl_signals", &module_identification::WordLevelOperation::ctrl_signals, R"(
518  A vector of control signals as Boolean functions.
519 
520  :type: list[hal_py.BooleanFunction]
521  )");
522 
523  py_word_level_operation.def_readwrite("operation", &module_identification::WordLevelOperation::operation, R"(
524  The Boolean function representing the word-level operation.
525 
526  :type: hal_py.BooleanFunction
527  )");
528 
529  // Define VerifiedCandidate class
530  py::class_<module_identification::VerifiedCandidate> py_verified_candidate(m, "VerifiedCandidate", R"(
531  This class is used to represent a verified candidate within the module identification process, providing methods for their creation, manipulation, and verification.
532  )");
533 
534  py_verified_candidate.def_static("merge", &module_identification::VerifiedCandidate::merge, py::arg("candidates"), R"(
535  Merge multiple verified candidates into a single candidate.
536 
537  This function merges a vector of verified candidates into a single candidate.
538 
539  :param list[module_identification.VerifiedCandidate] candidates: A vector of verified candidates to merge.
540  :returns: The merged verified candidate on success.
541  :rtype: module_identification.VerifiedCandidate
542  )");
543 
544  py_verified_candidate.def("get_candidate_info", &module_identification::VerifiedCandidate::get_candidate_info, R"(
545  Get the candidate information as a string.
546 
547  :returns: A string containing the candidate information.
548  :rtype: str
549  )");
550 
551  py_verified_candidate.def("is_verified", &module_identification::VerifiedCandidate::is_verified, R"(
552  Check if the candidate is verified.
553 
554  :returns: ``True`` if the candidate is verified, ``False`` otherwise.
555  :rtype: bool
556  )");
557 
558  py_verified_candidate.def("get_name", &module_identification::VerifiedCandidate::get_name, R"(
559  Get the name of the candidate that represents the functionality of the candidate.
560 
561  :returns: A string containing the name of the candidate.
562  :rtype: str
563  )");
564 
565  py_verified_candidate.def("get_merged_word_level_operation", &module_identification::VerifiedCandidate::get_merged_word_level_operation, R"(
566  Get the merged word-level operation for the candidate.
567 
568  The mergred word-level operation includes all word-level oprations that we were able to verify for different control mappings of the candidate.
569 
570  :returns: The merged word-level operation as a Boolean function.
571  :rtype: hal_py.BooleanFunction
572  )");
573 
574  py_verified_candidate.def_readwrite("operands", &module_identification::VerifiedCandidate::m_operands, R"(
575  A vector of operands.
576 
577  :type: list[list[hal_py.Net]]
578  )");
579 
580  py_verified_candidate.def_readwrite("output_nets", &module_identification::VerifiedCandidate::m_output_nets, R"(
581  A vector of output nets.
582 
583  :type: list[hal_py.Net]
584  )");
585 
586  py_verified_candidate.def_readwrite("control_signals", &module_identification::VerifiedCandidate::m_control_signals, R"(
587  A vector of control signal nets.
588 
589  :type: list[hal_py.Net]
590  )");
591 
592  py_verified_candidate.def_readwrite("control_signal_mappings", &module_identification::VerifiedCandidate::m_control_signal_mappings, R"(
593  A vector of all control mappings covered by this candidate.
594 
595  :type: list[dict[hal_py.Net, hal_py.BooleanFunction.Value]]
596  )");
597 
598  py_verified_candidate.def_readwrite("word_level_operations", &module_identification::VerifiedCandidate::m_word_level_operations, R"(
599  A map of control signal mappings to their respective word-level operations.
600 
601  :type: dict[dict[hal_py.Net, hal_py.BooleanFunction.Value], hal_py.BooleanFunction]
602  )");
603 
604  py_verified_candidate.def_readwrite("gates", &module_identification::VerifiedCandidate::m_gates, R"(
605  A vector of gates associated with the candidate.
606 
607  :type: list[hal_py.Gate]
608  )");
609 
610  py_verified_candidate.def_readwrite("base_gates", &module_identification::VerifiedCandidate::m_base_gates, R"(
611  A vector of base gates associated with the candidate.
612 
613  :type: list[hal_py.Gate]
614  )");
615 
616  py_verified_candidate.def_readwrite("total_input_nets", &module_identification::VerifiedCandidate::m_total_input_nets, R"(
617  A vector of all input nets to the gate subgraph, regardless of whether they appear in a word-level operation or not.
618 
619  :type: list[hal_py.Net]
620  )");
621 
622  py_verified_candidate.def_readwrite("total_output_nets", &module_identification::VerifiedCandidate::m_total_output_nets, R"(
623  A vector of all output nets of the subgraph, regardless of whether they appear in a word-level operation or not.
624 
625  :type: list[hal_py.Net]
626  )");
627 
628  py_verified_candidate.def_readwrite("types", &module_identification::VerifiedCandidate::m_types, R"(
629  The set of contained candidate types.
630 
631  :type: set[module_identification.CandidateType]
632  )");
633 
634  py_verified_candidate.def_readwrite("verified", &module_identification::VerifiedCandidate::m_verified, R"(
635  Indicates whether the candidate is verified.
636 
637  :type: bool
638  )");
639  }
640 } // namespace hal
This file contains the definition of the Architecture enum for the module identification plugin.
This file contains the enumeration and constants for the candidate types used in the module identific...
std::set< std::string > get_dependencies() const override
Get the plugin dependencies.
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.
bool is_verified() const
Check if the candidate is verified.
std::string get_name() const
Get the name of the candidate that represents the functionality of the candidate.
BooleanFunction get_merged_word_level_operation() const
Get the merged word-level operation for the candidate.
std::vector< std::map< Net *, BooleanFunction::Value > > m_control_signal_mappings
std::string get_candidate_info() const
Get the candidate information as a string.
std::map< std::map< Net *, BooleanFunction::Value >, BooleanFunction > m_word_level_operations
static hal::Result< VerifiedCandidate > merge(const std::vector< VerifiedCandidate > &candidates)
Merge multiple verified candidates into a single candidate.
std::vector< std::vector< Net * > > m_operands
uint32_t u32
Definition: defines.h:41
#define log_error(channel,...)
Definition: log.h:78
This file contains the struct Configuration for module identification analysis.
This file contains the function declarations for the Module Identification plugin in hal.
This file contains the enum class for multithreading strategies in the module identification process.
const Module * module(const Gate *g, const NodeBoxes &boxes)
hal::Result< Result > execute(const Configuration &config)
Perform a full run of the module identification process on the given netlist with the provided config...
hal::Result< Result > execute_on_gates(const std::vector< Gate * > &gates, const Configuration &config)
Perform a module identification run on the specified gates with the provided configuration.
@ mixed
Mixed operation, for merged VerifiedCandidates that contain multiple candidate types.
@ signed_less_equal
Signed less-than-or-equal comparison.
@ less_equal
Less-than-or-equal comparison.
@ value_check
Value check against a constant operation.
@ absolute
Absolute value operation.
@ constant_multiplication
Constant multiplication operation.
@ signed_less_than
Signed less-than comparison.
@ constant_multiplication_offset
Constant multiplication operation with a constant offset.
@ xilinx_unisim
Xilinx Unisim FPGA architecture.
@ lattice_ice40
Lattice iCE40 FPGA architecture.
@ time_priority
Prioritize time efficiency in multithreading.
@ memory_priority
Prioritize memory efficiency in multithreading.
Definition: defines.h:45
PYBIND11_PLUGIN(hal_py)
This file contains the structures and functions related to module identification results.
Configuration for the module identification analysis.
Definition: configuration.h:55
Configuration & with_multithreading_priority(const MultithreadingPriority &priority)
Set the multithreading priority type.
Configuration & with_types_to_check(const std::vector< module_identification::CandidateType > &types_to_check)
Set the candidate types to be checked.
Netlist * m_netlist
The netlist to be analyzed.
Definition: configuration.h:71
Configuration & with_already_classified_candidates(const std::vector< std::vector< Gate * >> &already_classified_candidates)
Add gates to be ignored during processing.
std::vector< std::set< Gate * > > m_blocked_base_candidates
Base candidates to block during analysis.
std::vector< module_identification::CandidateType > m_types_to_check
CandidateTypes that shall be checked. Defaults to all checkable candidate types.
Definition: configuration.h:81
std::vector< std::vector< Gate * > > m_known_registers
A vector handling possibly known registers.
Definition: configuration.h:76
u32 m_max_control_signals
Maximum number of control signals to be tested. Defaults to 3.
Definition: configuration.h:91
Configuration & with_known_registers(const std::vector< std::vector< Gate * >> &registers)
Set the known registers for prioritization.
Configuration & with_blocked_base_candidates(const std::vector< std::set< Gate * >> &blocked_base_candidates)
Add base candidates to be blocked during analysis.
std::vector< std::vector< Gate * > > m_already_classified_candidates
Gates to ignore during processing.
Definition: configuration.h:96
Configuration & with_max_control_signals(const u32 &max_control_signals)
Set the maximum number of control signals to be tested.
Configuration & with_max_thread_count(const u32 &max_thread_count)
Set the maximum number of threads.
MultithreadingPriority m_multithreading_priority
Choose which MultithreadingPriority to use for the analysis. Defaults to memory priority.
u32 m_max_thread_count
Maximum number of concurrent threads created during execution. Defaults to 1.
Definition: configuration.h:86
The result of a module identification run containing the candidates.
Definition: result.h:55
std::map< u32, std::vector< Gate * > > get_candidate_gates() const
Get a map of the candidate IDs to the gates contained inside the candidate.
Definition: result.cpp:57
std::map< u32, VerifiedCandidate > get_candidates() const
Get a map of the candidate IDs to the candidates.
Definition: result.cpp:68
std::set< Gate * > get_all_gates() const
Get all gates contained in any of the candidates.
Definition: result.cpp:107
std::map< u32, std::vector< Gate * > > get_verified_candidate_gates() const
Get a map of the candidate IDs to the gates contained inside the verified candidates.
Definition: result.cpp:28
std::set< Gate * > get_all_verified_gates() const
Get all gates contained in any of the verified candidates.
Definition: result.cpp:124
static std::vector< std::vector< std::set< Gate * > > > assign_base_candidates_to_iterations(const std::vector< Result > &iteration_results, const bool create_block_lists=false)
For different runs of the plugin figure out in which iteration the plugin found the highest quality r...
Definition: result.cpp:872
Netlist * get_netlist() const
Get the netlist on which module identification has been performed.
Definition: result.cpp:23
std::string get_timing_stats() const
Get the collected timing information formatted as a JSON string.
Definition: result.cpp:680
std::map< u32, VerifiedCandidate > get_verified_candidates() const
Get a map of the candidate IDs to the verified candidates.
Definition: result.cpp:43
BooleanFunction operation
The Boolean function representing the word-level operation.
std::map< std::string, BooleanFunction > operands
A map of operand names to their corresponding Boolean functions.
std::vector< BooleanFunction > ctrl_signals
A vector of control signals as Boolean functions.