CMakeCCompilerId.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  1. #ifdef __cplusplus
  2. # error "A C++ compiler has been selected for C."
  3. #endif
  4. #if defined(__18CXX)
  5. # define ID_VOID_MAIN
  6. #endif
  7. #if defined(__CLASSIC_C__)
  8. /* cv-qualifiers did not exist in K&R C */
  9. # define const
  10. # define volatile
  11. #endif
  12. #if !defined(__has_include)
  13. /* If the compiler does not have __has_include, pretend the answer is
  14. always no. */
  15. # define __has_include(x) 0
  16. #endif
  17. /* Version number components: V=Version, R=Revision, P=Patch
  18. Version date components: YYYY=Year, MM=Month, DD=Day */
  19. #if defined(__INTEL_COMPILER) || defined(__ICC)
  20. # define COMPILER_ID "Intel"
  21. # if defined(_MSC_VER)
  22. # define SIMULATE_ID "MSVC"
  23. # endif
  24. # if defined(__GNUC__)
  25. # define SIMULATE_ID "GNU"
  26. # endif
  27. /* __INTEL_COMPILER = VRP prior to 2021, and then VVVV for 2021 and later,
  28. except that a few beta releases use the old format with V=2021. */
  29. # if __INTEL_COMPILER < 2021 || __INTEL_COMPILER == 202110 || __INTEL_COMPILER == 202111
  30. # define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100)
  31. # define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10)
  32. # if defined(__INTEL_COMPILER_UPDATE)
  33. # define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE)
  34. # else
  35. # define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10)
  36. # endif
  37. # else
  38. # define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER)
  39. # define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER_UPDATE)
  40. /* The third version component from --version is an update index,
  41. but no macro is provided for it. */
  42. # define COMPILER_VERSION_PATCH DEC(0)
  43. # endif
  44. # if defined(__INTEL_COMPILER_BUILD_DATE)
  45. /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */
  46. # define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE)
  47. # endif
  48. # if defined(_MSC_VER)
  49. /* _MSC_VER = VVRR */
  50. # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
  51. # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
  52. # endif
  53. # if defined(__GNUC__)
  54. # define SIMULATE_VERSION_MAJOR DEC(__GNUC__)
  55. # elif defined(__GNUG__)
  56. # define SIMULATE_VERSION_MAJOR DEC(__GNUG__)
  57. # endif
  58. # if defined(__GNUC_MINOR__)
  59. # define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__)
  60. # endif
  61. # if defined(__GNUC_PATCHLEVEL__)
  62. # define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__)
  63. # endif
  64. #elif (defined(__clang__) && defined(__INTEL_CLANG_COMPILER)) || defined(__INTEL_LLVM_COMPILER)
  65. # define COMPILER_ID "IntelLLVM"
  66. #if defined(_MSC_VER)
  67. # define SIMULATE_ID "MSVC"
  68. #endif
  69. #if defined(__GNUC__)
  70. # define SIMULATE_ID "GNU"
  71. #endif
  72. /* __INTEL_LLVM_COMPILER = VVVVRP prior to 2021.2.0, VVVVRRPP for 2021.2.0 and
  73. * later. Look for 6 digit vs. 8 digit version number to decide encoding.
  74. * VVVV is no smaller than the current year when a version is released.
  75. */
  76. #if __INTEL_LLVM_COMPILER < 1000000L
  77. # define COMPILER_VERSION_MAJOR DEC(__INTEL_LLVM_COMPILER/100)
  78. # define COMPILER_VERSION_MINOR DEC(__INTEL_LLVM_COMPILER/10 % 10)
  79. # define COMPILER_VERSION_PATCH DEC(__INTEL_LLVM_COMPILER % 10)
  80. #else
  81. # define COMPILER_VERSION_MAJOR DEC(__INTEL_LLVM_COMPILER/10000)
  82. # define COMPILER_VERSION_MINOR DEC(__INTEL_LLVM_COMPILER/100 % 100)
  83. # define COMPILER_VERSION_PATCH DEC(__INTEL_LLVM_COMPILER % 100)
  84. #endif
  85. #if defined(_MSC_VER)
  86. /* _MSC_VER = VVRR */
  87. # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
  88. # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
  89. #endif
  90. #if defined(__GNUC__)
  91. # define SIMULATE_VERSION_MAJOR DEC(__GNUC__)
  92. #elif defined(__GNUG__)
  93. # define SIMULATE_VERSION_MAJOR DEC(__GNUG__)
  94. #endif
  95. #if defined(__GNUC_MINOR__)
  96. # define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__)
  97. #endif
  98. #if defined(__GNUC_PATCHLEVEL__)
  99. # define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__)
  100. #endif
  101. #elif defined(__PATHCC__)
  102. # define COMPILER_ID "PathScale"
  103. # define COMPILER_VERSION_MAJOR DEC(__PATHCC__)
  104. # define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__)
  105. # if defined(__PATHCC_PATCHLEVEL__)
  106. # define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__)
  107. # endif
  108. #elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__)
  109. # define COMPILER_ID "Embarcadero"
  110. # define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF)
  111. # define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF)
  112. # define COMPILER_VERSION_PATCH DEC(__CODEGEARC_VERSION__ & 0xFFFF)
  113. #elif defined(__BORLANDC__)
  114. # define COMPILER_ID "Borland"
  115. /* __BORLANDC__ = 0xVRR */
  116. # define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8)
  117. # define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF)
  118. #elif defined(__WATCOMC__) && __WATCOMC__ < 1200
  119. # define COMPILER_ID "Watcom"
  120. /* __WATCOMC__ = VVRR */
  121. # define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100)
  122. # define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10)
  123. # if (__WATCOMC__ % 10) > 0
  124. # define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10)
  125. # endif
  126. #elif defined(__WATCOMC__)
  127. # define COMPILER_ID "OpenWatcom"
  128. /* __WATCOMC__ = VVRP + 1100 */
  129. # define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100)
  130. # define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10)
  131. # if (__WATCOMC__ % 10) > 0
  132. # define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10)
  133. # endif
  134. #elif defined(__SUNPRO_C)
  135. # define COMPILER_ID "SunPro"
  136. # if __SUNPRO_C >= 0x5100
  137. /* __SUNPRO_C = 0xVRRP */
  138. # define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>12)
  139. # define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xFF)
  140. # define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF)
  141. # else
  142. /* __SUNPRO_CC = 0xVRP */
  143. # define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>8)
  144. # define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xF)
  145. # define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF)
  146. # endif
  147. #elif defined(__HP_cc)
  148. # define COMPILER_ID "HP"
  149. /* __HP_cc = VVRRPP */
  150. # define COMPILER_VERSION_MAJOR DEC(__HP_cc/10000)
  151. # define COMPILER_VERSION_MINOR DEC(__HP_cc/100 % 100)
  152. # define COMPILER_VERSION_PATCH DEC(__HP_cc % 100)
  153. #elif defined(__DECC)
  154. # define COMPILER_ID "Compaq"
  155. /* __DECC_VER = VVRRTPPPP */
  156. # define COMPILER_VERSION_MAJOR DEC(__DECC_VER/10000000)
  157. # define COMPILER_VERSION_MINOR DEC(__DECC_VER/100000 % 100)
  158. # define COMPILER_VERSION_PATCH DEC(__DECC_VER % 10000)
  159. #elif defined(__IBMC__) && defined(__COMPILER_VER__)
  160. # define COMPILER_ID "zOS"
  161. /* __IBMC__ = VRP */
  162. # define COMPILER_VERSION_MAJOR DEC(__IBMC__/100)
  163. # define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10)
  164. # define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)
  165. #elif defined(__open_xl__) && defined(__clang__)
  166. # define COMPILER_ID "IBMClang"
  167. # define COMPILER_VERSION_MAJOR DEC(__open_xl_version__)
  168. # define COMPILER_VERSION_MINOR DEC(__open_xl_release__)
  169. # define COMPILER_VERSION_PATCH DEC(__open_xl_modification__)
  170. # define COMPILER_VERSION_TWEAK DEC(__open_xl_ptf_fix_level__)
  171. # define COMPILER_VERSION_INTERNAL_STR __clang_version__
  172. #elif defined(__ibmxl__) && defined(__clang__)
  173. # define COMPILER_ID "XLClang"
  174. # define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__)
  175. # define COMPILER_VERSION_MINOR DEC(__ibmxl_release__)
  176. # define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__)
  177. # define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__)
  178. #elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ >= 800
  179. # define COMPILER_ID "XL"
  180. /* __IBMC__ = VRP */
  181. # define COMPILER_VERSION_MAJOR DEC(__IBMC__/100)
  182. # define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10)
  183. # define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)
  184. #elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ < 800
  185. # define COMPILER_ID "VisualAge"
  186. /* __IBMC__ = VRP */
  187. # define COMPILER_VERSION_MAJOR DEC(__IBMC__/100)
  188. # define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10)
  189. # define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)
  190. #elif defined(__NVCOMPILER)
  191. # define COMPILER_ID "NVHPC"
  192. # define COMPILER_VERSION_MAJOR DEC(__NVCOMPILER_MAJOR__)
  193. # define COMPILER_VERSION_MINOR DEC(__NVCOMPILER_MINOR__)
  194. # if defined(__NVCOMPILER_PATCHLEVEL__)
  195. # define COMPILER_VERSION_PATCH DEC(__NVCOMPILER_PATCHLEVEL__)
  196. # endif
  197. #elif defined(__PGI)
  198. # define COMPILER_ID "PGI"
  199. # define COMPILER_VERSION_MAJOR DEC(__PGIC__)
  200. # define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__)
  201. # if defined(__PGIC_PATCHLEVEL__)
  202. # define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__)
  203. # endif
  204. #elif defined(__clang__) && defined(__cray__)
  205. # define COMPILER_ID "CrayClang"
  206. # define COMPILER_VERSION_MAJOR DEC(__cray_major__)
  207. # define COMPILER_VERSION_MINOR DEC(__cray_minor__)
  208. # define COMPILER_VERSION_PATCH DEC(__cray_patchlevel__)
  209. # define COMPILER_VERSION_INTERNAL_STR __clang_version__
  210. #elif defined(_CRAYC)
  211. # define COMPILER_ID "Cray"
  212. # define COMPILER_VERSION_MAJOR DEC(_RELEASE_MAJOR)
  213. # define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR)
  214. #elif defined(__TI_COMPILER_VERSION__)
  215. # define COMPILER_ID "TI"
  216. /* __TI_COMPILER_VERSION__ = VVVRRRPPP */
  217. # define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000)
  218. # define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000)
  219. # define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000)
  220. #elif defined(__CLANG_FUJITSU)
  221. # define COMPILER_ID "FujitsuClang"
  222. # define COMPILER_VERSION_MAJOR DEC(__FCC_major__)
  223. # define COMPILER_VERSION_MINOR DEC(__FCC_minor__)
  224. # define COMPILER_VERSION_PATCH DEC(__FCC_patchlevel__)
  225. # define COMPILER_VERSION_INTERNAL_STR __clang_version__
  226. #elif defined(__FUJITSU)
  227. # define COMPILER_ID "Fujitsu"
  228. # if defined(__FCC_version__)
  229. # define COMPILER_VERSION __FCC_version__
  230. # elif defined(__FCC_major__)
  231. # define COMPILER_VERSION_MAJOR DEC(__FCC_major__)
  232. # define COMPILER_VERSION_MINOR DEC(__FCC_minor__)
  233. # define COMPILER_VERSION_PATCH DEC(__FCC_patchlevel__)
  234. # endif
  235. # if defined(__fcc_version)
  236. # define COMPILER_VERSION_INTERNAL DEC(__fcc_version)
  237. # elif defined(__FCC_VERSION)
  238. # define COMPILER_VERSION_INTERNAL DEC(__FCC_VERSION)
  239. # endif
  240. #elif defined(__ghs__)
  241. # define COMPILER_ID "GHS"
  242. /* __GHS_VERSION_NUMBER = VVVVRP */
  243. # ifdef __GHS_VERSION_NUMBER
  244. # define COMPILER_VERSION_MAJOR DEC(__GHS_VERSION_NUMBER / 100)
  245. # define COMPILER_VERSION_MINOR DEC(__GHS_VERSION_NUMBER / 10 % 10)
  246. # define COMPILER_VERSION_PATCH DEC(__GHS_VERSION_NUMBER % 10)
  247. # endif
  248. #elif defined(__TASKING__)
  249. # define COMPILER_ID "Tasking"
  250. # define COMPILER_VERSION_MAJOR DEC(__VERSION__/1000)
  251. # define COMPILER_VERSION_MINOR DEC(__VERSION__ % 100)
  252. # define COMPILER_VERSION_INTERNAL DEC(__VERSION__)
  253. #elif defined(__ORANGEC__)
  254. # define COMPILER_ID "OrangeC"
  255. # define COMPILER_VERSION_MAJOR DEC(__ORANGEC_MAJOR__)
  256. # define COMPILER_VERSION_MINOR DEC(__ORANGEC_MINOR__)
  257. # define COMPILER_VERSION_PATCH DEC(__ORANGEC_PATCHLEVEL__)
  258. #elif defined(__RENESAS__)
  259. # define COMPILER_ID "Renesas"
  260. /* __RENESAS_VERSION__ = 0xVVRRPP00 */
  261. # define COMPILER_VERSION_MAJOR HEX(__RENESAS_VERSION__ >> 24 & 0xFF)
  262. # define COMPILER_VERSION_MINOR HEX(__RENESAS_VERSION__ >> 16 & 0xFF)
  263. # define COMPILER_VERSION_PATCH HEX(__RENESAS_VERSION__ >> 8 & 0xFF)
  264. #elif defined(__TINYC__)
  265. # define COMPILER_ID "TinyCC"
  266. #elif defined(__BCC__)
  267. # define COMPILER_ID "Bruce"
  268. #elif defined(__SCO_VERSION__)
  269. # define COMPILER_ID "SCO"
  270. #elif defined(__ARMCC_VERSION) && !defined(__clang__)
  271. # define COMPILER_ID "ARMCC"
  272. #if __ARMCC_VERSION >= 1000000
  273. /* __ARMCC_VERSION = VRRPPPP */
  274. # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/1000000)
  275. # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 100)
  276. # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000)
  277. #else
  278. /* __ARMCC_VERSION = VRPPPP */
  279. # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/100000)
  280. # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 10)
  281. # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000)
  282. #endif
  283. #elif defined(__clang__) && defined(__apple_build_version__)
  284. # define COMPILER_ID "AppleClang"
  285. # if defined(_MSC_VER)
  286. # define SIMULATE_ID "MSVC"
  287. # endif
  288. # define COMPILER_VERSION_MAJOR DEC(__clang_major__)
  289. # define COMPILER_VERSION_MINOR DEC(__clang_minor__)
  290. # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
  291. # if defined(_MSC_VER)
  292. /* _MSC_VER = VVRR */
  293. # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
  294. # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
  295. # endif
  296. # define COMPILER_VERSION_TWEAK DEC(__apple_build_version__)
  297. #elif defined(__clang__) && defined(__ARMCOMPILER_VERSION)
  298. # define COMPILER_ID "ARMClang"
  299. # define COMPILER_VERSION_MAJOR DEC(__ARMCOMPILER_VERSION/1000000)
  300. # define COMPILER_VERSION_MINOR DEC(__ARMCOMPILER_VERSION/10000 % 100)
  301. # define COMPILER_VERSION_PATCH DEC(__ARMCOMPILER_VERSION/100 % 100)
  302. # define COMPILER_VERSION_INTERNAL DEC(__ARMCOMPILER_VERSION)
  303. #elif defined(__clang__) && defined(__ti__)
  304. # define COMPILER_ID "TIClang"
  305. # define COMPILER_VERSION_MAJOR DEC(__ti_major__)
  306. # define COMPILER_VERSION_MINOR DEC(__ti_minor__)
  307. # define COMPILER_VERSION_PATCH DEC(__ti_patchlevel__)
  308. # define COMPILER_VERSION_INTERNAL DEC(__ti_version__)
  309. #elif defined(__clang__)
  310. # define COMPILER_ID "Clang"
  311. # if defined(_MSC_VER)
  312. # define SIMULATE_ID "MSVC"
  313. # endif
  314. # define COMPILER_VERSION_MAJOR DEC(__clang_major__)
  315. # define COMPILER_VERSION_MINOR DEC(__clang_minor__)
  316. # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
  317. # if defined(_MSC_VER)
  318. /* _MSC_VER = VVRR */
  319. # define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
  320. # define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
  321. # endif
  322. #elif defined(__LCC__) && (defined(__GNUC__) || defined(__GNUG__) || defined(__MCST__))
  323. # define COMPILER_ID "LCC"
  324. # define COMPILER_VERSION_MAJOR DEC(__LCC__ / 100)
  325. # define COMPILER_VERSION_MINOR DEC(__LCC__ % 100)
  326. # if defined(__LCC_MINOR__)
  327. # define COMPILER_VERSION_PATCH DEC(__LCC_MINOR__)
  328. # endif
  329. # if defined(__GNUC__) && defined(__GNUC_MINOR__)
  330. # define SIMULATE_ID "GNU"
  331. # define SIMULATE_VERSION_MAJOR DEC(__GNUC__)
  332. # define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__)
  333. # if defined(__GNUC_PATCHLEVEL__)
  334. # define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__)
  335. # endif
  336. # endif
  337. #elif defined(__GNUC__)
  338. # define COMPILER_ID "GNU"
  339. # define COMPILER_VERSION_MAJOR DEC(__GNUC__)
  340. # if defined(__GNUC_MINOR__)
  341. # define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__)
  342. # endif
  343. # if defined(__GNUC_PATCHLEVEL__)
  344. # define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__)
  345. # endif
  346. #elif defined(_MSC_VER)
  347. # define COMPILER_ID "MSVC"
  348. /* _MSC_VER = VVRR */
  349. # define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100)
  350. # define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100)
  351. # if defined(_MSC_FULL_VER)
  352. # if _MSC_VER >= 1400
  353. /* _MSC_FULL_VER = VVRRPPPPP */
  354. # define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000)
  355. # else
  356. /* _MSC_FULL_VER = VVRRPPPP */
  357. # define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000)
  358. # endif
  359. # endif
  360. # if defined(_MSC_BUILD)
  361. # define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD)
  362. # endif
  363. #elif defined(_ADI_COMPILER)
  364. # define COMPILER_ID "ADSP"
  365. #if defined(__VERSIONNUM__)
  366. /* __VERSIONNUM__ = 0xVVRRPPTT */
  367. # define COMPILER_VERSION_MAJOR DEC(__VERSIONNUM__ >> 24 & 0xFF)
  368. # define COMPILER_VERSION_MINOR DEC(__VERSIONNUM__ >> 16 & 0xFF)
  369. # define COMPILER_VERSION_PATCH DEC(__VERSIONNUM__ >> 8 & 0xFF)
  370. # define COMPILER_VERSION_TWEAK DEC(__VERSIONNUM__ & 0xFF)
  371. #endif
  372. #elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)
  373. # define COMPILER_ID "IAR"
  374. # if defined(__VER__) && defined(__ICCARM__)
  375. # define COMPILER_VERSION_MAJOR DEC((__VER__) / 1000000)
  376. # define COMPILER_VERSION_MINOR DEC(((__VER__) / 1000) % 1000)
  377. # define COMPILER_VERSION_PATCH DEC((__VER__) % 1000)
  378. # define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__)
  379. # elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__) || defined(__ICCV850__) || defined(__ICC8051__) || defined(__ICCSTM8__))
  380. # define COMPILER_VERSION_MAJOR DEC((__VER__) / 100)
  381. # define COMPILER_VERSION_MINOR DEC((__VER__) - (((__VER__) / 100)*100))
  382. # define COMPILER_VERSION_PATCH DEC(__SUBVERSION__)
  383. # define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__)
  384. # endif
  385. #elif defined(__DCC__) && defined(_DIAB_TOOL)
  386. # define COMPILER_ID "Diab"
  387. # define COMPILER_VERSION_MAJOR DEC(__VERSION_MAJOR_NUMBER__)
  388. # define COMPILER_VERSION_MINOR DEC(__VERSION_MINOR_NUMBER__)
  389. # define COMPILER_VERSION_PATCH DEC(__VERSION_ARCH_FEATURE_NUMBER__)
  390. # define COMPILER_VERSION_TWEAK DEC(__VERSION_BUG_FIX_NUMBER__)
  391. #elif defined(__SDCC_VERSION_MAJOR) || defined(SDCC)
  392. # define COMPILER_ID "SDCC"
  393. # if defined(__SDCC_VERSION_MAJOR)
  394. # define COMPILER_VERSION_MAJOR DEC(__SDCC_VERSION_MAJOR)
  395. # define COMPILER_VERSION_MINOR DEC(__SDCC_VERSION_MINOR)
  396. # define COMPILER_VERSION_PATCH DEC(__SDCC_VERSION_PATCH)
  397. # else
  398. /* SDCC = VRP */
  399. # define COMPILER_VERSION_MAJOR DEC(SDCC/100)
  400. # define COMPILER_VERSION_MINOR DEC(SDCC/10 % 10)
  401. # define COMPILER_VERSION_PATCH DEC(SDCC % 10)
  402. # endif
  403. /* These compilers are either not known or too old to define an
  404. identification macro. Try to identify the platform and guess that
  405. it is the native compiler. */
  406. #elif defined(__hpux) || defined(__hpua)
  407. # define COMPILER_ID "HP"
  408. #else /* unknown compiler */
  409. # define COMPILER_ID ""
  410. #endif
  411. /* Construct the string literal in pieces to prevent the source from
  412. getting matched. Store it in a pointer rather than an array
  413. because some compilers will just produce instructions to fill the
  414. array rather than assigning a pointer to a static array. */
  415. char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]";
  416. #ifdef SIMULATE_ID
  417. char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
  418. #endif
  419. #ifdef __QNXNTO__
  420. char const* qnxnto = "INFO" ":" "qnxnto[]";
  421. #endif
  422. #if defined(__CRAYXT_COMPUTE_LINUX_TARGET)
  423. char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
  424. #endif
  425. #define STRINGIFY_HELPER(X) #X
  426. #define STRINGIFY(X) STRINGIFY_HELPER(X)
  427. /* Identify known platforms by name. */
  428. #if defined(__linux) || defined(__linux__) || defined(linux)
  429. # define PLATFORM_ID "Linux"
  430. #elif defined(__MSYS__)
  431. # define PLATFORM_ID "MSYS"
  432. #elif defined(__CYGWIN__)
  433. # define PLATFORM_ID "Cygwin"
  434. #elif defined(__MINGW32__)
  435. # define PLATFORM_ID "MinGW"
  436. #elif defined(__APPLE__)
  437. # define PLATFORM_ID "Darwin"
  438. #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
  439. # define PLATFORM_ID "Windows"
  440. #elif defined(__FreeBSD__) || defined(__FreeBSD)
  441. # define PLATFORM_ID "FreeBSD"
  442. #elif defined(__NetBSD__) || defined(__NetBSD)
  443. # define PLATFORM_ID "NetBSD"
  444. #elif defined(__OpenBSD__) || defined(__OPENBSD)
  445. # define PLATFORM_ID "OpenBSD"
  446. #elif defined(__sun) || defined(sun)
  447. # define PLATFORM_ID "SunOS"
  448. #elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__)
  449. # define PLATFORM_ID "AIX"
  450. #elif defined(__hpux) || defined(__hpux__)
  451. # define PLATFORM_ID "HP-UX"
  452. #elif defined(__HAIKU__)
  453. # define PLATFORM_ID "Haiku"
  454. #elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS)
  455. # define PLATFORM_ID "BeOS"
  456. #elif defined(__QNX__) || defined(__QNXNTO__)
  457. # define PLATFORM_ID "QNX"
  458. #elif defined(__tru64) || defined(_tru64) || defined(__TRU64__)
  459. # define PLATFORM_ID "Tru64"
  460. #elif defined(__riscos) || defined(__riscos__)
  461. # define PLATFORM_ID "RISCos"
  462. #elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__)
  463. # define PLATFORM_ID "SINIX"
  464. #elif defined(__UNIX_SV__)
  465. # define PLATFORM_ID "UNIX_SV"
  466. #elif defined(__bsdos__)
  467. # define PLATFORM_ID "BSDOS"
  468. #elif defined(_MPRAS) || defined(MPRAS)
  469. # define PLATFORM_ID "MP-RAS"
  470. #elif defined(__osf) || defined(__osf__)
  471. # define PLATFORM_ID "OSF1"
  472. #elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv)
  473. # define PLATFORM_ID "SCO_SV"
  474. #elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX)
  475. # define PLATFORM_ID "ULTRIX"
  476. #elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX)
  477. # define PLATFORM_ID "Xenix"
  478. #elif defined(__WATCOMC__)
  479. # if defined(__LINUX__)
  480. # define PLATFORM_ID "Linux"
  481. # elif defined(__DOS__)
  482. # define PLATFORM_ID "DOS"
  483. # elif defined(__OS2__)
  484. # define PLATFORM_ID "OS2"
  485. # elif defined(__WINDOWS__)
  486. # define PLATFORM_ID "Windows3x"
  487. # elif defined(__VXWORKS__)
  488. # define PLATFORM_ID "VxWorks"
  489. # else /* unknown platform */
  490. # define PLATFORM_ID
  491. # endif
  492. #elif defined(__INTEGRITY)
  493. # if defined(INT_178B)
  494. # define PLATFORM_ID "Integrity178"
  495. # else /* regular Integrity */
  496. # define PLATFORM_ID "Integrity"
  497. # endif
  498. # elif defined(_ADI_COMPILER)
  499. # define PLATFORM_ID "ADSP"
  500. #else /* unknown platform */
  501. # define PLATFORM_ID
  502. #endif
  503. /* For windows compilers MSVC and Intel we can determine
  504. the architecture of the compiler being used. This is because
  505. the compilers do not have flags that can change the architecture,
  506. but rather depend on which compiler is being used
  507. */
  508. #if defined(_WIN32) && defined(_MSC_VER)
  509. # if defined(_M_IA64)
  510. # define ARCHITECTURE_ID "IA64"
  511. # elif defined(_M_ARM64EC)
  512. # define ARCHITECTURE_ID "ARM64EC"
  513. # elif defined(_M_X64) || defined(_M_AMD64)
  514. # define ARCHITECTURE_ID "x64"
  515. # elif defined(_M_IX86)
  516. # define ARCHITECTURE_ID "X86"
  517. # elif defined(_M_ARM64)
  518. # define ARCHITECTURE_ID "ARM64"
  519. # elif defined(_M_ARM)
  520. # if _M_ARM == 4
  521. # define ARCHITECTURE_ID "ARMV4I"
  522. # elif _M_ARM == 5
  523. # define ARCHITECTURE_ID "ARMV5I"
  524. # else
  525. # define ARCHITECTURE_ID "ARMV" STRINGIFY(_M_ARM)
  526. # endif
  527. # elif defined(_M_MIPS)
  528. # define ARCHITECTURE_ID "MIPS"
  529. # elif defined(_M_SH)
  530. # define ARCHITECTURE_ID "SHx"
  531. # else /* unknown architecture */
  532. # define ARCHITECTURE_ID ""
  533. # endif
  534. #elif defined(__WATCOMC__)
  535. # if defined(_M_I86)
  536. # define ARCHITECTURE_ID "I86"
  537. # elif defined(_M_IX86)
  538. # define ARCHITECTURE_ID "X86"
  539. # else /* unknown architecture */
  540. # define ARCHITECTURE_ID ""
  541. # endif
  542. #elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)
  543. # if defined(__ICCARM__)
  544. # define ARCHITECTURE_ID "ARM"
  545. # elif defined(__ICCRX__)
  546. # define ARCHITECTURE_ID "RX"
  547. # elif defined(__ICCRH850__)
  548. # define ARCHITECTURE_ID "RH850"
  549. # elif defined(__ICCRL78__)
  550. # define ARCHITECTURE_ID "RL78"
  551. # elif defined(__ICCRISCV__)
  552. # define ARCHITECTURE_ID "RISCV"
  553. # elif defined(__ICCAVR__)
  554. # define ARCHITECTURE_ID "AVR"
  555. # elif defined(__ICC430__)
  556. # define ARCHITECTURE_ID "MSP430"
  557. # elif defined(__ICCV850__)
  558. # define ARCHITECTURE_ID "V850"
  559. # elif defined(__ICC8051__)
  560. # define ARCHITECTURE_ID "8051"
  561. # elif defined(__ICCSTM8__)
  562. # define ARCHITECTURE_ID "STM8"
  563. # else /* unknown architecture */
  564. # define ARCHITECTURE_ID ""
  565. # endif
  566. #elif defined(__ghs__)
  567. # if defined(__PPC64__)
  568. # define ARCHITECTURE_ID "PPC64"
  569. # elif defined(__ppc__)
  570. # define ARCHITECTURE_ID "PPC"
  571. # elif defined(__ARM__)
  572. # define ARCHITECTURE_ID "ARM"
  573. # elif defined(__x86_64__)
  574. # define ARCHITECTURE_ID "x64"
  575. # elif defined(__i386__)
  576. # define ARCHITECTURE_ID "X86"
  577. # else /* unknown architecture */
  578. # define ARCHITECTURE_ID ""
  579. # endif
  580. #elif defined(__clang__) && defined(__ti__)
  581. # if defined(__ARM_ARCH)
  582. # define ARCHITECTURE_ID "ARM"
  583. # else /* unknown architecture */
  584. # define ARCHITECTURE_ID ""
  585. # endif
  586. #elif defined(__TI_COMPILER_VERSION__)
  587. # if defined(__TI_ARM__)
  588. # define ARCHITECTURE_ID "ARM"
  589. # elif defined(__MSP430__)
  590. # define ARCHITECTURE_ID "MSP430"
  591. # elif defined(__TMS320C28XX__)
  592. # define ARCHITECTURE_ID "TMS320C28x"
  593. # elif defined(__TMS320C6X__) || defined(_TMS320C6X)
  594. # define ARCHITECTURE_ID "TMS320C6x"
  595. # else /* unknown architecture */
  596. # define ARCHITECTURE_ID ""
  597. # endif
  598. # elif defined(__ADSPSHARC__)
  599. # define ARCHITECTURE_ID "SHARC"
  600. # elif defined(__ADSPBLACKFIN__)
  601. # define ARCHITECTURE_ID "Blackfin"
  602. #elif defined(__TASKING__)
  603. # if defined(__CTC__) || defined(__CPTC__)
  604. # define ARCHITECTURE_ID "TriCore"
  605. # elif defined(__CMCS__)
  606. # define ARCHITECTURE_ID "MCS"
  607. # elif defined(__CARM__) || defined(__CPARM__)
  608. # define ARCHITECTURE_ID "ARM"
  609. # elif defined(__CARC__)
  610. # define ARCHITECTURE_ID "ARC"
  611. # elif defined(__C51__)
  612. # define ARCHITECTURE_ID "8051"
  613. # elif defined(__CPCP__)
  614. # define ARCHITECTURE_ID "PCP"
  615. # else
  616. # define ARCHITECTURE_ID ""
  617. # endif
  618. #elif defined(__RENESAS__)
  619. # if defined(__CCRX__)
  620. # define ARCHITECTURE_ID "RX"
  621. # elif defined(__CCRL__)
  622. # define ARCHITECTURE_ID "RL78"
  623. # elif defined(__CCRH__)
  624. # define ARCHITECTURE_ID "RH850"
  625. # else
  626. # define ARCHITECTURE_ID ""
  627. # endif
  628. #else
  629. # define ARCHITECTURE_ID
  630. #endif
  631. /* Convert integer to decimal digit literals. */
  632. #define DEC(n) \
  633. ('0' + (((n) / 10000000)%10)), \
  634. ('0' + (((n) / 1000000)%10)), \
  635. ('0' + (((n) / 100000)%10)), \
  636. ('0' + (((n) / 10000)%10)), \
  637. ('0' + (((n) / 1000)%10)), \
  638. ('0' + (((n) / 100)%10)), \
  639. ('0' + (((n) / 10)%10)), \
  640. ('0' + ((n) % 10))
  641. /* Convert integer to hex digit literals. */
  642. #define HEX(n) \
  643. ('0' + ((n)>>28 & 0xF)), \
  644. ('0' + ((n)>>24 & 0xF)), \
  645. ('0' + ((n)>>20 & 0xF)), \
  646. ('0' + ((n)>>16 & 0xF)), \
  647. ('0' + ((n)>>12 & 0xF)), \
  648. ('0' + ((n)>>8 & 0xF)), \
  649. ('0' + ((n)>>4 & 0xF)), \
  650. ('0' + ((n) & 0xF))
  651. /* Construct a string literal encoding the version number. */
  652. #ifdef COMPILER_VERSION
  653. char const* info_version = "INFO" ":" "compiler_version[" COMPILER_VERSION "]";
  654. /* Construct a string literal encoding the version number components. */
  655. #elif defined(COMPILER_VERSION_MAJOR)
  656. char const info_version[] = {
  657. 'I', 'N', 'F', 'O', ':',
  658. 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[',
  659. COMPILER_VERSION_MAJOR,
  660. # ifdef COMPILER_VERSION_MINOR
  661. '.', COMPILER_VERSION_MINOR,
  662. # ifdef COMPILER_VERSION_PATCH
  663. '.', COMPILER_VERSION_PATCH,
  664. # ifdef COMPILER_VERSION_TWEAK
  665. '.', COMPILER_VERSION_TWEAK,
  666. # endif
  667. # endif
  668. # endif
  669. ']','\0'};
  670. #endif
  671. /* Construct a string literal encoding the internal version number. */
  672. #ifdef COMPILER_VERSION_INTERNAL
  673. char const info_version_internal[] = {
  674. 'I', 'N', 'F', 'O', ':',
  675. 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','_',
  676. 'i','n','t','e','r','n','a','l','[',
  677. COMPILER_VERSION_INTERNAL,']','\0'};
  678. #elif defined(COMPILER_VERSION_INTERNAL_STR)
  679. char const* info_version_internal = "INFO" ":" "compiler_version_internal[" COMPILER_VERSION_INTERNAL_STR "]";
  680. #endif
  681. /* Construct a string literal encoding the version number components. */
  682. #ifdef SIMULATE_VERSION_MAJOR
  683. char const info_simulate_version[] = {
  684. 'I', 'N', 'F', 'O', ':',
  685. 's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[',
  686. SIMULATE_VERSION_MAJOR,
  687. # ifdef SIMULATE_VERSION_MINOR
  688. '.', SIMULATE_VERSION_MINOR,
  689. # ifdef SIMULATE_VERSION_PATCH
  690. '.', SIMULATE_VERSION_PATCH,
  691. # ifdef SIMULATE_VERSION_TWEAK
  692. '.', SIMULATE_VERSION_TWEAK,
  693. # endif
  694. # endif
  695. # endif
  696. ']','\0'};
  697. #endif
  698. /* Construct the string literal in pieces to prevent the source from
  699. getting matched. Store it in a pointer rather than an array
  700. because some compilers will just produce instructions to fill the
  701. array rather than assigning a pointer to a static array. */
  702. char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]";
  703. char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]";
  704. #define C_STD_99 199901L
  705. #define C_STD_11 201112L
  706. #define C_STD_17 201710L
  707. #define C_STD_23 202311L
  708. #ifdef __STDC_VERSION__
  709. # define C_STD __STDC_VERSION__
  710. #endif
  711. #if !defined(__STDC__) && !defined(__clang__) && !defined(__RENESAS__)
  712. # if defined(_MSC_VER) || defined(__ibmxl__) || defined(__IBMC__)
  713. # define C_VERSION "90"
  714. # else
  715. # define C_VERSION
  716. # endif
  717. #elif C_STD > C_STD_17
  718. # define C_VERSION "23"
  719. #elif C_STD > C_STD_11
  720. # define C_VERSION "17"
  721. #elif C_STD > C_STD_99
  722. # define C_VERSION "11"
  723. #elif C_STD >= C_STD_99
  724. # define C_VERSION "99"
  725. #else
  726. # define C_VERSION "90"
  727. #endif
  728. const char* info_language_standard_default =
  729. "INFO" ":" "standard_default[" C_VERSION "]";
  730. const char* info_language_extensions_default = "INFO" ":" "extensions_default["
  731. #if (defined(__clang__) || defined(__GNUC__) || defined(__xlC__) || \
  732. defined(__TI_COMPILER_VERSION__) || defined(__RENESAS__)) && \
  733. !defined(__STRICT_ANSI__)
  734. "ON"
  735. #else
  736. "OFF"
  737. #endif
  738. "]";
  739. /*--------------------------------------------------------------------------*/
  740. #ifdef ID_VOID_MAIN
  741. void main() {}
  742. #else
  743. # if defined(__CLASSIC_C__)
  744. int main(argc, argv) int argc; char *argv[];
  745. # else
  746. int main(int argc, char* argv[])
  747. # endif
  748. {
  749. int require = 0;
  750. require += info_compiler[argc];
  751. require += info_platform[argc];
  752. require += info_arch[argc];
  753. #ifdef COMPILER_VERSION_MAJOR
  754. require += info_version[argc];
  755. #endif
  756. #if defined(COMPILER_VERSION_INTERNAL) || defined(COMPILER_VERSION_INTERNAL_STR)
  757. require += info_version_internal[argc];
  758. #endif
  759. #ifdef SIMULATE_ID
  760. require += info_simulate[argc];
  761. #endif
  762. #ifdef SIMULATE_VERSION_MAJOR
  763. require += info_simulate_version[argc];
  764. #endif
  765. #if defined(__CRAYXT_COMPUTE_LINUX_TARGET)
  766. require += info_cray[argc];
  767. #endif
  768. require += info_language_standard_default[argc];
  769. require += info_language_extensions_default[argc];
  770. (void)argv;
  771. return require;
  772. }
  773. #endif