work/Scripts/gen_sram_wrap/get_ds_info.py

92 lines
3.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import glob
def extract_info(file_path):
"""提取关键信息"""
area_info = []
sram_timing = []
error_msgs = []
with open(file_path, 'r') as f:
lines = f.readlines()
in_area = False
for i, line in enumerate(lines):
# 提取Area信息块
if line.strip().startswith("1. Area"):
area_info = lines[i:i+8]
break # 每个文件只提取第一个Area块
# 提取时序信息直接搜索tcyc到tbwh
tcyc_line = next((i for i, line in enumerate(lines) if line.strip().startswith("2.2 SRAM timing")), None)
tbwh_line = next((i for i, line in enumerate(lines) if line.strip().startswith("tbwh")), None)
if tbwh_line is None:
tbwh_line = tcyc_line + 10
if tcyc_line is not None and tbwh_line is not None:
sram_timing = lines[tcyc_line+2:tbwh_line+1]
else:
print(f"Warning: Timing info not found in {file_path}")
# 新增数值提取逻辑
tcyc_value = None
tcd_value = None
# 提取时序值
for line in lines:
line_clean = line.strip()
# 提取tcyc值
if line_clean.startswith('tcyc'):
parts = line_clean.split()
if len(parts) >= 2:
val_str = parts[1]
print(f"Processing tcyc value: {val_str}")
try:
tcyc_value = float(val_str)
if tcyc_value > 0.8:
error_msgs.append(f"Error: tcyc OVER ({tcyc_value}ns > 0.8ns)")
except ValueError:
pass
# 提取tcd值
elif line_clean.startswith('tcd'):
parts = line_clean.split()
if len(parts) >= 2:
val_str = parts[1]
print(f"Processing tcyc value: {val_str}")
try:
tcd_value = float(val_str)
if tcd_value > 0.6:
error_msgs.append(f"Error: tcd OVER ({tcd_value}ns > 0.6ns)")
except ValueError:
pass
return area_info, sram_timing, error_msgs
def write_info():
output = []
# 递归所有子目录
for root, _, files in os.walk('.'):
# 匹配目标文件模式
for ds_file in glob.glob(os.path.join(root, '*_ssgnp0p72v125c.ds')):
print(f"Processing: {ds_file}")
area, timing, error_msgs = extract_info(ds_file)
output.append(f"======== {os.path.basename(ds_file)} ==========\n")
output.append("[Area Info]\n")
output.extend(area)
output.append("\n[Timing Info]\n")
output.extend(timing)
if error_msgs:
print (f"Errors found in {ds_file}: {error_msgs}")
output.extend([msg + "\n" for msg in error_msgs])
output.append("\n" + "="*80 + "\n")
output.append("\n")
# 写入结果文件
with open('area_and_timing.txt', 'w') as f:
f.writelines(output)
if __name__ == "__main__":
write_info()