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