Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

sc_module.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2004 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.3 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_module.h -- Base class of all hierarchical modules and channels.
00021 
00022   Original Author: Stan Y. Liao, Synopsys, Inc.
00023                    Martin Janssen, Synopsys, Inc.
00024 
00025  *****************************************************************************/
00026 
00027 /*****************************************************************************
00028 
00029   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00030   changes you are making here.
00031 
00032       Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc.
00033   Description of Modification: - Implementation of operator() and operator,
00034                                  positional connection method.
00035                                - Implementation of error checking in
00036                                  operator<<'s.
00037                                - Implementation of the function test_module_prm.
00038                                - Implementation of set_stack_size().
00039 
00040       Name, Affiliation, Date: Gene Bushuyev, Synopsys, Inc.
00041   Description of Modification: - Change implementation for VC6.
00042 
00043       Name, Affiliation, Date: Andy Godorich, Forte
00044                                Bishnupriya Bhattacharya, Cadence Design Systems,
00045                                25 August, 2003
00046   Description of Modification: inherit from sc_process_host as a part of
00047                                implementing dynamic processes
00048 
00049  *****************************************************************************/
00050 
00051 #ifndef SC_MODULE_H
00052 #define SC_MODULE_H
00053 
00054 #include "systemc/kernel/sc_kernel_ids.h"
00055 #include "systemc/kernel/sc_lambda.h"
00056 #include "systemc/kernel/sc_module_name.h"
00057 #include "systemc/kernel/sc_process.h"
00058 #include "systemc/kernel/sc_sensitive.h"
00059 #include "systemc/kernel/sc_time.h"
00060 #include "systemc/kernel/sc_wait.h"
00061 #include "systemc/kernel/sc_wait_cthread.h"
00062 #include "systemc/kernel/sc_process_host.h"
00063 #include "systemc/utils/sc_list.h"
00064 #include "systemc/utils/sc_string.h"
00065 
00066 class sc_name_gen;
00067 
00068 // ----------------------------------------------------------------------------
00069 //  STRUCT : sc_bind_proxy
00070 //
00071 //  Struct for temporarily storing a pointer to an interface or port.
00072 //  Used for positional binding.
00073 // ----------------------------------------------------------------------------
00074 
00075 struct sc_bind_proxy
00076 {
00077     sc_interface* iface;
00078     sc_port_base* port;
00079     
00080     sc_bind_proxy();
00081     sc_bind_proxy( sc_interface& );
00082     sc_bind_proxy( sc_port_base& );
00083 };
00084 
00085 
00086 extern const sc_bind_proxy SC_BIND_PROXY_NIL;
00087 
00088 
00089 // ----------------------------------------------------------------------------
00090 //  CLASS : sc_module
00091 //
00092 //  Base class for all structural entities.
00093 // ----------------------------------------------------------------------------
00094 
00095 class sc_module
00096 : public sc_process_host
00097 {
00098     friend class sc_module_name;
00099     friend class sc_module_registry;
00100     friend class sc_object;
00101     friend class sc_port_registry;
00102     friend class sc_simcontext;
00103 
00104 public:
00105 
00106     sc_simcontext* sc_get_curr_simcontext()
00107   { return simcontext(); }
00108 
00109     // to generate unique names for objects in an MT-Safe way
00110     const char* gen_unique_name( const char* basename_ );
00111 
00112     virtual const char* kind() const
00113         { return "sc_module"; }
00114 
00115 protected:
00116   
00117     // called by construction_done 
00118     virtual void before_end_of_elaboration();
00119 
00120     void construction_done();
00121 
00122     // called by elaboration_done (does nothing by default)
00123     virtual void end_of_elaboration();
00124 
00125     void elaboration_done( bool& );
00126 
00127     // called by start_simulation (does nothing by default)
00128     virtual void start_of_simulation();
00129 
00130     void start_simulation();
00131 
00132     // called by simulation_done (does nothing by default)
00133     virtual void end_of_simulation();
00134 
00135     void simulation_done();
00136 
00137     void sc_module_init();
00138 
00139     // constructor
00140     sc_module( const char* nm );
00141     sc_module( const sc_string& nm );
00142     sc_module( const sc_module_name& nm ); /* for those used to old style */
00143     sc_module();
00144 
00145 public:
00146 
00147     // destructor
00148     virtual ~sc_module();
00149 
00150     // positional binding methods
00151 
00152     sc_module& operator << ( sc_interface& );
00153     sc_module& operator << ( sc_port_base& );
00154 
00155     sc_module& operator , ( sc_interface& interface_ )
00156         { return operator << ( interface_ ); }
00157 
00158     sc_module& operator , ( sc_port_base& port_ )
00159         { return operator << ( port_ ); }
00160 
00161     // operator() is declared at the end of the class.
00162 
00163     const sc_pvector<sc_object*>& get_child_objects() const;
00164 
00165 protected:
00166 
00167     void add_child_object( sc_object* );
00168     void remove_child_object( sc_object* );
00169 
00170     // this must be called by user-defined modules
00171     void end_module();
00172 
00173 
00174     // to prevent initialization for SC_METHODs and SC_THREADs
00175     void dont_initialize();
00176 
00177 
00178     // static sensitivity for SC_THREADs and SC_CTHREADs
00179 
00180     void wait()
00181         { ::wait( simcontext() ); }
00182 
00183 
00184     // dynamic sensitivity for SC_THREADs and SC_CTHREADs
00185 
00186     void wait( const sc_event& e )
00187         { ::wait( e, simcontext() ); }
00188 
00189     void wait( sc_event_or_list& el )
00190   { ::wait( el, simcontext() ); }
00191 
00192     void wait( sc_event_and_list& el )
00193   { ::wait( el, simcontext() ); }
00194 
00195     void wait( const sc_time& t )
00196         { ::wait( t, simcontext() ); }
00197 
00198     void wait( double v, sc_time_unit tu )
00199         { ::wait( sc_time( v, tu, simcontext() ), simcontext() ); }
00200 
00201     void wait( const sc_time& t, const sc_event& e )
00202         { ::wait( t, e, simcontext() ); }
00203 
00204     void wait( double v, sc_time_unit tu, const sc_event& e )
00205         { ::wait( sc_time( v, tu, simcontext() ), e, simcontext() ); }
00206 
00207     void wait( const sc_time& t, sc_event_or_list& el )
00208         { ::wait( t, el, simcontext() ); }
00209 
00210     void wait( double v, sc_time_unit tu, sc_event_or_list& el )
00211         { ::wait( sc_time( v, tu, simcontext() ), el, simcontext() ); }
00212 
00213     void wait( const sc_time& t, sc_event_and_list& el )
00214         { ::wait( t, el, simcontext() ); }
00215 
00216     void wait( double v, sc_time_unit tu, sc_event_and_list& el )
00217         { ::wait( sc_time( v, tu, simcontext() ), el, simcontext() ); }
00218 
00219 
00220     // static sensitivity for SC_METHODs
00221 
00222     void next_trigger()
00223   { ::next_trigger( simcontext() ); }
00224 
00225 
00226     // dynamic sensitivty for SC_METHODs
00227 
00228     void next_trigger( const sc_event& e )
00229         { ::next_trigger( e, simcontext() ); }
00230 
00231     void next_trigger( sc_event_or_list& el )
00232         { ::next_trigger( el, simcontext() ); }
00233 
00234     void next_trigger( sc_event_and_list& el )
00235         { ::next_trigger( el, simcontext() ); }
00236 
00237     void next_trigger( const sc_time& t )
00238         { ::next_trigger( t, simcontext() ); }
00239 
00240     void next_trigger( double v, sc_time_unit tu )
00241         { ::next_trigger( sc_time( v, tu, simcontext() ), simcontext() ); }
00242 
00243     void next_trigger( const sc_time& t, const sc_event& e )
00244         { ::next_trigger( t, e, simcontext() ); }
00245 
00246     void next_trigger( double v, sc_time_unit tu, const sc_event& e )
00247         { ::next_trigger( sc_time( v, tu, simcontext() ), e, simcontext() ); }
00248 
00249     void next_trigger( const sc_time& t, sc_event_or_list& el )
00250         { ::next_trigger( t, el, simcontext() ); }
00251 
00252     void next_trigger( double v, sc_time_unit tu, sc_event_or_list& el )
00253         { ::next_trigger( sc_time( v, tu, simcontext() ), el, simcontext() ); }
00254 
00255     void next_trigger( const sc_time& t, sc_event_and_list& el )
00256         { ::next_trigger( t, el, simcontext() ); }
00257 
00258     void next_trigger( double v, sc_time_unit tu, sc_event_and_list& el )
00259         { ::next_trigger( sc_time( v, tu, simcontext() ), el, simcontext() ); }
00260 
00261 
00262     // for SC_METHODs and SC_THREADs and SC_CTHREADs
00263 
00264     bool timed_out()
00265   { return ::timed_out( simcontext() ); }
00266 
00267 
00268     // for SC_CTHREADs
00269 
00270     void halt()
00271         { ::halt( simcontext() ); }
00272 
00273     void wait( int n )
00274         { ::wait( n, simcontext() ); }
00275 
00276     void wait_until( const sc_lambda_ptr& l )
00277         { ::wait_until( l, simcontext() ); }
00278 
00279     void wait_until( const sc_signal_bool_deval& s )
00280         { ::wait_until( s, simcontext() ); }
00281 
00282     void at_posedge( const sc_signal_in_if<bool>& s )
00283   { ::at_posedge( s, simcontext() ); }
00284 
00285     void at_posedge( const sc_signal_in_if<sc_logic>& s )
00286   { ::at_posedge( s, simcontext() ); }
00287 
00288     void at_negedge( const sc_signal_in_if<bool>& s )
00289   { ::at_negedge( s, simcontext() ); }
00290 
00291     void at_negedge( const sc_signal_in_if<sc_logic>& s )
00292   { ::at_negedge( s, simcontext() ); }
00293 
00294     void watching( const sc_lambda_ptr& l )
00295         { ::watching( l, simcontext() ); }
00296 
00297     void watching( const sc_signal_bool_deval& s )
00298         { ::watching( s, simcontext() ); }
00299 
00300 
00301     // These are protected so that user derived classes can refer to them.
00302     sc_sensitive     sensitive;
00303     sc_sensitive_pos sensitive_pos;
00304     sc_sensitive_neg sensitive_neg;
00305 
00306     // Function to set the stack size of the current (c)thread process.
00307     void set_stack_size( size_t );
00308 
00309     int append_port( sc_port_base* );
00310 
00311 private:
00312     sc_module( const sc_module& );
00313 
00314 private:
00315 
00316     bool                       m_end_module_called;
00317     sc_pvector<sc_port_base*>* m_port_vec;
00318     int                        m_port_index;
00319     sc_name_gen*               m_name_gen;
00320     sc_pvector<sc_object*>     m_child_objects;
00321 
00322 public:
00323 
00324     void defunct() { }
00325 
00326     // positional binding methods (cont'd)
00327 
00328     void operator () ( const sc_bind_proxy& p001,
00329            const sc_bind_proxy& p002 = SC_BIND_PROXY_NIL,
00330            const sc_bind_proxy& p003 = SC_BIND_PROXY_NIL,
00331            const sc_bind_proxy& p004 = SC_BIND_PROXY_NIL,
00332            const sc_bind_proxy& p005 = SC_BIND_PROXY_NIL,
00333            const sc_bind_proxy& p006 = SC_BIND_PROXY_NIL,
00334            const sc_bind_proxy& p007 = SC_BIND_PROXY_NIL,
00335            const sc_bind_proxy& p008 = SC_BIND_PROXY_NIL,
00336            const sc_bind_proxy& p009 = SC_BIND_PROXY_NIL,
00337            const sc_bind_proxy& p010 = SC_BIND_PROXY_NIL,
00338            const sc_bind_proxy& p011 = SC_BIND_PROXY_NIL,
00339            const sc_bind_proxy& p012 = SC_BIND_PROXY_NIL,
00340            const sc_bind_proxy& p013 = SC_BIND_PROXY_NIL,
00341            const sc_bind_proxy& p014 = SC_BIND_PROXY_NIL,
00342            const sc_bind_proxy& p015 = SC_BIND_PROXY_NIL,
00343            const sc_bind_proxy& p016 = SC_BIND_PROXY_NIL,
00344            const sc_bind_proxy& p017 = SC_BIND_PROXY_NIL,
00345            const sc_bind_proxy& p018 = SC_BIND_PROXY_NIL,
00346            const sc_bind_proxy& p019 = SC_BIND_PROXY_NIL,
00347            const sc_bind_proxy& p020 = SC_BIND_PROXY_NIL,
00348            const sc_bind_proxy& p021 = SC_BIND_PROXY_NIL,
00349            const sc_bind_proxy& p022 = SC_BIND_PROXY_NIL,
00350            const sc_bind_proxy& p023 = SC_BIND_PROXY_NIL,
00351            const sc_bind_proxy& p024 = SC_BIND_PROXY_NIL,
00352            const sc_bind_proxy& p025 = SC_BIND_PROXY_NIL,
00353            const sc_bind_proxy& p026 = SC_BIND_PROXY_NIL,
00354            const sc_bind_proxy& p027 = SC_BIND_PROXY_NIL,
00355            const sc_bind_proxy& p028 = SC_BIND_PROXY_NIL,
00356            const sc_bind_proxy& p029 = SC_BIND_PROXY_NIL,
00357            const sc_bind_proxy& p030 = SC_BIND_PROXY_NIL,
00358            const sc_bind_proxy& p031 = SC_BIND_PROXY_NIL,
00359            const sc_bind_proxy& p032 = SC_BIND_PROXY_NIL,
00360            const sc_bind_proxy& p033 = SC_BIND_PROXY_NIL,
00361            const sc_bind_proxy& p034 = SC_BIND_PROXY_NIL,
00362            const sc_bind_proxy& p035 = SC_BIND_PROXY_NIL,
00363            const sc_bind_proxy& p036 = SC_BIND_PROXY_NIL,
00364            const sc_bind_proxy& p037 = SC_BIND_PROXY_NIL,
00365            const sc_bind_proxy& p038 = SC_BIND_PROXY_NIL,
00366            const sc_bind_proxy& p039 = SC_BIND_PROXY_NIL,
00367            const sc_bind_proxy& p040 = SC_BIND_PROXY_NIL,
00368            const sc_bind_proxy& p041 = SC_BIND_PROXY_NIL,
00369            const sc_bind_proxy& p042 = SC_BIND_PROXY_NIL,
00370            const sc_bind_proxy& p043 = SC_BIND_PROXY_NIL,
00371            const sc_bind_proxy& p044 = SC_BIND_PROXY_NIL,
00372            const sc_bind_proxy& p045 = SC_BIND_PROXY_NIL,
00373            const sc_bind_proxy& p046 = SC_BIND_PROXY_NIL,
00374            const sc_bind_proxy& p047 = SC_BIND_PROXY_NIL,
00375            const sc_bind_proxy& p048 = SC_BIND_PROXY_NIL,
00376            const sc_bind_proxy& p049 = SC_BIND_PROXY_NIL,
00377            const sc_bind_proxy& p050 = SC_BIND_PROXY_NIL,
00378            const sc_bind_proxy& p051 = SC_BIND_PROXY_NIL,
00379            const sc_bind_proxy& p052 = SC_BIND_PROXY_NIL,
00380            const sc_bind_proxy& p053 = SC_BIND_PROXY_NIL,
00381            const sc_bind_proxy& p054 = SC_BIND_PROXY_NIL,
00382            const sc_bind_proxy& p055 = SC_BIND_PROXY_NIL,
00383            const sc_bind_proxy& p056 = SC_BIND_PROXY_NIL,
00384            const sc_bind_proxy& p057 = SC_BIND_PROXY_NIL,
00385            const sc_bind_proxy& p058 = SC_BIND_PROXY_NIL,
00386            const sc_bind_proxy& p059 = SC_BIND_PROXY_NIL,
00387            const sc_bind_proxy& p060 = SC_BIND_PROXY_NIL,
00388            const sc_bind_proxy& p061 = SC_BIND_PROXY_NIL,
00389            const sc_bind_proxy& p062 = SC_BIND_PROXY_NIL,
00390            const sc_bind_proxy& p063 = SC_BIND_PROXY_NIL,
00391            const sc_bind_proxy& p064 = SC_BIND_PROXY_NIL );
00392 
00393 };
00394 
00395 extern sc_module* sc_module_dynalloc(sc_module*);
00396 #define SC_NEW(x)  sc_module_dynalloc(new x);
00397 
00398 
00399 // -----------------------------------------------------------------------------
00400 // SOME MACROS TO SIMPLIFY SYNTAX:
00401 // -----------------------------------------------------------------------------
00402 
00403 #define SC_MODULE(user_module_name)                                           \
00404     struct user_module_name : sc_module
00405 
00406 #define SC_CTOR(user_module_name)                                             \
00407     typedef user_module_name SC_CURRENT_USER_MODULE;                          \
00408     user_module_name( sc_module_name )
00409 
00410 // the SC_HAS_PROCESS macro call must be followed by a ;
00411 #define SC_HAS_PROCESS(user_module_name)                                      \
00412     typedef user_module_name SC_CURRENT_USER_MODULE
00413 
00414 
00415 #define declare_method_process(handle, name, host_tag, func)                  \
00416     {   \
00417         sc_method_handle handle = simcontext()->register_method_process( name,\
00418                      SC_MAKE_FUNC_PTR( host_tag, func ), this );            \
00419         sc_module::sensitive << handle;                                       \
00420         sc_module::sensitive_pos << handle;                                   \
00421         sc_module::sensitive_neg << handle;                                   \
00422     }
00423 
00424 #define declare_thread_process(handle, name, host_tag, func)                  \
00425     {                                                       \
00426         sc_thread_handle handle = simcontext()->register_thread_process( name,\
00427                      SC_MAKE_FUNC_PTR( host_tag, func ), this );            \
00428         sc_module::sensitive << handle;                                       \
00429         sc_module::sensitive_pos << handle;                                   \
00430         sc_module::sensitive_neg << handle;                                   \
00431     }
00432 
00433 #define declare_cthread_process(handle, name, host_tag, func, edge)           \
00434     {                                                                         \
00435         sc_cthread_handle handle = simcontext()->register_cthread_process(name,\
00436                      SC_MAKE_FUNC_PTR( host_tag, func ), this );              \
00437         sc_module::sensitive.operator() ( handle, edge );                     \
00438     }
00439 
00440 #define SC_CTHREAD(func, edge)                                                \
00441     declare_cthread_process( func ## _handle,                                 \
00442                              sc_gen_unique_name(#func),                       \
00443                              SC_CURRENT_USER_MODULE,                          \
00444                              func,                                            \
00445                              edge )
00446 
00447 #define SC_METHOD(func)                                                       \
00448     declare_method_process( func ## _handle,                                  \
00449                             sc_gen_unique_name(#func),                        \
00450                             SC_CURRENT_USER_MODULE,                           \
00451                             func )
00452 
00453 #define SC_THREAD(func)                                                       \
00454     declare_thread_process( func ## _handle,                                  \
00455                             sc_gen_unique_name(#func),                        \
00456                             SC_CURRENT_USER_MODULE,                           \
00457                             func )
00458 
00459 
00460 
00461 // ----------------------------------------------------------------------------
00462 //  TYPEDEFS
00463 // ----------------------------------------------------------------------------
00464 
00465 typedef sc_module sc_channel;
00466 typedef sc_module sc_behavior;
00467 
00468 
00469 #endif

Generated on Fri Jan 14 08:29:03 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18