HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
boolean_function_decorator.cpp
Go to the documentation of this file.
2 
3 namespace hal
4 {
6  {
7  py::class_<BooleanFunctionDecorator> py_boolean_function_decorator(m, "BooleanFunctionDecorator", R"(
8  A Boolean function decorator that provides functionality to operate on the associated Boolean function.
9  )");
10 
11  py_boolean_function_decorator.def(py::init<const BooleanFunction&>(), py::arg("bf"), R"(
12  Construct new BooleanFunctionDecorator object.
13 
14  :param hal_py.BooleanFunction bf: The Booelan function to operate on.
15  )");
16 
17  py_boolean_function_decorator.def(
18  "substitute_power_ground_nets",
19  [](const BooleanFunctionDecorator& self, const Netlist* nl) -> std::optional<BooleanFunction> {
20  auto res = self.substitute_power_ground_nets(nl);
21  if (res.is_ok())
22  {
23  return res.get();
24  }
25  else
26  {
27  log_error("python_context", "error encountered while substituting power and ground nets:\n{}", res.get_error().get());
28  return std::nullopt;
29  }
30  },
31  py::arg("nl"),
32  R"(
33  Substitute all Boolean function variables fed by power or ground gates by constant ``0`` and ``1``.
34 
35  :param hal_py.Netlist nl: The netlist to operate on.
36  :returns: The resulting Boolean function on success, ``None`` otherwise.
37  :rtype: hal_py.BooleanFunction or None
38  )");
39 
40  py_boolean_function_decorator.def(
41  "substitute_power_ground_pins",
42  [](const BooleanFunctionDecorator& self, const Gate* g) -> std::optional<BooleanFunction> {
43  auto res = self.substitute_power_ground_pins(g);
44  if (res.is_ok())
45  {
46  return res.get();
47  }
48  else
49  {
50  log_error("python_context", "error encountered while substituting power and ground pins:\n{}", res.get_error().get());
51  return std::nullopt;
52  }
53  },
54  py::arg("g"),
55  R"(
56  Substitute all Boolean function variables that belong to a pin connected to a power or ground gate by constant ``0`` and ``1``.
57 
58  :param hal_py.Gate g: The gate which is connected to the pins and belongs to the Boolean function under inspection.
59  :returns: The resulting Boolean function on success, ``None`` otherwise.
60  :rtype: hal_py.BooleanFunction or None
61  )");
62 
63  py_boolean_function_decorator.def_static(
64  "get_boolean_function_from",
65  [](const std::vector<BooleanFunction>& functions, u32 extend_to_size = 0, bool sign_extend = false, bool ascending = true) -> std::optional<BooleanFunction> {
66  auto res = BooleanFunctionDecorator::get_boolean_function_from(functions, extend_to_size, sign_extend, ascending);
67  if (res.is_ok())
68  {
69  return res.get();
70  }
71  else
72  {
73  log_error("python_context", "error encountered while getting Boolean function from Boolean function vector:\n{}", res.get_error().get());
74  return std::nullopt;
75  }
76  },
77  py::arg("functions"),
78  py::arg("extend_to_size") = 0,
79  py::arg("sign_extend") = false,
80  py::arg("ascending") = true,
81  R"(
82  Get the Boolean function that is the concatenation of Boolean functions.
83  The Boolean function can optionally be extended to any desired size greater the size of the given Boolean function list.
84 
85  :param list[hal_py.BooleanFunction] functions: The Boolean functions to concatenate.
86  :param int extend_to_size: The size to which to extend the Boolean function. Set to ``0`` to prevent extension. Defaults to ``0``.
87  :param bool sign_extend: Set ``True`` to sign extend, ``False`` to zero extend. Defaults to ``False``.
88  :param bool ascending: Set ``True`` to concatenate in ascending order (from ``0`` to ``n-1``), ``False`` for descending order (from ``n-1`` to ``0``). Defaults to ``True``.
89  :returns: The resulting Boolean function on success, ``None`` otherwise.
90  :rtype: hal_py.BooleanFunction or None
91  )");
92 
93  py_boolean_function_decorator.def_static(
94  "get_boolean_function_from",
95  [](const std::vector<Net*>& nets, u32 extend_to_size = 0, bool sign_extend = false, bool ascending = true) -> std::optional<BooleanFunction> {
96  auto res = BooleanFunctionDecorator::get_boolean_function_from(nets, extend_to_size, sign_extend, ascending);
97  if (res.is_ok())
98  {
99  return res.get();
100  }
101  else
102  {
103  log_error("python_context", "error encountered while getting Boolean function from net vector:\n{}", res.get_error().get());
104  return std::nullopt;
105  }
106  },
107  py::arg("nets"),
108  py::arg("extend_to_size") = 0,
109  py::arg("sign_extend") = false,
110  py::arg("ascending") = true,
111  R"(
112  Get the Boolean function that is the concatenation of variable names corresponding to nets of a netlist.
113  The Boolean function can optionally be extended to any desired size greater the size of the given net vector.
114 
115  :param list[hal_py.Net] nets: The nets to concatenate.
116  :param int extend_to_size: The size to which to extend the Boolean function. Set to ``0`` to prevent extension. Defaults to ``0``.
117  :param bool sign_extend: Set ``True`` to sign extend, ``False`` to zero extend. Defaults to ``False``.
118  :param bool ascending: Set ``True`` to concatenate in ascending order (from ``0`` to ``n-1``), ``False`` for descending order (from ``n-1`` to ``0``). Defaults to ``True``.
119  :returns: The resulting Boolean function on success, ``None`` otherwise.
120  :rtype: hal_py.BooleanFunction or None
121  )");
122 
123  py_boolean_function_decorator.def_static(
124  "get_boolean_function_from",
125  [](const PinGroup<ModulePin>* pin_group, u32 extend_to_size = 0, bool sign_extend = false) -> std::optional<BooleanFunction> {
126  auto res = BooleanFunctionDecorator::get_boolean_function_from(pin_group, extend_to_size, sign_extend);
127  if (res.is_ok())
128  {
129  return res.get();
130  }
131  else
132  {
133  log_error("python_context", "error encountered while getting Boolean function from net vector:\n{}", res.get_error().get());
134  return std::nullopt;
135  }
136  },
137  py::arg("pin_group"),
138  py::arg("extend_to_size") = 0,
139  py::arg("sign_extend") = false,
140  R"(
141  Get the Boolean function that is the concatenation of variable names corresponding to the nets connected to the pins of the given pin group.
142  The Boolean function can optionally be extended to any desired size greater the size of the given net vector.
143 
144  :param hal_py.ModulePinGroup pin_group: The module pin group.
145  :param int extend_to_size: The size to which to extend the Boolean function. Set to ``0`` to prevent extension. Defaults to ``0``.
146  :param bool sign_extend: Set ``True`` to sign extend, ``False`` to zero extend. Defaults to ``False``.
147  :returns: The resulting Boolean function on success, ``None`` otherwise.
148  :rtype: hal_py.BooleanFunction or None
149  )");
150  }
151 } // namespace hal
static Result< BooleanFunction > get_boolean_function_from(const std::vector< BooleanFunction > &functions, u32 extend_to_size=0, bool sign_extend=false, bool ascending=true)
Definition: gate.h:58
uint32_t u32
Definition: defines.h:41
void boolean_function_decorator_init(py::module &m)
#define log_error(channel,...)
Definition: log.h:78
const Module * module(const Gate *g, const NodeBoxes &boxes)
Definition: defines.h:45
bool ascending