EmbDev.net

Forum: FPGA, VHDL & Verilog Cannot get icarus to recognize enum or struct.


von Kevin S. (kvnsmnsn)


Rate this post
useful
not useful
I copied the following section of code:
1
// https://www.chipverify.com/systemverilog/systemverilog-enumeration
2
3
module tb;
4
  // "e_true_false" is a new data-type with two valid values: TRUE and FALSE
5
  typedef enum {TRUE, FALSE} e_true_false;
6
7
  initial begin
8
    // Declare a variable of type "e_true_false" that can store TRUE or FALSE
9
    e_true_false  answer;
10
11
    // Assign TRUE/FALSE to the enumerated variable
12
    answer = TRUE;
13
14
    // Display string value of the variable
15
    $display ("answer = %s", answer.name);
16
  end
17
endmodule
verbatim from 
"https://www.chipverify.com/systemverilog/systemverilog-enumeration";, 
fourth code listing, except I added that initial comment and a blank 
line. I'm currently using Icarus as my tool to simulate Verilog. When I 
execute the following:
1
D:\Hf\Verilog\Common>\Icarus\bin\iverilog tb.sv
2
tb.sv:5: syntax error
3
tb.sv:5: error: Invalid module instantiation
4
tb.sv:9: syntax error
5
tb.sv:9: error: malformed statement
6
7
D:\Hf\Verilog\Common>
I get those error messages. It would appear Icarus can't handle 
enumerations. In addition to not being able to use enumerations in 
Verilog with Icarus, it looks like I cannot use a struct either. My code 
uses the example from 
"http://www.testbench.in/SV_07_STRUCTURES_AND_UNIOUNS.html"; like so:
1
module Se;
2
3
struct packed {
4
integer a;
5
byte b;
6
bit[0:7] c;
7
} my_data;
8
9
my_data.b = 8'b10;
10
$display( "%d", my_data.a);
11
12
endmodule
This example is precisely the example on that page, sandwiched between a 
"module Se;" and an "endmodule". When I execute my simulator on it I 
get:
1
D:\Hf\Verilog\Common>\Icarus\bin\iverilog Se.sv
2
Se.sv:3: syntax error
3
Se.sv:3: error: Invalid module instantiation
4
Se.sv:5: syntax error
5
Se.sv:5: error: Invalid module instantiation
6
Se.sv:6: error: Invalid module instantiation
7
Se.sv:7: error: invalid module item.
8
Se.sv:9: syntax error
9
Se.sv:9: error: Invalid module instantiation
10
Se.sv:10: error: invalid module item.
11
12
D:\Hf\Verilog\Common>
What do I have to do to get Icarus to recognize enums and/or structs? Or 
if I can't do it with Icarus, is there a free simulator that does 
recognize enums and structs?

von Klakx (Guest)


Rate this post
useful
not useful
Use flag -g2009 to enable sv

von Kevin S (Guest)


Rate this post
useful
not useful
Okay, that fixed the biggest problem I had with enumerations. But I'm 
still having trouble getting structs to work. I modified "Se.sv" like 
follows:
1
module Se;
2
3
typedef struct packed {
4
integer a;
5
byte b;
6
bit[0:7] c;
7
} my_data;
8
9
my_data md;
10
md.b = 8'b10;
11
$display( "md.a: %d, md.b: %d", md.a, md.b);
12
13
endmodule
Then I executed my Icarus simulator and got the following error 
messages:
1
D:\Hf\Verilog\Common>\Icarus\bin\iverilog -g2009 Se.sv
2
Se.sv:10: syntax error
3
Se.sv:10: error: Invalid module instantiation
4
Se.sv:11: error: invalid module item.
5
6
D:\Hf\Verilog\Common>
Line 10 is the line that says, "md.b = 8'b10;". Does anyone know what 
the syntax error is my simulator is talking about? And what's wrong with 
the instantiation on that line? And why is it complaining about an 
"Invalid module item" on the next line?

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.