@@ -10,6 +10,12 @@ def custom_reformat_verilog(name: str, ref_file: str, in_file: str, io_list):
10
10
outputs = []
11
11
inputs = []
12
12
13
+ print (f"[DEBUG] custom_reformat_verilog called with:" )
14
+ print (f" name: { name } " )
15
+ print (f" ref_file: { ref_file } " )
16
+ print (f" in_file: { in_file } " )
17
+ print (f" io_list: { io_list } " )
18
+
13
19
for io in io_list :
14
20
#print(io)
15
21
if io [0 ] == "output" :
@@ -30,19 +36,29 @@ def custom_reformat_verilog(name: str, ref_file: str, in_file: str, io_list):
30
36
# if input_name != in_file_input_name:
31
37
# in_file_content = in_file_content.replace()
32
38
39
+ # Debug: Show original content
40
+ print (f"[DEBUG] Original Verilog content:\n { in_file_content } \n { '-' * 50 } " )
41
+
33
42
if len (outputs ) == 1 :
34
43
output_name = outputs [0 ][3 ]
35
- # Rename all lines that may have the output_name as a local wire
36
- in_file_content = in_file_content .replace (f"{ output_name } \n " , f"{ output_name } _w\n " )
37
- in_file_content = in_file_content .replace (f"{ output_name } ;" , f"{ output_name } _w;" )
38
- in_file_content = in_file_content .replace ("{" + output_name + "};" , "{" + output_name + "_w};" )
39
- in_file_content = in_file_content .replace (f" { output_name } " , f" { output_name } _w " )
40
- in_file_content = in_file_content .replace (f"({ output_name } );" , f"({ output_name } _w);" )
41
- # Rename output as desired output_name
42
- in_file_content = in_file_content .replace ("out\n " , output_name + "\n " )
43
- in_file_content = in_file_content .replace ("out;" , output_name + ";" )
44
- in_file_content = in_file_content .replace (" out " , " " + output_name + " " )
45
- in_file_content = in_file_content .replace ("(out);" , "(" + output_name + ");" )
44
+ # Rename internal wires that might conflict with the output name
45
+ in_file_content = in_file_content .replace (f'wire [63:0] { output_name } ;' , f'wire [63:0] { output_name } _w;' )
46
+ in_file_content = in_file_content .replace (f'assign { output_name } =' , f'assign { output_name } _w =' )
47
+ # Replace 'out' with the correct output name
48
+ pattern = r'\bout\b'
49
+ in_file_content = re .sub (pattern , output_name , in_file_content )
50
+
51
+ # # Rename all lines that may have the output_name as a local wire
52
+ # in_file_content = in_file_content.replace(f"{output_name}\n", f"{output_name}_w\n")
53
+ # in_file_content = in_file_content.replace(f"{output_name};", f"{output_name}_w;")
54
+ # in_file_content = in_file_content.replace("{" + output_name + "};", "{" + output_name + "_w};")
55
+ # in_file_content = in_file_content.replace(f" {output_name} ", f" {output_name}_w ")
56
+ # in_file_content = in_file_content.replace(f"({output_name});", f"({output_name}_w);")
57
+ # # Rename output as desired output_name
58
+ # in_file_content = in_file_content.replace("out\n", output_name + "\n")
59
+ # in_file_content = in_file_content.replace("out;", output_name + ";")
60
+ # in_file_content = in_file_content.replace(" out ", " " + output_name + " ")
61
+ # in_file_content = in_file_content.replace("(out);", "(" + output_name + ");")
46
62
else :
47
63
# Replace modules header 'out' with outputs directly
48
64
output_declarations = ""
0 commit comments