SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_macros.h
Go to the documentation of this file.
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 */
34 #ifndef SC_MACROS_H
35 #define SC_MACROS_H
36 
37 
38 namespace sc_dt {
39 
40 template <class T>
41 inline
42 const T
43 sc_min( const T& a, const T& b )
44 {
45  return ( ( a <= b ) ? a : b );
46 }
47 
48 template <class T>
49 inline
50 const T
51 sc_max( const T& a, const T& b )
52 {
53  return ( ( a >= b ) ? a : b );
54 }
55 
56 template <class T>
57 inline
58 const T
59 sc_abs( const T& a )
60 {
61  // return ( a >= 0 ? a : -a );
62  // the code below is functionaly the same as the code above; the
63  // difference is that the code below works for all arithmetic
64  // SystemC datatypes.
65  T z( a );
66  z = 0;
67  if( a >= z ) {
68  return a;
69  } else {
70  T c( a );
71  c = -a;
72  return c;
73  }
74 }
75 
76 } // namespace sc_dt
77 
78 namespace sc_core {
79 
80 // token stringification
81 
83 #define SC_STRINGIFY_HELPER_( Arg ) \
84  SC_STRINGIFY_HELPER_DEFERRED_( Arg )
85 
86 #define SC_STRINGIFY_HELPER_DEFERRED_( Arg ) \
87  SC_STRINGIFY_HELPER_MORE_DEFERRED_( Arg )
88 
89 #define SC_STRINGIFY_HELPER_MORE_DEFERRED_( Arg ) \
90  #Arg
91 
92 
93 // token concatenation
95 #define SC_CONCAT_HELPER_( a, b ) \
96  SC_CONCAT_HELPER_DEFERRED_( a, b )
97 
98 #define SC_CONCAT_HELPER_DEFERRED_( a, b ) \
99  SC_CONCAT_HELPER_MORE_DEFERRED_( a,b )
100 
101 #define SC_CONCAT_HELPER_MORE_DEFERRED_( a, b ) \
102  a ## b
103 
104 #define SC_CONCAT_UNDERSCORE_( a, b ) \
105  SC_CONCAT_HELPER_( a, SC_CONCAT_HELPER_( _, b ) )
106 
107 /*
108  * These help debugging --
109  * -- the user can find out at which location in their source file a process calls wait.
110  */
111 
113 #define SC_WAIT() \
114  ::sc_core::sc_set_location( __FILE__, __LINE__ ); \
115  ::sc_core::wait(); \
116  ::sc_core::sc_set_location( NULL, 0 )
117 
119 #define SC_WAITN(n) \
120  ::sc_core::sc_set_location( __FILE__, __LINE__ ); \
121  ::sc_core::wait(n); \
122  ::sc_core::sc_set_location( NULL, 0 )
123 
125 #define SC_WAIT_UNTIL(expr) \
126  do { SC_WAIT(); } while( !(expr) )
127 
128 } // namespace sc_core
129 
130 // $Log: sc_macros.h,v $
131 // Revision 1.5 2011/08/26 20:46:09 acg
132 // Andy Goodrich: moved the modification log to the end of the file to
133 // eliminate source line number skew when check-ins are done.
134 //
135 // Revision 1.4 2011/02/18 20:27:14 acg
136 // Andy Goodrich: Updated Copyrights.
137 //
138 // Revision 1.3 2011/02/13 21:47:37 acg
139 // Andy Goodrich: update copyright notice.
140 //
141 // Revision 1.2 2008/05/22 17:06:25 acg
142 // Andy Goodrich: updated copyright notice to include 2008.
143 //
144 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
145 // SystemC 2.3
146 //
147 // Revision 1.3 2006/01/13 18:44:29 acg
148 // Added $Log to record CVS changes into the source.
149 
150 #endif
const T sc_min(const T &a, const T &b)
Definition: sc_macros.h:43
const T sc_max(const T &a, const T &b)
Definition: sc_macros.h:51
const T sc_abs(const T &a)
Definition: sc_macros.h:59
uint64 const sc_uint_base int b
Definition: sc_fxval.h:1005