Cadence 的例子
module top;
class stack #(type T = int); // parameterized class syntax
local T items[$]; //使用Queues
task push( T a );
items.push_front(a); //Systemverilog queues function, inserts the given element at the front of the queue.
endtask
task pop (ref T a);
a = items.pop_back(); //Systemverilog queues function, inserts the given element at the end of the queue.
endtask
endclass
stack int_stack; // default: stack of ints
stack #(bit[9:0]) bit_stack; // stack of 10-bit vectors
stack #(real) real_stack; // stack of reals
int int_value;
bit[9:0] bit_value;
real real_value;
initial begin
int_stack=new(); bit_stack=new(); real_stack=new();
int_stack.push(400);
bit_stack.push('h200);
real_stack.push(40.5);
int_stack.pop(int_value);
bit_stack.pop(bit_value);
real_stack.pop(real_value);
$display("int:%0d bit:%0h real:%g", int_value, bit_value, real_value);
end
endmodule : top
沒有留言:
張貼留言