abi.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /*============================================================================
  2. Kitware Information Macro Library
  3. Copyright 2010-2018 Kitware, Inc.
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions
  7. are met:
  8. * Redistributions of source code must retain the above copyright
  9. notice, this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in the
  12. documentation and/or other materials provided with the distribution.
  13. * Neither the name of Kitware, Inc. nor the names of its contributors
  14. may be used to endorse or promote products derived from this
  15. software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  20. HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. ============================================================================*/
  28. /*
  29. This header defines macros with information about the C ABI.
  30. Only information that can be determined using the preprocessor at
  31. compilation time is available. No try-compile results may be added
  32. here. Instead we memorize results on platforms of interest.
  33. An includer may optionally define the following macros to suppress errors:
  34. KWIML_ABI_NO_VERIFY = skip verification declarations
  35. KWIML_ABI_NO_ERROR_CHAR_SIGN = signedness of 'char' may be unknown
  36. KWIML_ABI_NO_ERROR_LONG_LONG = existence of 'long long' may be unknown
  37. KWIML_ABI_NO_ERROR_ENDIAN = byte order of CPU may be unknown
  38. An includer may test the following macros after inclusion:
  39. KWIML_ABI_VERSION = interface version number # of this header
  40. KWIML_ABI_SIZEOF_DATA_PTR = sizeof(void*)
  41. KWIML_ABI_SIZEOF_CODE_PTR = sizeof(void(*)(void))
  42. KWIML_ABI_SIZEOF_FLOAT = sizeof(float)
  43. KWIML_ABI_SIZEOF_DOUBLE = sizeof(double)
  44. KWIML_ABI_SIZEOF_CHAR = sizeof(char)
  45. KWIML_ABI_SIZEOF_SHORT = sizeof(short)
  46. KWIML_ABI_SIZEOF_INT = sizeof(int)
  47. KWIML_ABI_SIZEOF_LONG = sizeof(long)
  48. KWIML_ABI_SIZEOF_LONG_LONG = sizeof(long long) or 0 if not a type
  49. Undefined if existence is unknown and error suppression macro
  50. KWIML_ABI_NO_ERROR_LONG_LONG was defined.
  51. KWIML_ABI_SIZEOF___INT64 = 8 if '__int64' exists or 0 if not
  52. Undefined if existence is unknown.
  53. KWIML_ABI___INT64_IS_LONG = 1 if '__int64' is 'long' (same type)
  54. Undefined otherwise.
  55. KWIML_ABI___INT64_IS_LONG_LONG = 1 if '__int64' is 'long long' (same type)
  56. Undefined otherwise.
  57. KWIML_ABI___INT64_IS_UNIQUE = 1 if '__int64' is a distinct type
  58. Undefined otherwise.
  59. KWIML_ABI_CHAR_IS_UNSIGNED = 1 if 'char' is unsigned, else undefined
  60. KWIML_ABI_CHAR_IS_SIGNED = 1 if 'char' is signed, else undefined
  61. One of these is defined unless signedness of 'char' is unknown and
  62. error suppression macro KWIML_ABI_NO_ERROR_CHAR_SIGN was defined.
  63. KWIML_ABI_ENDIAN_ID_BIG = id for big-endian (always defined)
  64. KWIML_ABI_ENDIAN_ID_LITTLE = id for little-endian (always defined)
  65. KWIML_ABI_ENDIAN_ID = id of byte order of target CPU
  66. Defined to KWIML_ABI_ENDIAN_ID_BIG or KWIML_ABI_ENDIAN_ID_LITTLE
  67. unless byte order is unknown and error suppression macro
  68. KWIML_ABI_NO_ERROR_ENDIAN was defined.
  69. We verify most results using dummy "extern" declarations that are
  70. invalid if the macros are wrong. Verification is disabled if
  71. suppression macro KWIML_ABI_NO_VERIFY was defined.
  72. */
  73. #define KWIML_ABI_private_VERSION 1
  74. /* Guard definition of this version. */
  75. #ifndef KWIML_ABI_detail_DEFINED_VERSION_1
  76. # define KWIML_ABI_detail_DEFINED_VERSION_1 1
  77. # define KWIML_ABI_private_DO_DEFINE
  78. #endif
  79. /* Guard verification of this version. */
  80. #if !defined(KWIML_ABI_NO_VERIFY)
  81. # ifndef KWIML_ABI_detail_VERIFIED_VERSION_1
  82. # define KWIML_ABI_detail_VERIFIED_VERSION_1
  83. # define KWIML_ABI_private_DO_VERIFY
  84. # endif
  85. #endif
  86. #ifdef KWIML_ABI_private_DO_DEFINE
  87. #undef KWIML_ABI_private_DO_DEFINE
  88. /* Define version as most recent of those included. */
  89. #if !defined(KWIML_ABI_VERSION) || KWIML_ABI_VERSION < KWIML_ABI_private_VERSION
  90. # undef KWIML_ABI_VERSION
  91. # define KWIML_ABI_VERSION 1
  92. #endif
  93. /*--------------------------------------------------------------------------*/
  94. #if !defined(KWIML_ABI_SIZEOF_DATA_PTR)
  95. # if defined(__SIZEOF_POINTER__)
  96. # define KWIML_ABI_SIZEOF_DATA_PTR __SIZEOF_POINTER__
  97. # elif defined(_SIZE_PTR)
  98. # define KWIML_ABI_SIZEOF_DATA_PTR (_SIZE_PTR >> 3)
  99. # elif defined(_LP64) || defined(__LP64__)
  100. # define KWIML_ABI_SIZEOF_DATA_PTR 8
  101. # elif defined(_ILP32)
  102. # define KWIML_ABI_SIZEOF_DATA_PTR 4
  103. # elif defined(__64BIT__) /* IBM XL */
  104. # define KWIML_ABI_SIZEOF_DATA_PTR 8
  105. # elif defined(_M_X64)
  106. # define KWIML_ABI_SIZEOF_DATA_PTR 8
  107. # elif defined(__ia64)
  108. # define KWIML_ABI_SIZEOF_DATA_PTR 8
  109. # elif defined(__sparcv9)
  110. # define KWIML_ABI_SIZEOF_DATA_PTR 8
  111. # elif defined(__x86_64) || defined(__x86_64__)
  112. # define KWIML_ABI_SIZEOF_DATA_PTR 8
  113. # elif defined(__amd64) || defined(__amd64__)
  114. # define KWIML_ABI_SIZEOF_DATA_PTR 8
  115. # elif defined(__i386) || defined(__i386__)
  116. # define KWIML_ABI_SIZEOF_DATA_PTR 4
  117. # elif defined(_M_ARM64)
  118. # define KWIML_ABI_SIZEOF_DATA_PTR 8
  119. # endif
  120. #endif
  121. #if !defined(KWIML_ABI_SIZEOF_DATA_PTR)
  122. # define KWIML_ABI_SIZEOF_DATA_PTR 4
  123. #endif
  124. #if !defined(KWIML_ABI_SIZEOF_CODE_PTR)
  125. # define KWIML_ABI_SIZEOF_CODE_PTR KWIML_ABI_SIZEOF_DATA_PTR
  126. #endif
  127. /*--------------------------------------------------------------------------*/
  128. #if !defined(KWIML_ABI_SIZEOF_CHAR)
  129. # define KWIML_ABI_SIZEOF_CHAR 1
  130. #endif
  131. #if !defined(KWIML_ABI_CHAR_IS_UNSIGNED) && !defined(KWIML_ABI_CHAR_IS_SIGNED)
  132. # if defined(__CHAR_UNSIGNED__) /* GNU, some IBM XL, others? */
  133. # define KWIML_ABI_CHAR_IS_UNSIGNED 1
  134. # elif defined(_CHAR_UNSIGNED) /* Intel, IBM XL, MSVC, Borland, others? */
  135. # define KWIML_ABI_CHAR_IS_UNSIGNED 1
  136. # elif defined(_CHAR_SIGNED) /* IBM XL, others? */
  137. # define KWIML_ABI_CHAR_IS_SIGNED 1
  138. # elif defined(__CHAR_SIGNED__) /* IBM XL, Watcom, others? */
  139. # define KWIML_ABI_CHAR_IS_SIGNED 1
  140. # elif defined(__SIGNED_CHARS__) /* EDG, Intel, SGI MIPSpro */
  141. # define KWIML_ABI_CHAR_IS_SIGNED 1
  142. # elif defined(_CHAR_IS_SIGNED) /* Some SunPro, others? */
  143. # define KWIML_ABI_CHAR_IS_SIGNED 1
  144. # elif defined(_CHAR_IS_UNSIGNED) /* SunPro, others? */
  145. # define KWIML_ABI_CHAR_IS_UNSIGNED 1
  146. # elif defined(__GNUC__) /* GNU default */
  147. # define KWIML_ABI_CHAR_IS_SIGNED 1
  148. # elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* SunPro default */
  149. # define KWIML_ABI_CHAR_IS_SIGNED 1
  150. # elif defined(__HP_cc) || defined(__HP_aCC) /* HP default (unless +uc) */
  151. # define KWIML_ABI_CHAR_IS_SIGNED 1
  152. # elif defined(_SGI_COMPILER_VERSION) /* SGI MIPSpro default */
  153. # define KWIML_ABI_CHAR_IS_UNSIGNED 1
  154. # elif defined(__PGIC__) /* PGI default */
  155. # define KWIML_ABI_CHAR_IS_SIGNED 1
  156. # elif defined(_MSC_VER) /* MSVC default */
  157. # define KWIML_ABI_CHAR_IS_SIGNED 1
  158. # elif defined(__WATCOMC__) /* Watcom default */
  159. # define KWIML_ABI_CHAR_IS_UNSIGNED 1
  160. # elif defined(__BORLANDC__) /* Borland default */
  161. # define KWIML_ABI_CHAR_IS_SIGNED 1
  162. # elif defined(__hpux) /* Old HP: no __HP_cc/__HP_aCC/__GNUC__ above */
  163. # define KWIML_ABI_CHAR_IS_SIGNED 1 /* (unless +uc) */
  164. # endif
  165. #endif
  166. #if !defined(KWIML_ABI_CHAR_IS_UNSIGNED) && !defined(KWIML_ABI_CHAR_IS_SIGNED) \
  167. && !defined(KWIML_ABI_NO_ERROR_CHAR_SIGN)
  168. # error "Signedness of 'char' unknown."
  169. #endif
  170. /*--------------------------------------------------------------------------*/
  171. #if !defined(KWIML_ABI_SIZEOF_SHORT)
  172. # if defined(__SIZEOF_SHORT__)
  173. # define KWIML_ABI_SIZEOF_SHORT __SIZEOF_SHORT__
  174. # endif
  175. #endif
  176. #if !defined(KWIML_ABI_SIZEOF_SHORT)
  177. # define KWIML_ABI_SIZEOF_SHORT 2
  178. #endif
  179. /*--------------------------------------------------------------------------*/
  180. #if !defined(KWIML_ABI_SIZEOF_INT)
  181. # if defined(__SIZEOF_INT__)
  182. # define KWIML_ABI_SIZEOF_INT __SIZEOF_INT__
  183. # elif defined(_SIZE_INT)
  184. # define KWIML_ABI_SIZEOF_INT (_SIZE_INT >> 3)
  185. # endif
  186. #endif
  187. #if !defined(KWIML_ABI_SIZEOF_INT)
  188. # define KWIML_ABI_SIZEOF_INT 4
  189. #endif
  190. /*--------------------------------------------------------------------------*/
  191. #if !defined(KWIML_ABI_SIZEOF_LONG)
  192. # if defined(__SIZEOF_LONG__)
  193. # define KWIML_ABI_SIZEOF_LONG __SIZEOF_LONG__
  194. # elif defined(_SIZE_LONG)
  195. # define KWIML_ABI_SIZEOF_LONG (_SIZE_LONG >> 3)
  196. # elif defined(__LONG_MAX__)
  197. # if __LONG_MAX__ == 0x7fffffff
  198. # define KWIML_ABI_SIZEOF_LONG 4
  199. # elif __LONG_MAX__>>32 == 0x7fffffff
  200. # define KWIML_ABI_SIZEOF_LONG 8
  201. # endif
  202. # elif defined(_MSC_VER) /* MSVC and Intel on Windows */
  203. # define KWIML_ABI_SIZEOF_LONG 4
  204. # endif
  205. #endif
  206. #if !defined(KWIML_ABI_SIZEOF_LONG)
  207. # define KWIML_ABI_SIZEOF_LONG KWIML_ABI_SIZEOF_DATA_PTR
  208. #endif
  209. /*--------------------------------------------------------------------------*/
  210. #if !defined(KWIML_ABI_SIZEOF_LONG_LONG)
  211. # if defined(__SIZEOF_LONG_LONG__)
  212. # define KWIML_ABI_SIZEOF_LONG_LONG __SIZEOF_LONG_LONG__
  213. # elif defined(__LONG_LONG_MAX__)
  214. # if __LONG_LONG_MAX__ == 0x7fffffff
  215. # define KWIML_ABI_SIZEOF_LONG_LONG 4
  216. # elif __LONG_LONG_MAX__>>32 == 0x7fffffff
  217. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  218. # endif
  219. # endif
  220. #endif
  221. #if !defined(KWIML_ABI_SIZEOF_LONG_LONG)
  222. # if defined(_LONGLONG) /* SGI, some GNU, perhaps others. */ \
  223. && !defined(_MSC_VER)
  224. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  225. # elif defined(_LONG_LONG) /* IBM XL, perhaps others. */
  226. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  227. # elif defined(__NO_LONG_LONG) /* EDG */
  228. # define KWIML_ABI_SIZEOF_LONG_LONG 0
  229. # elif defined(__cplusplus) && __cplusplus > 199711L /* C++0x */
  230. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  231. # elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
  232. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  233. # elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* SunPro */
  234. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  235. # elif defined(__HP_cc) || defined(__HP_aCC) /* HP */
  236. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  237. # elif defined(__PGIC__) /* PGI */
  238. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  239. # elif defined(__WATCOMC__) /* Watcom */
  240. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  241. # elif defined(__INTEL_COMPILER) /* Intel */
  242. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  243. # elif defined(__BORLANDC__) /* Borland */
  244. # if __BORLANDC__ >= 0x0560
  245. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  246. # else
  247. # define KWIML_ABI_SIZEOF_LONG_LONG 0
  248. # endif
  249. # elif defined(_MSC_VER) /* Microsoft */
  250. # if _MSC_VER >= 1310
  251. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  252. # else
  253. # define KWIML_ABI_SIZEOF_LONG_LONG 0
  254. # endif
  255. # elif defined(__GNUC__) /* GNU */
  256. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  257. # elif defined(__hpux) /* Old HP: no __HP_cc/__HP_aCC/__GNUC__ above */
  258. # define KWIML_ABI_SIZEOF_LONG_LONG 8
  259. # endif
  260. #endif
  261. #if !defined(KWIML_ABI_SIZEOF_LONG_LONG) && !defined(KWIML_ABI_NO_ERROR_LONG_LONG)
  262. # error "Existence of 'long long' unknown."
  263. #endif
  264. /*--------------------------------------------------------------------------*/
  265. #if !defined(KWIML_ABI_SIZEOF___INT64)
  266. # if defined(__INTEL_COMPILER)
  267. # define KWIML_ABI_SIZEOF___INT64 8
  268. # elif defined(_MSC_VER)
  269. # define KWIML_ABI_SIZEOF___INT64 8
  270. # elif defined(__BORLANDC__)
  271. # define KWIML_ABI_SIZEOF___INT64 8
  272. # else
  273. # define KWIML_ABI_SIZEOF___INT64 0
  274. # endif
  275. #endif
  276. #if defined(KWIML_ABI_SIZEOF___INT64) && KWIML_ABI_SIZEOF___INT64 > 0
  277. # if KWIML_ABI_SIZEOF_LONG == 8
  278. # define KWIML_ABI___INT64_IS_LONG 1
  279. # elif defined(KWIML_ABI_SIZEOF_LONG_LONG) && KWIML_ABI_SIZEOF_LONG_LONG == 8
  280. # define KWIML_ABI___INT64_IS_LONG_LONG 1
  281. # else
  282. # define KWIML_ABI___INT64_IS_UNIQUE 1
  283. # endif
  284. #endif
  285. /*--------------------------------------------------------------------------*/
  286. #if !defined(KWIML_ABI_SIZEOF_FLOAT)
  287. # if defined(__SIZEOF_FLOAT__)
  288. # define KWIML_ABI_SIZEOF_FLOAT __SIZEOF_FLOAT__
  289. # endif
  290. #endif
  291. #if !defined(KWIML_ABI_SIZEOF_FLOAT)
  292. # define KWIML_ABI_SIZEOF_FLOAT 4
  293. #endif
  294. /*--------------------------------------------------------------------------*/
  295. #if !defined(KWIML_ABI_SIZEOF_DOUBLE)
  296. # if defined(__SIZEOF_DOUBLE__)
  297. # define KWIML_ABI_SIZEOF_DOUBLE __SIZEOF_DOUBLE__
  298. # endif
  299. #endif
  300. #if !defined(KWIML_ABI_SIZEOF_DOUBLE)
  301. # define KWIML_ABI_SIZEOF_DOUBLE 8
  302. #endif
  303. /*--------------------------------------------------------------------------*/
  304. /* Identify possible endian cases. The macro KWIML_ABI_ENDIAN_ID will be
  305. defined to one of these, or undefined if unknown. */
  306. #if !defined(KWIML_ABI_ENDIAN_ID_BIG)
  307. # define KWIML_ABI_ENDIAN_ID_BIG 4321
  308. #endif
  309. #if !defined(KWIML_ABI_ENDIAN_ID_LITTLE)
  310. # define KWIML_ABI_ENDIAN_ID_LITTLE 1234
  311. #endif
  312. #if KWIML_ABI_ENDIAN_ID_BIG == KWIML_ABI_ENDIAN_ID_LITTLE
  313. # error "KWIML_ABI_ENDIAN_ID_BIG == KWIML_ABI_ENDIAN_ID_LITTLE"
  314. #endif
  315. #if defined(KWIML_ABI_ENDIAN_ID) /* Skip #elif cases if already defined. */
  316. /* Use dedicated symbols if the compiler defines them. Do this first
  317. because some architectures allow runtime byte order selection by
  318. the operating system (values for such architectures below are
  319. guesses for compilers that do not define a dedicated symbol).
  320. Ensure that only one is defined in case the platform or a header
  321. defines both as possible values for some third symbol. */
  322. #elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
  323. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  324. #elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
  325. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  326. #elif defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
  327. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  328. #elif defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
  329. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  330. /* Alpha */
  331. #elif defined(__alpha) || defined(__alpha__) || defined(_M_ALPHA)
  332. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  333. /* Arm */
  334. #elif defined(__arm__)
  335. # if !defined(__ARMEB__)
  336. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  337. # else
  338. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  339. # endif
  340. /* Intel x86 */
  341. #elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
  342. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  343. #elif defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
  344. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  345. #elif defined(__MWERKS__) && defined(__INTEL__)
  346. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  347. /* Intel x86-64 */
  348. #elif defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)
  349. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  350. #elif defined(__amd64) || defined(__amd64__)
  351. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  352. /* Intel Architecture-64 (Itanium) */
  353. #elif defined(__ia64) || defined(__ia64__)
  354. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  355. #elif defined(_IA64) || defined(__IA64__) || defined(_M_IA64)
  356. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  357. /* PowerPC */
  358. #elif defined(__powerpc) || defined(__powerpc__)
  359. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  360. #elif defined(__ppc) || defined(__ppc__) || defined(__POWERPC__)
  361. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  362. /* SPARC */
  363. #elif defined(__sparc) || defined(__sparc__)
  364. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  365. /* HP/PA RISC */
  366. #elif defined(__hppa) || defined(__hppa__)
  367. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  368. /* LoongArch64 */
  369. #elif defined(__loongarch64)
  370. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  371. /* Motorola 68k */
  372. #elif defined(__m68k__) || defined(M68000)
  373. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  374. /* MIPSel (MIPS little endian) */
  375. #elif defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)
  376. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  377. /* MIPSeb (MIPS big endian) */
  378. #elif defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB)
  379. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  380. /* MIPS (fallback, big endian) */
  381. #elif defined(__mips) || defined(__mips__) || defined(__MIPS__)
  382. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  383. /* NIOS2 */
  384. #elif defined(__NIOS2__) || defined(__NIOS2) || defined(__nios2__)
  385. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  386. /* OpenRISC 1000 */
  387. #elif defined(__or1k__)
  388. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  389. /* RS/6000 */
  390. #elif defined(__THW_RS600) || defined(_IBMR2) || defined(_POWER)
  391. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  392. #elif defined(_ARCH_PWR) || defined(_ARCH_PWR2)
  393. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  394. /* System/370 */
  395. #elif defined(__370__) || defined(__THW_370__)
  396. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  397. /* System/390 */
  398. #elif defined(__s390__) || defined(__s390x__)
  399. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  400. /* z/Architecture */
  401. #elif defined(__SYSC_ZARCH__)
  402. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  403. /* VAX */
  404. #elif defined(__vax__)
  405. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  406. /* Aarch64 */
  407. #elif defined(__aarch64__)
  408. # if !defined(__AARCH64EB__)
  409. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  410. # else
  411. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  412. # endif
  413. /* Aarch64 (Windows) */
  414. #elif defined(_M_ARM64)
  415. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  416. /* Xtensa */
  417. #elif defined(__XTENSA_EB__)
  418. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_BIG
  419. #elif defined(__XTENSA_EL__)
  420. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  421. /* RISC-V */
  422. #elif defined(__riscv) || defined(__riscv__)
  423. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  424. /* Sunway */
  425. #elif defined(__sw_64) || defined(__sw_64__)
  426. # define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
  427. /* Unknown CPU */
  428. #elif !defined(KWIML_ABI_NO_ERROR_ENDIAN)
  429. # error "Byte order of target CPU unknown."
  430. #endif
  431. #endif /* KWIML_ABI_private_DO_DEFINE */
  432. /*--------------------------------------------------------------------------*/
  433. #ifdef KWIML_ABI_private_DO_VERIFY
  434. #undef KWIML_ABI_private_DO_VERIFY
  435. #if defined(_MSC_VER)
  436. # pragma warning (push)
  437. # pragma warning (disable:4309) /* static_cast truncation of constant value */
  438. # pragma warning (disable:4310) /* cast truncates constant value */
  439. #endif
  440. #if defined(__cplusplus) && !defined(__BORLANDC__)
  441. #define KWIML_ABI_private_STATIC_CAST(t,v) static_cast<t>(v)
  442. #else
  443. #define KWIML_ABI_private_STATIC_CAST(t,v) (t)(v)
  444. #endif
  445. #define KWIML_ABI_private_VERIFY(n, x, y) KWIML_ABI_private_VERIFY_0(KWIML_ABI_private_VERSION, n, x, y)
  446. #define KWIML_ABI_private_VERIFY_0(V, n, x, y) KWIML_ABI_private_VERIFY_1(V, n, x, y)
  447. #define KWIML_ABI_private_VERIFY_1(V, n, x, y) extern int (*n##_v##V)[x]; extern int (*n##_v##V)[y]
  448. #define KWIML_ABI_private_VERIFY_SAME_IMPL(n, x, y) KWIML_ABI_private_VERIFY_SAME_IMPL_0(KWIML_ABI_private_VERSION, n, x, y)
  449. #define KWIML_ABI_private_VERIFY_SAME_IMPL_0(V, n, x, y) KWIML_ABI_private_VERIFY_SAME_IMPL_1(V, n, x, y)
  450. #define KWIML_ABI_private_VERIFY_SAME_IMPL_1(V, n, x, y) extern int (*n##_v##V)(x*); extern int (*n##_v##V)(y*)
  451. #define KWIML_ABI_private_VERIFY_DIFF_IMPL(n, x, y) KWIML_ABI_private_VERIFY_DIFF_IMPL_0(KWIML_ABI_private_VERSION, n, x, y)
  452. #define KWIML_ABI_private_VERIFY_DIFF_IMPL_0(V, n, x, y) KWIML_ABI_private_VERIFY_DIFF_IMPL_1(V, n, x, y)
  453. #if defined(__cplusplus)
  454. # define KWIML_ABI_private_VERIFY_DIFF_IMPL_1(V, n, x, y) extern int* n##_v##V(x*); extern char* n##_v##V(y*)
  455. #else
  456. # define KWIML_ABI_private_VERIFY_DIFF_IMPL_1(V, n, x, y) extern int* n##_v##V(x*) /* TODO: possible? */
  457. #endif
  458. #define KWIML_ABI_private_VERIFY_BOOL(m, b) KWIML_ABI_private_VERIFY(KWIML_ABI_detail_VERIFY_##m, 2, (b)?2:3)
  459. #define KWIML_ABI_private_VERIFY_SIZE(m, t) KWIML_ABI_private_VERIFY(KWIML_ABI_detail_VERIFY_##m, m, sizeof(t))
  460. #define KWIML_ABI_private_VERIFY_SAME(m, x, y) KWIML_ABI_private_VERIFY_SAME_IMPL(KWIML_ABI_detail_VERIFY_##m, x, y)
  461. #define KWIML_ABI_private_VERIFY_DIFF(m, x, y) KWIML_ABI_private_VERIFY_DIFF_IMPL(KWIML_ABI_detail_VERIFY_##m, x, y)
  462. KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_DATA_PTR, int*);
  463. KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_CODE_PTR, int(*)(int));
  464. KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_CHAR, char);
  465. KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_SHORT, short);
  466. KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_INT, int);
  467. KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_LONG, long);
  468. #if defined(KWIML_ABI_SIZEOF_LONG_LONG) && KWIML_ABI_SIZEOF_LONG_LONG > 0
  469. KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_LONG_LONG, long long);
  470. #endif
  471. #if defined(KWIML_ABI_SIZEOF___INT64) && KWIML_ABI_SIZEOF___INT64 > 0
  472. KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF___INT64, __int64);
  473. #endif
  474. KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_FLOAT, float);
  475. KWIML_ABI_private_VERIFY_SIZE(KWIML_ABI_SIZEOF_DOUBLE, double);
  476. #if defined(KWIML_ABI___INT64_IS_LONG)
  477. KWIML_ABI_private_VERIFY_SAME(KWIML_ABI___INT64_IS_LONG, __int64, long);
  478. #elif defined(KWIML_ABI___INT64_IS_LONG_LONG)
  479. KWIML_ABI_private_VERIFY_SAME(KWIML_ABI___INT64_IS_LONG_LONG, __int64, long long);
  480. #elif defined(KWIML_ABI_SIZEOF___INT64) && KWIML_ABI_SIZEOF___INT64 > 0
  481. KWIML_ABI_private_VERIFY_DIFF(KWIML_ABI___INT64_NOT_LONG, __int64, long);
  482. # if defined(KWIML_ABI_SIZEOF_LONG_LONG) && KWIML_ABI_SIZEOF_LONG_LONG > 0
  483. KWIML_ABI_private_VERIFY_DIFF(KWIML_ABI___INT64_NOT_LONG_LONG, __int64, long long);
  484. # endif
  485. #endif
  486. #if defined(KWIML_ABI_CHAR_IS_UNSIGNED)
  487. KWIML_ABI_private_VERIFY_BOOL(KWIML_ABI_CHAR_IS_UNSIGNED,
  488. KWIML_ABI_private_STATIC_CAST(char, 0x80) > 0);
  489. #elif defined(KWIML_ABI_CHAR_IS_SIGNED)
  490. KWIML_ABI_private_VERIFY_BOOL(KWIML_ABI_CHAR_IS_SIGNED,
  491. KWIML_ABI_private_STATIC_CAST(char, 0x80) < 0);
  492. #endif
  493. #undef KWIML_ABI_private_VERIFY_DIFF
  494. #undef KWIML_ABI_private_VERIFY_SAME
  495. #undef KWIML_ABI_private_VERIFY_SIZE
  496. #undef KWIML_ABI_private_VERIFY_BOOL
  497. #undef KWIML_ABI_private_VERIFY_DIFF_IMPL_1
  498. #undef KWIML_ABI_private_VERIFY_DIFF_IMPL_0
  499. #undef KWIML_ABI_private_VERIFY_DIFF_IMPL
  500. #undef KWIML_ABI_private_VERIFY_SAME_IMPL_1
  501. #undef KWIML_ABI_private_VERIFY_SAME_IMPL_0
  502. #undef KWIML_ABI_private_VERIFY_SAME_IMPL
  503. #undef KWIML_ABI_private_VERIFY_1
  504. #undef KWIML_ABI_private_VERIFY_0
  505. #undef KWIML_ABI_private_VERIFY
  506. #undef KWIML_ABI_private_STATIC_CAST
  507. #if defined(_MSC_VER)
  508. # pragma warning (pop)
  509. #endif
  510. #endif /* KWIML_ABI_private_DO_VERIFY */
  511. #undef KWIML_ABI_private_VERSION