'包含在系统Verilog中的函数定义中



我有一个简单的系统Verilog代码,其中包含一个包含文件,其中包含很少的函数定义。但是,当我有多个包含此文件的文件时,由于函数重新定义,我会收到编译错误。有什么建议可以解决吗?

代码 test.sv:

`include "constants.sv"
module test();
real myReal1;
real myReal2;
initial myReal1 = 10.1;
assign myReal2 = abs(myReal1);
endmodule

代码:测试2.sv:

`include "constants.sv"
module test2();
real myReal1;
real myReal2;
initial myReal1 = 10.1;
assign myReal2 = 10.2;
endmodule

错误:

function real abs(input real a);
                |
ncvlog: *E,DUPIDN (./constants.sv,19|16): identifier 'abs' previously declared [12.5(IEEE)].

一个快速的解决方案:

`ifndef CONSTANTS
   `define CONSTANTS
   `include "constants.sv"
`endif  

以下是对我有用的方法:文件 constants.sv 的内容:

`ifndef SVINCLUDES
   //define all macros here
   //define all functions here
   `define SVINCLUDES
`endif

尽量使用包或使用包含防护以避免冲突

最新更新