HAL  v4.5.0-254-g8f9f6a423
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
candidate_context.cpp
Go to the documentation of this file.
2 
7 
8 namespace hal
9 {
10  namespace module_identification
11  {
12  CandidateContext::CandidateContext(const Netlist* nl, const std::vector<Gate*>& gates) : m_gates(gates), m_netlist(nl){};
13 
14 #ifdef HAL_CANDIDATE_CONTEXT
16  {
17  const auto subgraph_dec = SubgraphNetlistDecorator(*m_netlist);
18  auto gate_cache_res = subgraph_dec.make_subgraph_function_cache(m_gates);
19  if (gate_cache_res.is_error())
20  {
21  return ERR_APPEND(gate_cache_res.get_error(), "cannot populate context with Boolean functions: failed to create subgraph function cache");
22  }
23  auto gate_cache = gate_cache_res.get();
24 
25  for (const auto& n : nets)
26  {
27  auto bf_res = subgraph_dec.get_subgraph_function(n, gate_cache);
28  if (bf_res.is_error())
29  {
30  return ERR_APPEND(bf_res.get_error(),
31  "cannot populate context with Boolean functions: failed to generate subgraph function for net " + n->get_name() + " with ID " + std::to_string(n->get_id()));
32  }
33  auto bf = bf_res.get();
34 
35  auto sub_res = BooleanFunctionDecorator(bf).substitute_power_ground_nets(m_netlist);
36  if (sub_res.is_error())
37  {
38  return ERR_APPEND(sub_res.get_error(),
39  "cannot populate context with Boolean functions: failed to substitute power and ground nets for net " + n->get_name() + " with ID "
40  + std::to_string(n->get_id()));
41  }
42 
43  m_boolean_function_cache.insert({{n, {}}, sub_res.get().simplify_local()});
44  }
45 
46  return OK({});
47  }
48 
49  Result<const BooleanFunction> CandidateContext::get_boolean_function_const(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping) const
50  {
51  if (const auto it = m_boolean_function_cache.find({n, ctrl_mapping}); it != m_boolean_function_cache.end())
52  {
53  return OK(it->second);
54  }
55 
56  return ERR("Failed to get boolean function from chache");
57  }
58 
59  Result<std::vector<BooleanFunction>> CandidateContext::get_boolean_functions_const(const std::vector<Net*> nets, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping) const
60  {
61  std::vector<BooleanFunction> functions;
62  for (const auto& net : nets)
63  {
64  const auto bf_res = get_boolean_function_const(net, ctrl_mapping);
65  if (bf_res.is_error())
66  {
67  return ERR(bf_res.get_error().get());
68  }
69  functions.push_back(bf_res.get().clone());
70  }
71 
72  return OK(functions);
73  }
74 
75  Result<const BooleanFunction> CandidateContext::get_boolean_function(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping)
76  {
77  if (const auto it = m_boolean_function_cache.find({n, ctrl_mapping}); it != m_boolean_function_cache.end())
78  {
79  return OK(it->second);
80  }
81 
82  if (ctrl_mapping.empty())
83  {
84  auto func_res = SubgraphNetlistDecorator(*m_netlist).get_subgraph_function(m_gates, n);
85  if (func_res.is_error())
86  {
87  return ERR_APPEND(func_res.get_error(),
88  "cannot get Boolean function from context for net " + n->get_name() + " with ID " + std::to_string(n->get_id()) + ": failed subgraph function generation");
89  }
90  auto bf = func_res.get();
91 
92  auto sub_res = BooleanFunctionDecorator(bf).substitute_power_ground_nets(m_netlist);
93  if (sub_res.is_error())
94  {
95  return ERR_APPEND(sub_res.get_error(),
96  "cannot get Boolean function from context for net " + n->get_name() + " with ID " + std::to_string(n->get_id()) + ": failed to substitute power/ground nets");
97  }
98  auto sub_bf = sub_res.get().simplify_local();
99 
100  const auto [it, _] = m_boolean_function_cache.insert({{n, ctrl_mapping}, sub_bf});
101  return OK(it->second);
102  }
103 
104  const auto bf_res = get_boolean_function(n, {});
105  if (bf_res.is_error())
106  {
107  return bf_res;
108  }
109  const auto& bf = bf_res.get();
110 
111  std::map<std::string, BooleanFunction> substitution_map;
112  for (const auto& [n_ctrl, val] : ctrl_mapping)
113  {
114  substitution_map.insert({BooleanFunctionNetDecorator(*n_ctrl).get_boolean_variable_name(), BooleanFunction::Const(val)});
115  }
116  auto sub_res = bf.substitute(substitution_map);
117  if (sub_res.is_error())
118  {
119  return ERR_APPEND(sub_res.get_error(),
120  "cannot get Boolean function from context for net " + n->get_name() + " with ID " + std::to_string(n->get_id()) + ": failed to substitute with input mapping");
121  }
122  const auto sub_bf = sub_res.get().simplify_local();
123 
124  const auto [it, _] = m_boolean_function_cache.insert({{n, ctrl_mapping}, sub_bf});
125  return OK(it->second);
126  }
127 
128  Result<std::vector<BooleanFunction>> CandidateContext::get_boolean_functions(const std::vector<Net*> nets, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping)
129  {
130  std::vector<BooleanFunction> functions;
131  for (const auto& net : nets)
132  {
133  const auto bf_res = get_boolean_function(net, ctrl_mapping);
134  if (bf_res.is_error())
135  {
136  return ERR(bf_res.get_error().get());
137  }
138  functions.push_back(bf_res.get().clone());
139  }
140 
141  return OK(functions);
142  }
143 
144  Result<const std::set<std::string>> CandidateContext::get_variable_names(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping)
145  {
146  if (const auto it = m_boolean_vars_cache.find({n, ctrl_mapping}); it != m_boolean_vars_cache.end())
147  {
148  return OK(it->second);
149  }
150 
151  const auto bf_res = get_boolean_function(n, ctrl_mapping);
152  if (bf_res.is_error())
153  {
154  return ERR_APPEND(bf_res.get_error(),
155  "cannot get variable names from context for net " + n->get_name() + " with ID " + std::to_string(n->get_id()) + ": failed to retrieve Boolean function from context");
156  }
157  const auto& bf = bf_res.get();
158 
159  const auto [it, _] = m_boolean_vars_cache.insert({{n, ctrl_mapping}, bf.get_variable_names()});
160  return OK(it->second);
161  }
162 
163  Result<const std::set<Net*>> CandidateContext::get_variable_nets(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping)
164  {
165  const auto& var_names_res = get_variable_names(n, ctrl_mapping);
166  if (var_names_res.is_error())
167  {
168  return ERR_APPEND(var_names_res.get_error(),
169  "cannot get variable nets from context for net " + n->get_name() + " with ID " + std::to_string(n->get_id()) + ": failed to retrieve variable names from context");
170  }
171  const auto& var_names = var_names_res.get();
172 
173  std::set<Net*> result;
174  for (const auto& var : var_names)
175  {
176  result.insert(BooleanFunctionNetDecorator::get_net_from(m_netlist, var).get());
177  }
178 
179  return OK(result);
180  }
181 
182  Result<std::unordered_map<std::string, double>> CandidateContext::get_boolean_influence(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping)
183  {
184  if (const auto it = m_boolean_influence_cache.find({n, ctrl_mapping}); it != m_boolean_influence_cache.end())
185  {
186  return OK(it->second);
187  }
188 
189  const auto bf_res = get_boolean_function(n, ctrl_mapping);
190  if (bf_res.is_error())
191  {
192  return ERR_APPEND(bf_res.get_error(),
193  "cannot get Boolean influence from context for net " + n->get_name() + " with ID " + std::to_string(n->get_id())
194  + ": failed to retrieve Boolean function from context");
195  }
196  const auto& bf = bf_res.get();
197 
198  const auto res = boolean_influence::get_boolean_influence(bf, 1024);
199  // const auto res = boolean_influence::get_boolean_influence(bf, 32000);
200  if (res.is_error())
201  {
202  return ERR_APPEND(res.get_error(),
203  "cannot get Boolean influence from context for net " + n->get_name() + " with ID " + std::to_string(n->get_id()) + ": failed to calculate Boolean influence");
204  }
205 
206  const auto [it, _] = m_boolean_influence_cache.insert({{n, ctrl_mapping}, res.get()});
207  return OK(it->second);
208  }
209 
210  Result<std::vector<BooleanFunction::Value>>
211  CandidateContext::evaluate(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping, const std::map<std::string, BooleanFunction::Value>& eval_mapping)
212  {
213  const auto bf = get_boolean_function(n, ctrl_mapping).get();
214  std::unordered_map<std::string, BooleanFunction::Value> unordered_eval_mapping = {eval_mapping.begin(), eval_mapping.end()};
215  return OK({bf.evaluate(unordered_eval_mapping).get()});
216  }
217 #endif
218 
219 #ifdef Z3_CANDIDATE_CONTEXT
220  Result<std::monostate> CandidateContext::populate_boolean_function_cache(const std::vector<Net*> nets)
221  {
222  auto func_res = z3_utils::get_subgraph_z3_functions(m_gates, nets, m_ctx);
223  if (func_res.is_error())
224  {
225  // TODO make all this return results
226  log_error("module_identification", "Error on boolean sugraph function creation, for nets: {}", func_res.get_error().get());
227  }
228  auto functions = func_res.get();
229 
230  for (u32 idx = 0; idx < nets.size(); idx++)
231  {
232  auto bf = functions.at(idx);
233  const auto vars = z3_utils::get_variable_names(bf);
234 
235  // substitute power and ground nets
236  z3::expr_vector from(m_ctx);
237  z3::expr_vector to(m_ctx);
238 
239  for (const std::string& var_name : vars)
240  {
241  const auto net_res = BooleanFunctionNetDecorator::get_net_from(m_netlist, var_name);
242  if (net_res.is_error())
243  {
244  log_error("module_identification", "Error when trying to replace gnd and vcc nets in boolean function for variable '{}': {}", var_name, net_res.get_error().get());
245  }
246  const Net* net = net_res.get();
247 
248  if (const auto sources = net->get_sources(); sources.size() == 1)
249  {
250  if (sources.front()->get_gate()->get_type()->has_property(GateTypeProperty::power))
251  {
252  from.push_back(m_ctx.bv_const(var_name.c_str(), 1));
253  to.push_back(m_ctx.bv_val(1, 1));
254  }
255  else if (sources.front()->get_gate()->get_type()->has_property(GateTypeProperty::ground))
256  {
257  from.push_back(m_ctx.bv_const(var_name.c_str(), 1));
258  to.push_back(m_ctx.bv_val(0, 1));
259  }
260  }
261  }
262 
263  bf = bf.substitute(from, to).simplify();
264 
265  const auto s_res = z3_utils::simplify_local(bf);
266  if (s_res.is_error())
267  {
268  std::cout << "ERROR: " << s_res.get_error().get() << std::endl;
269  }
270  bf = s_res.get();
271 
272  m_boolean_function_cache.insert({{nets.at(idx), {}}, bf});
273  }
274 
275  return OK({});
276  }
277 
278  Result<z3::expr> CandidateContext::get_boolean_function(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping)
279  {
280  if (const auto it = m_boolean_function_cache.find({n, ctrl_mapping}); it != m_boolean_function_cache.end())
281  {
282  return OK(it->second);
283  }
284 
285  if (ctrl_mapping.empty())
286  {
287  auto func_res = z3_utils::get_subgraph_z3_function(m_gates, n, m_ctx);
288  if (func_res.is_error())
289  {
290  // TODO make all this return results
291  log_error("module_identification", "Error on boolean sugraph function creation, for nets: {}", func_res.get_error().get());
292  }
293  auto bf = func_res.get();
294 
295  const auto vars = z3_utils::get_variable_names(bf);
296 
297  // substitute power and ground nets
298  z3::expr_vector from_power_gnd(m_ctx);
299  z3::expr_vector to_power_gnd(m_ctx);
300 
301  for (const std::string& var_name : vars)
302  {
303  const auto net_res = BooleanFunctionNetDecorator::get_net_from(m_netlist, var_name);
304  if (net_res.is_error())
305  {
306  log_error("module_identification", "Error when trying to replace gnd and vcc nets in boolean function for variable '{}': {}", var_name, net_res.get_error().get());
307  }
308  const Net* net = net_res.get();
309 
310  if (const auto sources = net->get_sources(); sources.size() == 1)
311  {
312  if (sources.front()->get_gate()->get_type()->has_property(GateTypeProperty::power))
313  {
314  from_power_gnd.push_back(m_ctx.bv_const(var_name.c_str(), 1));
315  to_power_gnd.push_back(m_ctx.bv_val(1, 1));
316  }
317  else if (sources.front()->get_gate()->get_type()->has_property(GateTypeProperty::ground))
318  {
319  from_power_gnd.push_back(m_ctx.bv_const(var_name.c_str(), 1));
320  to_power_gnd.push_back(m_ctx.bv_val(0, 1));
321  }
322  }
323  }
324 
325  bf = bf.substitute(from_power_gnd, to_power_gnd).simplify();
326 
327  const auto s_res = z3_utils::simplify_local(bf);
328  if (s_res.is_error())
329  {
330  std::cout << "ERROR: " << s_res.get_error().get() << std::endl;
331  }
332  bf = s_res.get();
333 
334  m_boolean_function_cache.insert({{n, {}}, bf});
335  }
336 
337  auto bf = get_boolean_function(n, {}).get();
338 
339  z3::expr_vector from(m_ctx);
340  z3::expr_vector to(m_ctx);
341  for (const auto& [cn, val] : ctrl_mapping)
342  {
343  from.push_back(m_ctx.bv_const(BooleanFunctionNetDecorator(*cn).get_boolean_variable_name().c_str(), 1));
344  to.push_back(m_ctx.bv_val(val == BooleanFunction::Value::ZERO ? 0 : 1, 1));
345  }
346  bf = bf.substitute(from, to).simplify();
347 
348  const auto s_res = z3_utils::simplify_local(bf);
349  if (s_res.is_error())
350  {
351  std::cout << "ERROR: " << s_res.get_error().get() << std::endl;
352  }
353  bf = s_res.get();
354 
355  const auto it = m_boolean_function_cache.insert({{n, ctrl_mapping}, bf});
356  return OK(it.first->second);
357  }
358 
359  Result<z3::expr> CandidateContext::get_boolean_function_const(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping) const
360  {
361  if (const auto it = m_boolean_function_cache.find({n, ctrl_mapping}); it != m_boolean_function_cache.end())
362  {
363  return OK(it->second);
364  }
365 
366  std::cout << "Control Mapping: " << std::endl;
367  for (const auto& [cn, v] : ctrl_mapping)
368  {
369  std::cout << "\t" << cn->get_id() << ": " << v << std::endl;
370  }
371 
372  std::cout << "Candidate Gates: " << std::endl;
373  for (const auto& g : this->m_gates)
374  {
375  std::cout << "\t" << g->get_id() << ": " << g->get_name() << std::endl;
376  }
377 
378  return ERR("Failed to get boolean function for net " + n->get_name() + " with ID " + std::to_string(n->get_id()) + " from boolean function cache");
379  }
380 
381  Result<BooleanFunction> CandidateContext::get_hal_boolean_function(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping)
382  {
383  if (const auto it = m_boolean_function_hal_cache.find({n, ctrl_mapping}); it != m_boolean_function_hal_cache.end())
384  {
385  return OK(it->second);
386  }
387 
388  const auto bf_res = get_boolean_function(n, ctrl_mapping);
389  if (bf_res.is_error())
390  {
391  return ERR(bf_res.get_error().get());
392  }
393 
394  const auto bf_hal_res = z3_utils::to_bf(bf_res.get());
395  if (bf_hal_res.is_error())
396  {
397  return ERR(bf_hal_res.get_error().get());
398  }
399 
400  const auto [it, _] = m_boolean_function_hal_cache.insert({{n, ctrl_mapping}, bf_hal_res.get()});
401  return OK(it->second);
402  }
403 
404  Result<BooleanFunction> CandidateContext::get_hal_boolean_function_const(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping)
405  {
406  if (const auto it = m_boolean_function_hal_cache.find({n, ctrl_mapping}); it != m_boolean_function_hal_cache.end())
407  {
408  return OK(it->second);
409  }
410 
411  std::cout << "Control Mapping: " << std::endl;
412  for (const auto& [cn, v] : ctrl_mapping)
413  {
414  std::cout << "\t" << cn->get_id() << ": " << v << std::endl;
415  }
416 
417  std::cout << "Candidate Gates: " << std::endl;
418  for (const auto& g : this->m_gates)
419  {
420  std::cout << "\t" << g->get_id() << ": " << g->get_name() << std::endl;
421  }
422 
423  return ERR("Failed to get boolean function for net " + n->get_name() + " with ID " + std::to_string(n->get_id()) + " from boolean function cache");
424  }
425 
426  Result<std::vector<BooleanFunction>> CandidateContext::get_boolean_functions(const std::vector<Net*>& nets, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping)
427  {
428  std::vector<BooleanFunction> functions;
429  for (const auto& net : nets)
430  {
431  const auto bf_hal_res = get_hal_boolean_function(net, ctrl_mapping);
432  if (bf_hal_res.is_error())
433  {
434  return ERR(bf_hal_res.get_error().get());
435  }
436 
437  functions.push_back(bf_hal_res.get());
438  }
439 
440  return OK(functions);
441  }
442 
443  Result<std::vector<BooleanFunction>> CandidateContext::get_boolean_functions_const(const std::vector<Net*>& nets, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping)
444  {
445  std::vector<BooleanFunction> functions;
446  for (const auto& net : nets)
447  {
448  const auto bf_hal_res = get_hal_boolean_function_const(net, ctrl_mapping);
449  if (bf_hal_res.is_error())
450  {
451  return ERR(bf_hal_res.get_error().get());
452  }
453 
454  functions.push_back(bf_hal_res.get());
455  }
456 
457  return OK(functions);
458  }
459 
460  Result<std::set<std::string>> CandidateContext::get_variable_names(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping)
461  {
462  if (const auto it = m_boolean_vars_cache.find({n, ctrl_mapping}); it != m_boolean_vars_cache.end())
463  {
464  return OK(it->second);
465  }
466 
467  const auto bf_res = get_boolean_function(n, ctrl_mapping);
468  if (bf_res.is_error())
469  {
470  return ERR_APPEND(bf_res.get_error(),
471  "cannot get variable names from context for net " + n->get_name() + " with ID " + std::to_string(n->get_id()) + ": failed to retrieve Boolean function from context");
472  }
473  const auto& bf = bf_res.get();
474 
475  const auto [it, _] = m_boolean_vars_cache.insert({{n, ctrl_mapping}, z3_utils::get_variable_names(bf)});
476  return OK(it->second);
477  }
478 
479  Result<std::set<Net*>> CandidateContext::get_variable_nets(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping)
480  {
481  const auto& var_names_res = get_variable_names(n, ctrl_mapping);
482  if (var_names_res.is_error())
483  {
484  return ERR_APPEND(var_names_res.get_error(),
485  "cannot get variable nets from context for net " + n->get_name() + " with ID " + std::to_string(n->get_id()) + ": failed to retrieve variable names from context");
486  }
487  const auto& var_names = var_names_res.get();
488 
489  std::set<Net*> result;
490  for (const auto& var : var_names)
491  {
492  result.insert(BooleanFunctionNetDecorator::get_net_from(m_netlist, var).get());
493  }
494 
495  return OK(result);
496  }
497 
498  Result<std::unordered_map<std::string, double>> CandidateContext::get_boolean_influence(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping)
499  {
500  if (const auto it = m_boolean_influence_cache.find({n, ctrl_mapping}); it != m_boolean_influence_cache.end())
501  {
502  return OK(it->second);
503  }
504 
505  const auto& bf = get_boolean_function(n, ctrl_mapping).get();
506  Result<std::unordered_map<std::string, double>> res = boolean_influence::get_boolean_influence(bf, 1024);
507  if (res.is_error())
508  {
509  return ERR_APPEND(res.get_error(), "failed to create boolean influence");
510  }
511  m_boolean_influence_cache.insert({{n, ctrl_mapping}, res.get()});
512 
513  return OK(m_boolean_influence_cache.at({n, ctrl_mapping}));
514  }
515 
516  Result<std::vector<BooleanFunction::Value>>
517  CandidateContext::evaluate(const Net* n, const std::map<Net*, BooleanFunction::Value>& ctrl_mapping, const std::map<std::string, BooleanFunction::Value>& eval_mapping)
518  {
519  auto bf_z3 = get_boolean_function(n, ctrl_mapping).get();
520 
521  z3::expr_vector from(m_ctx);
522  z3::expr_vector to(m_ctx);
523 
524  // Iterate over the map of variables and their assigned integer values.
525  for (const auto& [var_name, val] : eval_mapping)
526  {
527  z3::expr var = m_ctx.bv_const(var_name.c_str(), 1); // Create a variable expression.
528  z3::expr val_expr = m_ctx.bv_val(val, 1); // Create a value expression.
529  from.push_back(var); // Prepare for substitution.
530  to.push_back(val_expr);
531  }
532 
533  // Substitute variables in the original expression with the provided values.
534  z3::expr result = bf_z3.substitute(from, to).simplify();
535 
536  if (!result.is_numeral())
537  {
538  return ERR("eval result is non numeral");
539  }
540 
541  const u64 res_int = result.get_numeral_uint64();
542 
543  if (res_int == 1)
544  {
545  return OK({BooleanFunction::Value::ONE});
546  }
547 
548  if (res_int == 0)
549  {
550  return OK({BooleanFunction::Value::ZERO});
551  }
552 
553  return ERR("invalid value " + std::to_string(res_int) + " as result of eval");
554  };
555 #endif
556  } // namespace module_identification
557 } // namespace hal
This file contains the CandidateContext struct and that is used for optimization purposes during the ...
static BooleanFunction Const(const BooleanFunction::Value &value)
static Result< Net * > get_net_from(const Netlist *netlist, const BooleanFunction &var)
uint64_t u64
Definition: defines.h:42
uint32_t u32
Definition: defines.h:41
#define log_error(channel,...)
Definition: log.h:78
#define ERR(message)
Definition: result.h:60
#define OK(...)
Definition: result.h:56
#define ERR_APPEND(prev_error, message)
Definition: result.h:64
Result< std::unordered_map< std::string, double > > get_boolean_influence(const BooleanFunction &bf, const u32 num_evaluations=32000)
S to(const T &str)
std::set< std::string > get_variable_names(const z3::expr &e)
Extracts all variable names from a z3 expression.
Definition: z3_utils.cpp:481
Result< z3::expr > simplify_local(const z3::expr &e, std::unordered_map< u32, z3::expr > &cache, const bool check_correctness=false)
Applies hand-crafted simplification rules iteratively until no further simplifications can be made.
Result< z3::expr > get_subgraph_z3_function(const std::vector< Gate * > &subgraph_gates, const Net *subgraph_output, z3::context &ctx)
Get the z3 expression representation of a combined Boolean function of a subgraph of combinational ga...
Result< std::vector< z3::expr > > get_subgraph_z3_functions(const std::vector< Gate * > &subgraph_gates, const std::vector< Net * > &subgraph_outputs, z3::context &ctx)
Get the z3 expression representations of combined Boolean functions of a subgraph of combinational ga...
Result< BooleanFunction > to_bf(const z3::expr &e)
Definition: z3_utils.cpp:443
Definition: defines.h:45
Net * net
hal::Result< const std::set< Net * > > get_variable_nets(const Net *n, const std::map< Net *, BooleanFunction::Value > &ctrl_mapping)
Retrieves the variable nets for a given net and control mapping.
hal::Result< std::unordered_map< std::string, double > > get_boolean_influence(const Net *n, const std::map< Net *, BooleanFunction::Value > &ctrl_mapping)
Retrieves the boolean influence for a given net and control mapping.
std::vector< Gate * > m_gates
The gates of the corresponding structural candidate.
CandidateContext(const Netlist *nl, const std::vector< Gate * > &gates)
Constructs a new CandidateContext object saving results for one structural candidate.
hal::Result< std::vector< BooleanFunction > > get_boolean_functions_const(const std::vector< Net * > nets, const std::map< Net *, BooleanFunction::Value > &ctrl_mapping) const
Retrieves a set of constant boolean functions for a given set of nets and control mapping.
hal::Result< const BooleanFunction > get_boolean_function_const(const Net *n, const std::map< Net *, BooleanFunction::Value > &ctrl_mapping) const
Retrieves a constant boolean function for a given net and control mapping.
hal::Result< std::monostate > populate_boolean_function_cache(const std::vector< Net * > nets)
Populates the boolean function cache for a set of nets.
const Netlist * m_netlist
The netlist associated with the candidate context.
hal::Result< const BooleanFunction > get_boolean_function(const Net *n, const std::map< Net *, BooleanFunction::Value > &ctrl_mapping)
Retrieves a boolean function for a given net and control mapping.
hal::Result< std::vector< BooleanFunction::Value > > evaluate(const Net *n, const std::map< Net *, BooleanFunction::Value > &ctrl_mapping, const std::map< std::string, BooleanFunction::Value > &eval_mapping)
Evaluates the boolean function for a given net, control mapping, and evaluation mapping.
hal::Result< const std::set< std::string > > get_variable_names(const Net *n, const std::map< Net *, BooleanFunction::Value > &ctrl_mapping)
Retrieves the variable names for a given net and control mapping.
hal::Result< std::vector< BooleanFunction > > get_boolean_functions(const std::vector< Net * > nets, const std::map< Net *, BooleanFunction::Value > &ctrl_mapping)
Retrieves a set of boolean functions for a given set of nets and control mapping.
The result of a module identification run containing the candidates.
Definition: result.h:55