forked from rftafas/hdltools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dict_code.py
69 lines (49 loc) · 1.38 KB
/
dict_code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from format_text import indent
def VHDLenum(objects_dict : dict, indent_level : int = 0) -> str:
"""
Generate a string concatenating all the elements of a dictionary of
objects, removing the last terminating character (; or ,).
Parameters:
-----------
objects_dict : dictionary of objects.
The object must implement the code() method.
indent_level : int, optional
Number of indentations to insert between printed elements.
Return:
-------
hdl_code : str
Generated string
"""
hdl_code = ""
i = 0
for key in objects_dict:
i = i+1
if (i == len(objects_dict)):
# Remove terminating character
tmp = objects_dict[key].code()
tmp = tmp.replace(";", "")
tmp = tmp.replace(",", "")
hdl_code = hdl_code + indent(indent_level) + tmp
else:
hdl_code = hdl_code + indent(indent_level) + \
objects_dict[key].code()
return hdl_code
def DictCode(objects_dict : dict, indent_level : int = 0) -> str:
"""
Generate a string concatenating all the elements of a dictionary of
objects.
Parameters:
-----------
objects_dict : dictionary of objects.
The object must implement the code() method.
indent_level : int, optional
Number of indentations to insert between printed elements.
Return:
-------
hdl_code : str
Generated string
"""
hdl_code = ""
for key in objects_dict:
hdl_code = hdl_code + objects_dict[key].code(indent_level)
return hdl_code