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