在Verilog中“未声明标识符”。有谁知道为什么我得到这个?

问题描述 投票:0回答:1

已经工作了一段时间来解决这个问题,但简短的搜索没有产生任何东西,Verilog语法指南似乎没有提供任何有用的信息。我正在编译这两个Verilog文件以及另一个仅使用预制门(AND,OR,NAND,NOR和NOT)的文件。

// 2-to-4 Decoder implemented in structural verilog style.
module decoder_2_to_4 (B, A, G, Y0, Y1, Y2, Y3);
input B;
input A;
input G;
output Y0;
output Y1;
output Y2;
output Y3;
wire NOTB;
wire NOTA;

    // Structural verilog style.
NOT u1 (B,NOTB);
NOT u2 (A,NOTA);
AND3 u3 (NOTB,NOTA,G,Y0);
AND3 u4 (NOTB,A,G,Y1);
AND3 u5 (B,NOTA,G,Y2);
AND3 u6 (B,A,G,Y3);

endmodule

`timescale 1 ns / 100 ps

module test_fixture;
reg done;
//  reg [1:0] test_input;   //2 input
reg [2:0] test_input;   //3 input
wire f0, f1, f2, f3;        //Put output wires here

initial
begin
   $dumpfile("decoders.vcd"); // save waveforms in this file
   $dumpvars;                 // saves all waveforms

   // initialize done signal to 0
   done = 1'b0;
/*
//2 Input Test
   // test 00 case
   test_input[1] = 0;
   test_input[0] = 0;

   // wait 5 ns, then test 001 case
   #5 
   test_input[1] = 0;
   test_input[0] = 1;

   // wait another 5 ns, then test 010 case
   #5
   test_input[1] = 1;
   test_input[0] = 0;

   // wait another 5 ns, then test 011 case
   #5
   test_input[1] = 1;
   test_input[0] = 1;

   // Bogus kluge to extend simulation time for better viewing.
   #5 done = 1'b1;

   $finish;       // finished with simulation
end
*/
// 3 input test

   // test 000 case
   test_input[2] = 0;
   test_input[1] = 0;
   test_input[0] = 0;

   // wait 5 ns, then test 001 case
   #5 
   test_input[2] = 0;
   test_input[1] = 0;
   test_input[0] = 1;

   // wait another 5 ns, then test 010 case
   #5
   test_input[2] = 0;
   test_input[1] = 1;
   test_input[0] = 0;

   // wait another 5 ns, then test 011 case
   #5
   test_input[2] = 0;
   test_input[1] = 1;
   test_input[0] = 1;

   // wait another 5 ns, then test 100 case
   #5
   test_input[2] = 1;
   test_input[1] = 0;
   test_input[0] = 0;

   // wait another 5 ns, then test 101 case
   #5
   test_input[2] = 1;
   test_input[1] = 0;
   test_input[0] = 1;

   // wait another 5 ns, then test 110 case
   #5
   test_input[2] = 1;
   test_input[1] = 1;
   test_input[0] = 0;

   // wait another 5 ns, then test 111 case
   #5
   test_input[2] = 1;
   test_input[1] = 1;
   test_input[0] = 1;


// Instantiate circuit
decoder_2_to_4 u0 (test_input[2], test_input[1], test_input[0], f0, f1, f2, f3);
end
endmodule   // test_fixture

问题是,当我编译时,我收到以下错误:

Identifier (decoder_2_to_4) not declared
"test.v", 94:

syntax error
"test.v', 94: decoder_2_to_4 u0<-

有谁知道为什么我得到这个?我真的不知道发生了什么,向正确的方向推动肯定会有所帮助。提前致谢。

编辑:为了进一步确认编译错误,prebuilt_gates文件(未列出的文件)和Decoders.v(包含2到4解码器实现的文件)都编译在一起就好了没有test.v(第二个文件发布和错误所指出的那个。)问题肯定存在于某个地方。

verilog
1个回答
2
投票

该电路不应在initial块内实例化。

// Instantiate circuit
decoder_2_to_4 u0 (test_input[2], test_input[1], test_input[0], f0, f1, f2, f3);
end
endmodule   // test_fixture

应该:

end
// Instantiate circuit
decoder_2_to_4 u0 (test_input[2], test_input[1], test_input[0], f0, f1, f2, f3);
endmodule   // test_fixture

modules只能在其他modules或generated-blocks中实例化(而generate-blocks只能在模块内实例化)。以任何其他方式实例化模块是非法的,例如在initial-block或always-block中。

moduleinitialalwaystask中实例化function将尝试将module视为变量,其中不存在并给出错误。

实际规则本身是在IEEE Std 1800-2012附件A中发布的。查找附件A中使用的所有地方module_instantiation

© www.soinside.com 2019 - 2024. All rights reserved.