Vivado Sim 错误:“verilog 95/2K 模式下不允许声明根范围”

cra*_*ael 2 verilog hdl xilinx vivado

当我在 Xilinx Vivado 2016.4 中模拟我的顶级模块时,我收到了奇怪的错误:

ERROR: [VRFC 10-1342] root scope declaration is not allowed in verilog 95/2K mode [<...>/header.vh]
Run Code Online (Sandbox Code Playgroud)

我正在使用指定了 Verilog 2001 的内置Vivado 模拟器。我的header.vh如下所示:

`ifndef _header_vh_
`define _header_vh_

    function integer clog2;
        input integer value;
        begin 
            value = value - 1;
            for (clog2 = 0; value > 0; clog2 = clog2 + 1)
                value = value >> 1;
        end 
    endfunction

`endif
Run Code Online (Sandbox Code Playgroud)

cra*_*ael 5

当函数 的作用域clog2被有效设置为 root(因为它没有在模块内声明)时,就会出现此错误;此范围声明在 Verilog 2001 中是不允许的,但在更高版本(例如 SystemVerilog)中是允许的。切换到 SystemVerilog 可以解决该问题(但不推荐),但为该函数引入模块包装器就足够了。

`ifndef _header_vh_
`define _header_vh_

module header();
    function integer clog2;
        input integer value;
        begin 
            value = value - 1;
            for (clog2 = 0; value > 0; clog2 = clog2 + 1)
                value = value >> 1;
        end 
    endfunction
endmodule

`endif
Run Code Online (Sandbox Code Playgroud)

  • 从方法论的角度来看,在根范围中声明函数和其他任何内容都会由于不同部分和 ip 之间可能发生名称冲突而导致项目出现问题。因此,不要这样做,始终将其包装在模块或系统 verilog 包中。 (2认同)