VMM - std_lib/vmm_data.sv

std_lib/vmm_data.sv expanded source

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    this.notify.configure(EXECUTE, vmm_notify::ON_OFF);
00033    this.notify.configure(STARTED, vmm_notify::ON_OFF);
00034    this.notify.configure(ENDED,   vmm_notify::ON_OFF);
00035    this.notify.indicate(EXECUTE);
00036 endfunction: new
00037 
00038 
00039 function vmm_log vmm_data::set_log(vmm_log log);
00040    set_log = this.log;
00041    this.log = log;
00042    this.notify.log = log;
00043 endfunction: set_log
00044 
00045 
00046 function void vmm_data::display(string prefix);
00047    $display(this.psdisplay(prefix));
00048 endfunction: display
00049 
00050 
00051 function string vmm_data::psdisplay(string prefix);
00052    $sformat(psdisplay, "%0s#%0d.%0d.%0d", prefix,
00053             this.stream_id, this.scenario_id, this.data_id);
00054 endfunction: psdisplay
00055 
00056 
00057 function bit vmm_data::is_valid(bit silent,
00058                                 int kind);
00059   is_valid = 1;
00060 endfunction: is_valid
00061 
00062 
00063 function vmm_data vmm_data::allocate();
00064    string msg = "Virtual vmm_data::allocate() not implemented in derivative";
00065 
00066    if (this.log == null) begin
00067      $display(msg);
00068      $finish;
00069    end
00070    else `vmm_fatal(this.log, msg);
00071    allocate = null;
00072 endfunction: allocate
00073 
00074 
00075 function vmm_data vmm_data::copy(vmm_data to);
00076    string msg = "Virtual vmm_data::copy() not implemented in derivative";
00077 
00078    if (this.log == null) begin
00079      $display(msg);
00080      $finish;
00081    end
00082    else`vmm_fatal(this.log, msg);
00083    copy = to;
00084 endfunction: copy
00085 
00086 
00087 function void vmm_data::copy_data(vmm_data to);
00088    if (to == null) begin
00089       string msg = "vmm_data::copy_data() called with null reference";
00090 
00091       if (this.log == null) begin
00092          $display(msg);
00093          $finish;
00094       end
00095       else`vmm_fatal(this.log, msg);
00096       return;
00097    end
00098    else begin
00099       to.stream_id   = this.stream_id;
00100       to.scenario_id = this.scenario_id;
00101       to.data_id     = this.data_id;
00102    end
00103 endfunction: copy_data
00104 
00105    
00106 
00107 
00108 function bit vmm_data::compare(       vmm_data to,
00109                                output string   diff,
00110                                input  int      kind);
00111    string msg = "Virtual vmm_data::compare() not implemented in derivative";
00112    if (this.log == null) begin
00113      $display(msg);
00114      $finish;
00115    end
00116    else`vmm_fatal(this.log, msg);
00117    compare = 0;
00118 endfunction : compare
00119 
00120 
00121 function int unsigned vmm_data::byte_size(int kind);
00122    string msg = "Virtual vmm_data::byte_size() not implemented in derivative";
00123    if (this.log == null) begin
00124      $display(msg);
00125      $finish;
00126    end
00127    else`vmm_fatal(this.log, msg);
00128    byte_size = 0;
00129 endfunction : byte_size
00130 
00131 
00132 function int unsigned vmm_data::max_byte_size(int kind);
00133    max_byte_size = 0;
00134 endfunction : max_byte_size
00135 
00136 
00137 function int unsigned vmm_data::byte_pack(ref   logic [7:0]  bytes[],
00138                                           input int unsigned offset,
00139                                           input int          kind);
00140    string msg = "Virtual vmm_data::byte_pack() not implemented in derivative";
00141    if (this.log == null) begin
00142       $display(msg);
00143       $finish;
00144    end
00145    else`vmm_fatal(this.log, msg);
00146    byte_pack = 0;
00147 endfunction : byte_pack
00148 
00149 
00150 
00151 
00152 function int unsigned vmm_data::byte_unpack(const ref logic [7:0] bytes[],
00153                                             input int unsigned    offset,
00154                                             input int             len,
00155                                             input int             kind);
00156    string msg = "Virtual vmm_data::byte_unpack() not implemented in derivative";
00157    if (this.log == null) begin
00158       $display(msg);
00159       $finish;
00160    end
00161    else`vmm_fatal(this.log, msg);
00162    byte_unpack = 0;
00163 endfunction : byte_unpack
00164 
00165 
00166 function string vmm_data::do_psdisplay(string prefix);
00167    this.__vmm_done_user = 0;
00168 endfunction: do_psdisplay
00169 
00170 
00171 function bit vmm_data::do_is_valid(bit silent,
00172                                    int kind);
00173   this.__vmm_done_user = 0;
00174 endfunction: do_is_valid
00175 
00176 
00177 function vmm_data vmm_data::do_allocate();
00178    this.__vmm_done_user = 0;
00179 endfunction: do_allocate
00180 
00181 
00182 function vmm_data vmm_data::do_copy(vmm_data to);
00183    this.__vmm_done_user = 0;
00184 endfunction: do_copy
00185 
00186    
00187 function bit vmm_data::do_compare(       vmm_data to,
00188                                   output string   diff,
00189                                   input  int      kind);
00190    this.__vmm_done_user = 0;
00191 endfunction : do_compare
00192 
00193 
00194 function int unsigned vmm_data::do_byte_size(int kind);
00195    this.__vmm_done_user = 0;
00196 endfunction : do_byte_size
00197 
00198 
00199 function int unsigned vmm_data::do_max_byte_size(int kind);
00200    this.__vmm_done_user = 0;
00201 endfunction : do_max_byte_size
00202 
00203 
00204 function int unsigned vmm_data::do_byte_pack(ref   logic [7:0]  bytes[],
00205                                              input int unsigned offset,
00206                                              input int          kind);
00207    this.__vmm_done_user = 0;
00208 endfunction : do_byte_pack
00209 
00210 
00211 function int unsigned vmm_data::do_byte_unpack(const ref logic [7:0] bytes[],
00212                                                input int unsigned    offset,
00213                                                input int             len,
00214                                                input int             kind);
00215    this.__vmm_done_user = 0;
00216 endfunction : do_byte_unpack
00217 
00218 
00219 
00220 function bit vmm_data::load(int file);
00221    int len, i;
00222    logic [7:0] bytes[];
00223    bit escaped = 0;
00224 
00225    load = 0;
00226 
00227    // Expect one record for the object, with the following format:
00228    // [<blanks>]<n><SPACE><n bytes (potentially inclusing \n)>\n
00229    if ($fscanf(file, " %d", len) != 1) begin
00230       string msg = "Invalid input record in vmm_data::load()";
00231       if (this.log == null) begin
00232          $display(msg);
00233          $finish;
00234       end
00235       else`vmm_fatal(this.log, msg);
00236       return 0;
00237    end
00238 
00239    // Skip the <SPACE>
00240    begin
00241       bit [7:0] c;
00242       c = $fgetc(file);
00243    end
00244 
00245    // Read the next 'len' characters and unpack
00246    bytes = new [len];
00247    i = 0;
00248    while (i < len) begin
00249       int c = $fgetc(file);
00250       if (c < 0) begin
00251          string msg = "Truncated input record in vmm_data::load()";
00252          if (this.log == null) begin
00253             $display(msg);
00254             $finish;
00255          end
00256          else`vmm_fatal(this.log, msg);
00257          return 0;
00258       end
00259       bytes[i] = c;
00260       // Some characters have been escaped
00261       if (bytes[i] == 8'h2E) begin
00262          escaped = 1;
00263          continue;
00264       end
00265       if (escaped) begin
00266          bit [7:0] c = bytes[i];
00267          c[7] = ~c[7];
00268          bytes[i] = c;
00269          escaped = 0;
00270       end
00271       i++;
00272    end
00273    if (this.byte_unpack(bytes) != len) begin
00274       string msg = "Unable to fully unpack input record in vmm_data::load()";
00275       if (this.log == null) begin
00276          $display(msg);
00277          $finish;
00278       end
00279       else`vmm_fatal(this.log, msg);
00280       return 0;
00281    end
00282 
00283    // Skip the final \n
00284    begin
00285       bit [7:0] c;
00286       c = $fgetc(file);
00287    end
00288 
00289    load = 1;
00290 endfunction: load
00291    
00292 
00293 function void vmm_data::save(int file);
00294    logic [7:0] bytes[];
00295    int   i;
00296 
00297    // Produce the format expected by vmm_data::load()
00298    void'(this.byte_pack(bytes));
00299    $fwrite(file, "%0d ", bytes.size());
00300    for (i = 0; i < bytes.size(); i++) begin
00301       bit [7:0] a_byte = bytes[i]; // Make sure there are no X's
00302       // Some characters need to be escaped
00303       case (a_byte)
00304       8'h00,
00305       8'hFF,
00306       8'h2E: begin
00307          bit [7:0] c = a_byte;
00308          c[7] = ~c[7];
00309          $fwrite(file, ".%c", c);
00310       end
00311 
00312       default: $fwrite(file, "%c", a_byte);
00313       endcase
00314    end
00315    $fwrite(file, "\n");
00316 endfunction: save
00317 
00318 
00319 
00320 `ifdef VCS
00321 function int vmm_data::vmt_hook(vmm_xactor xactor,
00322      			        vmm_data   obj);
00323 endfunction: vmt_hook
00324 
00325 `endif