00001 // $Id: ovm_factory.sv 19 2009-12-28 21:40:27Z seanoboyle $ 00002 //---------------------------------------------------------------------- 00003 // Copyright 2007-2009 Mentor Graphics Corporation 00004 // Copyright 2007-2009 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 00024 //------------------------------------------------------------------------------ 00025 // 00026 // CLASS- ovm_factory 00027 // 00028 //------------------------------------------------------------------------------ 00029 00030 // get 00031 // --- 00032 00033 function ovm_factory ovm_factory::get(); 00034 if (m_inst == null) begin 00035 m_inst = new(); 00036 end 00037 return m_inst; 00038 endfunction 00039 00040 // new 00041 // --- 00042 00043 function ovm_factory::new (); 00044 endfunction 00045 00046 00047 // auto_register (static) 00048 // ------------- 00049 00050 function void ovm_factory::auto_register (ovm_object_wrapper obj); 00051 static bit issued=0; 00052 if (!issued) begin 00053 issued=1; 00054 ovm_report_warning("deprecated", 00055 {"ovm_factory::auto_register() has been deprecated and replaced by ", 00056 "factory.register()"}, OVM_NONE); 00057 end 00058 m_inst = ovm_factory::get(); 00059 m_inst.register(obj); 00060 endfunction 00061 00062 00063 // register 00064 // -------- 00065 00066 function void ovm_factory::register (ovm_object_wrapper obj); 00067 00068 if (obj == null) begin 00069 ovm_report_fatal ("NULLWR", "Attempting to register a null object with the factory", OVM_NONE); 00070 end 00071 if (obj.get_type_name() == "" || obj.get_type_name() == "<unknown>") begin 00072 //ovm_report_warning("EMPTNM", {"Factory registration with ", 00073 // "unknown type name prevents name-based operations. "}); 00074 end 00075 else begin 00076 if (m_type_names.exists(obj.get_type_name())) 00077 ovm_report_warning("TPRGED", {"Type name '",obj.get_type_name(), 00078 "' already registered with factory. No string-based lookup ", 00079 "support for multiple types with the same type name."}, OVM_NONE); 00080 else 00081 m_type_names[obj.get_type_name()] = obj; 00082 end 00083 00084 if (m_types.exists(obj)) begin 00085 if (obj.get_type_name() != "" && obj.get_type_name() != "<unknown>") 00086 ovm_report_warning("TPRGED", {"Object type '",obj.get_type_name(), 00087 "' already registered with factory. "}, OVM_NONE); 00088 end 00089 else begin 00090 m_types[obj] = 1; 00091 // If a named override happens before the type is registered, need to copy 00092 // the override queue. 00093 if(m_inst_override_name_queues.exists(obj.get_type_name())) begin 00094 m_inst_override_queues[obj] = new; 00095 m_inst_override_queues[obj].queue = m_inst_override_name_queues[obj.get_type_name()].queue; 00096 m_inst_override_name_queues.delete(obj.get_type_name()); 00097 end 00098 if(m_wildcard_inst_overrides.size()) begin 00099 if(! m_inst_override_queues.exists(obj)) 00100 m_inst_override_queues[obj] = new; 00101 foreach (m_wildcard_inst_overrides[i]) begin 00102 if(ovm_is_match(obj.get_type_name(), m_wildcard_inst_overrides[i].orig_type_name)) 00103 m_inst_override_queues[obj].queue.push_back(m_wildcard_inst_overrides[i]); 00104 end 00105 end 00106 00107 end 00108 00109 endfunction 00110 00111 00112 00113 // set_type_override (static) 00114 // ----------------- 00115 00116 function void ovm_factory::set_type_override (string original_type_name, 00117 string override_type_name, 00118 bit replace=1); 00119 static bit issued=0; 00120 if (!issued) begin 00121 issued=1; 00122 ovm_report_warning("deprecated", 00123 {"ovm_factory::set_type_override() has been deprecated and replaced by ", 00124 "factory.set_type_override_by_name()"}, OVM_NONE); 00125 end 00126 m_inst = ovm_factory::get(); 00127 m_inst.set_type_override_by_name (original_type_name, override_type_name, replace); 00128 endfunction 00129 00130 00131 // set_type_override_by_type 00132 // ------------------------- 00133 00134 function void ovm_factory::set_type_override_by_type (ovm_object_wrapper original_type, 00135 ovm_object_wrapper override_type, 00136 bit replace=1); 00137 bit replaced; 00138 00139 // check that old and new are not the same 00140 if (original_type == override_type) begin 00141 if (original_type.get_type_name() == "" || original_type.get_type_name() == "<unknown>") 00142 ovm_report_warning("TYPDUP", {"Original and override type ", 00143 "arguments are identical"}, OVM_NONE); 00144 else 00145 ovm_report_warning("TYPDUP", {"Original and override type ", 00146 "arguments are identical: ", 00147 original_type.get_type_name()}, OVM_NONE); 00148 return; 00149 end 00150 00151 // register the types if not already done so, for the benefit of string-based lookup 00152 if (!m_types.exists(original_type)) 00153 register(original_type); 00154 00155 if (!m_types.exists(override_type)) 00156 register(override_type); 00157 00158 00159 // check for existing type override 00160 foreach (m_type_overrides[index]) begin 00161 if (m_type_overrides[index].orig_type == original_type || 00162 (m_type_overrides[index].orig_type_name != "<unknown>" && 00163 m_type_overrides[index].orig_type_name != "" && 00164 m_type_overrides[index].orig_type_name == original_type.get_type_name())) begin 00165 string msg; 00166 msg = {"Original object type '",original_type.get_type_name(), 00167 "' already registered to produce '", 00168 m_type_overrides[index].ovrd_type_name,"'"}; 00169 if (!replace) begin 00170 msg = {msg, ". Set 'replace' argument to replace the existing entry."}; 00171 ovm_report_info("TPREGD", msg, OVM_MEDIUM); 00172 return; 00173 end 00174 msg = {msg, ". Replacing with override to produce type '", 00175 override_type.get_type_name(),"'."}; 00176 ovm_report_info("TPREGR", msg, OVM_MEDIUM); 00177 replaced = 1; 00178 m_type_overrides[index].orig_type = original_type; 00179 m_type_overrides[index].orig_type_name = original_type.get_type_name(); 00180 m_type_overrides[index].ovrd_type = override_type; 00181 m_type_overrides[index].ovrd_type_name = override_type.get_type_name(); 00182 end 00183 end 00184 00185 // make a new entry 00186 if (!replaced) begin 00187 ovm_factory_override override; 00188 override = new(.orig_type(original_type), 00189 .orig_type_name(original_type.get_type_name()), 00190 .full_inst_path("*"), 00191 .ovrd_type(override_type)); 00192 00193 m_type_overrides.push_back(override); 00194 end 00195 00196 endfunction 00197 00198 00199 // set_type_override_by_name 00200 // ------------------------- 00201 00202 function void ovm_factory::set_type_override_by_name (string original_type_name, 00203 string override_type_name, 00204 bit replace=1); 00205 bit replaced; 00206 00207 ovm_object_wrapper original_type=null; 00208 ovm_object_wrapper override_type=null; 00209 00210 if(m_type_names.exists(original_type_name)) 00211 original_type = m_type_names[original_type_name]; 00212 00213 if(m_type_names.exists(override_type_name)) 00214 override_type = m_type_names[override_type_name]; 00215 00216 // check that type is registered with the factory 00217 if (override_type == null) begin 00218 ovm_report_error("TYPNTF", {"Cannot register override for original type '", 00219 original_type_name,"' because the override type '", 00220 override_type_name, "' is not registered with the factory."}, OVM_NONE); 00221 return; 00222 end 00223 00224 // check that old and new are not the same 00225 if (original_type_name == override_type_name) begin 00226 ovm_report_warning("TYPDUP", {"Requested and actual type name ", 00227 " arguments are identical: ",original_type_name,". Ignoring this override."}, OVM_NONE); 00228 return; 00229 end 00230 00231 foreach (m_type_overrides[index]) begin 00232 if (m_type_overrides[index].orig_type_name == original_type_name) begin 00233 if (!replace) begin 00234 ovm_report_info("TPREGD", {"Original type '",original_type_name, 00235 "' already registered to produce '",m_type_overrides[index].ovrd_type_name, 00236 "'. Set 'replace' argument to replace the existing entry."}, OVM_MEDIUM); 00237 return; 00238 end 00239 ovm_report_info("TPREGR", {"Original object type '",original_type_name, 00240 "' already registered to produce '",m_type_overrides[index].ovrd_type_name, 00241 "'. Replacing with override to produce type '",override_type_name,"'."}, OVM_MEDIUM); 00242 replaced = 1; 00243 m_type_overrides[index].ovrd_type = override_type; 00244 m_type_overrides[index].ovrd_type_name = override_type_name; 00245 end 00246 end 00247 00248 if (original_type == null) 00249 m_lookup_strs[original_type_name] = 1; 00250 00251 if (!replaced) begin 00252 ovm_factory_override override; 00253 override = new(.orig_type(original_type), 00254 .orig_type_name(original_type_name), 00255 .full_inst_path("*"), 00256 .ovrd_type(override_type)); 00257 00258 m_type_overrides.push_back(override); 00259 // m_type_names[original_type_name] = override.ovrd_type; 00260 end 00261 00262 endfunction 00263 00264 00265 // set_inst_override (static) 00266 // ----------------- 00267 00268 function void ovm_factory::set_inst_override (string full_inst_path, 00269 string original_type_name, 00270 string override_type_name); 00271 static bit issued=0; 00272 if (!issued) begin 00273 issued=1; 00274 ovm_report_warning("deprecated", 00275 {"ovm_factory::set_inst_override() has been deprecated and replaced by ", 00276 "factory.set_inst_override_by_name()"}, OVM_NONE); 00277 end 00278 m_inst = ovm_factory::get(); 00279 m_inst.set_inst_override_by_name (original_type_name, override_type_name, full_inst_path); 00280 endfunction 00281 00282 00283 // check_inst_override_exists 00284 // -------------------------- 00285 function bit ovm_factory::check_inst_override_exists (ovm_object_wrapper original_type, 00286 ovm_object_wrapper override_type, 00287 string full_inst_path); 00288 ovm_factory_override override; 00289 ovm_factory_queue_class qc; 00290 00291 if (m_inst_override_queues.exists(original_type)) 00292 qc = m_inst_override_queues[original_type]; 00293 else 00294 return 0; 00295 00296 for (int index=0; index<qc.queue.size(); ++index) begin 00297 00298 override = qc.queue[index]; 00299 if (override.full_inst_path == full_inst_path && 00300 override.orig_type == original_type && 00301 override.ovrd_type == override_type && 00302 override.orig_type_name == original_type.get_type_name()) begin 00303 ovm_report_info("DUPOVRD",{"Instance override for '", 00304 original_type.get_type_name(),"' already exists: override type '", 00305 override_type.get_type_name(),"' with full_inst_path '", 00306 full_inst_path,"'"},OVM_HIGH); 00307 return 1; 00308 end 00309 end 00310 return 0; 00311 endfunction 00312 00313 // set_inst_override_by_type 00314 // ------------------------- 00315 00316 function void ovm_factory::set_inst_override_by_type (ovm_object_wrapper original_type, 00317 ovm_object_wrapper override_type, 00318 string full_inst_path); 00319 00320 ovm_factory_override override; 00321 00322 // register the types if not already done so 00323 if (!m_types.exists(original_type)) 00324 register(original_type); 00325 00326 if (!m_types.exists(override_type)) 00327 register(override_type); 00328 00329 if (check_inst_override_exists(original_type,override_type,full_inst_path)) 00330 return; 00331 00332 if(!m_inst_override_queues.exists(original_type)) 00333 m_inst_override_queues[original_type] = new; 00334 00335 override = new(.full_inst_path(full_inst_path), 00336 .orig_type(original_type), 00337 .orig_type_name(original_type.get_type_name()), 00338 .ovrd_type(override_type)); 00339 00340 00341 m_inst_override_queues[original_type].queue.push_back(override); 00342 00343 endfunction 00344 00345 00346 // set_inst_override_by_name 00347 // ------------------------- 00348 00349 function void ovm_factory::set_inst_override_by_name (string original_type_name, 00350 string override_type_name, 00351 string full_inst_path); 00352 00353 ovm_factory_override override; 00354 ovm_object_wrapper original_type=null; 00355 ovm_object_wrapper override_type=null; 00356 00357 if(m_type_names.exists(original_type_name)) 00358 original_type = m_type_names[original_type_name]; 00359 00360 if(m_type_names.exists(override_type_name)) 00361 override_type = m_type_names[override_type_name]; 00362 00363 // check that type is registered with the factory 00364 if (override_type == null) begin 00365 ovm_report_error("TYPNTF", {"Cannot register instance override with type name '", 00366 original_type_name,"' and instance path '",full_inst_path,"' because the type it's supposed ", 00367 "to produce, '",override_type_name,"', is not registered with the factory."}, OVM_NONE); 00368 return; 00369 end 00370 00371 if (original_type == null) 00372 m_lookup_strs[original_type_name] = 1; 00373 00374 override = new(.full_inst_path(full_inst_path), 00375 .orig_type(original_type), 00376 .orig_type_name(original_type_name), 00377 .ovrd_type(override_type)); 00378 00379 if(original_type != null) begin 00380 if (check_inst_override_exists(original_type,override_type,full_inst_path)) 00381 return; 00382 if(!m_inst_override_queues.exists(original_type)) 00383 m_inst_override_queues[original_type] = new; 00384 m_inst_override_queues[original_type].queue.push_back(override); 00385 end 00386 else begin 00387 if(m_has_wildcard(original_type_name)) begin 00388 foreach(m_type_names[i]) begin 00389 if(ovm_is_match(original_type_name,i)) begin 00390 this.set_inst_override_by_name(i, override_type_name, full_inst_path); 00391 end 00392 end 00393 m_wildcard_inst_overrides.push_back(override); 00394 end 00395 else begin 00396 if(!m_inst_override_name_queues.exists(original_type_name)) 00397 m_inst_override_name_queues[original_type_name] = new; 00398 m_inst_override_name_queues[original_type_name].queue.push_back(override); 00399 end 00400 end 00401 00402 endfunction 00403 00404 function bit ovm_factory::m_has_wildcard(string nm); 00405 foreach (nm[i]) 00406 if(nm[i] == "*" || nm[i] == "?") return 1; 00407 return 0; 00408 endfunction 00409 00410 // create_object (static) 00411 // ------------- 00412 00413 function ovm_object ovm_factory::create_object (string requested_type_name, 00414 string parent_inst_path="", 00415 string name=""); 00416 static bit issued=0; 00417 if (!issued) begin 00418 issued=1; 00419 ovm_report_warning("deprecated", 00420 {"ovm_factory::create_object() has been deprecated and replaced by ", 00421 "factory.create_object_by_name()"}, OVM_NONE); 00422 end 00423 m_inst = ovm_factory::get(); 00424 return m_inst.create_object_by_name(requested_type_name, parent_inst_path, name); 00425 endfunction 00426 00427 00428 // create_object_by_name 00429 // --------------------- 00430 00431 function ovm_object ovm_factory::create_object_by_name (string requested_type_name, 00432 string parent_inst_path="", 00433 string name=""); 00434 00435 ovm_object_wrapper wrapper; 00436 string inst_path; 00437 00438 if (parent_inst_path == "") 00439 inst_path = name; 00440 else if (name != "") 00441 inst_path = {parent_inst_path,".",name}; 00442 else 00443 inst_path = parent_inst_path; 00444 00445 `ovm_clear_queue(m_override_info) 00446 00447 wrapper = find_override_by_name(requested_type_name, inst_path); 00448 00449 // if no override exists, try to use requested_type_name directly 00450 if (wrapper==null) begin 00451 if(!m_type_names.exists(requested_type_name)) begin 00452 ovm_report_warning("BDTYP",{"Cannot create an object of type '", 00453 requested_type_name,"' because it is not registered with the factory."}, OVM_NONE); 00454 return null; 00455 end 00456 wrapper = m_type_names[requested_type_name]; 00457 end 00458 00459 return wrapper.create_object(name); 00460 00461 endfunction 00462 00463 00464 // create_object_by_type 00465 // --------------------- 00466 00467 function ovm_object ovm_factory::create_object_by_type (ovm_object_wrapper requested_type, 00468 string parent_inst_path="", 00469 string name=""); 00470 00471 string full_inst_path; 00472 00473 if (parent_inst_path == "") 00474 full_inst_path = name; 00475 else if (name != "") 00476 full_inst_path = {parent_inst_path,".",name}; 00477 else 00478 full_inst_path = parent_inst_path; 00479 00480 `ovm_clear_queue(m_override_info) 00481 00482 requested_type = find_override_by_type(requested_type, full_inst_path); 00483 00484 return requested_type.create_object(name); 00485 00486 endfunction 00487 00488 00489 // create_component (static) 00490 // ---------------- 00491 00492 function ovm_component ovm_factory::create_component (string requested_type_name, 00493 string parent_inst_path="", 00494 string name, 00495 ovm_component parent); 00496 static bit issued=0; 00497 if (!issued) begin 00498 issued=1; 00499 ovm_report_warning("deprecated", 00500 {"ovm_factory::create_component() has been deprecated and replaced by ", 00501 "factory.create_component_by_name()"}, OVM_NONE); 00502 end 00503 m_inst = ovm_factory::get(); 00504 return m_inst.create_component_by_name(requested_type_name, parent_inst_path, name, parent); 00505 endfunction 00506 00507 00508 // create_component_by_name 00509 // ------------------------ 00510 00511 function ovm_component ovm_factory::create_component_by_name (string requested_type_name, 00512 string parent_inst_path="", 00513 string name, 00514 ovm_component parent); 00515 ovm_object_wrapper wrapper; 00516 string inst_path; 00517 00518 if (parent_inst_path == "") 00519 inst_path = name; 00520 else if (name != "") 00521 inst_path = {parent_inst_path,".",name}; 00522 else 00523 inst_path = parent_inst_path; 00524 00525 `ovm_clear_queue(m_override_info) 00526 00527 wrapper = find_override_by_name(requested_type_name, inst_path); 00528 00529 // if no override exists, try to use requested_type_name directly 00530 if (wrapper == null) begin 00531 if(!m_type_names.exists(requested_type_name)) begin 00532 ovm_report_warning("BDTYP",{"Cannot create a component of type '", 00533 requested_type_name,"' because it is not registered with the factory."}, OVM_NONE); 00534 return null; 00535 end 00536 wrapper = m_type_names[requested_type_name]; 00537 end 00538 00539 return wrapper.create_component(name, parent); 00540 00541 endfunction 00542 00543 00544 // create_component_by_type 00545 // ------------------------ 00546 00547 function ovm_component ovm_factory::create_component_by_type (ovm_object_wrapper requested_type, 00548 string parent_inst_path="", 00549 string name, 00550 ovm_component parent); 00551 string full_inst_path; 00552 00553 if (parent_inst_path == "") 00554 full_inst_path = name; 00555 else if (name != "") 00556 full_inst_path = {parent_inst_path,".",name}; 00557 else 00558 full_inst_path = parent_inst_path; 00559 00560 `ovm_clear_queue(m_override_info) 00561 00562 requested_type = find_override_by_type(requested_type, full_inst_path); 00563 00564 return requested_type.create_component(name, parent); 00565 00566 endfunction 00567 00568 00569 00570 // find_by_name 00571 // ------------ 00572 00573 function ovm_object_wrapper ovm_factory::find_by_name(string type_name); 00574 00575 if (m_type_names.exists(type_name)) 00576 return m_type_names[type_name]; 00577 00578 ovm_report_warning("UnknownTypeName", {"find_by_name: Type name '",type_name, 00579 "' not registered with the factory."}, OVM_NONE); 00580 00581 endfunction 00582 00583 00584 // find_override_by_name 00585 // --------------------- 00586 00587 function ovm_object_wrapper ovm_factory::find_override_by_name (string requested_type_name, 00588 string full_inst_path); 00589 ovm_object_wrapper rtype = null; 00590 ovm_factory_queue_class qc; 00591 00592 ovm_object_wrapper override; 00593 00594 if (m_type_names.exists(requested_type_name)) 00595 rtype = m_type_names[requested_type_name]; 00596 00597 /*** 00598 if(rtype == null) begin 00599 if(requested_type_name != "") begin 00600 ovm_report_warning("TYPNTF", {"Requested type name ", 00601 requested_type_name, " is not registered with the factory. The instance override to ", 00602 full_inst_path, " is ignored"}, OVM_NONE); 00603 end 00604 m_lookup_strs[requested_type_name] = 1; 00605 return null; 00606 end 00607 ***/ 00608 00609 if (full_inst_path != "") begin 00610 if(rtype == null) begin 00611 if(m_inst_override_name_queues.exists(requested_type_name)) 00612 qc = m_inst_override_name_queues[requested_type_name]; 00613 end 00614 else begin 00615 if(m_inst_override_queues.exists(rtype)) 00616 qc = m_inst_override_queues[rtype]; 00617 end 00618 if(qc != null) 00619 for(int index = 0; index<qc.queue.size(); ++index) begin 00620 if (ovm_is_match(qc.queue[index].orig_type_name, requested_type_name) && 00621 ovm_is_match(qc.queue[index].full_inst_path, full_inst_path)) begin 00622 m_override_info.push_back(qc.queue[index]); 00623 if (m_debug_pass) begin 00624 if (override == null) begin 00625 override = qc.queue[index].ovrd_type; 00626 qc.queue[index].selected = 1; 00627 end 00628 end 00629 else begin 00630 if (qc.queue[index].ovrd_type.get_type_name() == requested_type_name) 00631 return qc.queue[index].ovrd_type; 00632 else 00633 return find_override_by_type(qc.queue[index].ovrd_type,full_inst_path); 00634 end 00635 end 00636 end 00637 end 00638 00639 if(rtype != null && !m_inst_override_queues.exists(rtype) && m_wildcard_inst_overrides.size()) begin 00640 m_inst_override_queues[rtype] = new; 00641 foreach (m_wildcard_inst_overrides[i]) begin 00642 if(ovm_is_match(m_wildcard_inst_overrides[i].orig_type_name, requested_type_name)) 00643 m_inst_override_queues[rtype].queue.push_back(m_wildcard_inst_overrides[i]); 00644 end 00645 end 00646 00647 // type override - exact match 00648 foreach (m_type_overrides[index]) 00649 if (m_type_overrides[index].orig_type_name == requested_type_name) begin 00650 m_override_info.push_back(m_type_overrides[index]); 00651 if (m_debug_pass) begin 00652 if (override == null) begin 00653 override = m_type_overrides[index].ovrd_type; 00654 m_type_overrides[index].selected = 1; 00655 end 00656 end 00657 else begin 00658 return find_override_by_type(m_type_overrides[index].ovrd_type,full_inst_path); 00659 end 00660 end 00661 00662 00663 if (m_debug_pass && override != null) 00664 return find_override_by_type(override, full_inst_path); 00665 00666 // No override found 00667 return null; 00668 00669 00670 endfunction 00671 00672 00673 // find_override_by_type 00674 // --------------------- 00675 00676 function ovm_object_wrapper ovm_factory::find_override_by_type(ovm_object_wrapper requested_type, 00677 string full_inst_path); 00678 00679 ovm_object_wrapper override; 00680 ovm_factory_queue_class qc = null; 00681 if (m_inst_override_queues.exists(requested_type)) 00682 qc = m_inst_override_queues[requested_type]; 00683 00684 foreach (m_override_info[index]) begin 00685 if ( //index != m_override_info.size()-1 && 00686 m_override_info[index].orig_type == requested_type) begin 00687 ovm_report_error("OVRDLOOP", "Recursive loop detected while finding override.", OVM_NONE); 00688 if (!m_debug_pass) 00689 debug_create_by_type (requested_type, full_inst_path); 00690 00691 return requested_type; 00692 end 00693 end 00694 00695 // inst override; return first match; takes precedence over type overrides 00696 if (full_inst_path != "" && qc != null) 00697 for (int index = 0; index < qc.queue.size(); ++index) begin 00698 if ((qc.queue[index].orig_type == requested_type || 00699 (qc.queue[index].orig_type_name != "<unknown>" && 00700 qc.queue[index].orig_type_name != "" && 00701 qc.queue[index].orig_type_name == requested_type.get_type_name())) && 00702 ovm_is_match(qc.queue[index].full_inst_path, full_inst_path)) begin 00703 m_override_info.push_back(qc.queue[index]); 00704 if (m_debug_pass) begin 00705 if (override == null) begin 00706 override = qc.queue[index].ovrd_type; 00707 qc.queue[index].selected = 1; 00708 end 00709 end 00710 else begin 00711 if (qc.queue[index].ovrd_type == requested_type) 00712 return requested_type; 00713 else 00714 return find_override_by_type(qc.queue[index].ovrd_type,full_inst_path); 00715 end 00716 end 00717 end 00718 00719 // type override - exact match 00720 foreach (m_type_overrides[index]) begin 00721 if (m_type_overrides[index].orig_type == requested_type || 00722 (m_type_overrides[index].orig_type_name != "<unknown>" && 00723 m_type_overrides[index].orig_type_name != "" && 00724 requested_type != null && 00725 m_type_overrides[index].orig_type_name == requested_type.get_type_name())) begin 00726 m_override_info.push_back(m_type_overrides[index]); 00727 if (m_debug_pass) begin 00728 if (override == null) begin 00729 override = m_type_overrides[index].ovrd_type; 00730 m_type_overrides[index].selected = 1; 00731 end 00732 end 00733 else begin 00734 if (m_type_overrides[index].ovrd_type == requested_type) 00735 return requested_type; 00736 else 00737 return find_override_by_type(m_type_overrides[index].ovrd_type,full_inst_path); 00738 end 00739 end 00740 end 00741 00742 // type override with wildcard match 00743 //foreach (m_type_overrides[index]) 00744 // if (ovm_is_match(index,requested_type.get_type_name())) begin 00745 // m_override_info.push_back(m_inst_overrides[index]); 00746 // return find_override_by_type(m_type_overrides[index],full_inst_path); 00747 // end 00748 00749 if (m_debug_pass && override != null) 00750 if (override == requested_type) 00751 return requested_type; 00752 else 00753 return find_override_by_type(override,full_inst_path); 00754 00755 return requested_type; 00756 00757 endfunction 00758 00759 00760 // print_all_overrides (static) 00761 // ------------------- 00762 00763 function void ovm_factory::print_all_overrides (int all_types=0); 00764 static bit issued=0; 00765 if (!issued) begin 00766 issued=1; 00767 ovm_report_warning("deprecated", 00768 {"ovm_factory::print_all_overrides() has been deprecated and replaced by ", 00769 "factory.print()"}, OVM_NONE); 00770 end 00771 m_inst = ovm_factory::get(); 00772 m_inst.print(all_types); 00773 endfunction 00774 00775 00776 // print 00777 // ----- 00778 00779 function void ovm_factory::print (int all_types=1); 00780 00781 string key; 00782 ovm_factory_queue_class sorted_override_queues[string]; 00783 00784 string tmp; 00785 int id=0; 00786 ovm_object_wrapper obj; 00787 00788 //sort the override queues 00789 foreach (m_inst_override_queues[i]) begin 00790 obj = i; 00791 tmp = obj.get_type_name(); 00792 if(tmp == "") $swrite(tmp, "__unnamed_id_%0d", id++); 00793 sorted_override_queues[tmp] = m_inst_override_queues[i]; 00794 00795 end 00796 foreach (m_inst_override_name_queues[i]) begin 00797 sorted_override_queues[i] = m_inst_override_name_queues[i]; 00798 end 00799 00800 $display("\n#### Factory Configuration (*)\n"); 00801 00802 // print instance overrides 00803 if(!m_type_overrides.size() && !sorted_override_queues.num()) 00804 $display(" No instance or type overrides are registered with this factory"); 00805 else begin 00806 int max1,max2,max3; 00807 string dash = "---------------------------------------------------------------------------------------------------"; 00808 string space= " "; 00809 00810 // print instance overrides 00811 if(!sorted_override_queues.num()) 00812 $display("No instance overrides are registered with this factory"); 00813 else begin 00814 foreach(sorted_override_queues[j]) begin 00815 ovm_factory_queue_class qc = sorted_override_queues[j]; 00816 for (int i=0; i<qc.queue.size(); ++i) begin 00817 if (qc.queue[i].orig_type_name.len() > max1) 00818 max1=qc.queue[i].orig_type_name.len(); 00819 if (qc.queue[i].full_inst_path.len() > max2) 00820 max2=qc.queue[i].full_inst_path.len(); 00821 if (qc.queue[i].ovrd_type_name.len() > max3) 00822 max3=qc.queue[i].ovrd_type_name.len(); 00823 end 00824 end 00825 if (max1 < 14) max1 = 14; 00826 if (max2 < 13) max2 = 13; 00827 if (max3 < 13) max3 = 13; 00828 00829 $display("Instance Overrides:\n"); 00830 $display(" %0s%0s %0s%0s %0s%0s","Requested Type",space.substr(1,max1-14), 00831 "Override Path", space.substr(1,max2-13), 00832 "Override Type", space.substr(1,max3-13)); 00833 $display(" %0s %0s %0s",dash.substr(1,max1), 00834 dash.substr(1,max2), 00835 dash.substr(1,max3)); 00836 00837 foreach(sorted_override_queues[j]) begin 00838 ovm_factory_queue_class qc = sorted_override_queues[j]; 00839 for (int i=0; i<qc.queue.size(); ++i) begin 00840 $write(" %0s%0s",qc.queue[i].orig_type_name, 00841 space.substr(1,max1-qc.queue[i].orig_type_name.len())); 00842 $write(" %0s%0s", qc.queue[i].full_inst_path, 00843 space.substr(1,max2-qc.queue[i].full_inst_path.len())); 00844 $display(" %0s", qc.queue[i].ovrd_type_name); 00845 end 00846 end 00847 end 00848 00849 // print type overrides 00850 if (!m_type_overrides.size()) 00851 $display("\nNo type overrides are registered with this factory"); 00852 else begin 00853 foreach (m_type_overrides[i]) begin 00854 if (m_type_overrides[i].orig_type_name.len() > max1) 00855 max1=m_type_overrides[i].orig_type_name.len(); 00856 if (m_type_overrides[i].ovrd_type_name.len() > max3) 00857 max2=m_type_overrides[i].ovrd_type_name.len(); 00858 end 00859 if (max1 < 14) max1 = 14; 00860 if (max2 < 13) max2 = 13; 00861 $display("\nType Overrides:\n"); 00862 $display(" %0s%0s %0s%0s","Requested Type",space.substr(1,max1-14), 00863 "Override Type", space.substr(1,max2-13)); 00864 $display(" %0s %0s",dash.substr(1,max1), 00865 dash.substr(1,max2)); 00866 foreach (m_type_overrides[index]) 00867 $display(" %0s%0s %0s", 00868 m_type_overrides[index].orig_type_name, 00869 space.substr(1,max1-m_type_overrides[index].orig_type_name.len()), 00870 m_type_overrides[index].ovrd_type_name); 00871 end 00872 end 00873 00874 // print all registered types, if all_types >= 1 00875 if (all_types >= 1 && m_type_names.first(key)) begin 00876 bit banner; 00877 $display("\nAll types registered with the factory: %0d total",m_types.num()); 00878 $display("(types without type names will not be printed)\n"); 00879 do begin 00880 // filter out ovm_ classes (if all_types<2) and non-types (lookup strings) 00881 if (!(all_types < 2 && ovm_is_match("ovm_*", 00882 m_type_names[key].get_type_name())) && 00883 key == m_type_names[key].get_type_name()) begin 00884 if (!banner) begin 00885 $display(" Type Name"); 00886 $display(" ---------"); 00887 banner=1; 00888 end 00889 $display(" ", m_type_names[key].get_type_name()); 00890 end 00891 end while(m_type_names.next(key)); 00892 end 00893 00894 $display("(*) Types with no associated type name will be printed as <unknown>"); 00895 00896 $display("\n####\n"); 00897 00898 endfunction 00899 00900 00901 // print_override_info (static) 00902 // ------------------- 00903 00904 function void ovm_factory::print_override_info (string requested_type_name, 00905 string parent_inst_path="", 00906 string name=""); 00907 static bit issued=0; 00908 if (!issued) begin 00909 issued=1; 00910 ovm_report_warning("deprecated", 00911 {"ovm_factory::print_override_info() has been deprecated and replaced by ", 00912 "factory.debug_create_by_name()"}, OVM_NONE); 00913 end 00914 m_inst = ovm_factory::get(); 00915 m_inst.m_debug_create(requested_type_name, null, parent_inst_path, name); 00916 endfunction 00917 00918 00919 // debug_create_by_name 00920 // -------------------- 00921 00922 function void ovm_factory::debug_create_by_name (string requested_type_name, 00923 string parent_inst_path="", 00924 string name=""); 00925 m_debug_create(requested_type_name, null, parent_inst_path, name); 00926 endfunction 00927 00928 00929 // debug_create_by_type 00930 // -------------------- 00931 00932 function void ovm_factory::debug_create_by_type (ovm_object_wrapper requested_type, 00933 string parent_inst_path="", 00934 string name=""); 00935 m_debug_create("", requested_type, parent_inst_path, name); 00936 endfunction 00937 00938 00939 // m_debug_create 00940 // -------------- 00941 00942 function void ovm_factory::m_debug_create (string requested_type_name, 00943 ovm_object_wrapper requested_type, 00944 string parent_inst_path, 00945 string name); 00946 00947 string full_inst_path; 00948 ovm_object_wrapper result; 00949 00950 if (parent_inst_path == "") 00951 full_inst_path = name; 00952 else if (name != "") 00953 full_inst_path = {parent_inst_path,".",name}; 00954 else 00955 full_inst_path = parent_inst_path; 00956 00957 `ovm_clear_queue(m_override_info) 00958 00959 if (requested_type == null) begin 00960 if (!m_type_names.exists(requested_type_name) && 00961 !m_lookup_strs.exists(requested_type_name)) begin 00962 ovm_report_warning("Factory Warning", {"The factory does not recognize '", 00963 requested_type_name,"' as a registered type."}, OVM_NONE); 00964 return; 00965 end 00966 m_debug_pass = 1; 00967 00968 result = find_override_by_name(requested_type_name,full_inst_path); 00969 end 00970 else begin 00971 m_debug_pass = 1; 00972 if (!m_types.exists(requested_type)) 00973 register(requested_type); 00974 result = find_override_by_type(requested_type,full_inst_path); 00975 if (requested_type_name == "") 00976 requested_type_name = requested_type.get_type_name(); 00977 end 00978 00979 m_debug_display(requested_type_name, result, full_inst_path); 00980 m_debug_pass = 0; 00981 00982 foreach (m_override_info[index]) 00983 m_override_info[index].selected = 0; 00984 00985 endfunction 00986 00987 00988 // m_debug_display 00989 // --------------- 00990 00991 function void ovm_factory::m_debug_display (string requested_type_name, 00992 ovm_object_wrapper result, 00993 string full_inst_path); 00994 00995 int max1,max2,max3; 00996 string dash = "---------------------------------------------------------------------------------------------------"; 00997 string space= " "; 00998 00999 $display("\n#### Factory Override Information (*)\n"); 01000 $write("Given a request for an object of type '",requested_type_name, 01001 "' with an instance\npath of '",full_inst_path, 01002 "', the factory encountered\n"); 01003 01004 if (m_override_info.size() == 0) 01005 $display("no relevant overrides.\n"); 01006 else begin 01007 01008 $display("the following relevant overrides. An 'x' next to a match indicates a", 01009 "\nmatch that was ignored.\n"); 01010 01011 foreach (m_override_info[i]) begin 01012 if (m_override_info[i].orig_type_name.len() > max1) 01013 max1=m_override_info[i].orig_type_name.len(); 01014 if (m_override_info[i].full_inst_path.len() > max2) 01015 max2=m_override_info[i].full_inst_path.len(); 01016 if (m_override_info[i].ovrd_type_name.len() > max3) 01017 max3=m_override_info[i].ovrd_type_name.len(); 01018 end 01019 01020 if (max1 < 13) max1 = 13; 01021 if (max2 < 13) max2 = 13; 01022 if (max3 < 13) max3 = 13; 01023 01024 $display(" %0s%0s", "Original Type", space.substr(1,max1-13), 01025 " %0s%0s", "Instance Path", space.substr(1,max2-13), 01026 " %0s%0s", "Override Type", space.substr(1,max3-13)); 01027 01028 $display(" %0s %0s %0s",dash.substr(1,max1), 01029 dash.substr(1,max2), 01030 dash.substr(1,max3)); 01031 01032 foreach (m_override_info[i]) begin 01033 $write("%s%0s%0s", 01034 m_override_info[i].selected ? " " : "x ", 01035 m_override_info[i].orig_type_name, 01036 space.substr(1,max1-m_override_info[i].orig_type_name.len())); 01037 $write(" %0s%0s", m_override_info[i].full_inst_path, 01038 space.substr(1,max2-m_override_info[i].full_inst_path.len())); 01039 $write(" %0s%0s", m_override_info[i].ovrd_type_name, 01040 space.substr(1,max3-m_override_info[i].ovrd_type_name.len())); 01041 if (m_override_info[i].full_inst_path == "*") 01042 $display(" <type override>"); 01043 else 01044 $display(); 01045 end 01046 $display(); 01047 end 01048 01049 01050 $display("Result:\n"); 01051 $display(" The factory will produce an object of type '%0s'", 01052 result == null ? requested_type_name : result.get_type_name()); 01053 01054 $display("\n(*) Types with no associated type name will be printed as <unknown>"); 01055 01056 $display("\n####\n"); 01057 01058 endfunction 01059 01060
![]() Intelligent Design Verification Project: OVM, Revision: 2.1.0 |
Copyright (c) 2008-2010 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 Version: 1.6.3 IDV SV Filter Version: 2.6.3 Sat Jun 19 11:51:28 2010 |