00001 //
00002 // -------------------------------------------------------------
00003 // Copyright 2004-2008 Synopsys, Inc.
00004 // All Rights Reserved Worldwide
00005 //
00006 // Licensed under the Apache License, Version 2.0 (the
00007 // "License"); you may not use this file except in
00008 // compliance with the License. You may obtain a copy of
00009 // the License at
00010 //
00011 // http://www.apache.org/licenses/LICENSE-2.0
00012 //
00013 // Unless required by applicable law or agreed to in
00014 // writing, software distributed under the License is
00015 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
00016 // CONDITIONS OF ANY KIND, either express or implied. See
00017 // the License for the specific language governing
00018 // permissions and limitations under the License.
00019 // -------------------------------------------------------------
00020 //
00021
00022
00023 function vmm_data::new(vmm_log log
00024 `VMM_DATA_BASE_NEW_EXTERN_ARGS);
00025 `ifdef VMM_DATA_BASE_NEW_CALL
00026 super.new(`VMM_DATA_BASE_NEW_CALL);
00027 `endif
00028
00029 this.log = log;
00030
00031 this.notify = new(log);
00032 `VMM_OBJECT_SET_PARENT(this.notify, this)
00033
00034 void'(this.notify.configure(EXECUTE, vmm_notify::ON_OFF));
00035 void'(this.notify.configure(STARTED, vmm_notify::ON_OFF));
00036 void'(this.notify.configure(ENDED, vmm_notify::ON_OFF));
00037 this.notify.indicate(EXECUTE);
00038 endfunction: new
00039
00040
00041 function vmm_log vmm_data::set_log(vmm_log log);
00042 set_log = this.log;
00043 this.log = log;
00044 this.notify.log = log;
00045 endfunction: set_log
00046
00047
00048 function void vmm_data::display(string prefix="");
00049 $display(this.psdisplay(prefix));
00050 endfunction: display
00051
00052
00053 function string vmm_data::psdisplay(string prefix="");
00054 $sformat(psdisplay, "%0s#%0d.%0d.%0d", prefix,
00055 this.stream_id, this.scenario_id, this.data_id);
00056 endfunction: psdisplay
00057
00058
00059 function bit vmm_data::is_valid(bit silent = 1,
00060 int kind = -1);
00061 is_valid = 1;
00062 endfunction: is_valid
00063
00064
00065 function vmm_data vmm_data::allocate();
00066 string msg = "Virtual vmm_data::allocate() not implemented in derivative";
00067
00068 if (this.log == null) begin
00069 $display(msg);
00070 $finish;
00071 end
00072 else `vmm_fatal(this.log, msg);
00073 allocate = null;
00074 endfunction: allocate
00075
00076
00077 function vmm_data vmm_data::copy(vmm_data to = null);
00078 string msg = "Virtual vmm_data::copy() not implemented in derivative";
00079
00080 if (this.log == null) begin
00081 $display(msg);
00082 $finish;
00083 end
00084 else`vmm_fatal(this.log, msg);
00085 copy = to;
00086 endfunction: copy
00087
00088
00089 function void vmm_data::copy_data(vmm_data to);
00090 if (to == null) begin
00091 string msg = "vmm_data::copy_data() called with null reference";
00092
00093 if (this.log == null) begin
00094 $display(msg);
00095 $finish;
00096 end
00097 else`vmm_fatal(this.log, msg);
00098 return;
00099 end
00100 else begin
00101 `ifdef VMM_DATA_BASE_COPY_DATA_CALL
00102 `VMM_DATA_BASE_COPY_DATA_CALL ;
00103 `endif
00104 to.stream_id = this.stream_id;
00105 to.scenario_id = this.scenario_id;
00106 to.data_id = this.data_id;
00107 end
00108 endfunction: copy_data
00109
00110
00111
00112
00113 function bit vmm_data::compare( vmm_data to,
00114 output string diff,
00115 input int kind = -1);
00116 string msg = "Virtual vmm_data::compare() not implemented in derivative";
00117 if (this.log == null) begin
00118 $display(msg);
00119 $finish;
00120 end
00121 else`vmm_fatal(this.log, msg);
00122 compare = 0;
00123 endfunction : compare
00124
00125
00126 function int unsigned vmm_data::__vmm_byte_size(int kind = -1);
00127 return 0;
00128 endfunction : __vmm_byte_size
00129
00130
00131 function int unsigned vmm_data::byte_size(int kind = -1);
00132 string msg = "Virtual vmm_data::byte_size() not implemented in derivative";
00133 if (this.log == null) begin
00134 $display(msg);
00135 $finish;
00136 end
00137 else`vmm_fatal(this.log, msg);
00138 byte_size = 0;
00139 endfunction : byte_size
00140
00141
00142 function int unsigned vmm_data::max_byte_size(int kind = -1);
00143 max_byte_size = 0;
00144 endfunction : max_byte_size
00145
00146
00147 function int unsigned vmm_data::byte_pack(ref logic [7:0] bytes[],
00148 input int unsigned offset,
00149 input int kind = -1);
00150 string msg = "Virtual vmm_data::byte_pack() not implemented in derivative";
00151 if (this.log == null) begin
00152 $display(msg);
00153 $finish;
00154 end
00155 else`vmm_fatal(this.log, msg);
00156 byte_pack = 0;
00157 endfunction : byte_pack
00158
00159
00160
00161
00162 function int unsigned vmm_data::byte_unpack(const ref logic [7:0] bytes[],
00163 input int unsigned offset = 0,
00164 input int len = -1,
00165 input int kind = -1);
00166 string msg = "Virtual vmm_data::byte_unpack() not implemented in derivative";
00167 if (this.log == null) begin
00168 $display(msg);
00169 $finish;
00170 end
00171 else`vmm_fatal(this.log, msg);
00172 byte_unpack = 0;
00173 endfunction : byte_unpack
00174
00175
00176 function string vmm_data::do_psdisplay(string prefix = "");
00177 this.__vmm_done_user = 0;
00178 return "";
00179 endfunction: do_psdisplay
00180
00181
00182 function bit vmm_data::do_is_valid(bit silent = 1,
00183 int kind = -1);
00184 this.__vmm_done_user = 0;
00185 return 0;
00186 endfunction: do_is_valid
00187
00188
00189 function vmm_data vmm_data::do_allocate();
00190 this.__vmm_done_user = 0;
00191 return null;
00192 endfunction: do_allocate
00193
00194
00195 function vmm_data vmm_data::do_copy(vmm_data to = null);
00196 this.__vmm_done_user = 0;
00197 return null;
00198 endfunction: do_copy
00199
00200
00201 function bit vmm_data::do_compare( vmm_data to,
00202 output string diff,
00203 input int kind = -1);
00204 this.__vmm_done_user = 0;
00205 return 0;
00206 endfunction : do_compare
00207
00208
00209 function int unsigned vmm_data::do_byte_size(int kind = -1);
00210 this.__vmm_done_user = 0;
00211 return 0;
00212 endfunction : do_byte_size
00213
00214
00215 function int unsigned vmm_data::do_max_byte_size(int kind = -1);
00216 this.__vmm_done_user = 0;
00217 return 0;
00218 endfunction : do_max_byte_size
00219
00220
00221 function int unsigned vmm_data::do_byte_pack(ref logic [7:0] bytes[],
00222 input int unsigned offset = 0,
00223 input int kind = -1);
00224 this.__vmm_done_user = 0;
00225 return 0;
00226 endfunction : do_byte_pack
00227
00228
00229 function int unsigned vmm_data::do_byte_unpack(const ref logic [7:0] bytes[],
00230 input int unsigned offset =0,
00231 input int len = -1,
00232 input int kind = -1);
00233 this.__vmm_done_user = 0;
00234 return 0;
00235 endfunction : do_byte_unpack
00236
00237
00238
00239 function bit vmm_data::load(int file);
00240 int len, i;
00241 logic [7:0] bytes[];
00242 bit escaped = 0;
00243
00244 load = 0;
00245
00246 // Expect one record for the object, with the following format:
00247 // [<blanks>]<n><SPACE><n bytes (potentially inclusing \n)>\n
00248 if ($fscanf(file, " %d", len) != 1) begin
00249 string msg = "Invalid input record in vmm_data::load()";
00250 if (this.log == null) begin
00251 $display(msg);
00252 $finish;
00253 end
00254 else`vmm_fatal(this.log, msg);
00255 return 0;
00256 end
00257
00258 // Skip the <SPACE>
00259 begin
00260 bit [7:0] c;
00261 c = $fgetc(file);
00262 end
00263
00264 // Read the next 'len' characters and unpack
00265 bytes = new [len];
00266 i = 0;
00267 while (i < len) begin
00268 int c = $fgetc(file);
00269 if (c < 0) begin
00270 string msg = "Truncated input record in vmm_data::load()";
00271 if (this.log == null) begin
00272 $display(msg);
00273 $finish;
00274 end
00275 else`vmm_fatal(this.log, msg);
00276 return 0;
00277 end
00278 bytes[i] = c;
00279 // Some characters have been escaped
00280 if (bytes[i] == 8'h2E) begin
00281 escaped = 1;
00282 continue;
00283 end
00284 if (escaped) begin
00285 bit [7:0] c = bytes[i];
00286 c[7] = ~c[7];
00287 bytes[i] = c;
00288 escaped = 0;
00289 end
00290 i++;
00291 end
00292 if (this.byte_unpack(bytes) != len) begin
00293 string msg = "Unable to fully unpack input record in vmm_data::load()";
00294 if (this.log == null) begin
00295 $display(msg);
00296 $finish;
00297 end
00298 else`vmm_fatal(this.log, msg);
00299 return 0;
00300 end
00301
00302 // Skip the final \n
00303 begin
00304 bit [7:0] c;
00305 c = $fgetc(file);
00306 end
00307
00308 load = 1;
00309 endfunction: load
00310
00311
00312 function void vmm_data::save(int file);
00313 logic [7:0] bytes[];
00314 int i;
00315
00316 // Produce the format expected by vmm_data::load()
00317 void'(this.byte_pack(bytes));
00318 $fwrite(file, "%0d ", bytes.size());
00319 for (i = 0; i < bytes.size(); i++) begin
00320 bit [7:0] a_byte = bytes[i]; // Make sure there are no X's
00321 // Some characters need to be escaped
00322 case (a_byte)
00323 8'h00,
00324 8'hFF,
00325 8'h2E: begin
00326 bit [7:0] c = a_byte;
00327 c[7] = ~c[7];
00328 $fwrite(file, ".%c", c);
00329 end
00330
00331 default: $fwrite(file, "%c", a_byte);
00332 endcase
00333 end
00334 $fwrite(file, "\n");
00335 endfunction: save
00336
00337
00338
00339 `ifdef VCS
00340 function int vmm_data::vmt_hook(vmm_xactor xactor = null,
00341 vmm_data obj = null);
00342 endfunction: vmt_hook
00343
00344 `endif