ovm_factory.svh

Go to the documentation of this file.
00001 // $Id: ovm__factory_8svh-source.html,v 1.1 2008/10/07 21:54:27 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_FACTORY_SVH
00023 `define OVM_FACTORY_SVH
00024 
00025 typedef class ovm_object;
00026 typedef class ovm_component;
00027 
00028 //------------------------------------------------------------------------------
00029 //
00030 // CLASS: ovm_object_wrapper (OVM)
00031 //
00032 //------------------------------------------------------------------------------
00033 
00034 // To register with a factory, a class must create a wrapper which implements
00035 // either the create_object (for generic data object) or create_component (for
00036 // hierarchical elements).
00037 
00038 virtual class ovm_object_wrapper;
00039 
00040   virtual function ovm_object create_object (string name="");
00041     return null;
00042   endfunction
00043 
00044   virtual function ovm_component create_component (string name, 
00045                                                    ovm_component parent); 
00046     return null;
00047   endfunction
00048 
00049   // Subtypes must specify the type that it creates
00050   pure virtual function string get_type_name();
00051 
00052 endclass
00053 
00054 
00055 //------------------------------------------------------------------------------
00056 //
00057 // CLASS: ovm_factory_override
00058 //
00059 //------------------------------------------------------------------------------
00060 
00061 class ovm_factory_override;
00062   string full_inst_path;
00063   string orig_type_name;
00064   string ovrd_type_name;
00065   ovm_object_wrapper orig_type;
00066   ovm_object_wrapper ovrd_type;
00067   function new (string full_inst_path="",
00068                 string orig_type_name="",
00069                 ovm_object_wrapper orig_type=null,
00070                 ovm_object_wrapper ovrd_type);
00071     assert (ovrd_type != null);
00072     this.full_inst_path= full_inst_path;
00073     this.orig_type_name = orig_type == null ? orig_type_name : orig_type.get_type_name();
00074     this.orig_type      = orig_type;
00075     this.ovrd_type_name = ovrd_type.get_type_name();
00076     this.ovrd_type      = ovrd_type;
00077   endfunction
00078 endclass
00079 
00080 
00081 //------------------------------------------------------------------------------
00082 //
00083 // CLASS: ovm_factory
00084 //
00085 //------------------------------------------------------------------------------
00086 //
00087 // Type-based factory configuration (preferred)
00088 //
00089 //
00090 // String-based factory configuration
00091 //
00092 // set_type_override
00093 //
00094 //    Configures the factory to produce an object of type 'override_type_name'
00095 //    when a request is made using 'requested_type_name', which often is the
00096 //    base type but can be any arbitrary string.
00097 //
00098 //      set_type_override("driver", "my_driver")
00099 //
00100 //    This says: "When a request for 'driver' is made, produce and return an
00101 //    object whose type name is 'my_driver'." Overrides are recursive. That is:
00102 //
00103 //      set_type_override("my_driver", "special_driver")
00104 //
00105 //    This says: "When a request for 'driver' or 'my_driver' is made, produce
00106 //    and return an object whose type name is 'special_driver'." 
00107 //
00108 //    This says: "When a request for 'driver' or 'my_driver' is made, produce
00109 //    and return an object whose type name is 'special_driver'." 
00110 //
00111 // set_inst_override
00112 //
00113 //    Configures the factory to produce an object of type 'override_type_name'
00114 //    when a request is made using 'requested_type_name' *and* 
00115 //      {parent_inst_path,".",name}
00116 //    matches the 'inst_path' string. The 'inst_path' string allows overrides
00117 //    to occur on an instance basis. It may contain wildcards so as to apply to
00118 //    more than one context. The 'requested_type_name' is often the base type
00119 //    but can be any arbitrary string.
00120 //
00121 //      set_inst_override("top.a1.master", "some_monitor", "really_special_monitor")
00122 //      set_inst_override("top.*.master",  "some_monitor", "special_monitor")
00123 //      set_type_override("some_monitor",  "basic_monitor")
00124 //
00125 //    This says: "When a request for 'some_monitor' is made, produce 
00126 //    'really_special_monitor' when the context is 'top.a1.master',
00127 //    'special_monitor' when the context is 'top.*.master', and 'basic_monitor'
00128 //    in every other context." Note how the order goes from most specific to
00129 //    most general. That's important. A type override can be expressed as
00130 //    an instance override. The following is equivalent to, although less
00131 //    efficient than, the type override above:
00132 //
00133 //      set_inst_override("*", "some_monitor",  "basic_monitor")
00134 //
00135 //    Because the requested_type_name does not necessarily represent the type
00136 //    name of an actual class, the factory *must* be configured to map it to some
00137 //    concreate type, else a run-time error will occur when a request is made using
00138 //    'some_monitor' as the original_type_name.
00139 //
00140 //
00141 // create_object
00142 // create_component
00143 //    Methods for creating objects
00144 //
00145 // auto_register
00146 //    Method for registering an object creator. This is called automatically
00147 //    by the `ovm_*_utils macros
00148 //
00149 //------------------------------------------------------------------------------
00150 
00151 class ovm_factory;
00152 
00153   extern `_protected function new ();
00154 
00155   extern static function ovm_factory get();
00156 
00157 
00158   extern function void          set_inst_override_by_type(ovm_object_wrapper original_type,
00159                                                          ovm_object_wrapper override_type,
00160                                                          string full_inst_path);
00161 
00162   extern function void          set_type_override_by_type(ovm_object_wrapper original_type,
00163                                                          ovm_object_wrapper override_type,
00164                                                          bit replace=1);
00165 
00166   extern function ovm_object    create_object_by_type   (ovm_object_wrapper requested_type,  
00167                                                          string parent_inst_path="",
00168                                                          string name=""); 
00169 
00170   extern function ovm_component create_component_by_type(ovm_object_wrapper requested_type,  
00171                                                          string parent_inst_path="",
00172                                                          string name, 
00173                                                          ovm_component parent);
00174   extern
00175     function ovm_object_wrapper find_override_by_type   (ovm_object_wrapper requested_type,
00176                                                          string full_inst_path);
00177 
00178   extern function void          debug_create_by_type    (ovm_object_wrapper requested_type,
00179                                                          string parent_inst_path="",
00180                                                          string name="");
00181 
00182 
00183   extern function void          set_inst_override_by_name(string original_type_name,
00184                                                          string override_type_name,
00185                                                          string full_inst_path);
00186 
00187   extern function void          set_type_override_by_name(string original_type_name,
00188                                                          string override_type_name,
00189                                                          bit replace=1);
00190 
00191   extern function ovm_object    create_object_by_name   (string requested_type_name,  
00192                                                          string parent_inst_path="",
00193                                                          string name=""); 
00194 
00195   extern function ovm_component create_component_by_name(string requested_type_name,  
00196                                                          string parent_inst_path="",
00197                                                          string name, 
00198                                                          ovm_component parent);
00199   extern
00200     function ovm_object_wrapper find_override_by_name   (string requested_type_name,
00201                                                          string full_inst_path);
00202 
00203   extern function void          debug_create_by_name    (string requested_type_name,
00204                                                          string parent_inst_path="",
00205                                                          string name="");
00206 
00207 
00208   extern function void          print                   (int all_types=1);
00209 
00210 
00211   extern function void          register                (ovm_object_wrapper obj);
00212 
00213 
00214 
00215   //-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
00216 
00217   // name-based static methods - deprecated
00218 
00219   extern static function void          set_type_override (string original_type_name,
00220                                                          string override_type_name,
00221                                                          bit    replace=1);
00222 
00223   extern static function void          set_inst_override(string full_inst_path,
00224                                                          string original_type_name,
00225                                                          string override_type_name);
00226 
00227   extern static function ovm_object    create_object    (string requested_type_name,  
00228                                                          string parent_inst_path="",
00229                                                          string name="");
00230 
00231   extern static function ovm_component create_component (string requested_type_name,
00232                                                          string parent_inst_path="",
00233                                                          string name, 
00234                                                          ovm_component parent);
00235 
00236 
00237   extern static function void          print_override_info(string requested_type_name,
00238                                                          string parent_inst_path="",
00239                                                          string name="");
00240 
00241   extern static function void          print_all_overrides(int all_types=0);
00242 
00243   extern static function void          auto_register    (ovm_object_wrapper obj);
00244 
00245 
00246   //----------------------------------------------------------------------------
00247   // PRIVATE MEMBERS
00248   
00249   extern protected function void  m_debug_create        (string requested_type_name,
00250                                                          ovm_object_wrapper requested_type,
00251                                                          string parent_inst_path,
00252                                                          string name);
00253   
00254   extern protected function void  m_debug_display       (string requested_type_name,
00255                                                          ovm_object_wrapper result,
00256                                                          string full_inst_path);
00257   static local ovm_factory m_inst;
00258 
00259   protected bit                  m_types[ovm_object_wrapper];
00260   protected bit                  m_lookup_strs[string];
00261   protected ovm_object_wrapper   m_type_names[string];
00262 
00263   protected ovm_factory_override m_type_overrides[$];
00264   protected ovm_factory_override m_inst_overrides[$];
00265 
00266   local ovm_factory_override     m_override_info[$];
00267   local static bit m_debug_pass;
00268 
00269 endclass
00270 
00271 
00272 // our singleton factory; it is initialized upon first call to ovm_factory::get
00273 
00274 `const ovm_factory factory = ovm_factory::get();
00275 
00276 
00277 
00278 `endif // OVM_FACTORY_SVH
00279 

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:23:29 2008
Find a documentation bug? Report bugs to: bugs.intelligentdv.com Project: DoxygenFilterSV