sc_macros.h revision 12027
1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 sc_macros.h -- Miscellaneous definitions that are needed by the headers. 23 24 Original Author: Stan Y. Liao, Synopsys, Inc. 25 26 CHANGE LOG AT THE END OF THE FILE 27 *****************************************************************************/ 28 29 30#ifndef SC_MACROS_H 31#define SC_MACROS_H 32 33 34namespace sc_dt { 35 36template <class T> 37inline 38const T 39sc_min( const T& a, const T& b ) 40{ 41 return ( ( a <= b ) ? a : b ); 42} 43 44template <class T> 45inline 46const T 47sc_max( const T& a, const T& b ) 48{ 49 return ( ( a >= b ) ? a : b ); 50} 51 52template <class T> 53inline 54const T 55sc_abs( const T& a ) 56{ 57 // return ( a >= 0 ? a : -a ); 58 // the code below is functionaly the same as the code above; the 59 // difference is that the code below works for all arithmetic 60 // SystemC datatypes. 61 T z( a ); 62 z = 0; 63 if( a >= z ) { 64 return a; 65 } else { 66 T c( a ); 67 c = -a; 68 return c; 69 } 70} 71 72} // namespace sc_dt 73 74namespace sc_core { 75 76// token stringification 77 78#define SC_STRINGIFY_HELPER_( Arg ) \ 79 SC_STRINGIFY_HELPER_DEFERRED_( Arg ) 80#define SC_STRINGIFY_HELPER_DEFERRED_( Arg ) \ 81 SC_STRINGIFY_HELPER_MORE_DEFERRED_( Arg ) 82#define SC_STRINGIFY_HELPER_MORE_DEFERRED_( Arg ) \ 83 #Arg 84 85 86// token concatenation 87 88#define SC_CONCAT_HELPER_( a, b ) \ 89 SC_CONCAT_HELPER_DEFERRED_( a, b ) 90#define SC_CONCAT_HELPER_DEFERRED_( a, b ) \ 91 SC_CONCAT_HELPER_MORE_DEFERRED_( a,b ) 92#define SC_CONCAT_HELPER_MORE_DEFERRED_( a, b ) \ 93 a ## b 94#define SC_CONCAT_UNDERSCORE_( a, b ) \ 95 SC_CONCAT_HELPER_( a, SC_CONCAT_HELPER_( _, b ) ) 96 97/* 98 * These help debugging -- 99 * -- user can find out where each process is stopped at. 100 */ 101 102#define WAIT() \ 103 ::sc_core::sc_set_location( __FILE__, __LINE__ ); \ 104 ::sc_core::wait() 105 106#define WAITN(n) \ 107 ::sc_core::sc_set_location( __FILE__, __LINE__ ); \ 108 ::sc_core::wait(n) 109 110#define WAIT_UNTIL(expr) \ 111 ::sc_core::sc_set_location( __FILE__, __LINE__ ); \ 112 do { ::sc_core::wait(); } while( !(expr) ) 113 114} // namespace sc_core 115 116// $Log: sc_macros.h,v $ 117// Revision 1.5 2011/08/26 20:46:09 acg 118// Andy Goodrich: moved the modification log to the end of the file to 119// eliminate source line number skew when check-ins are done. 120// 121// Revision 1.4 2011/02/18 20:27:14 acg 122// Andy Goodrich: Updated Copyrights. 123// 124// Revision 1.3 2011/02/13 21:47:37 acg 125// Andy Goodrich: update copyright notice. 126// 127// Revision 1.2 2008/05/22 17:06:25 acg 128// Andy Goodrich: updated copyright notice to include 2008. 129// 130// Revision 1.1.1.1 2006/12/15 20:20:05 acg 131// SystemC 2.3 132// 133// Revision 1.3 2006/01/13 18:44:29 acg 134// Added $Log to record CVS changes into the source. 135 136#endif 137