Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2007-2008 VMware, Inc.
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21.  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  22.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27.  
  28. #ifndef P_COMPILER_H
  29. #define P_COMPILER_H
  30.  
  31.  
  32. #include "c99_compat.h" /* inline, __func__, etc. */
  33.  
  34. #include "p_config.h"
  35.  
  36. #include "util/macros.h"
  37.  
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <stddef.h>
  41. #include <stdarg.h>
  42. #include <limits.h>
  43.  
  44.  
  45. #if defined(_WIN32) && !defined(__WIN32__)
  46. #define __WIN32__
  47. #endif
  48.  
  49. #if defined(_MSC_VER)
  50.  
  51. /* Avoid 'expression is always true' warning */
  52. #pragma warning(disable: 4296)
  53.  
  54. #endif /* _MSC_VER */
  55.  
  56.  
  57. /*
  58.  * Alternative stdint.h and stdbool.h headers are supplied in include/c99 for
  59.  * systems that lack it.
  60.  */
  61. #ifndef __STDC_LIMIT_MACROS
  62. #define __STDC_LIMIT_MACROS 1
  63. #endif
  64. #include <stdint.h>
  65. #include <stdbool.h>
  66.  
  67.  
  68. #ifdef __cplusplus
  69. extern "C" {
  70. #endif
  71.  
  72.  
  73. #if !defined(__HAIKU__) && !defined(__USE_MISC)
  74. #if !defined(PIPE_OS_ANDROID)
  75. typedef unsigned int       uint;
  76. #endif
  77. typedef unsigned short     ushort;
  78. #endif
  79. typedef unsigned char      ubyte;
  80.  
  81. typedef unsigned char boolean;
  82. #ifndef TRUE
  83. #define TRUE  true
  84. #endif
  85. #ifndef FALSE
  86. #define FALSE false
  87. #endif
  88.  
  89. #ifndef va_copy
  90. #ifdef __va_copy
  91. #define va_copy(dest, src) __va_copy((dest), (src))
  92. #else
  93. #define va_copy(dest, src) (dest) = (src)
  94. #endif
  95. #endif
  96.  
  97. /* XXX: Use standard `inline` keyword instead */
  98. #ifndef INLINE
  99. #  define INLINE inline
  100. #endif
  101.  
  102. /* Forced function inlining */
  103. #ifndef ALWAYS_INLINE
  104. #  ifdef __GNUC__
  105. #    define ALWAYS_INLINE inline __attribute__((always_inline))
  106. #  elif defined(_MSC_VER)
  107. #    define ALWAYS_INLINE __forceinline
  108. #  else
  109. #    define ALWAYS_INLINE INLINE
  110. #  endif
  111. #endif
  112.  
  113.  
  114. /* XXX: Use standard `__func__` instead */
  115. #ifndef __FUNCTION__
  116. #  define __FUNCTION__ __func__
  117. #endif
  118.  
  119.  
  120. /* This should match linux gcc cdecl semantics everywhere, so that we
  121.  * just codegen one calling convention on all platforms.
  122.  */
  123. #ifdef _MSC_VER
  124. #define PIPE_CDECL __cdecl
  125. #else
  126. #define PIPE_CDECL
  127. #endif
  128.  
  129.  
  130.  
  131. #if defined(__GNUC__)
  132. #define PIPE_DEPRECATED  __attribute__((__deprecated__))
  133. #else
  134. #define PIPE_DEPRECATED
  135. #endif
  136.  
  137.  
  138.  
  139. /* Macros for data alignment. */
  140. #if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) || defined(__SUNPRO_CC)
  141.  
  142. /* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Type-Attributes.html */
  143. #define PIPE_ALIGN_TYPE(_alignment, _type) _type __attribute__((aligned(_alignment)))
  144.  
  145. /* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Variable-Attributes.html */
  146. #define PIPE_ALIGN_VAR(_alignment) __attribute__((aligned(_alignment)))
  147.  
  148. #if defined(__GNUC__) && !defined(PIPE_ARCH_X86_64)
  149. #define PIPE_ALIGN_STACK __attribute__((force_align_arg_pointer))
  150. #else
  151. #define PIPE_ALIGN_STACK
  152. #endif
  153.  
  154. #elif defined(_MSC_VER)
  155.  
  156. /* See http://msdn.microsoft.com/en-us/library/83ythb65.aspx */
  157. #define PIPE_ALIGN_TYPE(_alignment, _type) __declspec(align(_alignment)) _type
  158. #define PIPE_ALIGN_VAR(_alignment) __declspec(align(_alignment))
  159.  
  160. #define PIPE_ALIGN_STACK
  161.  
  162. #elif defined(SWIG)
  163.  
  164. #define PIPE_ALIGN_TYPE(_alignment, _type) _type
  165. #define PIPE_ALIGN_VAR(_alignment)
  166.  
  167. #define PIPE_ALIGN_STACK
  168.  
  169. #else
  170.  
  171. #error "Unsupported compiler"
  172.  
  173. #endif
  174.  
  175.  
  176. #if defined(__GNUC__)
  177.  
  178. #define PIPE_READ_WRITE_BARRIER() __asm__("":::"memory")
  179.  
  180. #elif defined(_MSC_VER)
  181.  
  182. void _ReadWriteBarrier(void);
  183. #pragma intrinsic(_ReadWriteBarrier)
  184. #define PIPE_READ_WRITE_BARRIER() _ReadWriteBarrier()
  185.  
  186. #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
  187.  
  188. #define PIPE_READ_WRITE_BARRIER() __machine_rw_barrier()
  189.  
  190. #else
  191.  
  192. #warning "Unsupported compiler"
  193. #define PIPE_READ_WRITE_BARRIER() /* */
  194.  
  195. #endif
  196.  
  197. #if defined(__cplusplus)
  198. }
  199. #endif
  200.  
  201.  
  202. #endif /* P_COMPILER_H */
  203.