You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求使用TCL脚本修改指定硬件层次路径语句(含特殊字符替换)

TCL脚本实现硬件层次路径修改方案

原路径与目标路径

原路径:

top.dut.fe.stk.pma.phy.phy0.pma.dig.lane0.asic_xface.\range_counter_reg[0]

目标路径:

top.dut.fe.stk.pma.phy.phy0.pma.dig.lane0.asic_xface.@ {\/range_counter_reg[0]}.Q

实现脚本

利用TCL的regsub正则替换命令,可精准匹配并修改路径的最后一段:

# 定义原始路径(注意TCL中单个反斜杠需转义为双反斜杠)
set original_path "top.dut.fe.stk.pma.phy.phy0.pma.dig.lane0.asic_xface.\\range_counter_reg[0]"

# 正则替换:匹配末尾的".\range_counter_reg[0]"格式,替换为目标结构
regsub {\.\\(.+\[.+\])$} $original_path {.@ {\/\1}.Q} modified_path

# 输出修改后的路径
puts $modified_path

批量处理扩展

如果需要处理多条类似路径,可封装为过程复用:

proc modify_hw_path {original_path} {
    regsub {\.\\(.+\[.+\])$} $original_path {.@ {\/\1}.Q} modified_path
    return $modified_path
}

# 示例:批量处理路径列表
set path_list [list \
    "top.dut.fe.stk.pma.phy.phy0.pma.dig.lane0.asic_xface.\\range_counter_reg[0]" \
    "top.dut.fe.stk.pma.phy.phy0.pma.dig.lane1.asic_xface.\\range_counter_reg[1]" \
]

foreach path $path_list {
    puts [modify_hw_path $path]
}

正则规则说明

  • \.\\(.+\[.+\])$:匹配路径末尾的.\xxx[num]格式,捕获其中的xxx[num]部分
  • {.@ {\/\1}.Q}:将捕获的内容代入目标格式,\1代表正则中捕获的分组内容

内容的提问来源于stack exchange,提问作者deb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 07:20:04