All, As part of my prep for Monday, I've been collecting a set of examples to illuminate the questions that I raised earlier. I've attached the examples to this note without commentary or other notes since I am still working on a discussion framework. I did think it was useful to raise at least this set of examples early in case people wanted to work through the "what would I expect here" exercise prior to Monday. I will likely have a few additional examples with me and, as with the topics, if anyone has additional examples that they believe are particularly illuminating to some issue, I can try to incorporate those. Gord. -- -------------------------------------------------------------------- Gordon Vreugdenhil 503-685-0808 Model Technology (Mentor Graphics) gordonv@model.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. Example 1 module top; int x = $unit::y; endmodule int y; Example 2 module top; $unit::T x; endmodule typedef int T; Example 3 module top; initial t(); endmodule task t; endtask Example 4 module top; initial $unit::t(); endmodule task t; endtask Example 5 module top; typedef C; C::T x; class C; typdef int T; endclass endmodule Example 6 typedef int T; generate if (1) begin : b T x; int T; end endgenerate Example 7 int x; generate if (1) begin : b int z; initial z = x; int x; end endgenerate Example 8 struct { int y; } x; generate if (1) begin : b int z; initial z = x.y; struct { int y; } x; end endgenerate Example 9 struct { int y; } x; generate if (1) begin : b int z; initial z = x.y; class C; function int x(int y = 1); return y; endfunction endclass C x = new; end endgenerate Example 10 typedef int T; class C; T x; int T; endclass Example 11 module top(output wire state, input bit clk); initial cb.x <= 1; clocking cb @(posedge clk); output state; endclocking endmodule Example 12 task t; int x; endtask module top; child c(); endmodule module child; int x = t.x; endmodule Example 12 Assume separate compilation units file1.sv task t; int x; endtask module top; child c(); endmodule file2.sv module child; int x = t.x; endmodule Example 13 file1.sv task t; int x; endtask module top; endmodule file2.sv module child; int x = t.x; endmodule bind top child(); Example 14 -- 14-16 are from Gord's quiz: http://www.eda-stds.org/sv-bc/hm/6017.html task a1; int x; endtask struct { int x; } a2; class A3; int x; endclass A3 a3; int b1, b3; module top; int y; initial begin y = a1.x; // (1) y = a2.x; // (2) y = a3.x; // (3) y = a4.x; // (4) y = a5.x; // (5) y = a6.x; // (6) y = b1; // (7) y = b2; // (8) y = b3; // (9) t; // (10) end int b3; endmodule task a4; int x; endtask struct { int x; } a5; A3 a6; int b2; task t; endtask Example 15 module top; task a1; int x; endtask struct { int x; } a2; int b1,b3; for (genvar g = 0; g < 5; g++) begin : b int y; initial begin y = a1.x; // (1) y = a2.x; // (2) // be careful here! y = a4.x; // (3) y = a5.x; // (4) y = b1; // (5) y = b2; // (6) y = b3; // (7) end int b3; struct { int x; } a2; end task a4; int x; endtask struct { int x; } a5; int b2; endmodule Example 16 module top; task a1; int x; endtask struct { int x; } a2; int b1, b3; module nest; int y; initial begin y = a1.x; // (1) y = a2.x; // (2) // be careful here! y = a4.x; // (3) y = a5.x; // (4) y = b1; // (5) y = b2; // (6) y = b3; // (7) end int b3; task a2; int x; endtask endmodule task a4; int x; endtask struct { int x; } a5; int b2; endmodule Example 17 (From Mark's quiz resonse: http://www.eda-stds.org/sv-bc/hm/6021.html) typedef struct { int x; int y; } ST; class A; function void f1(); endfunction function void f2(); endfunction endclass ST a1; A a2; module child; parameter P = 1; initial begin a1.x = 0; // (1) a2.f1(); // (2) a3.x = 0; // (3) a4.f1(); // (4) end generate if (P == 0) begin : a1 int x; int y; end : a1 if (P == 0) begin : a2 function void f1(); endfunction function void f2(); endfunction end : a2 if (P == 0) begin : a3 int x; int y; end : a3 if (P == 0) begin : a4 function void f1(); endfunction function void f2(); endfunction end : a4 endgenerate initial begin a1.y = 0; // (5) a2.f2(); // (6) a3.y = 0; // (7) a4.f2(); // (8) end endmodule ST a3; A a4; module top(); child #(.P(0)) u0(); child #(.P(1)) u1(); endmodule Example 18 class C#(int p = p2); localparam p2 = 1; endclass Example 19 package pkg; localparam width = 1; endpackage ... module child; parameter P = 1; parameter the_moon_is_blue = 0; import pkg::*; if (P == the_moon_is_blue) begin class some_special_monitor; int x; function new; x = width; endfunction endclass end localparam width = 5; ... endmodule Example 20 module m #(parameter type T = int); int x; class C extends T; function int get_from_env(); return x; endfunction endclass endmodule Example 21 module m #(parameter type T = int); class C extends T; int y; function void do_rand(int x); this.randomize with (x < y); endfunction endclass endmodule Example 22 package pkg; int x; endpackage module m #(parameter type T = int); import pkg::*; class C extends T; function int get_from_env(); return x; endfunction endclass int x; endmodule Example 23 package P: function void f1(); f2(); // is this hierarchical? endfunction function void f2(); endfunction endpackage - Can we have hierarchical references *within* a package - From Mark: http://www.eda-stds.org/sv-bc/hm/6023.html Example 24 module child #(type T = int); int T2; class C extends T; T2 x; endclass endmodule Example 25 module child #(type T = int); int T2; class C extends T; type(T2) x; endclass endmoduleReceived on Thu Sep 20 16:31:58 2007
This archive was generated by hypermail 2.1.8 : Thu Sep 20 2007 - 16:32:06 PDT