From e41bc017d211c6ead21f63a3fa2163bdf3fc2d57 Mon Sep 17 00:00:00 2001 From: Lennart Reimann Date: Thu, 16 Dec 2021 15:35:37 +0100 Subject: [PATCH 1/3] [PARTSELECT PLUS MINUS FIX] Fixed the MSB or LSB computation for the indexed vector partselect for Verilog. The second value is not a direct offset but the width of the selected part. So the value needs to be decreased by 1 before adding or subtracting it from the base. --- pyverilog/vparser/parser.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/pyverilog/vparser/parser.py b/pyverilog/vparser/parser.py index 3a82912..c9f760e 100644 --- a/pyverilog/vparser/parser.py +++ b/pyverilog/vparser/parser.py @@ -854,12 +854,16 @@ def p_lpartselect_lpointer(self, p): def p_lpartselect_lpointer_plus(self, p): 'lpartselect : pointer LBRACKET expression PLUSCOLON expression RBRACKET' - p[0] = Partselect(p[1], p[3], Plus(p[3], p[5]), lineno=p.lineno(1)) + inc_value = p[5] + inc_value.value = str(int(inc_value.value)-1) + p[0] = Partselect(p[1], p[3], Plus(p[3], inc_value), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) def p_lpartselect_lpointer_minus(self, p): 'lpartselect : pointer LBRACKET expression MINUSCOLON expression RBRACKET' - p[0] = Partselect(p[1], p[3], Minus(p[3], p[5]), lineno=p.lineno(1)) + dec_value = p[5] + dec_value.value = str(int(dec_value.value)-1) + p[0] = Partselect(p[1], p[3], Minus(p[3], dec_value), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) def p_lpartselect(self, p): @@ -869,12 +873,16 @@ def p_lpartselect(self, p): def p_lpartselect_plus(self, p): 'lpartselect : identifier LBRACKET expression PLUSCOLON expression RBRACKET' - p[0] = Partselect(p[1], p[3], Plus(p[3], p[5]), lineno=p.lineno(1)) + inc_value = p[5] + inc_value.value = str(int(inc_value.value)-1) + p[0] = Partselect(p[1], p[3], Plus(p[3], inc_value), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) def p_lpartselect_minus(self, p): 'lpartselect : identifier LBRACKET expression MINUSCOLON expression RBRACKET' - p[0] = Partselect(p[1], p[3], Minus(p[3], p[5]), lineno=p.lineno(1)) + dec_value = p[5] + dec_value.value = str(int(dec_value.value)-1) + p[0] = Partselect(p[1], p[3], Minus(p[3], dec_value), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) def p_lpointer(self, p): @@ -1215,14 +1223,18 @@ def p_partselect(self, p): def p_partselect_plus(self, p): 'partselect : identifier LBRACKET expression PLUSCOLON expression RBRACKET' + inc_value = p[5] + inc_value.value = str(int(inc_value.value)-1) p[0] = Partselect(p[1], p[3], Plus( - p[3], p[5], lineno=p.lineno(1)), lineno=p.lineno(1)) + p[3], inc_value, lineno=p.lineno(1)), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) def p_partselect_minus(self, p): 'partselect : identifier LBRACKET expression MINUSCOLON expression RBRACKET' + dec_value = p[5] + dec_value.value = str(int(dec_value.value)-1) p[0] = Partselect(p[1], p[3], Minus( - p[3], p[5], lineno=p.lineno(1)), lineno=p.lineno(1)) + p[3], dec_value, lineno=p.lineno(1)), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) def p_partselect_pointer(self, p): @@ -1232,14 +1244,18 @@ def p_partselect_pointer(self, p): def p_partselect_pointer_plus(self, p): 'partselect : pointer LBRACKET expression PLUSCOLON expression RBRACKET' + inc_value = p[5] + inc_value.value = str(int(inc_value.value)-1) p[0] = Partselect(p[1], p[3], Plus( - p[3], p[5], lineno=p.lineno(1)), lineno=p.lineno(1)) + p[3], inc_value, lineno=p.lineno(1)), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) def p_partselect_pointer_minus(self, p): 'partselect : pointer LBRACKET expression MINUSCOLON expression RBRACKET' + dec_value = p[5] + dec_value.value = str(int(dec_value.value)-1) p[0] = Partselect(p[1], p[3], Minus( - p[3], p[5], lineno=p.lineno(1)), lineno=p.lineno(1)) + p[3], dec_value, lineno=p.lineno(1)), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) def p_pointer(self, p): From 8413a6b220fa5c10b41924b0ab225643bfb199a1 Mon Sep 17 00:00:00 2001 From: lreim <64039638+lreim@users.noreply.github.com> Date: Mon, 31 Jul 2023 21:26:31 +0200 Subject: [PATCH 2/3] [MINUS] Change - to Minus for lpointer. --- pyverilog/vparser/parser.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pyverilog/vparser/parser.py b/pyverilog/vparser/parser.py index c9f760e..4ab7b6a 100644 --- a/pyverilog/vparser/parser.py +++ b/pyverilog/vparser/parser.py @@ -854,15 +854,13 @@ def p_lpartselect_lpointer(self, p): def p_lpartselect_lpointer_plus(self, p): 'lpartselect : pointer LBRACKET expression PLUSCOLON expression RBRACKET' - inc_value = p[5] - inc_value.value = str(int(inc_value.value)-1) + inc_value = Minus(p[5], IntConst('1')) p[0] = Partselect(p[1], p[3], Plus(p[3], inc_value), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) def p_lpartselect_lpointer_minus(self, p): 'lpartselect : pointer LBRACKET expression MINUSCOLON expression RBRACKET' - dec_value = p[5] - dec_value.value = str(int(dec_value.value)-1) + dec_value = Minus(p[5], IntConst('1')) p[0] = Partselect(p[1], p[3], Minus(p[3], dec_value), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) From fde63a2035efd45405ce6966e1ea8504cb09d7f5 Mon Sep 17 00:00:00 2001 From: lreim <64039638+lreim@users.noreply.github.com> Date: Mon, 31 Jul 2023 21:32:53 +0200 Subject: [PATCH 3/3] [FIX REMAINING MINUS] Change all remaining - to Minus. --- pyverilog/vparser/parser.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/pyverilog/vparser/parser.py b/pyverilog/vparser/parser.py index 4ab7b6a..7815e8f 100644 --- a/pyverilog/vparser/parser.py +++ b/pyverilog/vparser/parser.py @@ -871,15 +871,13 @@ def p_lpartselect(self, p): def p_lpartselect_plus(self, p): 'lpartselect : identifier LBRACKET expression PLUSCOLON expression RBRACKET' - inc_value = p[5] - inc_value.value = str(int(inc_value.value)-1) + inc_value = Minus(p[5], IntConst('1')) p[0] = Partselect(p[1], p[3], Plus(p[3], inc_value), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) def p_lpartselect_minus(self, p): 'lpartselect : identifier LBRACKET expression MINUSCOLON expression RBRACKET' - dec_value = p[5] - dec_value.value = str(int(dec_value.value)-1) + dec_value = Minus(p[5], IntConst('1')) p[0] = Partselect(p[1], p[3], Minus(p[3], dec_value), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) @@ -1221,16 +1219,14 @@ def p_partselect(self, p): def p_partselect_plus(self, p): 'partselect : identifier LBRACKET expression PLUSCOLON expression RBRACKET' - inc_value = p[5] - inc_value.value = str(int(inc_value.value)-1) + inc_value = Minus(p[5], IntConst('1')) p[0] = Partselect(p[1], p[3], Plus( p[3], inc_value, lineno=p.lineno(1)), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) def p_partselect_minus(self, p): 'partselect : identifier LBRACKET expression MINUSCOLON expression RBRACKET' - dec_value = p[5] - dec_value.value = str(int(dec_value.value)-1) + dec_value = Minus(p[5], IntConst('1')) p[0] = Partselect(p[1], p[3], Minus( p[3], dec_value, lineno=p.lineno(1)), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) @@ -1242,16 +1238,14 @@ def p_partselect_pointer(self, p): def p_partselect_pointer_plus(self, p): 'partselect : pointer LBRACKET expression PLUSCOLON expression RBRACKET' - inc_value = p[5] - inc_value.value = str(int(inc_value.value)-1) + inc_value = Minus(p[5], IntConst('1')) p[0] = Partselect(p[1], p[3], Plus( p[3], inc_value, lineno=p.lineno(1)), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1)) def p_partselect_pointer_minus(self, p): 'partselect : pointer LBRACKET expression MINUSCOLON expression RBRACKET' - dec_value = p[5] - dec_value.value = str(int(dec_value.value)-1) + dec_value = Minus(p[5], IntConst('1')) p[0] = Partselect(p[1], p[3], Minus( p[3], dec_value, lineno=p.lineno(1)), lineno=p.lineno(1)) p.set_lineno(0, p.lineno(1))