Utility Functions Reference¶
A collection of utility functions. Most of them are used internally by FlooGen to render SystemVerilog templates.
bool_to_sv(value)
¶
camel_to_snake(name)
¶
cdiv(x, y)
¶
clog2(x)
¶
int_to_hex(value, width)
¶
short_dir(direction)
¶
Returns the short direction string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
|
"input" or "output". |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
|
"in" or "out". |
snake_to_camel(name)
¶
sv_enum_typedef(name, fields_dict=None, fields_list=None)
¶
Declare a SystemVerilog enum typedef.
Examples:
>>> sv_enum_typedef("my_enum_e", fields_list=["field_one", "field_two"])
"typedef enum logic[0:0] {
FieldOne = 0,
FieldTwo = 1
} my_enum_e;"
>>> sv_enum_typedef("my_enum_e", fields_dict={"field_one": 4, "field_two": 6})
"typedef enum logic[2:0] {
FieldOne = 4,
FieldTwo = 6
} my_enum_e;"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
|
Name of the enum typedef. |
required |
fields_dict
|
|
Dictionary of field names and their corresponding values. Defaults to None. |
None
|
fields_list
|
|
List of field names. Values will be assigned automatically starting from 0. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
|
SystemVerilog enum typedef declaration. |
sv_param_decl(name, value, ptype='localparam', dtype='int unsigned', array_size=None)
¶
Declare a SystemVerilog parameter.
Examples:
>>> sv_param_decl("Width", 8)
"localparam int unsigned Width = 8;"
>>> sv_param_decl("Depth", 16, ptype="parameter", dtype="my_type_t", array_size=4)
"parameter my_type_t [3:0] Depth = 16;"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
|
Name of the parameter. |
required |
value
|
(
|
Value of the parameter. |
required |
ptype
|
|
Type of the parameter, either "localparam" or "parameter". Defaults to "localparam". |
'localparam'
|
dtype
|
|
Data type of the parameter. Defaults to "int unsigned". |
'int unsigned'
|
array_size
|
(
|
Size of the array. Can be an integer, a string (for expressions), or a list of integers/strings for multi-dimensional arrays. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
|
SystemVerilog parameter declaration. |
sv_struct_render(fields)
¶
Declare a SystemVerilog struct based on a (nested) dictionary, where they keys of the dictionary are the field names, and the values are the actual values to assign.
Example
fields = {'field1': '3'd0', 'field2': {'subfield1': 'some_signal', 'subfield2': 'SomeParam'}} sv_struct_render(fields) -> '{ field1: 3'd0, field2: '{ subfield1: some_signal, subfield2: SomeParam }, }'
sv_struct_typedef(name, fields, union=False)
¶
Declare a SystemVerilog struct typedef.
sv_typedef(name, dtype='logic', array_size=None)
¶
Declare a SystemVerilog typedef.
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
|
Name of the typedef. |
required |
dtype
|
|
Data type of the typedef. Defaults to "logic". |
'logic'
|
array_size
|
|
Size of the array. If None, a scalar type is declared. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
|
SystemVerilog typedef declaration. |
verible_format(string, verible_fmt_bin=None, verible_fmt_args=None)
¶
Format the string using verible-verilog-format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
|
Input string to format. |
required |
verible_fmt_bin
|
|
Path to the verible-verilog-format binary. If None, it will try to find it in the PATH. Defaults to None. |
None
|
verible_fmt_args
|
|
Additional arguments to pass to verible-verilog-format. If None, no additional arguments are passed. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
|
Formatted string, or the original string if verible-verilog-format is not found. |