ovm_factory.sv

Go to the documentation of this file.
00001 // $Id: a00232.html,v 1.1 2009/01/07 19:30:00 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 `include "base/ovm_factory.svh"
00023 `include "base/ovm_object.svh"
00024 
00025 //------------------------------------------------------------------------------
00026 //
00027 // CLASS: ovm_factory
00028 //
00029 //------------------------------------------------------------------------------
00030 
00031 // get
00032 // ---
00033 
00034 function ovm_factory ovm_factory::get();
00035   if (m_inst == null) begin
00036     m_inst = new();
00037   end
00038   return m_inst;
00039 endfunction
00040 
00041 // new
00042 // ---
00043 
00044 function ovm_factory::new ();
00045 endfunction
00046 
00047 
00048 // auto_register (static)
00049 // -------------
00050 
00051 function void ovm_factory::auto_register (ovm_object_wrapper obj);
00052   static bit issued=0;
00053   if (!issued) begin
00054     issued=1;
00055     ovm_report_warning("deprecated",
00056       {"ovm_factory::auto_register() has been deprecated and replaced by ",
00057       "factory.register()"});
00058   end
00059   m_inst = ovm_factory::get();
00060   m_inst.register(obj);
00061 endfunction
00062 
00063 
00064 // register
00065 // --------
00066 
00067 function void ovm_factory::register (ovm_object_wrapper obj);
00068 
00069   assert(obj!=null);
00070   if (obj.get_type_name() == "" || obj.get_type_name() == "<unknown>") begin
00071     //ovm_report_warning("EMPTNM", {"Factory registration with ",
00072     //  "unknown type name prevents name-based operations. "});
00073   end
00074   else begin
00075     if (m_type_names.exists(obj.get_type_name()))
00076       ovm_report_warning("TPRGED", {"Type name '",obj.get_type_name(),
00077         "' already registered with factory. No string-based lookup ",
00078         "support for multiple types with the same type name."});
00079     else 
00080       m_type_names[obj.get_type_name()] = obj;
00081   end
00082 
00083   if (m_types.exists(obj)) begin
00084     if (obj.get_type_name() != "" && obj.get_type_name() != "<unknown>")
00085       ovm_report_warning("TPRGED", {"Object type '",obj.get_type_name(),
00086                          "' already registered with factory. "});
00087   end
00088   else 
00089     m_types[obj] = 1;
00090 
00091 endfunction
00092 
00093 
00094 
00095 // set_type_override (static)
00096 // -----------------
00097 
00098 function void ovm_factory::set_type_override (string original_type_name,
00099                                               string override_type_name,
00100                                               bit replace=1);
00101   static bit issued=0;
00102   if (!issued) begin
00103     issued=1;
00104     ovm_report_warning("deprecated",
00105       {"ovm_factory::set_type_override() has been deprecated and replaced by ",
00106       "factory.set_type_override_by_name()"});
00107   end
00108   m_inst = ovm_factory::get();
00109   m_inst.set_type_override_by_name (original_type_name, override_type_name, replace);
00110 endfunction
00111 
00112 
00113 // set_type_override_by_type
00114 // -------------------------
00115 
00116 function void ovm_factory::set_type_override_by_type (ovm_object_wrapper original_type,
00117                                                       ovm_object_wrapper override_type,
00118                                                       bit replace=1);
00119   bit replaced;
00120 
00121   // check that old and new are not the same
00122   if (original_type == override_type) begin
00123     if (original_type.get_type_name() == "" || original_type.get_type_name() == "<unknown>")
00124       ovm_report_warning("TYPDUP", {"Original and override type ",
00125                                     "arguments are identical"});
00126     else
00127       ovm_report_warning("TYPDUP", {"Original and override type ",
00128                                     "arguments are identical: ",
00129                                     original_type.get_type_name()});
00130     return;
00131   end
00132 
00133   // register the types if not already done so, for the benefit of string-based lookup
00134   if (!m_types.exists(original_type))
00135     register(original_type); 
00136 
00137   if (!m_types.exists(override_type))
00138     register(override_type); 
00139 
00140 
00141   // check for existing type override
00142   foreach (m_type_overrides[index]) begin
00143     if (m_type_overrides[index].orig_type == original_type ||
00144         (m_type_overrides[index].orig_type_name != "<unknown>" &&
00145          m_type_overrides[index].orig_type_name != "" &&
00146          m_type_overrides[index].orig_type_name == original_type.get_type_name())) begin
00147       string msg;
00148       msg = {"Original object type '",original_type.get_type_name(),
00149              "' already registered to produce '",
00150              m_type_overrides[index].ovrd_type_name,"'"};
00151       if (!replace) begin
00152         msg = {msg, ".  Set 'replace' argument to replace the existing entry."};
00153         ovm_report_warning("TPREGD", msg);
00154         return;
00155       end
00156       msg = {msg, ".  Replacing with override to produce type '",
00157                   override_type.get_type_name(),"'."};
00158       ovm_report_warning("TPREGD", msg);
00159       replaced = 1;
00160       m_type_overrides[index].orig_type = original_type; 
00161       m_type_overrides[index].orig_type_name = original_type.get_type_name(); 
00162       m_type_overrides[index].ovrd_type = override_type; 
00163       m_type_overrides[index].ovrd_type_name = override_type.get_type_name(); 
00164     end
00165   end
00166 
00167   // make a new entry
00168   if (!replaced) begin
00169     ovm_factory_override override;
00170     override = new(.orig_type(original_type),
00171                    .orig_type_name(original_type.get_type_name()),
00172                    .full_inst_path("*"),
00173                    .ovrd_type(override_type));
00174 
00175     m_type_overrides.push_back(override);
00176   end
00177 
00178 endfunction
00179 
00180 
00181 // set_type_override_by_name
00182 // -------------------------
00183 
00184 function void ovm_factory::set_type_override_by_name (string original_type_name,
00185                                                       string override_type_name,
00186                                                       bit replace=1);
00187   bit replaced;
00188   
00189   // check that type is registered with the factory
00190   if (!m_type_names.exists(override_type_name)) begin
00191       ovm_report_error("TYPNTF", {"Cannot register override for original type '",
00192       original_type_name,"' because the override type '",
00193       override_type_name, "' is not registered with the factory."});
00194     return;
00195   end
00196 
00197   // check that old and new are not the same
00198   if (original_type_name == override_type_name) begin
00199       ovm_report_warning("TYPDUP", {"Requested and actual type name ",
00200       " arguments are identical: ",original_type_name,". Ignoring this override."});
00201     return;
00202   end
00203 
00204   foreach (m_type_overrides[index]) begin
00205     if (m_type_overrides[index].orig_type_name == original_type_name) begin
00206       if (!replace) begin
00207         ovm_report_warning("TPREGD", {"Original type '",original_type_name,
00208           "' already registered to produce '",m_type_overrides[index].ovrd_type_name,
00209           "'.  Set 'replace' argument to replace the existing entry."});
00210         return;
00211       end
00212       ovm_report_warning("TPREGR", {"Original object type '",original_type_name,
00213         "' already registered to produce '",m_type_overrides[index].ovrd_type_name,
00214         "'.  Replacing with override to produce type '",override_type_name,"'."});
00215       replaced = 1;
00216       m_type_overrides[index].ovrd_type = m_type_names[override_type_name]; 
00217       m_type_overrides[index].ovrd_type_name = override_type_name; 
00218     end
00219   end
00220 
00221   if (!m_type_names.exists(original_type_name))
00222       m_lookup_strs[original_type_name] = 1;
00223 
00224   if (!replaced) begin
00225     ovm_factory_override override;
00226     override = new(.orig_type(m_type_names[original_type_name]),
00227                    .orig_type_name(original_type_name),
00228                    .full_inst_path("*"),
00229                    .ovrd_type(m_type_names[override_type_name]));
00230 
00231     m_type_overrides.push_back(override);
00232     //m_type_names[original_type_name] = override.ovrd_type;
00233   end
00234 
00235 endfunction
00236 
00237 
00238 // set_inst_override (static)
00239 // -----------------
00240 
00241 function void ovm_factory::set_inst_override (string full_inst_path,
00242                                               string original_type_name,
00243                                               string override_type_name);
00244   static bit issued=0;
00245   if (!issued) begin
00246     issued=1;
00247     ovm_report_warning("deprecated",
00248       {"ovm_factory::set_inst_override() has been deprecated and replaced by ",
00249       "factory.set_inst_override_by_name()"});
00250   end
00251   m_inst = ovm_factory::get();
00252   m_inst.set_inst_override_by_name (original_type_name, override_type_name, full_inst_path);
00253 endfunction
00254 
00255 
00256 // set_inst_override_by_type
00257 // -------------------------
00258 
00259 function void ovm_factory::set_inst_override_by_type (ovm_object_wrapper original_type,
00260                                                       ovm_object_wrapper override_type,
00261                                                       string full_inst_path);
00262   
00263   ovm_factory_override override;
00264 
00265   // register the types if not already done so
00266   if (!m_types.exists(original_type))
00267     register(original_type); 
00268 
00269   if (!m_types.exists(override_type))
00270     register(override_type); 
00271 
00272   override = new(.full_inst_path(full_inst_path),
00273                  .orig_type(original_type),
00274                  .orig_type_name(original_type.get_type_name()),
00275                  .ovrd_type(override_type));
00276 
00277   m_inst_overrides.push_back(override);
00278 
00279 endfunction
00280 
00281 
00282 // set_inst_override_by_name
00283 // -------------------------
00284 
00285 function void ovm_factory::set_inst_override_by_name (string original_type_name,
00286                                                       string override_type_name,
00287                                                       string full_inst_path);
00288   
00289   ovm_factory_override override;
00290 
00291   // check that type is registered with the factory
00292   if (!m_type_names.exists(override_type_name)) begin
00293     ovm_report_error("TYPNTF", {"Cannot register instance override with type name '",
00294     original_type_name,"' and instance path '",full_inst_path,"' because the type it's supposed ",
00295     "to produce, '",override_type_name,"', is not registered with the factory."});
00296     return;
00297   end
00298 
00299   if (!m_type_names.exists(original_type_name))
00300       m_lookup_strs[original_type_name] = 1;
00301 
00302   override = new(.full_inst_path(full_inst_path),
00303                  .orig_type(m_type_names[original_type_name]),
00304                  .orig_type_name(original_type_name),
00305                  .ovrd_type(m_type_names[override_type_name]));
00306 
00307   m_inst_overrides.push_back(override);
00308 
00309 endfunction
00310 
00311 
00312 // create_object (static)
00313 // -------------
00314 
00315 function ovm_object ovm_factory::create_object (string requested_type_name,  
00316                                                 string parent_inst_path="", 
00317                                                 string name="");
00318   static bit issued=0;
00319   if (!issued) begin
00320     issued=1;
00321     ovm_report_warning("deprecated",
00322       {"ovm_factory::create_object() has been deprecated and replaced by ",
00323       "factory.create_object_by_name()"});
00324   end
00325   m_inst = ovm_factory::get();
00326   return m_inst.create_object_by_name(requested_type_name, parent_inst_path, name);
00327 endfunction
00328 
00329 
00330 // create_object_by_name
00331 // ---------------------
00332 
00333 function ovm_object ovm_factory::create_object_by_name (string requested_type_name,  
00334                                                         string parent_inst_path="",  
00335                                                         string name=""); 
00336 
00337   ovm_object_wrapper wrapper;
00338   string inst_path;
00339 
00340   if (parent_inst_path == "")
00341     inst_path = name;
00342   else if (name != "")
00343     inst_path = {parent_inst_path,".",name};
00344   else
00345     inst_path = parent_inst_path;
00346 
00347   `ovm_clear_queue(m_override_info)
00348 
00349   wrapper = find_override_by_name(requested_type_name, inst_path);
00350 
00351   // if no override exists, try to use requested_type_name directly
00352   if (wrapper==null) begin
00353     if(!m_type_names.exists(requested_type_name)) begin
00354       ovm_report_warning("BDTYP",{"Cannot create an object of type '",
00355       requested_type_name,"' because it is not registered with the factory."});
00356       return null;
00357     end
00358     wrapper = m_type_names[requested_type_name];
00359   end
00360 
00361   return wrapper.create_object(name);
00362 
00363 endfunction
00364 
00365 
00366 // create_object_by_type
00367 // ---------------------
00368 
00369 function ovm_object ovm_factory::create_object_by_type (ovm_object_wrapper requested_type,  
00370                                                         string parent_inst_path="",  
00371                                                         string name=""); 
00372 
00373   string full_inst_path;
00374 
00375   if (parent_inst_path == "")
00376     full_inst_path = name;
00377   else if (name != "")
00378     full_inst_path = {parent_inst_path,".",name};
00379   else
00380     full_inst_path = parent_inst_path;
00381 
00382   `ovm_clear_queue(m_override_info)
00383 
00384   requested_type = find_override_by_type(requested_type, full_inst_path);
00385 
00386   return requested_type.create_object(name);
00387 
00388 endfunction
00389 
00390 
00391 // create_component (static)
00392 // ----------------
00393 
00394 function ovm_component ovm_factory::create_component (string requested_type_name,  
00395                                                       string parent_inst_path="", 
00396                                                       string name, 
00397                                                       ovm_component parent);
00398   static bit issued=0;
00399   if (!issued) begin
00400     issued=1;
00401     ovm_report_warning("deprecated",
00402       {"ovm_factory::create_component() has been deprecated and replaced by ",
00403       "factory.create_component_by_name()"});
00404   end
00405   m_inst = ovm_factory::get();
00406   return m_inst.create_component_by_name(requested_type_name, parent_inst_path, name, parent);
00407 endfunction
00408 
00409 
00410 // create_component_by_name
00411 // ------------------------
00412 
00413 function ovm_component ovm_factory::create_component_by_name (string requested_type_name,  
00414                                                               string parent_inst_path="",  
00415                                                               string name, 
00416                                                               ovm_component parent);
00417   ovm_object_wrapper wrapper;
00418   string inst_path;
00419 
00420   if (parent_inst_path == "")
00421     inst_path = name;
00422   else if (name != "")
00423     inst_path = {parent_inst_path,".",name};
00424   else
00425     inst_path = parent_inst_path;
00426 
00427   `ovm_clear_queue(m_override_info)
00428 
00429   wrapper = find_override_by_name(requested_type_name, inst_path);
00430 
00431   // if no override exists, try to use requested_type_name directly
00432   if (wrapper == null) begin
00433     if(!m_type_names.exists(requested_type_name)) begin 
00434       ovm_report_warning("BDTYP",{"Cannot create a component of type '",
00435       requested_type_name,"' because it is not registered with the factory."});
00436       return null;
00437     end
00438     wrapper = m_type_names[requested_type_name];
00439   end
00440 
00441   return wrapper.create_component(name, parent);
00442 
00443 endfunction
00444 
00445 
00446 // create_component_by_type
00447 // ------------------------
00448 
00449 function ovm_component ovm_factory::create_component_by_type (ovm_object_wrapper requested_type,  
00450                                                             string parent_inst_path="",  
00451                                                             string name, 
00452                                                             ovm_component parent);
00453   string full_inst_path;
00454 
00455   if (parent_inst_path == "")
00456     full_inst_path = name;
00457   else if (name != "")
00458     full_inst_path = {parent_inst_path,".",name};
00459   else
00460     full_inst_path = parent_inst_path;
00461 
00462   `ovm_clear_queue(m_override_info)
00463 
00464   requested_type = find_override_by_type(requested_type, full_inst_path);
00465 
00466   return requested_type.create_component(name, parent);
00467 
00468 endfunction
00469 
00470 
00471 
00472 // find_by_name
00473 // ------------
00474 
00475 function ovm_object_wrapper ovm_factory::find_by_name(string type_name);
00476 
00477   if (m_type_names.exists(type_name))
00478     return m_type_names[type_name];
00479 
00480   ovm_report_warning("UnknownTypeName", {"find_by_name: Type name '",type_name,
00481       "' not registered with the factory."});
00482   
00483 endfunction
00484 
00485 
00486 // find_override_by_name
00487 // ---------------------
00488 
00489 function ovm_object_wrapper ovm_factory::find_override_by_name (string requested_type_name,
00490                                                                 string full_inst_path);
00491 
00492   // inst override; return first match; takes precedence over type overrides
00493   if (full_inst_path != "")
00494     foreach (m_inst_overrides[index])
00495       if (ovm_is_match(m_inst_overrides[index].orig_type_name, requested_type_name) &&
00496           ovm_is_match(m_inst_overrides[index].full_inst_path, full_inst_path)) begin
00497         m_override_info.push_back(m_inst_overrides[index]);
00498         if (m_inst_overrides[index].ovrd_type.get_type_name() == requested_type_name)
00499           return m_inst_overrides[index].ovrd_type;
00500         else
00501           return find_override_by_type(m_inst_overrides[index].ovrd_type,full_inst_path);
00502       end
00503 
00504   // type override - exact match
00505   foreach (m_type_overrides[index])
00506     if (m_type_overrides[index].orig_type_name == requested_type_name) begin
00507       m_override_info.push_back(m_type_overrides[index]);
00508       return find_override_by_type(m_type_overrides[index].ovrd_type,full_inst_path);
00509     end
00510 
00511   // type override with wildcard match
00512   //foreach (m_type_overrides[index])
00513   //  if (ovm_is_match(index,requested_type_name)) begin
00514   //    m_override_info.push_back(m_inst_overrides[index]);
00515   //    return find_override_by_type(m_type_overrides[index].ovrd_type,full_inst_path);
00516   //  end
00517 
00518   // No override found
00519   return null;
00520 
00521 endfunction
00522 
00523 
00524 // find_override_by_type
00525 // ---------------------
00526 
00527 function ovm_object_wrapper ovm_factory::find_override_by_type(ovm_object_wrapper requested_type,
00528                                                                string full_inst_path);
00529 
00530 
00531   foreach (m_override_info[index]) begin
00532     if ( //index != m_override_info.size()-1 &&
00533        m_override_info[index].orig_type == requested_type) begin
00534       ovm_report_error("OVRDLOOP", "Recursive loop detected while finding override.");
00535       if (!m_debug_pass)
00536         m_debug_display(requested_type.get_type_name(),requested_type,full_inst_path);
00537       return requested_type;
00538     end
00539   end
00540 
00541   // inst override; return first match; takes precedence over type overrides
00542   if (full_inst_path != "")
00543     foreach (m_inst_overrides[index]) begin
00544       if ((m_inst_overrides[index].orig_type == requested_type ||
00545            (m_inst_overrides[index].orig_type_name != "<unknown>" &&
00546             m_inst_overrides[index].orig_type_name != "" &&
00547             m_inst_overrides[index].orig_type_name == requested_type.get_type_name())) &&
00548           ovm_is_match(m_inst_overrides[index].full_inst_path, full_inst_path)) begin
00549         m_override_info.push_back(m_inst_overrides[index]);
00550         if (m_inst_overrides[index].ovrd_type == requested_type)
00551           return requested_type;
00552         else
00553           return find_override_by_type(m_inst_overrides[index].ovrd_type,full_inst_path);
00554       end
00555     end
00556 
00557   // type override - exact match
00558   foreach (m_type_overrides[index]) begin
00559     if (m_type_overrides[index].orig_type == requested_type ||
00560         (m_type_overrides[index].orig_type_name != "<unknown>" &&
00561          m_type_overrides[index].orig_type_name != "" &&
00562          m_type_overrides[index].orig_type_name == requested_type.get_type_name())) begin
00563       m_override_info.push_back(m_type_overrides[index]);
00564       if (m_type_overrides[index].ovrd_type == requested_type)
00565         return requested_type;
00566       else
00567         return find_override_by_type(m_type_overrides[index].ovrd_type,full_inst_path);
00568     end
00569   end
00570 
00571   // type override with wildcard match
00572   //foreach (m_type_overrides[index])
00573   //  if (ovm_is_match(index,requested_type.get_type_name())) begin
00574   //    m_override_info.push_back(m_inst_overrides[index]);
00575   //    return find_override_by_type(m_type_overrides[index],full_inst_path);
00576   //  end
00577   return requested_type;
00578 
00579 endfunction
00580 
00581 
00582 // print_all_overrides (static)
00583 // -------------------
00584 
00585 function void  ovm_factory::print_all_overrides (int all_types=0);
00586   static bit issued=0;
00587   if (!issued) begin
00588     issued=1;
00589     ovm_report_warning("deprecated",
00590       {"ovm_factory::print_all_overrides() has been deprecated and replaced by ",
00591       "factory.print()"});
00592   end
00593   m_inst = ovm_factory::get();
00594   m_inst.print(all_types);
00595 endfunction
00596 
00597 
00598 // print
00599 // -----
00600 
00601 function void ovm_factory::print (int all_types=1);
00602 
00603   string key;
00604 
00605   $display("\n#### Factory Configuration (*)\n");
00606 
00607   // print instance overrides
00608   if(!m_type_overrides.size() && !m_inst_overrides.size())
00609     $display("  No instance or type overrides are registered with this factory");
00610   else begin
00611     int max1,max2,max3;
00612     string dash = "---------------------------------------------------------------------------------------------------";
00613     string space= "                                                                                                   ";
00614 
00615     // print instance overrides
00616     if(!m_inst_overrides.size())
00617       $display("No instance overrides are registered with this factory");
00618     else begin
00619       foreach (m_inst_overrides[i]) begin
00620         if (m_inst_overrides[i].orig_type_name.len() > max1)
00621           max1=m_inst_overrides[i].orig_type_name.len();
00622         if (m_inst_overrides[i].full_inst_path.len() > max2)
00623           max2=m_inst_overrides[i].full_inst_path.len();
00624         if (m_inst_overrides[i].ovrd_type_name.len() > max3)
00625           max3=m_inst_overrides[i].ovrd_type_name.len();
00626       end
00627       if (max1 < 14) max1 = 14;
00628       if (max2 < 13) max2 = 13;
00629       if (max3 < 13) max3 = 13;
00630 
00631       $display("Instance Overrides:\n");
00632       $display("  %0s%0s  %0s%0s  %0s%0s","Requested Type",space.substr(1,max1-14),
00633                                           "Override Path", space.substr(1,max2-13),
00634                                           "Override Type", space.substr(1,max3-13));
00635       $display("  %0s  %0s  %0s",dash.substr(1,max1),
00636                                  dash.substr(1,max2),
00637                                  dash.substr(1,max3));
00638 
00639       foreach (m_inst_overrides[i]) begin
00640         $write("  %0s%0s",m_inst_overrides[i].orig_type_name,
00641                space.substr(1,max1-m_inst_overrides[i].orig_type_name.len()));
00642         $write("  %0s%0s",  m_inst_overrides[i].full_inst_path,
00643                space.substr(1,max2-m_inst_overrides[i].full_inst_path.len()));
00644         $display("  %0s",     m_inst_overrides[i].ovrd_type_name);
00645       end
00646     end
00647 
00648     // print type overrides
00649     if (!m_type_overrides.size())
00650       $display("\nNo type overrides are registered with this factory");
00651     else begin
00652       foreach (m_type_overrides[i]) begin
00653         if (m_type_overrides[i].orig_type_name.len() > max1)
00654           max1=m_type_overrides[i].orig_type_name.len();
00655         if (m_type_overrides[i].ovrd_type_name.len() > max3)
00656           max2=m_type_overrides[i].ovrd_type_name.len();
00657       end
00658       if (max1 < 14) max1 = 14;
00659       if (max2 < 13) max2 = 13;
00660       $display("\nType Overrides:\n");
00661       $display("  %0s%0s  %0s%0s","Requested Type",space.substr(1,max1-14),
00662                                   "Override Type", space.substr(1,max2-13));
00663       $display("  %0s  %0s",dash.substr(1,max1),
00664                             dash.substr(1,max2));
00665       foreach (m_type_overrides[index]) 
00666         $display("  %0s%0s  %0s",
00667                  m_type_overrides[index].orig_type_name,
00668                  space.substr(1,max1-m_type_overrides[index].orig_type_name.len()),
00669                  m_type_overrides[index].ovrd_type_name);
00670     end
00671   end
00672 
00673   // print all registered types, if all_types >= 1 
00674   if (all_types >= 1 && m_type_names.first(key)) begin
00675     bit banner;
00676     $display("\nAll types registered with the factory: %0d total",m_types.num());
00677     $display("(types without type names will not be printed)\n");
00678     do begin
00679       // filter out ovm_ classes (if all_types<2) and non-types (lookup strings)
00680       if (!(all_types < 2 && ovm_is_match("ovm_*",
00681            m_type_names[key].get_type_name())) &&
00682            key == m_type_names[key].get_type_name()) begin
00683         if (!banner) begin
00684           $display("  Type Name");
00685           $display("  ---------");
00686           banner=1;
00687         end
00688         $display("  ", m_type_names[key].get_type_name());
00689       end
00690     end while(m_type_names.next(key));
00691   end
00692 
00693   $display("(*) Types with no associated type name will be printed as <unknown>");
00694 
00695   $display("\n####\n");
00696 
00697 endfunction
00698 
00699 
00700 // print_override_info (static)
00701 // -------------------
00702 
00703 function void  ovm_factory::print_override_info (string requested_type_name,
00704                                                  string parent_inst_path="",
00705                                                  string name="");
00706   static bit issued=0;
00707   if (!issued) begin
00708     issued=1;
00709     ovm_report_warning("deprecated",
00710       {"ovm_factory::print_override_info() has been deprecated and replaced by ",
00711       "factory.debug_create_by_name()"});
00712   end
00713   m_inst = ovm_factory::get();
00714   m_inst.m_debug_create(requested_type_name, null, parent_inst_path, name);
00715 endfunction
00716 
00717 
00718 // debug_create_by_name
00719 // --------------------
00720 
00721 function void  ovm_factory::debug_create_by_name (string requested_type_name,
00722                                                   string parent_inst_path="",
00723                                                   string name="");
00724   m_debug_create(requested_type_name, null, parent_inst_path, name);
00725 endfunction
00726 
00727 
00728 // debug_create_by_type
00729 // --------------------
00730 
00731 function void  ovm_factory::debug_create_by_type (ovm_object_wrapper requested_type,
00732                                                   string parent_inst_path="",
00733                                                   string name="");
00734   m_debug_create("", requested_type, parent_inst_path, name);
00735 endfunction
00736 
00737 
00738 // m_debug_create
00739 // --------------
00740 
00741 function void  ovm_factory::m_debug_create (string requested_type_name,
00742                                             ovm_object_wrapper requested_type,
00743                                             string parent_inst_path,
00744                                             string name);
00745 
00746   string full_inst_path;
00747   ovm_object_wrapper result;
00748   
00749   if (parent_inst_path == "")
00750     full_inst_path = name;
00751   else if (name != "")
00752     full_inst_path = {parent_inst_path,".",name};
00753   else
00754     full_inst_path = parent_inst_path;
00755 
00756   `ovm_clear_queue(m_override_info)
00757 
00758   if (requested_type == null) begin
00759     if (!m_type_names.exists(requested_type_name) &&
00760       !m_lookup_strs.exists(requested_type_name)) begin
00761       ovm_report_warning("Factory Warning", {"The factory does not recognize '",
00762         requested_type_name,"' as a registered type."});
00763       return;
00764     end
00765     m_debug_pass = 1;
00766     result = find_override_by_name(requested_type_name,full_inst_path);
00767   end
00768   else begin
00769     m_debug_pass = 1;
00770     if (!m_types.exists(requested_type))
00771       register(requested_type); 
00772     result = find_override_by_type(requested_type,full_inst_path);
00773     if (requested_type_name == "")
00774       requested_type_name = requested_type.get_type_name();
00775   end
00776 
00777   m_debug_display(requested_type_name, result, full_inst_path);
00778   m_debug_pass = 0;
00779 
00780 endfunction
00781 
00782 
00783 // m_debug_display
00784 // ---------------
00785 
00786 function void  ovm_factory::m_debug_display (string requested_type_name,
00787                                              ovm_object_wrapper result,
00788                                              string full_inst_path);
00789 
00790   int    max1,max2,max3;
00791   string dash = "---------------------------------------------------------------------------------------------------";
00792   string space= "                                                                                                   ";
00793 
00794   $display("\n#### Factory Override Information (*)\n");
00795   $write("Given a request for an object of type '",requested_type_name,
00796          "' with an instance\npath of '",full_inst_path,
00797          "', the factory encountered\n");
00798 
00799   if (m_override_info.size() == 0)
00800     $display("no relevant overrides.\n");
00801   else begin
00802 
00803     $display("the following relevant overrides:\n");
00804 
00805     foreach (m_override_info[i]) begin
00806       if (m_override_info[i].orig_type_name.len() > max1)
00807         max1=m_override_info[i].orig_type_name.len();
00808       if (m_override_info[i].full_inst_path.len() > max2)
00809         max2=m_override_info[i].full_inst_path.len();
00810       if (m_override_info[i].ovrd_type_name.len() > max3)
00811         max3=m_override_info[i].ovrd_type_name.len();
00812     end
00813 
00814     if (max1 < 13) max1 = 13;
00815     if (max2 < 13) max2 = 13;
00816     if (max3 < 13) max3 = 13;
00817 
00818     $display("  %0s%0s", "Original Type", space.substr(1,max1-13),
00819              "  %0s%0s", "Instance Path", space.substr(1,max2-13),
00820              "  %0s%0s", "Override Type", space.substr(1,max3-13));
00821 
00822     $display("  %0s  %0s  %0s",dash.substr(1,max1),
00823                                dash.substr(1,max2),
00824                                dash.substr(1,max3));
00825 
00826     foreach (m_override_info[i]) begin
00827       $write("  %0s%0s", m_override_info[i].orig_type_name,
00828              space.substr(1,max1-m_override_info[i].orig_type_name.len()));
00829       $write("  %0s%0s", m_override_info[i].full_inst_path,
00830              space.substr(1,max2-m_override_info[i].full_inst_path.len()));
00831       $write("  %0s%0s", m_override_info[i].ovrd_type_name,
00832              space.substr(1,max3-m_override_info[i].ovrd_type_name.len()));
00833       if (m_override_info[i].full_inst_path == "*")
00834         $display("  <type override>");
00835       else
00836         $display();
00837     end
00838     $display();
00839   end
00840 
00841 
00842   $display("Result:\n");
00843   $display("  The factory will produce an object of type '%0s'", 
00844            result == null ? requested_type_name : result.get_type_name());
00845 
00846   $display("\n(*) Types with no associated type name will be printed as <unknown>");
00847 
00848   $display("\n####\n");
00849 
00850 endfunction
00851 
00852 

Intelligent Design Verification
Intelligent Design Verification
Project: OVM, Revision: 2.0.1
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.5.5
Wed Jan 7 19:27:17 2009
Find a documentation bug? Report bugs to: bugs.intelligentdv.com Project: DoxygenFilterSV