Hello!
I’m trying to build a mailbox using inheritance. Here is the code:
class properties;
//declare properties
int i,j;
mailbox mbx;
endclass: properties
class data extends properties;
task op;
fork
begin
$display("\n----------------Sending data------------------");
for (i=1;i<=5;i++)
begin: PUT
#1;
mbx.put(i);
$display("\ndata sent = %0d at time =%0dns",i,$time);
end: PUT
$display("\n-----------------Receiving data-------");
begin: GET
repeat(5)
begin
#1;
mbx.get(j);
$display("\ndata received = %0d atime = %0dns",j,$time);
end
end:P2
end
join
endtask: op
endclass:data
module mailbox_using_inheritance;
initial begin
mailbox mbx = new();
data h_1 = new();
h_1.op;
end
endmodule
The warnings and errors:
# ** Warning: (vlib-34) Library already exists at "work".
# QuestaSim-64 vlog 10.7c Compiler 2018.08 Aug 18 2018
# Start time: 09:03:02 on Apr 12,2022
# vlog -reportprogress 300 mailbox_using_inheritance.sv
# ** Warning: mailbox_using_inheritance.sv(75): (vlog-2244) Variable 'mbx' is implicitly static. You must either explicitly declare it as static or automatic
# or remove the initialization in the declaration of variable.
# -- Compiling package mailbox_using_inheritance_sv_unit
# -- Compiling module mailbox_using_inheritance
# ** Warning: mailbox_using_inheritance.sv(75): (vlog-2244) Variable 'mbx' is implicitly static. You must either explicitly declare it as static or automatic
# or remove the initialization in the declaration of variable.
#
# Top level modules:
# mailbox_using_inheritance
# End time: 09:03:02 on Apr 12,2022, Elapsed time: 0:00:00
# Errors: 0, Warnings: 2
# vsim work.mailbox_using_inheritance -l run.log
# Start time: 09:03:02 on Apr 12,2022
# ** Note: (vsim-3812) Design is being optimized...
# ** Error (suppressible): mailbox_using_inheritance.sv(29): (vopt-7063) Failed to find 'mbx' in hierarchical name 'mbx.put'.
# Region: mailbox_using_inheritance_sv_unit
# ** Error (suppressible): mailbox_using_inheritance.sv(48): (vopt-7063) Failed to find 'mbx' in hierarchical name 'mbx.get'.
# Region: mailbox_using_inheritance_sv_unit
# Optimization failed
# Error loading design
# Error: Error loading design
# Pausing macro execution
# MACRO ./run37.do PAUSED at line 3
The o/p I was expectinng:
# --------------Sending data----------------
#
# data sent = 1 at time = 1ns
#
# data sent = 2 at time = 2ns
#
# data sent = 3 at time = 3ns
#
# data sent = 4 at time = 4ns
#
# data sent = 5 at time = 5ns
#
# -----------------Receiving data----------------
#
# data received = 1 at time = 6ns
#
# data received = 2 at time = 7ns
#
# data received = 3 at time = 8ns
#
# data received = 4 at time = 9ns
#
# data received = 5 at time = 10ns
Hope I’m clear with my question.