Utils
bool_to_sv(value)
Converts a boolean to a SystemVerilog string.
Examples:
>>> bool_to_sv(True)
"1'b1"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
bool
|
Input boolean value. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
"1'b1" if True, "1'b0" if False. |
Source code in floogen/utils.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
camel_to_snake(name)
Converts a camel case string to snake case.
Examples:
>>> camel_to_snake("CamelCase")
'camel_case'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Input camel case string. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Converted snake case string. |
Source code in floogen/utils.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
cdiv(x, y)
Compute the ceiling of x / y.
Examples:
>>> cdiv(7, 2)
4
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
(int, float)
|
Numerator. |
required |
y
|
(int, float)
|
Denominator. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Ceiling of x / y. |
Source code in floogen/utils.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
clog2(x)
Returns the ceiling of log2(x).
Examples:
>>> clog2(7)
3
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
int
|
Input value. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Ceiling of log2(x). |
Source code in floogen/utils.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
int_to_hex(value, width)
Converts an integer to a hex string.
Examples:
>>> int_to_hex(255, 8)
"8'hff"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
int
|
Input integer value. |
required |
width
|
int
|
Bit width of the value. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Hex string representation of the integer. |
Source code in floogen/utils.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
short_dir(direction)
Returns the short direction string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
direction
|
str
|
"input" or "output". |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
"in" or "out". |
Source code in floogen/utils.py
80 81 82 83 84 85 86 87 88 89 |
|
snake_to_camel(name)
Converts a snake case string to camel case.
Examples:
>>> snake_to_camel("snake_case")
'SnakeCase'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Input snake case string. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Converted camel case string. |
Source code in floogen/utils.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
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
|
str
|
Name of the enum typedef. |
required |
fields_dict
|
dict
|
Dictionary of field names and their corresponding values. Defaults to None. |
None
|
fields_list
|
list
|
List of field names. Values will be assigned automatically starting from 0. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
SystemVerilog enum typedef declaration. |
Source code in floogen/utils.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
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
|
str
|
Name of the parameter. |
required |
value
|
(int, str)
|
Value of the parameter. |
required |
ptype
|
str
|
Type of the parameter, either "localparam" or "parameter". Defaults to "localparam". |
'localparam'
|
dtype
|
str
|
Data type of the parameter. Defaults to "int unsigned". |
'int unsigned'
|
array_size
|
(int, str, list)
|
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 |
str
|
SystemVerilog parameter declaration. |
Source code in floogen/utils.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
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.
Examples:
>>> sv_struct_render({'field1': '3'd0', 'field2': 'some_signal'})
"'{field1: 3'd0,field2: some_signal}'"
>>> sv_struct_render({'field1': '3'd0', 'field2': {'subfield1': 'some_signal', 'subfield2': 'SomeParam'}})
"'{
field1: 3'd0,
field2: '{
subfield1: some_signal,
subfield2: SomeParam
}
}"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fields
|
dict
|
Dictionary of field names and their corresponding values. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
SystemVerilog struct instantiation. |
Source code in floogen/utils.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
sv_struct_typedef(name, fields, union=False)
Declare a SystemVerilog struct typedef.
Source code in floogen/utils.py
187 188 189 190 191 192 193 194 195 196 |
|
sv_typedef(name, dtype='logic', array_size=None)
Declare a SystemVerilog typedef.
Examples:
>>> sv_typedef("my_type_t", "logic", 8)
"typedef logic[7:0] my_type_t;"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the typedef. |
required |
dtype
|
str
|
Data type of the typedef. Defaults to "logic". |
'logic'
|
array_size
|
int
|
Size of the array. If None, a scalar type is declared. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
SystemVerilog typedef declaration. |
Source code in floogen/utils.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
verible_format(string, verible_fmt_bin=None, verible_fmt_args=None)
Format the string using verible-verilog-format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string
|
str
|
Input string to format. |
required |
verible_fmt_bin
|
str
|
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
|
str
|
Additional arguments to pass to verible-verilog-format. If None, no additional arguments are passed. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Formatted string, or the original string if verible-verilog-format is not found. |
Source code in floogen/utils.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|