File: oop.sv

package info (click to toggle)
geany 2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 39,448 kB
  • sloc: ansic: 168,606; cpp: 77,562; sh: 5,344; makefile: 1,694; cs: 1,233; javascript: 1,024; python: 580; f90: 537; vhdl: 504; sql: 503; lisp: 436; fortran: 389; php: 278; ada: 201; ruby: 163; java: 131; asm: 131; perl: 119; cobol: 88; tcl: 77; erlang: 73; xml: 66; ml: 27; sed: 16; pascal: 15; haskell: 6
file content (145 lines) | stat: -rw-r--r-- 2,607 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* Tests the following SystemVerilog ctags:
 * - [x] constant
 * - [x] define
 * - [ ] event
 * - [x] function
 * - [ ] module
 * - [ ] net
 * - [ ] port
 * - [x] register
 * - [x] task
 * - [ ] block
 * - [ ] instance
 * - [x] class
 * - [x] enum
 * - [x] interface
 * - [x] modport
 * - [x] package
 * - [ ] program
 * - [x] prototype
 * - [x] struct
 * - [x] typedef
 * - [z] member
 * - [x] ifclass
 * - [x] nettype
 */

package oop;

`define MACRO 1234 // NB: Shouldn't the ctag for this be outside of the package? (ctags bug?)

/* Constants */

const      int  ANSWER_TO_LIFE = 42;
localparam real APPROX_PI      = 3.14;

/* Methods */

task display_int(int x);
    $display("%0d", x);
endtask

function automatic resolve_nettype(real driver[]);
    resolve_nettype = 0.0;
    foreach (driver[i])
        resolve_nettype += driver[i];
endfunction

/* Typedefs */

nettype real net_t with resolve_nettype;

typedef struct packed {
    logic [7:0] data;
    logic       parity;
} struct_t;

typedef union packed {
    logic [7:0] data;
    logic [3:0] control;
} union_t;

typedef enum {
    red,
    yellow,
    green
} enum_t;

/* Classes */

interface class ifclass #(
    type T = logic
);
    pure virtual function T    get_value();
    pure virtual function void set_value(T x);
endclass : ifclass

class a_class implements ifclass #(int);

    int value;

    virtual function int get_value();
        get_value = value;
    endfunction

    virtual function void put_value(int x);
        value = x;
    endfunction

    task print_value();
        $display("value = %0d", value);
    endtask

    function value_plus(int x);
        value_plus = value + x;
    endfunction

endclass : a_class

class other_class;

    struct packed {
        byte s_a, s_b, s_c;
        string s_str;
    } s_member;

    union  packed {
        byte u_a;
        int  u_b;
    } u_member;

    enum { ready, steady, go } e_member;

    struct_t st_member;
    union_t  ut_member;
    enum_t   et_member;

endclass : other_class

/*virtual*/ class vclass; // NB: ctags bug!!  Declaring class as virtual inhibits detection of next element.
    pure virtual function void do_something();
endclass : vclass

/* Interface (not related to "interface class") */

interface spi;

    logic sclk;
    logic cs_n;
    logic mosi;
    logic miso;

    modport master (output sclk, cs_n, mosi,  input  miso);
    modport slave  (input  sclk, cs_n, mosi,  output miso);

    task enable_cs();
        cs_n <= 1'b0;
    endtask

    task disable_cs();
        cs_n <= 1'b1;
    endtask

endinterface : spi

endpackage : oop