pyipcore 0.4.3__tar.gz → 0.4.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyipcore-0.4.3 → pyipcore-0.4.8}/PKG-INFO +6 -1
- pyipcore-0.4.8/pyipcore/__init__.py +6 -0
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore/ipc_utils.py +64 -7
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore/ipcore.py +52 -2
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore/main.py +6 -2
- pyipcore-0.4.8/pyipcore/parsetab.py +443 -0
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore/ui_creater/__init__.py +21 -7
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore/ui_main/__init__.py +41 -7
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore/ui_main/ui_main.py +29 -9
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore.egg-info/PKG-INFO +6 -1
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore.egg-info/SOURCES.txt +1 -0
- pyipcore-0.4.8/pyipcore.egg-info/entry_points.txt +2 -0
- {pyipcore-0.4.3 → pyipcore-0.4.8}/setup.py +2 -2
- pyipcore-0.4.3/pyipcore/__init__.py +0 -6
- pyipcore-0.4.3/pyipcore.egg-info/entry_points.txt +0 -2
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore/icon_rc.py +0 -0
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore/ui_creater/ui_creater.py +0 -0
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore/ui_utils.py +0 -0
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore.egg-info/dependency_links.txt +0 -0
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore.egg-info/requires.txt +0 -0
- {pyipcore-0.4.3 → pyipcore-0.4.8}/pyipcore.egg-info/top_level.txt +0 -0
- {pyipcore-0.4.3 → pyipcore-0.4.8}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyipcore
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.8
|
|
4
4
|
Summary: (PyQt5 based) Create "Ipcore" from verilog(Need iverilog). Provide "Param Value" and "Port Control" function. This kind of IpCore is not safe, only for convenience
|
|
5
5
|
Author-email: 2229066748@qq.com
|
|
6
6
|
Maintainer: Eagle'sBaby
|
|
@@ -10,3 +10,8 @@ Keywords: verilog,ipcore,pyqt5
|
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
11
11
|
Classifier: Operating System :: Microsoft :: Windows
|
|
12
12
|
Requires-Python: >=3
|
|
13
|
+
Requires-Dist: PyQt5
|
|
14
|
+
Requires-Dist: reft==0.1.0
|
|
15
|
+
Requires-Dist: pyverilog==1.3.0
|
|
16
|
+
Requires-Dist: rbpop==0.1.2
|
|
17
|
+
Requires-Dist: files3>=0.6
|
|
@@ -8,12 +8,19 @@ from files3 import files, F3False
|
|
|
8
8
|
|
|
9
9
|
IPC_SUFFIX = '.ipc'
|
|
10
10
|
|
|
11
|
+
V_SUFFIXS = ['.v', '.sv']
|
|
12
|
+
|
|
13
|
+
OPEN_TYPE = "Verilog (*.v);;SystemVerilog (*.sv);;IP Core (*.ipc)"
|
|
14
|
+
SAVE_TYPE = "IP Core (*.ipc);;Verilog (*.v);;SystemVerilog (*.sv)"
|
|
15
|
+
|
|
16
|
+
VERILOG_TYPE = "Verilog (*.v);;SystemVerilog (*.sv)"
|
|
17
|
+
|
|
11
18
|
# 读取变量默认值的正则表达式参数, 例如: // $a = 1
|
|
12
19
|
IPC_VAL_GS = [
|
|
13
20
|
"//+\s*\$", # 0 "// $"
|
|
14
21
|
FT.VARIABLE, # 1 "a"
|
|
15
22
|
"\s*=\s*", # 2 " = "
|
|
16
|
-
"
|
|
23
|
+
"[^;/\s]+", # 3 "1"
|
|
17
24
|
]
|
|
18
25
|
IPC_VAL_KVID = (1, 3) # (key, value) index in IPC_VAL_GS
|
|
19
26
|
|
|
@@ -80,7 +87,7 @@ def get_module_parameters(param_s) -> dict:
|
|
|
80
87
|
rslt[name] = value
|
|
81
88
|
|
|
82
89
|
# group1: name, group2: value
|
|
83
|
-
pat = re.compile(fr"parameter\s+({FT.VARIABLE})\s*=\s*([^,^\n]+)")
|
|
90
|
+
pat = re.compile(fr"parameter\s+({FT.VARIABLE})\s*=\s*([^,^\n,^(parameter)]+)")
|
|
84
91
|
|
|
85
92
|
re.sub(pat, _sub_fn, param_s)
|
|
86
93
|
|
|
@@ -117,7 +124,7 @@ def get_module_ports(ports_s) -> dict:
|
|
|
117
124
|
rslt[name] = (direction, prefix, width)
|
|
118
125
|
|
|
119
126
|
# group1: direction, group2: prefix, group3: width, group4: name
|
|
120
|
-
pat = re.compile(fr"(input|output|inout)\s+(reg
|
|
127
|
+
pat = re.compile(fr"(input|output|inout)\s+(reg|wire|logic)?\s*(\[[^\]]+\]\s+)?({FT.VARIABLE})(,\s*)?")
|
|
121
128
|
|
|
122
129
|
re.sub(pat, _sub_fn, ports_s)
|
|
123
130
|
|
|
@@ -161,7 +168,56 @@ def create_module_inst_code(txt: str) -> str:
|
|
|
161
168
|
:param txt: 整个module的代码
|
|
162
169
|
:return: module的实例代码
|
|
163
170
|
"""
|
|
164
|
-
|
|
171
|
+
|
|
172
|
+
current_idx = 0
|
|
173
|
+
spec_sv = {} # 把不属于verilog的部分放到这里,$SPEC_SV_{i}$: sv code
|
|
174
|
+
new_txt = ""
|
|
175
|
+
for line in txt.split("\n"):
|
|
176
|
+
# 1. remove typedef
|
|
177
|
+
if line.find("typedef") != -1:
|
|
178
|
+
key = f"$SPEC_SV_{current_idx}$"
|
|
179
|
+
spec_sv[key] = line
|
|
180
|
+
# new_txt += key + "\n" # 暂时不添加
|
|
181
|
+
current_idx += 1
|
|
182
|
+
continue
|
|
183
|
+
new_txt += line + "\n\n"
|
|
184
|
+
txt = new_txt
|
|
185
|
+
|
|
186
|
+
# remove all between ');' and 'endmodule'
|
|
187
|
+
pat = re.compile("\)\s*;")
|
|
188
|
+
new_txt = ""
|
|
189
|
+
left_txt = txt
|
|
190
|
+
while True:
|
|
191
|
+
matched = pat.search(left_txt)
|
|
192
|
+
if matched is None:
|
|
193
|
+
break
|
|
194
|
+
start, end = matched.span()
|
|
195
|
+
|
|
196
|
+
# find the endmodule
|
|
197
|
+
endmodule_idx = left_txt.find("endmodule")
|
|
198
|
+
if endmodule_idx == -1:
|
|
199
|
+
raise ValueError("Can't find 'endmodule' after ');'.")
|
|
200
|
+
new_txt += left_txt[:end] + "\nendmodule\n"
|
|
201
|
+
left_txt = left_txt[endmodule_idx + len("endmodule"):]
|
|
202
|
+
new_txt += left_txt
|
|
203
|
+
txt = new_txt
|
|
204
|
+
|
|
205
|
+
# remove more \n
|
|
206
|
+
txt = re.sub(r"\n\n+", "\n", txt)
|
|
207
|
+
|
|
208
|
+
# logic -> reg
|
|
209
|
+
txt = re.sub(r"\blogic\b", "reg", txt)
|
|
210
|
+
|
|
211
|
+
# WRITE TO FILE # DEBUG
|
|
212
|
+
# open("temp.v", "w").write(txt)
|
|
213
|
+
|
|
214
|
+
try:
|
|
215
|
+
ast, _ = verilog_parse([txt])
|
|
216
|
+
except FileNotFoundError as err:
|
|
217
|
+
pre_found_error = "[WinError 2]"
|
|
218
|
+
if str(err).find(pre_found_error) != -1:
|
|
219
|
+
raise Exception("Please retry after install 'iverilog' from 'http://bleyer.org/icarus/' and add it to path.")
|
|
220
|
+
raise err
|
|
165
221
|
for description in ast.children():
|
|
166
222
|
if description.definitions:
|
|
167
223
|
for part_code in description.definitions:
|
|
@@ -184,12 +240,13 @@ def create_module_inst_code(txt: str) -> str:
|
|
|
184
240
|
# print(ss)
|
|
185
241
|
# /// build inst code
|
|
186
242
|
ic = ""
|
|
187
|
-
ic += f"{part_code.name} #(\n"
|
|
243
|
+
ic += f"{part_code.name} " + ("#(\n" if params else "") # module name
|
|
188
244
|
# /// add parameters
|
|
189
245
|
for k, v in params.items():
|
|
190
246
|
ic += f"\t.{k}({v}),\n"
|
|
191
|
-
|
|
192
|
-
|
|
247
|
+
if params:
|
|
248
|
+
ic = ic[:-2] + "\n"
|
|
249
|
+
ic += (") " if params else "") + f"{part_code.name.lower()}_inst (\n"
|
|
193
250
|
# /// add ports
|
|
194
251
|
for k, v in ports.items():
|
|
195
252
|
ic += f"\t.{k}({k}),\n"
|
|
@@ -36,13 +36,63 @@ class IpCore:
|
|
|
36
36
|
|
|
37
37
|
VERILOG_NUMBER = f"({FT.DIGIT_CHAR}+'{FT.ALPHA})?[0-9_]+"
|
|
38
38
|
|
|
39
|
+
@staticmethod
|
|
40
|
+
def _auto_type_change(params_dict):
|
|
41
|
+
"""
|
|
42
|
+
自动转换参数类型,会自动检查str类型的int, float数据,并转换为int, float。
|
|
43
|
+
:param params_dict: 包含参数的字典,其中值可能是str, int, float等类型
|
|
44
|
+
:return: 转换后的字典
|
|
45
|
+
"""
|
|
46
|
+
for key, value in params_dict.items():
|
|
47
|
+
# 尝试将值转换为整数
|
|
48
|
+
if isinstance(value, str) and value.isdigit():
|
|
49
|
+
params_dict[key] = int(value)
|
|
50
|
+
# 尝试将值转换为浮点数
|
|
51
|
+
elif isinstance(value, str):
|
|
52
|
+
try:
|
|
53
|
+
# 尝试转换为浮点数
|
|
54
|
+
params_dict[key] = float(value)
|
|
55
|
+
except ValueError:
|
|
56
|
+
# 如果转换失败,保留原始字符串
|
|
57
|
+
pass
|
|
58
|
+
return params_dict
|
|
59
|
+
|
|
60
|
+
@staticmethod
|
|
61
|
+
def _handle_eval(txt, params_dict):
|
|
62
|
+
"""
|
|
63
|
+
处理EVAL表达式。
|
|
64
|
+
要求格式为'$(表达式)',最后将结果的str替换原表达式。
|
|
65
|
+
能使用的环境只有params_dict。
|
|
66
|
+
:param txt: 原始文本
|
|
67
|
+
:param params_dict: 包含变量名和值的字典
|
|
68
|
+
:return: 替换后的文本
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
# 定义一个函数,用于计算表达式并返回结果
|
|
72
|
+
def eval_expr(match):
|
|
73
|
+
# 获取匹配到的表达式部分
|
|
74
|
+
expr = match.group(1)
|
|
75
|
+
try:
|
|
76
|
+
# 使用eval函数计算表达式,传入params_dict作为局部变量环境
|
|
77
|
+
result = eval(expr, {}, params_dict)
|
|
78
|
+
# 返回计算结果的字符串形式
|
|
79
|
+
return str(result)
|
|
80
|
+
except Exception as e:
|
|
81
|
+
# 如果表达式计算出错,返回原始表达式
|
|
82
|
+
return '$EVAL({})'.format(expr)
|
|
83
|
+
|
|
84
|
+
# 使用re.sub函数替换文本中的所有EVAL表达式
|
|
85
|
+
return re.sub(r'\$\((.*?)\)', eval_expr, txt)
|
|
86
|
+
|
|
39
87
|
def build(self, **params) -> str:
|
|
40
88
|
"""Build the IP core with the given parameters."""
|
|
41
89
|
content = self.content
|
|
42
90
|
ft = FT()
|
|
43
91
|
ft.login(lambda key: str(params[key]), *IPC_W_VAL_GS, areas=[IPC_W_VAL_VID])
|
|
44
92
|
ft.login(lambda k, v: (v if params[k] else ""), *IPC_REMOVE_GS, areas=list(IPC_REMOVE_KVID))
|
|
45
|
-
|
|
93
|
+
_content = ft.handle(content)
|
|
94
|
+
_content = self._handle_eval(_content, self._auto_type_change(params))
|
|
95
|
+
self._built = _content
|
|
46
96
|
return self._built
|
|
47
97
|
|
|
48
98
|
# ----------------------------------------- Following are properties -----------------------------------------
|
|
@@ -108,7 +158,7 @@ class IpCore:
|
|
|
108
158
|
|
|
109
159
|
|
|
110
160
|
if __name__ == '__main__':
|
|
111
|
-
IpCore.FromVerilog("", 'test', 'counter.v')
|
|
161
|
+
IpCore.FromVerilog("", 'test', r'H:\FPGA_Learns\00 IPC\_raw\counter.v2.v')
|
|
112
162
|
# raise
|
|
113
163
|
ip = IpCore("", 'test')
|
|
114
164
|
d = ip.dict
|
|
@@ -2,7 +2,11 @@ from pyipcore.ui_main import GUI_Main, QApplication, QMessageBox
|
|
|
2
2
|
import sys
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
def
|
|
5
|
+
def pyipc():
|
|
6
|
+
"""
|
|
7
|
+
Run the GUI application.
|
|
8
|
+
CMD主函数入口
|
|
9
|
+
"""
|
|
6
10
|
app = QApplication(sys.argv)
|
|
7
11
|
gui = GUI_Main()
|
|
8
12
|
gui.show()
|
|
@@ -13,4 +17,4 @@ def ipc_ui():
|
|
|
13
17
|
|
|
14
18
|
|
|
15
19
|
if __name__ == '__main__':
|
|
16
|
-
|
|
20
|
+
pyipc()
|