SystemC 3.0.0
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
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
34
35namespace sc_dt {
36
37template <class T>
38inline
39const T
40sc_min( const T& a, const T& b )
41{
42 return ( ( a <= b ) ? a : b );
43}
44
45template <class T>
46inline
47const T
48sc_max( const T& a, const T& b )
49{
50 return ( ( a >= b ) ? a : b );
51}
52
53template <class T>
54inline
55const T
56sc_abs( const T& a )
57{
58 // return ( a >= 0 ? a : -a );
59 // the code below is functionaly the same as the code above; the
60 // difference is that the code below works for all arithmetic
61 // SystemC datatypes.
62 T z( a );
63 z = 0;
64 if( a >= z ) {
65 return a;
66 } else {
67 T c( a );
68 c = -a;
69 return c;
70 }
71}
72
73} // namespace sc_dt
74
75// token stringification
76
77#define SC_STRINGIFY_HELPER_( Arg ) \
78 SC_STRINGIFY_HELPER_DEFERRED_( Arg )
79#define SC_STRINGIFY_HELPER_DEFERRED_( Arg ) \
80 SC_STRINGIFY_HELPER_MORE_DEFERRED_( Arg )
81#define SC_STRINGIFY_HELPER_MORE_DEFERRED_( Arg ) \
82 #Arg
83
84
85// token concatenation
86#define SC_CONCAT_HELPER_( a, b ) \
87 SC_CONCAT_HELPER_DEFERRED_( a, b )
88#define SC_CONCAT_HELPER_DEFERRED_( a, b ) \
89 SC_CONCAT_HELPER_MORE_DEFERRED_( a,b )
90#define SC_CONCAT_HELPER_MORE_DEFERRED_( a, b ) \
91 a ## b
92#define SC_CONCAT_UNDERSCORE_( a, b ) \
93 SC_CONCAT_HELPER_( a, SC_CONCAT_HELPER_( _, b ) )
94
95
96// forced token expansion
97#define SC_EXPAND_HELPER_(x) x
98
99/*
100 * These help debugging --
101 * -- the user can find out at which location in their source file a process calls wait.
102 */
103
104#define SC_WAIT() \
105 ::sc_core::sc_set_location( __FILE__, __LINE__ ); \
106 ::sc_core::wait(); \
107 ::sc_core::sc_set_location( NULL, 0 )
108
109#define SC_WAITN(n) \
110 ::sc_core::sc_set_location( __FILE__, __LINE__ ); \
111 ::sc_core::wait(n); \
112 ::sc_core::sc_set_location( NULL, 0 )
113
114#define SC_WAIT_UNTIL(expr) \
115 do { SC_WAIT(); } while( !(expr) )
116
117// ----------------------------------------------------------------------------
118// SC_NAMED - helper macro to create named objects
119
120#define SC_NAMED(...) \
121 SC_NAMED_IMPL_(__VA_ARGS__)(__VA_ARGS__)
122
123# define SC_NAMED_IMPL_ONE_(inst) \
124 inst { SC_STRINGIFY_HELPER_(inst) }
125# define SC_NAMED_IMPL_MORE_(inst, ...) \
126 inst { SC_STRINGIFY_HELPER_(inst), __VA_ARGS__ }
127
128#define SC_NAMED_IMPL_(...) \
129 SC_CONCAT_HELPER_(SC_NAMED_IMPL_, SC_VARARG_HELPER_EXPAND_(__VA_ARGS__))
130
131#define SC_VARARG_HELPER_EXPAND_(...) \
132 SC_EXPAND_HELPER_( SC_VARARG_HELPER_EXPAND_SEQ_( \
133 __VA_ARGS__, \
134 MORE_,MORE_,MORE_,MORE_,MORE_,MORE_,MORE_,MORE_, \
135 MORE_,MORE_,MORE_,MORE_,MORE_,MORE_,MORE_,MORE_, \
136 MORE_,MORE_,MORE_,MORE_,MORE_,MORE_,MORE_,MORE_, \
137 MORE_,MORE_,MORE_,MORE_,MORE_,MORE_,ONE_, FAIL_ ) )
138#define SC_VARARG_HELPER_EXPAND_SEQ_( \
139 _1, _2, _3, _4, _5, _6, _7, _8, \
140 _9,_10,_11,_12,_13,_14,_15,_16, \
141 _17,_18,_19,_20,_21,_22,_23,_24, \
142 _25,_26,_27,_28,_29,_30,_31, N, ...) N
143
144// $Log: sc_macros.h,v $
145// Revision 1.5 2011/08/26 20:46:09 acg
146// Andy Goodrich: moved the modification log to the end of the file to
147// eliminate source line number skew when check-ins are done.
148//
149// Revision 1.4 2011/02/18 20:27:14 acg
150// Andy Goodrich: Updated Copyrights.
151//
152// Revision 1.3 2011/02/13 21:47:37 acg
153// Andy Goodrich: update copyright notice.
154//
155// Revision 1.2 2008/05/22 17:06:25 acg
156// Andy Goodrich: updated copyright notice to include 2008.
157//
158// Revision 1.1.1.1 2006/12/15 20:20:05 acg
159// SystemC 2.3
160//
161// Revision 1.3 2006/01/13 18:44:29 acg
162// Added $Log to record CVS changes into the source.
163
164#endif
const T sc_min(const T &a, const T &b)
Definition: sc_macros.h:40
const T sc_abs(const T &a)
Definition: sc_macros.h:56
const T sc_max(const T &a, const T &b)
Definition: sc_macros.h:48
uint64 const sc_uint_base int b
Definition: sc_fxval.h:955