ovm_report_handler.svh

Go to the documentation of this file.
00001 // $Id: ovm__report__handler_8svh-source.html,v 1.1 2008/10/07 21:54:41 alex.marin Exp $
00002 //----------------------------------------------------------------------
00003 //   Copyright 2007-2008 Mentor Graphics Corporation
00004 //   Copyright 2007-2008 Cadence Design Systems, Inc.
00005 //   All Rights Reserved Worldwide
00006 //
00007 //   Licensed under the Apache License, Version 2.0 (the
00008 //   "License"); you may not use this file except in
00009 //   compliance with the License.  You may obtain a copy of
00010 //   the License at
00011 //
00012 //       http://www.apache.org/licenses/LICENSE-2.0
00013 //
00014 //   Unless required by applicable law or agreed to in
00015 //   writing, software distributed under the License is
00016 //   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
00017 //   CONDITIONS OF ANY KIND, either express or implied.  See
00018 //   the License for the specific language governing
00019 //   permissions and limitations under the License.
00020 //----------------------------------------------------------------------
00021 
00022 `ifndef OVM_REPORT_HANDLER_SVH
00023 `define OVM_REPORT_HANDLER_SVH
00024 
00025 typedef class ovm_report_object;
00026 typedef class ovm_report_server;
00027 typedef class ovm_report_global_server;
00028 
00029 `ifdef INCA
00030 
00031     class ovm_hash #(type T=int, I1=int, I2=int);
00032       local T d[string];
00033       function void set(I1 i1, I2 i2, T t);
00034         string s;
00035         $swrite(s,i1,":",i2);
00036         d[s] = t;
00037       endfunction
00038       function T get(I1 i1,I2 i2);
00039         string s;
00040         $swrite(s,i1,":",i2);
00041         return d[s];
00042       endfunction
00043       function int exists(I1 i1, I2 i2);
00044         string s;
00045         $swrite(s,i1,":",i2);
00046         return d.exists(s);
00047       endfunction
00048       function int first(string index);
00049         return d.first(index);
00050       endfunction
00051       function int next(string index);
00052         return d.next(index);
00053       endfunction
00054       function T fetch(string index);
00055         return d[index];
00056       endfunction
00057     endclass : ovm_hash
00058 `endif
00059    
00060 //----------------------------------------------------------------------
00061 // CLASS ovm_report_handler
00062 //----------------------------------------------------------------------
00063 class ovm_report_handler;
00064 
00065   ovm_report_global_server m_glob;
00066 
00067   // This is the maximum verbosity level for this report
00068   // handler.  If any report has a higher verbosity level,
00069   // it is simply ignored
00070 
00071   int m_max_verbosity_level;
00072 
00073   // actions : severity, id, (severity,id)
00074   ovm_action severity_actions[ovm_severity];
00075   `ifndef INCA
00076     id_actions_array id_actions;
00077     id_actions_array severity_id_actions[ovm_severity];
00078 
00079     // file handles : default, severity, action, (severity,id)
00080     OVM_FILE default_file_handle;
00081     OVM_FILE severity_file_handles[ovm_severity];
00082     id_file_array id_file_handles;
00083     id_file_array severity_id_file_handles[ovm_severity];
00084   `endif
00085   `ifdef INCA
00086     ovm_action id_actions[string];
00087     ovm_hash #(ovm_action,ovm_severity,string) severity_id_actions = new;
00088 
00089     OVM_FILE default_file_handle;
00090     OVM_FILE severity_file_handles[ovm_severity];
00091     OVM_FILE id_file_handles[string];
00092     ovm_hash #(OVM_FILE,ovm_severity,string) severity_id_file_handles = new;
00093   `endif
00094 
00095   function new();
00096     m_glob = new();
00097     initialize;
00098   endfunction
00099 
00100   function ovm_report_server get_server();
00101     return m_glob.get_server();
00102   endfunction
00103 
00104   // forward the call to the server
00105   function void set_max_quit_count(int m);
00106     ovm_report_server srvr;
00107     srvr = m_glob.get_server();
00108     srvr.set_max_quit_count(m);
00109   endfunction
00110 
00111   function void summarize(OVM_FILE f = 0);
00112     ovm_report_server srvr;
00113     srvr = m_glob.get_server();
00114     srvr.summarize(f);
00115   endfunction
00116 
00117   function void report_header(OVM_FILE f = 0);
00118 
00119     ovm_report_server srvr;
00120 
00121     srvr = m_glob.get_server();
00122     srvr.f_display(f, "----------------------------------------------------------------");
00123     srvr.f_display(f, ovm_revision_string());
00124     srvr.f_display(f, ovm_mgc_copyright);
00125     srvr.f_display(f, ovm_cdn_copyright);
00126     srvr.f_display(f, "----------------------------------------------------------------");
00127   endfunction
00128 
00129   //--------------------------------------------------------------------
00130   // initialize
00131   // UPDATE COMMENTS
00132   // all severities both DISPLAY and LOG each report. In
00133   // addition, ERRORs are also COUNTED (so the simulation
00134   // will terminate when max_quit_count is reached) FATALs
00135   // also EXIT (ie, the simulation is immediately
00136   // terminated)
00137   //
00138   // All files (default, severity, id and (severity,id))
00139   // are initially set to zero. This means that they will be
00140   // ignored.
00141   //--------------------------------------------------------------------
00142 
00143   function void initialize();
00144     set_default_file(0);
00145     m_max_verbosity_level = 10000;
00146     set_defaults();
00147   endfunction
00148 
00149   //--------------------------------------------------------------------
00150   // run_hooks
00151   //
00152   // run the report hooks
00153   //--------------------------------------------------------------------
00154   virtual function bit run_hooks(ovm_report_object client,
00155                                  ovm_severity s,
00156                                  string id,
00157                                  string mess,
00158                                  int verbosity,
00159                                  string filename,
00160                                  int line);
00161 
00162     bit ok;
00163 
00164     ok = client.report_hook(id, mess, verbosity, filename, line);
00165 
00166     case(s)
00167       OVM_INFO:     begin
00168                   ok &= client.report_info_hook(id, mess, verbosity, filename, line);
00169                   ok &= client.report_message_hook(id, mess, verbosity, filename, line);
00170                 end
00171       OVM_WARNING:  ok &= client.report_warning_hook(id, mess, verbosity, filename, line);
00172       OVM_ERROR:    ok &= client.report_error_hook(id, mess, verbosity, filename, line);
00173       OVM_FATAL:    ok &= client.report_fatal_hook(id, mess, verbosity, filename, line);
00174     endcase
00175 
00176     return ok;
00177 
00178   endfunction
00179 
00180   //--------------------------------------------------------------------
00181   // get_severity_id_file
00182   //
00183   // Return the file id based on the severity and the id
00184   //--------------------------------------------------------------------
00185   local function OVM_FILE get_severity_id_file(ovm_severity s, string id);
00186 
00187    `ifndef INCA
00188     id_file_array array;
00189 
00190     if(severity_id_file_handles.exists(s)) begin
00191       array = severity_id_file_handles[s];      
00192       if(array.exists(id))
00193         return array[id];
00194     end
00195    `else
00196     if (severity_id_file_handles.exists(s,id))
00197       return severity_id_file_handles.get(s,id);
00198    `endif
00199 
00200 
00201     if(id_file_handles.exists(id))
00202       return id_file_handles[id];
00203 
00204     if(severity_file_handles.exists(s))
00205       return severity_file_handles[s];
00206 
00207     return default_file_handle;
00208 
00209   endfunction
00210 
00211   //--------------------------------------------------------------------
00212   // set_verbosity_level
00213   //
00214   // sets the maximum verbosity level
00215   // for this report handler. All reports of higher
00216   // verbosity will be ignored
00217   //--------------------------------------------------------------------
00218   function void set_verbosity_level(int verbosity_level);
00219     m_max_verbosity_level = verbosity_level;
00220   endfunction
00221 
00222   //--------------------------------------------------------------------
00223   // get_verbosity_level
00224   //--------------------------------------------------------------------
00225   function int get_verbosity_level();
00226     return m_max_verbosity_level;
00227   endfunction
00228 
00229   //--------------------------------------------------------------------
00230   // get_action
00231   //
00232   // Retrieve the action based on severity and id.  First,
00233   // look to see if there is an action associated with the
00234   // (severity,id) pair.  Second, look to see if there is an
00235   // action associated with the id.  If neither of those has
00236   // an action then return the action associated with the
00237   // severity.
00238   //--------------------------------------------------------------------
00239   function ovm_action get_action(ovm_severity s, string id);
00240 
00241    `ifndef INCA
00242     id_actions_array array;
00243 
00244     if(severity_id_actions.exists(s)) begin
00245       array = severity_id_actions[s];
00246       if(array.exists(id))
00247         return array[id];
00248     end
00249    `else
00250     if (severity_id_actions.exists(s,id))
00251       return severity_id_actions.get(s,id);
00252    `endif
00253 
00254     if(id_actions.exists(id))
00255       return id_actions[id];
00256 
00257     return severity_actions[s];
00258 
00259   endfunction
00260 
00261   //--------------------------------------------------------------------
00262   // get_file_handle
00263   //
00264   // Retrieve the file handle associated with the severity
00265   // and id. First, look to see if there is a file handle
00266   // associated with the (severity,id) pair.  Second, look
00267   // to see if there is a file handle associated with the
00268   // id.  If neither the (severity,id) pair nor the id has
00269   // an associated action then return the action associated
00270   // with the severity.
00271   //--------------------------------------------------------------------
00272   function OVM_FILE get_file_handle(ovm_severity s, string id);
00273     OVM_FILE f;
00274   
00275     // ADAM: Why does this function first call a near-identical function
00276     // that is not conditional on  f != 0? 
00277 
00278     f = get_severity_id_file(s, id);
00279     if(f != 0) return f;
00280   
00281     if(id_file_handles.exists(id)) begin
00282       f = id_file_handles[id];
00283       if(f != 0) return f;
00284     end
00285 
00286     if(severity_file_handles.exists(s)) begin
00287       f = severity_file_handles[s];
00288       if(f != 0) return f;
00289     end
00290 
00291     return default_file_handle;
00292   endfunction
00293 
00294   //--------------------------------------------------------------------
00295   // report
00296   //
00297   // add line and file info later ...
00298   //
00299   // this is the public access report function. It is not
00300   // visible to the user but is accessed via
00301   // ovm_report_info, ovm_report_warning,
00302   // ovm_report_error and ovm_report_fatal.
00303   //--------------------------------------------------------------------
00304   function void report(
00305       ovm_severity s,
00306       string name,
00307       string id,
00308       string mess,
00309       int verbosity_level,
00310       string filename,
00311       int line,
00312       ovm_report_object client
00313       );
00314  
00315     ovm_report_server srvr;
00316     srvr = m_glob.get_server();
00317     srvr.report(s,name,id,mess,verbosity_level,filename,line,client);
00318     
00319   endfunction
00320 
00321   //--------------------------------------------------------------------
00322   // format_action
00323   //--------------------------------------------------------------------
00324   function string format_action(ovm_action a);
00325     string s;
00326 
00327     if(a == OVM_NO_ACTION) begin
00328       s = "NO ACTION";
00329     end
00330     else begin
00331       s = "";
00332       if(a & OVM_DISPLAY)   s = {s, "DISPLAY "};
00333       if(a & OVM_LOG)       s = {s, "LOG "};
00334       if(a & OVM_COUNT)     s = {s, "COUNT "};
00335       if(a & OVM_EXIT)      s = {s, "EXIT "};
00336       if(a & OVM_CALL_HOOK) s = {s, "CALL_HOOK "};
00337       if(a & OVM_STOP)      s = {s, "STOP "};
00338     end
00339 
00340     return s;
00341   endfunction
00342 
00343   function void set_severity_action(input ovm_severity s,
00344                                     input ovm_action a);
00345     severity_actions[s] = a;
00346   endfunction
00347 
00348   function void set_defaults();
00349     set_severity_action(OVM_INFO,    OVM_DISPLAY);
00350     set_severity_action(OVM_WARNING, OVM_DISPLAY);
00351     set_severity_action(OVM_ERROR,   OVM_DISPLAY | OVM_COUNT);
00352     set_severity_action(OVM_FATAL,   OVM_DISPLAY | OVM_EXIT);
00353 
00354     set_severity_file(OVM_INFO, default_file_handle);
00355     set_severity_file(OVM_WARNING, default_file_handle);
00356     set_severity_file(OVM_ERROR,   default_file_handle);
00357     set_severity_file(OVM_FATAL,   default_file_handle);
00358   endfunction
00359 
00360   function void set_id_action(input string id, input ovm_action a);
00361     id_actions[id] = a;
00362   endfunction
00363 
00364   function void set_severity_id_action(ovm_severity s,
00365                                        string id,
00366                                        ovm_action a);
00367     `ifndef INCA
00368     severity_id_actions[s][id] = a;
00369     `else
00370     severity_id_actions.set(s,id,a);
00371     `endif
00372   endfunction
00373   
00374   // set_default_file, set_severity_file, set_id_file and
00375   // set_severity_id_file associate verilog file descriptors
00376   // with different kinds of reports in this report
00377   // handler. It is the users responsbility to open and
00378   // close these file descriptors correctly. Users may take
00379   // advantage of the fact that up to 32 files can be
00380   // described by the same file descriptor to send one
00381   // report to many files.
00382   //
00383   // set_default_file sets the default file associated with
00384   // any severity or id in this report handler.
00385 
00386   function void set_default_file(input OVM_FILE f);
00387     default_file_handle = f;
00388   endfunction
00389 
00390   // set_severity_file sets the file associated with a
00391   // severity in this report handler.  It is not visible to
00392   // the user but is accessed via ovm_set_severity_file. A
00393   // file associated with a severity overrides the default
00394   // file for this report handler.
00395 
00396   function void set_severity_file(input ovm_severity s, input OVM_FILE f);
00397     severity_file_handles[s] = f;
00398   endfunction
00399 
00400   // set_id_file sets the file associated with an id in this
00401   // report handler. It is not visible to the user but is
00402   // accessed via ovm_set_id_file. A file associated with an
00403   // id overrides the default file and any files associated
00404   // with a severity.
00405 
00406   function void set_id_file(input string id, input OVM_FILE f);
00407     id_file_handles[id] = f;
00408   endfunction
00409 
00410   // set_severity_id_file sets the file associated with a
00411   // (severity,id) pair. It is not visible to the user but
00412   // is accessed via ovm_set_severity_id_file. A file
00413   // associated with a (severity,id) pair overrides any
00414   // other file settings in this report handler
00415 
00416   function void set_severity_id_file(input ovm_severity s,
00417                                       input string id,
00418                                       input OVM_FILE f);
00419   
00420     `ifndef INCA
00421     severity_id_file_handles[s][id] = f;
00422     `else
00423     severity_id_file_handles.set(s,id,f);
00424     `endif
00425   endfunction
00426 
00427   //--------------------------------------------------------------------
00428   // dump_state
00429   //--------------------------------------------------------------------
00430   function void dump_state();
00431 
00432     string s;
00433     ovm_severity_type sev;
00434     ovm_action a;
00435     string idx;
00436     OVM_FILE f;
00437     ovm_report_server srvr;
00438  
00439    `ifndef INCA
00440      id_actions_array id_a_ary;
00441      id_file_array id_f_ary;
00442    `else
00443      OVM_FILE id_f_ary[string];
00444    `endif
00445 
00446     srvr = m_glob.get_server();
00447 
00448     srvr.f_display(0, "----------------------------------------------------------------------");
00449     srvr.f_display(0, "report handler state dump");
00450     srvr.f_display(0, "");
00451 
00452     $sformat(s, "max verbosity level = %d", m_max_verbosity_level);
00453     srvr.f_display(0, s);
00454 
00455     //------------------------------------------------------------------
00456     // actions
00457     //------------------------------------------------------------------
00458 
00459     srvr.f_display(0, "");   
00460     srvr.f_display(0, "+-------------+");
00461     srvr.f_display(0, "|   actions   |");
00462     srvr.f_display(0, "+-------------+");
00463     srvr.f_display(0, "");   
00464 
00465     srvr.f_display(0, "*** actions by severity");
00466     foreach( severity_actions[sev] ) begin
00467       $sformat(s, "%s = %s", ovm_severity_type'(sev), format_action(severity_actions[sev]));
00468       srvr.f_display(0, s);
00469     end
00470 
00471     srvr.f_display(0, "");
00472     srvr.f_display(0, "*** actions by id");
00473 
00474     foreach( id_actions[idx] ) begin
00475       $sformat(s, "[%-20s] --> %s", idx, format_action(id_actions[idx]));
00476       srvr.f_display(0, s);
00477     end
00478 
00479     // actions by id
00480 
00481     srvr.f_display(0, "");
00482     srvr.f_display(0, "*** actions by id and severity");
00483 
00484     `ifndef INCA
00485     foreach( severity_id_actions[sev] ) begin
00486       // ADAM: is id_a_ary __copied__?
00487       id_a_ary = severity_id_actions[sev];
00488       foreach( id_a_ary[idx] ) begin
00489         $sformat(s, "%s:%s --> %s", ovm_severity_type'(sev), idx, format_action(id_a_ary[idx]));
00490         srvr.f_display(0, s);        
00491       end
00492     end
00493     `else
00494     begin
00495       string idx;
00496       if ( severity_id_actions.first( idx ) )
00497         do begin
00498             $sformat(s, "%s --> %s", idx,
00499               format_action(severity_id_actions.fetch(idx)));
00500             srvr.f_display(0, s);        
00501         end
00502         while ( severity_id_actions.next( idx ) );
00503     end
00504     `endif
00505 
00506     //------------------------------------------------------------------
00507     // Files
00508     //------------------------------------------------------------------
00509 
00510     srvr.f_display(0, "");
00511     srvr.f_display(0, "+-------------+");
00512     srvr.f_display(0, "|    files    |");
00513     srvr.f_display(0, "+-------------+");
00514     srvr.f_display(0, "");   
00515 
00516     $sformat(s, "default file handle = %d", default_file_handle);
00517     srvr.f_display(0, s);
00518 
00519     srvr.f_display(0, "");
00520     srvr.f_display(0, "*** files by severity");
00521     foreach( severity_file_handles[sev] ) begin
00522       f = severity_file_handles[sev];
00523       $sformat(s, "%s = %d", ovm_severity_type'(sev), f);
00524       srvr.f_display(0, s);
00525     end
00526 
00527     srvr.f_display(0, "");
00528     srvr.f_display(0, "*** files by id");
00529 
00530     foreach ( id_file_handles[idx] ) begin
00531       f = id_file_handles[idx];
00532       $sformat(s, "id %s --> %d", idx, f);
00533       srvr.f_display(0, s);
00534     end
00535 
00536     srvr.f_display(0, "");
00537     srvr.f_display(0, "*** files by id and severity");
00538 
00539     `ifndef INCA
00540     foreach( severity_id_file_handles[sev] ) begin
00541       // ADAM: is id_f_ary __copied__?
00542       id_f_ary = severity_id_file_handles[sev];
00543       foreach ( id_f_ary[idx] ) begin
00544         $sformat(s, "%s:%s --> %d", ovm_severity_type'(sev), idx, id_f_ary[idx]);
00545         srvr.f_display(0, s);
00546       end
00547     end
00548     `else
00549     begin
00550       string idx;
00551       if ( severity_id_file_handles.first( idx ) )
00552         do begin
00553             $sformat(s, "%s --> %s", idx,
00554               format_action(severity_id_file_handles.fetch(idx)));
00555             srvr.f_display(0, s);        
00556         end
00557         while ( severity_id_file_handles.next( idx ) );
00558     end
00559     `endif
00560 
00561     srvr.dump_server_state();
00562     
00563     srvr.f_display(0, "----------------------------------------------------------------------");
00564   endfunction
00565 
00566 endclass : ovm_report_handler
00567 
00568 //----------------------------------------------------------------------
00569 // CLASS default_report_server
00570 //
00571 // wrapper around ovm_report_global_server
00572 //----------------------------------------------------------------------
00573 class default_report_server;
00574 
00575   ovm_report_global_server glob;
00576 
00577   function new();
00578     glob = new;
00579   endfunction
00580 
00581   function ovm_report_server get_server();
00582     return glob.get_server();
00583   endfunction
00584   
00585 endclass
00586 
00587 `endif // OVM_REPORT_HANDLER_SVH

Intelligent Design Verification
Intelligent Design Verification
Project: OVM, Revision: 1.1.0
Copyright (c) 2008 Intelligent Design Verification.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included here:
http://www.intelligentdv.com/licenses/fdl.txt
doxygen
Doxygen Version: 1.4.6
Mon Sep 29 14:20:12 2008
Find a documentation bug? Report bugs to: bugs.intelligentdv.com Project: DoxygenFilterSV