Home > Community > Forums > Functional Verification > Creating a Queue of Classes

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 Creating a Queue of Classes 

Last post Tue, Feb 13 2007 8:39 AM by archive. 2 replies.
Started by archive 13 Feb 2007 08:39 AM. Topic has 2 replies and 1155 views
Page 1 of 1 (3 items)
Sort Posts:
  • Tue, Feb 13 2007 8:39 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    Creating a Queue of Classes Reply

    This is an example of using a queue of classes. ----file: queue_of_classes.sv---- // compile with: ncverilog queue_of_classes.sv +sv package mypack; class some_class; randc shortint myint; constraint c1 {myint inside {[1:20]}; } function void printit; $display("value= %d", myint); endfunction endclass endpackage // --------------------- // this module creates a queue of classes module queue_of_classes(); import mypack::*; logic clk = 'b1; initial forever clk = #10 ~clk; int success; some_class myQ[$]; some_class myclass; task dowrite; $display("--------Write Queue--------"); myclass = new; // create point to new class object success = myclass.randomize(); myclass.printit; myQ.push_front(myclass ); // push onto queue endtask task doread; $display("--------Read Queue---------"); if (myQ.size() > 0) begin: datainQ myclass = myQ.pop_back(); // pop queue myclass.printit; end: datainQ else $display("Queue Empty - cant read"); endtask task doQueContents; // non-destructive read $display("--------Queue Stats-------------"); $display("Que Size= %d", myQ.size() ); for (int j=0; j < myQ.size(); j++) begin: showQ // myclass = myQ[j]; // $display("Contents %d", myclass ); // myclass.printit; $display("CONTENTS %d",j); myQ[j].printit; end: showQ endtask always @(posedge clk) begin: main for (int i=1; i <5; i++) begin: for1 randcase 1: dowrite; 1: doread; endcase doQueContents; end: for1 end: main endmodule


    Originally posted in cdnusers.org by tmackett
    • Post Points: 0
  • Wed, Feb 14 2007 1:05 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: Creating a Queue of Classes Reply

    Hi Todd,

    Could you please describe briefly what queue of class mean?
    Dose it mean you can send objects of different class to one queue?
    Thanks!

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Post Points: 0
  • Wed, Feb 14 2007 9:32 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: Creating a Queue of Classes Reply

    A queue of classes allow you to encapsulate the data and the functions that operate on it in a single class. If you compare this to just having a queue of a data structure, the you are forced to operate on ONLY that data structure. I can't populate the queue with different classes, but I can populate the queue with extended classes, which may have different/more variables, constraints, different/overloaded functions or even new functions inside the extended class. Here's my example extended to show an extended class with a different contraint block. In my extended example if you are using the extended class and call the 'printit' function, it actually calls the 'printit' function from the inherited class. package mypack; class some_class; randc shortint myint; constraint c1 {myint inside {[1:20]}; } function void printit; $display("value= %d", myint); endfunction endclass class other_class extends some_class; randc shortint myint; constraint c1 {myint inside {[75:80]}; } // Notice there is no 'printit' function here // FYI - calling 'printit' using this class will // call 'printit' from the inherited class endclass endpackage // --------------------- // this module creates a queue of classes module queue_of_classes(); import mypack::*; logic clk = 'b1; initial forever clk = #10 ~clk; int success; some_class myQ[$]; some_class myclass; other_class myotherclass; task dowrite; $display("--------Write Queue--------"); myclass = new; // create point to new class object success = myclass.randomize(); myclass.printit; myQ.push_front(myclass ); // push onto queue endtask task otherdowrite; $display("--------Other Write Queue--------"); myotherclass = new; // create point to new class object success = myotherclass.randomize(); myotherclass.printit; myQ.push_front(myotherclass ); // push onto queue endtask task doread; $display("--------Read Queue---------"); if (myQ.size() > 0) begin: datainQ myclass = myQ.pop_back(); // pop queue myclass.printit; end: datainQ else $display("Queue Empty - cant read"); endtask task doQueContents; // non-destructive read $display("--------Queue Stats-------------"); $display("Que Size= %d", myQ.size() ); for (int j=0; j < myQ.size(); j++) begin: showQ // myclass = myQ[j]; // $display("Contents %d", myclass ); // myclass.printit; $display("CONTENTS %d",j); myQ[j].printit; end: showQ endtask always @(posedge clk) begin: main for (int i=1; i <5; i++) begin: for1 randcase 1: dowrite; 1: doread; 1: otherdowrite; endcase doQueContents; end: for1 end: main endmodule


    Originally posted in cdnusers.org by tmackett
    • Post Points: 0
Page 1 of 1 (3 items)
Sort Posts:
Started by archive at 13 Feb 2007 08:39 AM. Topic has 2 replies.