问题描述
我正在为大学学习 SystemVerilog。我在 Visual Studio Code 中安装了用于语法突出显示的扩展:SystemVerilog、Verilog-HDL/SystemVerilog/bluespec SystemVerilog(扩展名称)。 我安装了编译器 Icarus Verilog 并将地址插入到环境变量(PATH)中。
所以我复制了这段代码:
module adder
(s,b,c_in,sum,c_out);
input logic [7:0] a;
input logic [7:0] b;
input logic c_in;
output logic [7:0] sum;
output logic c_out;
logic [8:0] result;
assign result = a + b + c_in;
assign sum = result [7:0];
assign c_out = result[8];
endmodule: adder
并试图运行它,但它给了我这个错误:
Module end labels require SystemVerilog.
我什至尝试从 cmd 编译,结果相同。
我注意到的一件事是,当我对 .v
文件 (Verilog) 执行相同操作时,它可以工作。
解决方法
我在您的端口列表中收到一个编译错误。更改:
(s,b,c_in,sum,c_out);
到:
(a,c_out);
您没有在列表中声明 a
,而是在代码中使用了 a
。 s
不在代码中。
更改后,您的代码是合法的 SystemVerilog 语法,并且可以在 edaplayground 上的多个模拟器上编译而不会出错。
我确实在 edaplayground 上使用 Icarus Verilog 0.10.0 遇到了与您不同的编译错误。也许您正在使用不同的版本进行编译。请记住,iverilog
尚不支持所有 SV 功能。
如果模块标签仍然给您带来问题,您可以简单地将其删除,因为它是可选的。更改:
endmodule: adder
到:
endmodule
关于文件扩展名(.v
和.sv
),一些编译器会在你使用.sv
时自动启用SV特性;也许有些甚至需要 .sv
。由于您的代码使用了 SV 关键字 (logic
),因此您必须启用 SV 功能才能进行编译。
以下是不依赖 SV 功能的代码版本:
module adder
(a,c_out);
input [7:0] a;
input [7:0] b;
input c_in;
output [7:0] sum;
output c_out;
wire [8:0] result;
assign result = a + b + c_in;
assign sum = result [7:0];
assign c_out = result[8];
endmodule
在端口声明中使用 logic
是可选的,您可以将 result
声明为 wire
。