src/sysc/kernel/sc_macros.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-2005 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.4 (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_macros.h -- Miscellaneous definitions that are needed by the headers.
00021 
00022   Original Author: Stan Y. Liao, Synopsys, Inc.
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date:
00032   Description of Modification:
00033 
00034  *****************************************************************************/
00035 
00036 #ifndef SC_MACROS_H
00037 #define SC_MACROS_H
00038 
00039 
00040 namespace sc_dt {
00041 
00042 template <class T>
00043 inline
00044 const T
00045 sc_min( const T& a, const T& b )
00046 {
00047     return ( ( a <= b ) ? a : b );
00048 }
00049 
00050 template <class T>
00051 inline
00052 const T
00053 sc_max( const T& a, const T& b )
00054 {
00055     return ( ( a >= b ) ? a : b );
00056 }
00057 
00058 template <class T>
00059 inline
00060 const T
00061 sc_abs( const T& a )
00062 {
00063     // return ( a >= 0 ? a : -a );
00064     // the code below is functionaly the same as the code above; the
00065     // difference is that the code below works for all arithmetic
00066     // SystemC datatypes.
00067     T z( a );
00068     z = 0;
00069     if( a >= z ) {
00070         return a;
00071     } else {
00072         T c( a );
00073         c = -a;
00074         return c;
00075     }
00076 }
00077 
00078 } // namespace sc_dt 
00079 
00080 namespace sc_core {
00081 
00082 
00083 #if defined(__GNUC__) && defined(USE_RTTI)
00084 #define HAVE_CAST_OPERATORS
00085 #endif
00086 
00087 
00088 #if defined(__GNUC__)
00089 // 10.3.5 - Some compilers (e.g. K&A C++) do not support the
00090 // construct in which a virtual function defined in a subclass returns
00091 // a pointer or reference to a class D whereas the declaration of the
00092 // same virtual function in the base class returns a pointer or
00093 // reference to a base class B of D.
00094 #define ANSI_VIRTUAL_RETURN_INHERITED_TYPE
00095 #endif
00096 
00097 
00098 /*
00099  *  Note that sc_get_curr_simcontext() may also be a member
00100  *  of sc_module. The idea is that if we are inside an sc_module,
00101  *  then its associated simcontext should always be the current
00102  *  simcontext.
00103  */
00104 
00105 #define W_BEGIN                                                               \
00106     do {                                                                      \
00107         sc_watch __aux_watch( sc_get_curr_simcontext() );
00108 
00109 #define W_DO                                                                  \
00110         try {                                                                 \
00111             __watching_first( __aux_watch.cthread_h );
00112 
00113 #define W_ESCAPE                                                              \
00114         }                                                                     \
00115         catch( int sc_level ) {                                               \
00116             __sanitycheck_watchlists( __aux_watch.cthread_h );                \
00117             if( sc_level < __watch_level( __aux_watch.cthread_h ) ) {         \
00118                 throw sc_level;                                               \
00119             }
00120 
00121 #define W_END                                                                 \
00122         }                                                                     \
00123     } while( false );
00124 
00125 
00126 /*
00127  *  These help debugging --
00128  *  -- user can find out where each process is stopped at.
00129  */
00130 
00131 #define WAIT()                                                                \
00132     sc_set_location( __FILE__, __LINE__ );                                    \
00133     wait()
00134 
00135 #define WAITN(n)                                                              \
00136     sc_set_location( __FILE__, __LINE__ );                                    \
00137     wait(n)
00138 
00139 #define WAIT_UNTIL(lambda)                                                    \
00140     sc_set_location( __FILE__, __LINE__ );                                    \
00141     wait_until( lambda )
00142 
00143 } // namespace sc_core
00144 
00145 #endif

Generated on Wed Apr 25 13:53:27 2007 for SystemC by  doxygen 1.5.1