相关阅读
Design Compiler可以使用read_file读取RTL设计,本文将对此进行详细阐述。
read_file命令
使用read_file命令不同于analyze/elaborate命令,默认不会产生中间文件(.syn、.pvl、.mr文件)而是直接将设计读取进内存。
read_file -format verilog/sverilog/vhdl **
以下是支持的RTL格式:
- Verilog源代码格式以及gzip压缩格式
- SystemVerilog源代码格式以及gzip压缩格式
- VHDL源代码格式以及gzip压缩格式
虽然推荐始终使用-format选项指定格式,但如果未指定该选项,则会尝试根据文件扩展名自动推断格式,以下是支持的RTL文件拓展名(不区分大小写):
- Verilog拓展名:.v、.verilog、.v.gz、.verilog.gz
- SystemVerilog拓展名:.sv、.sverilog、.sv.gz、.sverilog.gz
- VHDL拓展名:.vhd、.vhdl、.vhd.gz、.vhdl.gz
如果文件扩展名不属于已知类型,工具会默认使用ddc格式。需要注意的是,ddc文件压缩后不支持使用read_file命令读取,因为这种文件已经是压缩格式了。
尽管read_file命令会执行隐式的link命令(手册中并没有说明这点),还是建议在使用读取命令后执行link命令,因为如果设计存在链接问题,显式执行link命令可以帮助设计者发现并修正这些问题。
link命令将会搜索link_path以及search_path并尝试解析引用,随后尝试在默认设计库WORK中解析引用。
关于默认设计库,参考下面这篇博客。
Design Compiler:使用analyze/elaborate命令读取RTL设计https://blog.csdn.net/weixin_45791458/article/details/144949582?sharetype=blogdetail&sharerId=144949582&sharerefer=PC&sharesource=weixin_45791458&spm=1011.2480.3001.8118 关于link_path以及search_path的详细信息,参考下面这篇博客。
读取参数化设计
当使用read_file命令读取参数化设计时,可能会出现问题,如下例所示。
// 文件:adder.v
module adder #(
parameter WIDTH = 8
)(
input wire [WIDTH-1:0] a,
input wire [WIDTH-1:0] b,
output wire [WIDTH-1:0] sum
);
assign sum = a + b;
endmodule
// 文件:top.v
module top (
input wire [7:0] a8, b8,
input wire [15:0] a16, b16,
input wire [3:0] a4, b4,
output wire [7:0] sum8,
output wire [15:0] sum16,
output wire [3:0] sum4
);
adder #(.WIDTH(8)) u_adder8 (
.a(a8),
.b(b8),
.sum(sum8)
);
adder #(.WIDTH(16)) u_adder16 (
.a(a16),
.b(b16),
.sum(sum16)
);
adder #(.WIDTH(4)) u_adder4 (
.a(a4),
.b(b4),
.sum(sum4)
);
endmodule
首先使用read_file命令读取设计文件。
dc_shell> read_file -format verilog "top.v adder.v"
当使用link命令尝试链接时却出现了错误,如下所示。
dc_shell> link
Linking design 'top'
Using the following designs and libraries:
--------------------------------------------------------------------------
Information: Building the design 'adder' instantiated from design 'top' with
the parameters "WIDTH=16". (HDL-193)
Warning: Cannot find the design 'adder' in the library 'WORK'. (LBR-1)
Information: Building the design 'adder' instantiated from design 'top' with
the parameters "WIDTH=4". (HDL-193)
Warning: Cannot find the design 'adder' in the library 'WORK'. (LBR-1)
Warning: Unable to resolve reference 'adder' in 'top'. (LINK-5)
警告显示,除了默认的WIDTH参数为8的情况,另外两个设计尝试在默认设计库WORK中读取失败了。
这是因为读取参数化设计时需要中间文件,而read_file命令默认不产生中间文件(使用analyze/elaborate命令读取时不存在该问题),需要将hdlin_auto_save_templates变量设置为true允许保存中间文件。
dc_shell> set_app_var hdlin_auto_save_templates true
举例说明
下面是三个分属于三个文件的模块,其中顶层模块top定义在top.v文件中,其中例化了adder模块,而adder模块定义在ADDER.v和adder.v文件中。
// 文件:adder.v
module adder(
input wire [7:0] a,
input wire [7:0] b,
output wire [7:0] sum
);
assign sum = a * b;
endmodule
// 文件:ADDER.v
module adder(
input wire [7:0] a,
input wire [7:0] b,
output wire [7:0] sum
);
assign sum = a + b;
endmodule
// 文件:top.v
module top(
input wire [7:0] in_a,
input wire [7:0] in_b,
output wire [7:0] out_sum
);
adder u_adder (
.a(in_a),
.b(in_b),
.sum(out_sum)
);
endmodule
假设已经将ADDER.v保存为ADDER.ddc文件,并且在link_library中指定了该文件,而adder模块(来自adder.v文件)在默认设计库WORK中,read_file命令读取top模块后会优先使用该.ddc文件,而不是设计库中的adder模块(来自adder.v文件),如下脚本所示。
define_design_lib -path ./work/ WORK
analyze -format verilog "adder.v"
set_app_var link_library ADDER.ddc
read_file -format verilog "top.v" // 使用ADDER.ddc而不是WORK库中的adder.v
写在最后
不建议使用read_file命令读取除ddc格式外的设计文件,使用analyze/elaborate命令读取RTL设计更稳妥,功能也更加强大。