7 py::class_<Parameter> py_parameter(m,
"Parameter", R
"(
8 A typed, named parameter declaration.
11 py::enum_<Parameter::Type>(py_parameter, "Type", R
"(
12 Type tag for typed parameters across the netlist.
16 .value("LogicVector",
Parameter::Type::LogicVector, R
"(A multi-bit 9-state logic vector; each bit may be ``0``, ``1``, ``X``, ``Z``, ``U``, ``L``, ``H``, ``W``, or ``-``.)")
20 .value("Time",
Parameter::Type::Time, R
"(A time value with a unit suffix (``fs``, ``ps``, ``ns``, ``us``, ``ms``, ``s``, ``min``, ``h``).)")
21 .value("Enum",
Parameter::Type::Enum, R
"(A finite, ordered set of named values; encoded as an integer index.)");
23 py_parameter.def_static(
25 [](
const std::string&
name,
const std::string& default_value) -> std::optional<Parameter> {
33 log_error(
"python_context",
"{}", res.get_error().get());
38 py::arg(
"default_value"),
40 Construct a boolean parameter. Accepts only the value strings ``"true"`` and ``"false"``.
42 :param str name: Parameter name (must be non-empty).
43 :param str default_value: Default value, either ``"true"`` or ``"false"``.
46 py_parameter.def_static(
48 [](
const std::string&
name,
u16 size,
const std::string& default_value) -> std::optional<Parameter> {
56 log_error(
"python_context",
"{}", res.get_error().get());
62 py::arg(
"default_value"),
64 Construct a bit-vector parameter. Values use the prefixes ``0b`` / ``0o`` / ``0x``.
66 :param str name: Parameter name (must be non-empty).
67 :param int size: Bit-width (must be at least 1; up to 65535).
68 :param str default_value: Default value as a string.
71 py_parameter.def_static(
73 [](
const std::string&
name,
u16 size,
const std::string& default_value) -> std::optional<Parameter> {
81 log_error(
"python_context",
"{}", res.get_error().get());
87 py::arg(
"default_value"),
89 Construct a 9-state logic-vector parameter. Values use the prefixes ``0b`` / ``0o`` / ``0x``,
90 with any of the VHDL ``std_logic`` state characters (``X``, ``Z``, ``U``, ``L``, ``H``, ``W``, ``-``)
91 appearing in place of digits (case-insensitive; for octal/hex, a state-character digit expands to
92 3/4 copies of that state).
94 :param str name: Parameter name (must be non-empty).
95 :param int size: Bit-width (must be at least 1; up to 65535).
96 :param str default_value: Default value as a 9-state literal string (empty for "no default").
99 py_parameter.def_static(
101 [](
const std::string&
name,
const std::string& default_value) -> std::optional<Parameter> {
109 log_error(
"python_context",
"{}", res.get_error().get());
114 py::arg(
"default_value"),
116 Construct a signed-integer parameter. Values are parsed in base 10 and must fit in ``i64``.
118 :param str name: Parameter name (must be non-empty).
119 :param str default_value: Default value as a decimal string (optional leading ``+``/``-``).
122 py_parameter.def_static(
124 [](
const std::string&
name,
const std::string& default_value) -> std::optional<Parameter> {
132 log_error(
"python_context",
"{}", res.get_error().get());
137 py::arg(
"default_value"),
139 Construct a string parameter. Any value (including the empty string) is accepted.
141 :param str name: Parameter name (must be non-empty).
142 :param str default_value: Default value.
145 py_parameter.def_static(
147 [](
const std::string&
name,
const std::string& default_value) -> std::optional<Parameter> {
155 log_error(
"python_context",
"{}", res.get_error().get());
160 py::arg(
"default_value"),
162 Construct a floating-point parameter. Values are parsed via ``std::stod``.
164 :param str name: Parameter name (must be non-empty).
165 :param str default_value: Default value as a decimal float (e.g. ``3.14``, ``1e-5``).
168 py_parameter.def_static(
170 [](
const std::string&
name,
const std::string& default_value) -> std::optional<Parameter> {
178 log_error(
"python_context",
"{}", res.get_error().get());
183 py::arg(
"default_value"),
185 Construct a time parameter. Values are of the form ``<number><unit>`` with the unit
186 in {``fs``, ``ps``, ``ns``, ``us``, ``ms``, ``s``, ``min``, ``h``}; the number is a
187 non-negative decimal.
189 :param str name: Parameter name (must be non-empty).
190 :param str default_value: Default value, e.g. ``10ns``.
193 py_parameter.def_static(
195 [](
const std::string&
name,
const std::vector<std::string>& values,
const std::string& default_value) -> std::optional<Parameter> {
203 log_error(
"python_context",
"{}", res.get_error().get());
209 py::arg(
"default_value"),
211 Construct an enum parameter. ``size`` is auto-computed as ``ceil(log2(len(values)))``.
213 :param str name: Parameter name (must be non-empty).
214 :param list[str] values: Ordered list of enum values (at least two, unique, non-empty).
215 :param str default_value: Default value, must equal one of `values`.
219 The name of the parameter (read-only).
225 Get the name of the parameter.
227 :returns: The parameter name.
232 The data type of the parameter (read-only).
234 :type: hal_py.Parameter.Type
238 Get the data type of the parameter.
240 :returns: The parameter type.
241 :rtype: hal_py.Parameter.Type
245 The bit-width of the parameter (read-only).
246 Fixed at 1 for ``Boolean``, 64 for ``Integer`` and ``Float``, 0 for ``String`` and ``Time``,
247 ``ceil(log2(N))`` for ``Enum`` with N values, and the declared width for ``BitVector`` / ``LogicVector``.
253 Get the bit-width of the parameter.
254 Fixed at 1 for ``Boolean``, 64 for ``Integer`` and ``Float``, 0 for ``String`` and ``Time``,
255 ``ceil(log2(N))`` for ``Enum`` with N values, and the declared width for ``BitVector`` / ``LogicVector``.
257 :returns: The bit-width.
262 The default value of the parameter as a string (read-only).
263 An empty string signals "no default"; all other values satisfy the type's grammar.
269 Get the default value of the parameter as a string.
270 An empty string signals "no default"; all other values satisfy the type's grammar.
272 :returns: The default value string.
277 The ordered list of named values for an ``Enum`` parameter (read-only).
278 Always empty for every other type.
284 Get the ordered list of named values for an ``Enum`` parameter.
285 Always empty for every other type.
287 :returns: The enum value list.
292 Check whether a candidate value is valid for this parameter declaration.
296 * ``Boolean``: value must be ``"true"`` or ``"false"``.
297 * ``BitVector``: parses as a non-negative integer (``0b``, ``0o``, ``0x``) that fits in ``size``.
298 * ``LogicVector``: parses as a 4-state literal (``0b``, ``0o``, ``0x``) whose total bit-length fits in ``size``.
299 * ``Integer``: parses as a signed decimal integer (fits in ``i64``).
300 * ``String``: any value (including the empty string) is accepted.
301 * ``Float``: parses as a ``double`` via ``std::stod``.
302 * ``Time``: matches ``<number><unit>`` with unit in {``fs``, ``ps``, ``ns``, ``us``, ``ms``, ``s``, ``min``, ``h``}.
303 * ``Enum``: must equal one of the declared enum values.
305 :param str value: The candidate value string.
306 :returns: ``True`` if the value is valid, ``False`` otherwise.
312 [](
Parameter&
self,
const std::string& value) -> std::optional<u64> {
313 auto res =
self.encode_as_int(value);
320 log_error(
"python_context",
"{}", res.get_error().get());
326 Convert a string value to its canonical integer encoding for this parameter.
330 * ``Boolean``: returns 0 for ``false``, 1 for ``true``.
331 * ``BitVector``: parses the value (``0b``, ``0o``, ``0x``).
332 * ``Integer``: returns the bit-pattern of the signed value reinterpreted as ``u64``.
333 * ``LogicVector``, ``String``, ``Float``, ``Time``: no canonical integer encoding; returns ``None``.
334 * ``Enum``: returns the index of the value in the declared value list.
336 :param str value: The string value to encode.
337 :returns: The integer encoding on success, ``None`` otherwise.
341 py_parameter.def(py::self == py::self);
342 py_parameter.def(py::self != py::self);
void parameter_init(py::module &m)
#define log_error(channel,...)
const Module * module(const Gate *g, const NodeBoxes &boxes)
static Result< Parameter > Boolean(const std::string &name, const std::string &default_value)
static Result< Parameter > BitVector(const std::string &name, u16 size, const std::string &default_value)
static Result< Parameter > Integer(const std::string &name, const std::string &default_value)
static Result< Parameter > String(const std::string &name, const std::string &default_value)
static Result< Parameter > LogicVector(const std::string &name, u16 size, const std::string &default_value)
const std::string & get_name() const
const std::vector< std::string > & get_enum_values() const
static Result< Parameter > Time(const std::string &name, const std::string &default_value)
static Result< Parameter > Enum(const std::string &name, const std::vector< std::string > &values, const std::string &default_value)
bool validate(const std::string &value) const
static Result< Parameter > Float(const std::string &name, const std::string &default_value)
const std::string & get_default_value() const