xref: /Universal-ctags/Units/parser-verilog.r/systemverilog-task-function.d/input.sv (revision 5cd8612d493dcb63ad6a649fbe096e28149417cf)
1// LRM 13.5.2 Pass by Reference
2module task_func;
3
4  function automatic int crc( ref byte packet [1000:1] );
5    for( int j= 1; j <= 1000; j++ ) begin
6      crc ^= packet[j];
7    end
8  endfunction
9
10  task automatic show ( const ref byte data [] );
11    for ( int j = 0; j < data.size ; j++ )
12      $display( data[j] ); // data can be read but not written
13  endtask
14
15  task automatic attr ( (* my_attr *) const ref foo, enum { s0, s1 } sel_e );
16  endtask
17
18endmodule
19
20// disabled K_PROTOTYPE: don't use "--extras=+q" for coverage
21class C;
22  extern function ext_func ();
23  pure virtual task ext_pure_virt_task (x);
24  typedef class   fwd_type_class;
25endclass
26
27// LRM 13.4.1 Return values and void functions
28module M (output a, input b, c, d);
29  always_comb begin
30    a = b + myfunc1(c, d); // call myfunc1 (defined above) as an expression
31    myprint(a); // call myprint (defined below) as a statement
32  end
33
34  function void myprint (int a);
35    logic x;
36  endfunction
37endmodule
38
39// 7.12 Array manipulation methods
40module N;
41  // 7.12.1 Array locator methods
42  function array_locator();
43    string SA[10], qs[$];
44    int IA[int], qi[$];
45    // Find all items greater than 5
46    qi = IA.find( x ) with ( x > 5 );
47  endfunction
48
49  // 7.12.2 Array ordering methods
50  function array_ordering();
51    struct { byte red, green, blue; } c [512];
52    c.sort with ( item.red );               // sort c using the red field only
53    c.sort( x ) with ( {x.blue, x.green} ); // sort by blue then green
54  endfunction
55endmodule
56
57// from UVM-1.2
58package foo;
59  import "DPI-C" context function int import_func (string str);
60  typedef logic uvm_object;
61  function logic bar (uvm_object baz);
62    return 1'b1;
63  endfunction
64endpackage
65
66class func_test;
67  typedef logic uvm_object;
68  typedef logic uvm_comparer;
69  typedef logic uvm_packer;
70
71  function void foo::bar(uvm_object element);	// FIXME
72  endfunction
73
74  function bit do_compare(uvm_object rhs, uvm_comparer comparer);
75    foo::bar(rhs);
76  endfunction
77
78  function void do_pack(uvm_packer packer);
79    for (int i = 0; i < 10; i++)
80      ;
81  endfunction
82
83  function uvm_port_base #(IF) get_if(int index=0);	// FIXME
84  endfunction
85
86  function void bind_vitf(virtual wb_if.master sigs);
87    this.sigs = sigs;
88  endfunction
89
90  // paren
91  function string get(string v);
92      if (v[0] == "(")  // "(" in paired paren '( ... )'
93        ;
94  endfunction
95
96  function string get_arg();
97  endfunction
98
99  // cf. LRM 13.8 Parameterized tasks and functions
100  function parameterized_task;
101    // src/reg/uvm_reg_indirect.svh
102    uvm_resource_db#(bit)::set({"REG::", get_full_name()}, "NO_REG_TESTS", 1);
103  endfunction
104
105  function void foo (inout bar::type_t baz);
106  endfunction
107endclass
108