HAL  v4.5.0-124-g47ab54673
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
symbolic_state.cpp
Go to the documentation of this file.
2 
3 namespace hal
4 {
5  namespace SMT
6  {
7  SymbolicState::SymbolicState(const std::vector<BooleanFunction>& variables)
8  {
9  for (const auto& v : variables)
10  {
11  if (v.is_variable())
12  {
13  this->variable.emplace(v.clone(), v.clone());
14  }
15  }
16  }
17 
19  {
20  auto it = this->variable.find(key);
21  return (it == this->variable.end()) ? key : it->second;
22  }
23 
24  std::unordered_map<std::string, const BooleanFunction*> SymbolicState::get_bindings() const
25  {
26  std::unordered_map<std::string, const BooleanFunction*> res;
27  for (const auto& [key, value] : this->variable)
28  {
29  const auto& key_node = key.get_top_level_node();
30  if (key_node.is_variable())
31  {
32  res.emplace(key_node.variable, &value);
33  }
34  }
35  return res;
36  }
37 
38  void SymbolicState::set(const BooleanFunction& key, const BooleanFunction& value)
39  {
40  if (key.is_variable())
41  {
42  // insert_or_assign, not emplace: emplace leaves an existing binding untouched, so
43  // setting a variable a second time did nothing and a loop that steps a state forward
44  // silently kept the value it started with.
45  this->variable.insert_or_assign(key.clone(), value.clone());
46  }
47  }
48  } // namespace SMT
49 } // namespace hal
BooleanFunction clone() const
const BooleanFunction & get(const BooleanFunction &key) const
std::unordered_map< std::string, const BooleanFunction * > get_bindings() const
SymbolicState(const std::vector< BooleanFunction > &variables={})
void set(const BooleanFunction &key, const BooleanFunction &value)
Definition: defines.h:45