OpenCores
URL https://opencores.org/ocsvn/uart2bus_testbench/uart2bus_testbench/trunk

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [comps/] [uvm_pair.svh] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//
2
//-----------------------------------------------------------------------------
3
//   Copyright 2007-2011 Mentor Graphics Corporation
4
//   Copyright 2007-2011 Cadence Design Systems, Inc.
5
//   Copyright 2010-2011 Synopsys, Inc.
6
//   All Rights Reserved Worldwide
7
//
8
//   Licensed under the Apache License, Version 2.0 (the
9
//   "License"); you may not use this file except in
10
//   compliance with the License.  You may obtain a copy of
11
//   the License at
12
//
13
//       http://www.apache.org/licenses/LICENSE-2.0
14
//
15
//   Unless required by applicable law or agreed to in
16
//   writing, software distributed under the License is
17
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
18
//   CONDITIONS OF ANY KIND, either express or implied.  See
19
//   the License for the specific language governing
20
//   permissions and limitations under the License.
21
//-----------------------------------------------------------------------------
22
 
23
//-----------------------------------------------------------------------------
24
// Title: uvm_pair classes
25
//-----------------------------------------------------------------------------
26
// This section defines container classes for handling value pairs.
27
//-----------------------------------------------------------------------------
28
 
29
 
30
//-----------------------------------------------------------------------------
31
// Class: uvm_class_pair #(T1,T2)
32
//
33
// Container holding handles to two objects whose types are specified by the
34
// type parameters, T1 and T2.
35
//-----------------------------------------------------------------------------
36
 
37
class uvm_class_pair #(type T1=int, T2=T1) extends uvm_object;
38
 
39
  typedef uvm_class_pair #(T1, T2 ) this_type;
40
 
41
  `uvm_object_param_utils(this_type)
42
 
43
  const static string type_name = "uvm_class_pair #(T1,T2)";
44
 
45
// Variable: T1 first
46
//
47
// The handle to the first object in the pair
48
 
49
  T1 first;
50
 
51
// Variable: T2 second
52
//
53
// The handle to the second object in the pair
54
 
55
  T2 second;
56
 
57
  // Function: new
58
  //
59
  // Creates an instance that holds a handle to two objects.
60
  // The optional name argument gives a name to the new pair object.
61
 
62
  function new (string name="", T1 f=null, T2 s=null);
63
 
64
    super.new(name);
65
 
66
    if (f == null)
67
      first = new;
68
    else
69
      first = f;
70
 
71
    if (s == null)
72
      second = new;
73
    else
74
      second = s;
75
 
76
  endfunction
77
 
78
  virtual function string get_type_name ();
79
    return type_name;
80
  endfunction
81
 
82
  virtual function string convert2string;
83
    string s;
84
    $sformat(s, "pair : %s, %s",
85
             first.convert2string(), second.convert2string());
86
    return s;
87
  endfunction
88
 
89
  virtual function bit do_compare(uvm_object rhs, uvm_comparer comparer);
90
    this_type rhs_;
91
    if(!$cast(rhs_,rhs)) begin
92
      `uvm_error("WRONG_TYPE", {"do_compare: rhs argument is not of type '",get_type_name(),"'"})
93
      return 0;
94
    end
95
    return first.compare(rhs_.first) && second.compare(rhs_.second);
96
  endfunction
97
 
98
  virtual function void do_copy (uvm_object rhs);
99
    this_type rhs_;
100
    if(!$cast(rhs_,rhs))
101
      `uvm_fatal("WRONG_TYPE", {"do_copy: rhs argument is not of type '",get_type_name(),"'"})
102
    first.copy(rhs_.first);
103
    second.copy(rhs_.second);
104
  endfunction
105
 
106
endclass
107
 
108
//-----------------------------------------------------------------------------
109
// CLASS: uvm_built_in_pair #(T1,T2)
110
//
111
// Container holding two variables of built-in types (int, string, etc.). The
112
// types are specified by the type parameters, T1 and T2.
113
//-----------------------------------------------------------------------------
114
 
115
class uvm_built_in_pair #(type T1=int, T2=T1) extends uvm_object;
116
 
117
  typedef uvm_built_in_pair #(T1,T2) this_type;
118
 
119
  `uvm_object_param_utils(this_type)
120
 
121
  const static string type_name = "uvm_built_in_pair #(T1,T2)";
122
 
123
// Variable: T1 first
124
//
125
// The first value in the pair
126
 
127
  T1 first;
128
 
129
// Variable: T2 second
130
//
131
// The second value in the pair
132
 
133
  T2 second;
134
 
135
  // Function: new
136
  //
137
  // Creates an instance that holds two built-in type values.
138
  // The optional name argument gives a name to the new pair object.
139
 
140
  function new (string name="");
141
    super.new(name);
142
  endfunction
143
 
144
  virtual function string get_type_name ();
145
    return type_name;
146
  endfunction
147
 
148
  virtual function string convert2string;
149
    return $sformatf("built-in pair : %p, %p", first, second);
150
  endfunction
151
 
152
  virtual function bit do_compare(uvm_object rhs, uvm_comparer comparer);
153
    this_type rhs_;
154
    if(!$cast(rhs_,rhs)) begin
155
      `uvm_error("WRONG_TYPE", {"do_compare: rhs argument is not of type '",get_type_name(),"'"})
156
      return 0;
157
    end
158
    return first == rhs_.first && second == rhs_.second;
159
  endfunction
160
 
161
  function void do_copy (uvm_object rhs);
162
    this_type rhs_;
163
    if(!$cast(rhs_,rhs))
164
      `uvm_fatal("WRONG_TYPE", {"do_copy: rhs argument is not of type '",get_type_name(),"'"})
165
    first = rhs_.first;
166
    second = rhs_.second;
167
  endfunction
168
 
169
endclass
170
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.