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