有没有办法用 Yosys 获取 verilog 模块的默认参数值

Is there any way to get default parameter value for verilog module with Yosys

我正在尝试使用 Yosys 命令 shell 获取 verilog 模块的默认参数值。 有什么办法吗? 此外,解析 `write_ilang' 命令输出文件是个好主意还是它的格式在不久的将来会发生巨大变化?

尝试在 ilang、json、table 转储中查找默认值,甚至使用 chparam -list 命令,但没有找到任何结果。

考虑这个例子(文件param_test.v):

module stub();
  parameter PUBLIC_PARAM = 1;
  parameter HIDDEN_PARAM = 2;
endmodule

module testbench();
  stub no_param_stub ();
  stub #(.PUBLIC_PARAM(1)) one_param_stub ();
endmodule

我遵循以下步骤:

  1. 加载源代码read -sv param_test.v
  2. 精心设计hierarchy -top testbench
  3. 尝试获取参数值。

write_ilang 命令的输出:

# Generated by Yosys 0.8+634 (git sha1 ac2fc3a, clang 3.8.0-2ubuntu4 -fPIC -Os)
autoidx 1
attribute \blackbox 1
attribute \src "param_test.v:1"
module $paramod\stub\PUBLIC_PARAM=1
  parameter \HIDDEN_PARAM
  parameter \PUBLIC_PARAM
end
attribute \blackbox 1
attribute \src "param_test.v:1"
module \stub
  parameter \HIDDEN_PARAM
  parameter \PUBLIC_PARAM
end
attribute \top 1
attribute \src "param_test.v:6"
module \testbench
  attribute \module_not_derived 1
  attribute \src "param_test.v:8"
  cell \stub \no_param_stub
  end
  attribute \module_not_derived 1
  attribute \src "param_test.v:10"
  cell $paramod\stub\PUBLIC_PARAM=1 \one_param_stub
  end
end

write_json 命令的输出甚至不包含有关 HIDDEN_PARAM 参数的信息:

{
  "creator": "Yosys 0.8+634 (git sha1 ac2fc3a, clang 3.8.0-2ubuntu4 -fPIC -Os)",
  "modules": {
    "$paramod\stub\PUBLIC_PARAM=1": {
      "attributes": {
        "blackbox": 1,
        "src": "param_test.v:1"
      },
      "ports": {
      },
      "cells": {
      },
      "netnames": {
      }
    },
    "stub": {
      "attributes": {
        "blackbox": 1,
        "src": "param_test.v:1"
      },
      "ports": {
      },
      "cells": {
      },
      "netnames": {
      }
    },
    "testbench": {
      "attributes": {
        "top": 1,
        "src": "param_test.v:6"
      },
      "ports": {
      },
      "cells": {
        "no_param_stub": {
          "hide_name": 0,
          "type": "stub",
          "parameters": {
          },
          "attributes": {
            "module_not_derived": 1,
            "src": "param_test.v:8"
          },
          "port_directions": {
          },
          "connections": {
          }
        },
        "one_param_stub": {
          "hide_name": 0,
          "type": "$paramod\stub\PUBLIC_PARAM=1",
          "parameters": {
          },
          "attributes": {
            "module_not_derived": 1,
            "src": "param_test.v:10"
          },
          "port_directions": {
          },
          "connections": {
          }
        }
      },
      "netnames": {
      }
    }
  }
}

Yosys 最近通过细化获得了保留参数的功能(而它们通常会被丢弃)。将-pwires添加到read_verilog,参数将转换为由参数默认值驱动的线,parameter属性设置为1。

在稳定性方面,还有其他几个工具(例如 nMigen)可以创建或读取 RTLIL ilang,因此现在不太可能有重大的重大更改。