上传所有文件
This commit is contained in:
98
main.py
Normal file
98
main.py
Normal file
@@ -0,0 +1,98 @@
|
||||
"""
|
||||
TBgen_App - 入口文件
|
||||
|
||||
用法:
|
||||
python main.py -d <dut.v> -w <description.txt> -o <output_dir> -m <model>
|
||||
|
||||
示例:
|
||||
python main.py -d dut.v -w description.txt --header "module example(...)" -m qwen-max
|
||||
"""
|
||||
import sys
|
||||
import getopt
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# 添加项目路径
|
||||
PROJECT_ROOT = Path(__file__).parent
|
||||
sys.path.insert(0, str(PROJECT_ROOT))
|
||||
|
||||
from run_tbgen import generate_tb
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], "h:d:w:o:m:",
|
||||
["help", "dut=", "desc=", "header=", "output=", "model="])
|
||||
except getopt.GetoptError as err:
|
||||
print(err)
|
||||
sys.exit(2)
|
||||
|
||||
dut_path = None
|
||||
desc_path = None
|
||||
header = None
|
||||
output = "./output"
|
||||
model = "qwen-max"
|
||||
|
||||
for opt, arg in opts:
|
||||
if opt in ("-h", "--help"):
|
||||
print("Usage: python main.py -d <dut.v> -w <description.txt> [options]")
|
||||
print("")
|
||||
print("Options:")
|
||||
print(" -d, --dut <file> DUT文件路径 (必需)")
|
||||
print(" -w, --desc <file> 描述文件路径 (必需)")
|
||||
print(" --header <string> Module header (必需)")
|
||||
print(" -o, --output <dir> 输出目录 (默认: ./output)")
|
||||
print(" -m, --model <model> 使用的模型 (默认: qwen-max)")
|
||||
print(" -h, --help 显示帮助信息")
|
||||
sys.exit(0)
|
||||
elif opt in ("-d", "--dut"):
|
||||
dut_path = arg
|
||||
elif opt in ("-w", "--desc"):
|
||||
desc_path = arg
|
||||
elif opt in ("--header"):
|
||||
header = arg
|
||||
elif opt in ("-o", "--output"):
|
||||
output = arg
|
||||
elif opt in ("-m", "--model"):
|
||||
model = arg
|
||||
|
||||
if not dut_path or not desc_path:
|
||||
print("Error: -d (dut) and -w (desc) are required")
|
||||
print("Use -h or --help for usage information")
|
||||
sys.exit(2)
|
||||
|
||||
if not header:
|
||||
print("Error: --header is required")
|
||||
print("Use -h or --help for usage information")
|
||||
sys.exit(2)
|
||||
|
||||
# 读取文件
|
||||
with open(dut_path, "r") as f:
|
||||
dut_code = f.read()
|
||||
with open(desc_path, "r") as f:
|
||||
description = f.read()
|
||||
|
||||
# 生成TB
|
||||
task_id = Path(dut_path).stem
|
||||
print(f"Generating TB for task: {task_id}")
|
||||
print(f"Model: {model}")
|
||||
print(f"Output directory: {output}")
|
||||
|
||||
tb_path, result = generate_tb(
|
||||
dut_code=dut_code,
|
||||
description=description,
|
||||
header=header,
|
||||
task_id=task_id,
|
||||
model=model,
|
||||
output_dir=output
|
||||
)
|
||||
|
||||
print(f"\nTB generated successfully: {tb_path}")
|
||||
if result.get("cga_coverage"):
|
||||
print(f"Coverage: {result['cga_coverage']}")
|
||||
if result.get("full_pass"):
|
||||
print(f"Full Pass: {result['full_pass']}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user