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-2006 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 // $Log: sc_macros.h,v $
00037 // Revision 1.1.1.1  2006/12/15 20:31:37  acg
00038 // SystemC 2.2
00039 //
00040 // Revision 1.3  2006/01/13 18:44:29  acg
00041 // Added $Log to record CVS changes into the source.
00042 //
00043 
00044 #ifndef SC_MACROS_H
00045 #define SC_MACROS_H
00046 
00047 
00048 namespace sc_dt {
00049 
00050 template <class T>
00051 inline
00052 const T
00053 sc_min( 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_max( const T& a, const T& b )
00062 {
00063     return ( ( a >= b ) ? a : b );
00064 }
00065 
00066 template <class T>
00067 inline
00068 const T
00069 sc_abs( const T& a )
00070 {
00071     // return ( a >= 0 ? a : -a );
00072     // the code below is functionaly the same as the code above; the
00073     // difference is that the code below works for all arithmetic
00074     // SystemC datatypes.
00075     T z( a );
00076     z = 0;
00077     if( a >= z ) {
00078     return a;
00079     } else {
00080     T c( a );
00081     c = -a;
00082     return c;
00083     }
00084 }
00085 
00086 } // namespace sc_dt 
00087 
00088 namespace sc_core {
00089 
00090 
00091 #if defined(__GNUC__) && defined(USE_RTTI)
00092 #define HAVE_CAST_OPERATORS
00093 #endif
00094 
00095 
00096 #if defined(__GNUC__)
00097 // 10.3.5 - Some compilers (e.g. K&A C++) do not support the
00098 // construct in which a virtual function defined in a subclass returns
00099 // a pointer or reference to a class D whereas the declaration of the
00100 // same virtual function in the base class returns a pointer or
00101 // reference to a base class B of D.
00102 #define ANSI_VIRTUAL_RETURN_INHERITED_TYPE
00103 #endif
00104 
00105 
00106 /*
00107  *  Note that sc_get_curr_simcontext() may also be a member
00108  *  of sc_module. The idea is that if we are inside an sc_module,
00109  *  then its associated simcontext should always be the current
00110  *  simcontext.
00111  */
00112 
00113 #define W_BEGIN                                                               \
00114     do {                                                                      \
00115         sc_watch __aux_watch( sc_get_curr_simcontext() );
00116 
00117 #define W_DO                                                                  \
00118         try {                                                                 \
00119             __watching_first( __aux_watch.cthread_h );
00120 
00121 #define W_ESCAPE                                                              \
00122         }                                                                     \
00123         catch( int sc_level ) {                                               \
00124             __sanitycheck_watchlists( __aux_watch.cthread_h );                \
00125             if( sc_level < __watch_level( __aux_watch.cthread_h ) ) {         \
00126                 throw sc_level;                                               \
00127             }
00128 
00129 #define W_END                                                                 \
00130         }                                                                     \
00131     } while( false );
00132 
00133 
00134 /*
00135  *  These help debugging --
00136  *  -- user can find out where each process is stopped at.
00137  */
00138 
00139 #define WAIT()                                                                \
00140     sc_set_location( __FILE__, __LINE__ );                                    \
00141     wait()
00142 
00143 #define WAITN(n)                                                              \
00144     sc_set_location( __FILE__, __LINE__ );                                    \
00145     wait(n)
00146 
00147 #define WAIT_UNTIL(expr)                                                    \
00148     sc_set_location( __FILE__, __LINE__ );                                    \
00149     do { wait(); } while( !(expr) )
00150 
00151 } // namespace sc_core
00152 
00153 #endif

Generated on Wed Jan 21 15:32:09 2009 for SystemC by  doxygen 1.5.5