diff --git a/Scripts/gen_sram_wrap/gen_sram_wrap.py b/Scripts/gen_sram_wrap/gen_sram_wrap.py index e4f617b..75d047f 100644 --- a/Scripts/gen_sram_wrap/gen_sram_wrap.py +++ b/Scripts/gen_sram_wrap/gen_sram_wrap.py @@ -18,6 +18,94 @@ def validate_sheet(rb, sheet_name): print(f"[Error] Sheet '{sheet_name}' not found in {rb}") sys.exit(1) + + +def generate_sram_wrapper(template_file, sram_name, width, depth, ref_name,\ + asmbly_depth_nums,asmbly_width_nums,compile_depth,compile_width,\ + wtsel,\ + output_dir): + """生成单个SRAM包装文件""" + with open(template_file, 'r') as f: + template = f.read() + + # 执行模板替换(根据您提供的模板结构) + replaced = template.replace('${SramWrapName}', sram_name)\ + .replace('${Width}', str(width))\ + .replace('${Depth}', str(depth))\ + .replace('${AssemblyDepth}',str(asmbly_depth_nums))\ + .replace('${AssemblyWidth}',str(asmbly_width_nums))\ + .replace('${CompileDepth}',str(compile_depth))\ + .replace('${CompileWidth}',str(compile_width))\ + .replace('${WTselRange}', str(wtsel))\ + .replace('${ReferenceName}', ref_name) + + # 写入输出文件 + output_path = f"{output_dir}/{sram_name}.v" + with open(output_path, 'w') as f: + f.write(replaced) + +def get_mem_ctrl_bus_fields(i_compilerName,mux,width, depth): + compilerName = i_compilerName.split('_')[0] + # get WTSEL + wtsel = '[45:44]' + if compilerName == 'tsn12ffcllspsram': + if (mux == 4 and (depth>1024 and depth <= 4096)) or \ + (mux == 8 and (depth>2048 and depth <= 8192)) or \ + (mux == 16 and (depth>4096 and depth <= 16384)): + wtsel = '[47:46]' + + return wtsel + +def gen_sram_sh(rb,sheet_name, output_dir): + """生成SRAM相关的Shell脚本""" + config_dir = os.path.join(output_dir, "config") + os.makedirs(config_dir, exist_ok=True) + try: + sheet = rb.sheet_by_name(sheet_name) + headers = sheet.row_values(1) + + # 获取关键列索引 + name_col = headers.index('SramWrapName') + compiler_col = headers.index('CompilerName') if 'CompilerName' in headers else -1 + + if compiler_col == -1: + print(f"[Error] Missing 'CompilerName' column in sheet {sheet_name}") + return + + commands = [] + for row_idx in range(2, sheet.nrows): + row = sheet.row_values(row_idx) + sram_name = row[name_col] + compiler = row[compiler_col] + + if sram_name and compiler: # 空值检查 + cmd = f"../{compiler}.pl -file {sram_name}_{compiler}_config.txt -ColRed -NonBist" + commands.append(cmd) + else: + print(f"[Warning] Missing data in row {row_idx} for SRAM '{sram_name}' with compiler '{compiler}', skipping.") + + + # 写入bash文件 + sh_path = os.path.join(config_dir, f"run_{sheet_name}.sh") + with open(sh_path, 'w') as f: + f.write("#!/bin/bash\n") + f.write("\n".join(sorted(commands))) + + except Exception as e: + print(f"Generate shell script failed: {str(e)}") + +def gen_config_txt(sram_name, compiler, compile_depth, compile_width, mux, output_dir): + """生成SRAM配置文本文件到config子目录""" + config_dir = os.path.join(output_dir, "config") + os.makedirs(config_dir, exist_ok=True) + + config_content = f"{compile_depth}x{compile_width}m{mux}scp ulvt" + + config_path = os.path.join(config_dir, f"{sram_name}_{compiler}_config.txt") + with open(config_path, 'w') as f: + f.write(config_content) + + def generate_files(xls_path, sheet_name=None): """主生成函数""" rb = xlrd.open_workbook(xls_path) @@ -131,92 +219,6 @@ def generate_files(xls_path, sheet_name=None): gen_sram_sh(rb, sheet.name, output_dir) - -def generate_sram_wrapper(template_file, sram_name, width, depth, ref_name,\ - asmbly_depth_nums,asmbly_width_nums,compile_depth,compile_width,\ - wtsel,\ - output_dir): - """生成单个SRAM包装文件""" - with open(template_file, 'r') as f: - template = f.read() - - # 执行模板替换(根据您提供的模板结构) - replaced = template.replace('${SramWrapName}', sram_name)\ - .replace('${Width}', str(width))\ - .replace('${Depth}', str(depth))\ - .replace('${AssemblyDepth}',str(asmbly_depth_nums))\ - .replace('${AssemblyWidth}',str(asmbly_width_nums))\ - .replace('${CompileDepth}',str(compile_depth))\ - .replace('${CompileWidth}',str(compile_width))\ - .replace('${WTselRange}', str(wtsel))\ - .replace('${ReferenceName}', ref_name) - - # 写入输出文件 - output_path = f"{output_dir}/{sram_name}.v" - with open(output_path, 'w') as f: - f.write(replaced) - -def get_mem_ctrl_bus_fields(i_compilerName,mux,width, depth): - compilerName = i_compilerName.split('_')[0] - # get WTSEL - wtsel = '[45:44]' - if compilerName == 'tsn12ffcllspsram': - if (mux == 4 and (depth>1024 and depth <= 4096)) or \ - (mux == 8 and (depth>2048 and depth <= 8192)) or \ - (mux == 16 and (depth>4096 and depth <= 16384)): - wtsel = '[47:46]' - - return wtsel - -def gen_sram_sh(rb,sheet_name, output_dir): - """生成SRAM相关的Shell脚本""" - config_dir = os.path.join(output_dir, "config") - os.makedirs(config_dir, exist_ok=True) - try: - sheet = rb.sheet_by_name(sheet_name) - headers = sheet.row_values(1) - - # 获取关键列索引 - name_col = headers.index('SramWrapName') - compiler_col = headers.index('CompilerName') if 'CompilerName' in headers else -1 - - if compiler_col == -1: - print(f"[Error] Missing 'CompilerName' column in sheet {sheet_name}") - return - - commands = [] - for row_idx in range(2, sheet.nrows): - row = sheet.row_values(row_idx) - sram_name = row[name_col] - compiler = row[compiler_col] - - if sram_name and compiler: # 空值检查 - cmd = f"../{compiler}.pl -file {sram_name}_{compiler}_config.txt -ColRed -NonBist" - commands.append(cmd) - else: - print(f"[Warning] Missing data in row {row_idx} for SRAM '{sram_name}' with compiler '{compiler}', skipping.") - - - # 写入bash文件 - sh_path = os.path.join(config_dir, f"run_{sheet_name}.sh") - with open(sh_path, 'w') as f: - f.write("#!/bin/bash\n") - f.write("\n".join(sorted(commands))) - - except Exception as e: - print(f"Generate shell script failed: {str(e)}") - -def gen_config_txt(sram_name, compiler, compile_depth, compile_width, mux, output_dir): - """生成SRAM配置文本文件到config子目录""" - config_dir = os.path.join(output_dir, "config") - os.makedirs(config_dir, exist_ok=True) - - config_content = f"{compile_depth}x{compile_width}m{mux}scp ulvt" - - config_path = os.path.join(config_dir, f"{sram_name}_{compiler}_config.txt") - with open(config_path, 'w') as f: - f.write(config_content) - if __name__ == "__main__": args = parse_args()