sram_size_collect.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import os
  2. import re
  3. import argparse
  4. from datetime import datetime
  5. # Define a function to extract information from a given Verilog file
  6. def extract_info_from_verilog(file_path):
  7. with open(file_path, 'r') as file:
  8. content = file.read()
  9. # Use regular expressions to extract information from the comment line
  10. match = re.search(r'// name:array_(\d+)_ext depth:(\d+) width:(\d+) masked:(\w+) maskGran:(\d+) maskSeg:(\d+)', content)
  11. if match:
  12. x = int(match.group(1))
  13. y = int(match.group(2))
  14. z = int(match.group(3))
  15. t = match.group(4) == 'true'
  16. m = int(match.group(5))
  17. n = int(match.group(6))
  18. return (x, y, z, m, n, t)
  19. else:
  20. return None
  21. # Create an argument parser
  22. parser = argparse.ArgumentParser(description="Process Verilog files in a directory")
  23. # Add an argument for the directory path
  24. parser.add_argument("directory", help="Path to the directory containing Verilog files")
  25. # Parse the command line arguments
  26. args = parser.parse_args()
  27. # Get the last level directory name from the input path
  28. last_dir = os.path.basename(os.path.normpath(args.directory))
  29. # Generate the output file name with the current time and last level directory name
  30. output_file_name = f"{last_dir}_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.txt"
  31. # List to store extracted information
  32. info_list = []
  33. # Iterate through the files in the specified directory
  34. for filename in os.listdir(args.directory):
  35. if filename.startswith("array_") and filename.endswith("_ext.v"):
  36. file_path = os.path.join(args.directory, filename)
  37. info = extract_info_from_verilog(file_path)
  38. if info is not None:
  39. info_list.append(info)
  40. # Sort the list of tuples based on Y, Z, M, N, and T (excluding X)
  41. info_list.sort(key=lambda tup: tup[1:])
  42. # Define the order for printing the information
  43. output_order = ["X", "Y", "Z", "M", "N", "T"]
  44. # Write the information to the output file
  45. with open(output_file_name, 'w') as output_file:
  46. for info in info_list:
  47. info_dict = dict(zip(output_order, info))
  48. output_file.write(f"Y:{info_dict['Y']} Z:{info_dict['Z']} M:{info_dict['M']} N:{info_dict['N']} T:{info_dict['T']}\n")
  49. print(f"File info has been written to {output_file_name}")