Can this code be used to verify both, synchronous and asynchronous FIFOs? I would instantiate it inside a scoreboard.
typedef longint int64;
class sync_fifo#(type T = int64);
T sync_fifo[$];
int fifo_size;
function new(int size = 10);
fifo_size = size;
endfunction
function void write(T data);
if(sync_fifo.size() <= fifo_size) begin
sync_fifo.push_front(data);
fifo_size++;
end
else begin
$error("Writing full fifo!");
end
endfunction
function T read();
if(sync_fifo.size != 0) begin
fifo_size--;
return sync_fifo.pop_back();
end
else begin
$error("Reading empty fifo!");
return 0;
end
endfunction
endclass;