HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
combinational_function.cpp
Go to the documentation of this file.
1 
7 #include "verilator/verilator.h"
8 
9 #include <filesystem>
10 #include <sstream>
11 #include <vector>
12 
13 namespace hal
14 {
15  namespace verilator
16  {
17  namespace converter
18  {
20  {
21  std::stringstream function;
22 
23  for (const auto& [output_pin_name, bf] : gt->get_boolean_functions())
24  {
25  BooleanFunction bf_copy = bf;
26  function << "assign ";
27 
28  const GatePin* output_pin = gt->get_pin_by_name(output_pin_name);
29  if (output_pin == nullptr)
30  {
31  continue;
32  }
33 
34  const auto group = output_pin->get_group();
35  if (group.first->size() > 1)
36  {
37  function << group.first->get_name() << "[" << group.second << "]";
38  }
39  else
40  {
41  function << output_pin->get_name();
42  }
43 
44  for (const std::string& var : bf_copy.get_variable_names())
45  {
46  if (const auto* pin = gt->get_pin_by_name(var); pin != nullptr)
47  {
48  const auto pin_group = pin->get_group();
49  std::string pin_str = pin_group.first->get_name() + "[" + std::to_string(pin_group.second) + "]";
50  bf_copy = bf_copy.substitute(var, pin_str);
51  }
52  }
53 
54  function << " = " << bf_copy.to_string(verilog_function_printer) << ";" << std::endl;
55  }
56 
57  return function.str();
58  }
59  } // namespace converter
60  } // namespace verilator
61 } // namespace hal
const std::string & get_name() const
Definition: base_pin.h:110
const std::pair< PinGroup< T > *, i32 > & get_group() const
Definition: base_pin.h:160
std::set< std::string > get_variable_names() const
static std::string to_string(Value value)
BooleanFunction substitute(const std::string &old_variable_name, const std::string &new_variable_name) const
GatePin * get_pin_by_name(const std::string &name) const
Definition: gate_type.cpp:318
const std::unordered_map< std::string, BooleanFunction > & get_boolean_functions() const
Definition: gate_type.cpp:746
Result< std::string > verilog_function_printer(const BooleanFunction::Node &node, std::vector< std::string > &&operands)
Definition: converter.cpp:304
std::string get_function_for_combinational_gate(const GateType *gt)
Definition: defines.h:45