v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
macros.h
1 /* -*- mode: C; c-basic-offset: 4; intent-tabs-mode: nil -*-
2  *
3  * This file is part of the public interface to the Sifteo SDK.
4  * Copyright <c> 2012 Sifteo, Inc. All rights reserved.
5  */
6 
7 #pragma once
8 #ifdef NOT_USERSPACE
9 # error This is a userspace-only header, not allowed by the current build.
10 #endif
11 
12 #include <sifteo/abi.h>
13 
40 #define NOINLINE __attribute__ ((noinline))
41 
57 #define ALWAYS_INLINE __attribute__ ((always_inline))
58 
61 #define STRINGIFY(_x) #_x
62 
71 #define TOSTRING(_x) STRINGIFY(_x)
72 
75 #define SRCLINE __FILE__ ":" TOSTRING(__LINE__)
76 
98 #define DEBUG_ONLY(_x) \
99 do { \
100  if (_SYS_lti_isDebug()) { \
101  _x \
102  } \
103 } while (0)
104 
105 #ifdef NO_LOG
106 # define LOG(...)
107 #else
108 
160 # define LOG(...) \
161 do { \
162  if (_SYS_lti_isDebug()) \
163  _SYS_lti_log(__VA_ARGS__); \
164 } while (0)
165 #endif
166 
167 #ifdef NO_ASSERT
168 # define ASSERT(_x)
169 #else
170 
186 # define ASSERT(_x) \
187 do { \
188  if (_SYS_lti_isDebug() && !(_x)) { \
189  _SYS_lti_log("ASSERT failure at %s:%d, (%s)\n", __FILE__, __LINE__, #_x); \
190  _SYS_abort(); \
191  } \
192 } while (0)
193 #endif
194 
208 #define SCRIPT_TYPE(_type) \
209 do { \
210  _SYS_log((_SYS_SCRIPT_ ## _type) | (_SYS_LOGTYPE_SCRIPT << 27), \
211  0,0,0,0,0,0,0); \
212 } while (0)
213 
247 #define SCRIPT(_type, _code) \
248 do { \
249  if (_SYS_lti_isDebug()) { \
250  SCRIPT_TYPE(_type); \
251  _SYS_lti_log("%s", #_code); \
252  SCRIPT_TYPE(NONE); \
253  } \
254 } while (0)
255 
284 #define SCRIPT_FMT(_type, ...) \
285 do { \
286  if (_SYS_lti_isDebug()) { \
287  SCRIPT_TYPE(_type); \
288  _SYS_lti_log(__VA_ARGS__); \
289  SCRIPT_TYPE(NONE); \
290  } \
291 } while (0)
292 
295 #define LOG_INT(_x) LOG("%s = %d\n", #_x, (_x));
296 
299 #define LOG_HEX(_x) LOG("%s = 0x%08x\n", #_x, (_x));
300 
303 #define LOG_FLOAT(_x) LOG("%s = %f\n", #_x, (_x));
304 
307 #define LOG_STR(_x) LOG("%s = \"%s\"\n", #_x, (const char*)(_x));
308 
311 #define LOG_INT2(_x) LOG("%s = (%d, %d)\n", #_x, (_x).x, (_x).y);
312 
315 #define LOG_INT3(_x) LOG("%s = (%d, %d, %d)\n", #_x, (_x).x, (_x).y, (_x).z);
316 
319 #define LOG_FLOAT2(_x) LOG("%s = (%f, %f)\n", #_x, (_x).x, (_x).y);
320 
323 #define STATIC_ASSERT(_x) ((void)sizeof(char[1 - 2*!(_x)]))
324 
325 #ifndef MIN
326 
327 
328 #define MIN(a,b) ((a) < (b) ? (a) : (b))
329 
330 
331 #define MAX(a,b) ((a) > (b) ? (a) : (b))
332 #endif
333 
334 #ifndef NULL
335 
336 
337 #define NULL 0
338 #endif
339 
340 #ifndef arraysize
341 
342 
343 #define arraysize(a) (sizeof(a) / sizeof((a)[0]))
344 #endif
345 
346 #ifndef offsetof
347 
348 
349 #define offsetof(t,m) ((uintptr_t)(uint8_t*)&(((t*)0)->m))
350 #endif
351