HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
simulation_gate_combinational.cpp
Go to the documentation of this file.
2 
3 namespace hal
4 {
5  NetlistSimulator::SimulationGateCombinational::SimulationGateCombinational(const Gate* gate) : SimulationGate(gate)
6  {
7  std::unordered_map<std::string, BooleanFunction> functions = gate->get_boolean_functions();
8 
9  m_output_pins = gate->get_type()->get_output_pins();
10 
11  for (const GatePin* pin : m_output_pins)
12  {
13  const Net* out_net = gate->get_fan_out_net(pin);
14  m_output_nets.push_back(out_net);
15 
16  // resolve recursion within output functions
17  BooleanFunction& func = functions.at(pin->get_name());
18  while (true)
19  {
20  auto vars = func.get_variable_names();
21  bool exit = true;
22  for (const GatePin* other_pin : m_output_pins)
23  {
24  if (const std::string& other_pin_name = other_pin->get_name(); std::find(vars.begin(), vars.end(), other_pin_name) != vars.end())
25  {
26  func = func.substitute(other_pin_name, functions.at(other_pin_name)).get();
27  exit = false;
28  }
29  }
30  if (exit)
31  {
32  break;
33  }
34  }
35  m_functions.emplace(out_net, func);
36  }
37  }
38 
39  bool NetlistSimulator::SimulationGateCombinational::simulate(const Simulation& simulation, const WaveEvent& event, std::map<std::pair<const Net*, u64>, BooleanFunction::Value>& new_events)
40  {
41  UNUSED(simulation);
42 
43  // compute delay, currently just a placeholder
44  u64 delay = 0;
45 
46  for (auto out_net : m_output_nets)
47  {
48  BooleanFunction::Value result = m_functions[out_net].evaluate(m_input_values).get();
49 
50  new_events[std::make_pair(out_net, event.time + delay)] = result;
51  }
52 
53  return true;
54  }
55 } // namespace hal
uint64_t u64
Definition: defines.h:42
#define UNUSED(expr)
Definition: defines.h:49
Definition: defines.h:45