tcctok.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /* keywords */
  2. DEF(TOK_INT, "int")
  3. DEF(TOK_VOID, "void")
  4. DEF(TOK_CHAR, "char")
  5. DEF(TOK_IF, "if")
  6. DEF(TOK_ELSE, "else")
  7. DEF(TOK_WHILE, "while")
  8. DEF(TOK_BREAK, "break")
  9. DEF(TOK_RETURN, "return")
  10. DEF(TOK_FOR, "for")
  11. DEF(TOK_EXTERN, "extern")
  12. DEF(TOK_STATIC, "static")
  13. DEF(TOK_UNSIGNED, "unsigned")
  14. DEF(TOK_GOTO, "goto")
  15. DEF(TOK_DO, "do")
  16. DEF(TOK_CONTINUE, "continue")
  17. DEF(TOK_SWITCH, "switch")
  18. DEF(TOK_CASE, "case")
  19. DEF(TOK_CONST1, "const")
  20. DEF(TOK_CONST2, "__const") /* gcc keyword */
  21. DEF(TOK_CONST3, "__const__") /* gcc keyword */
  22. DEF(TOK_VOLATILE1, "volatile")
  23. DEF(TOK_VOLATILE2, "__volatile") /* gcc keyword */
  24. DEF(TOK_VOLATILE3, "__volatile__") /* gcc keyword */
  25. DEF(TOK_LONG, "long")
  26. DEF(TOK_REGISTER, "register")
  27. DEF(TOK_SIGNED1, "signed")
  28. DEF(TOK_SIGNED2, "__signed") /* gcc keyword */
  29. DEF(TOK_SIGNED3, "__signed__") /* gcc keyword */
  30. DEF(TOK_AUTO, "auto")
  31. DEF(TOK_INLINE1, "inline")
  32. DEF(TOK_INLINE2, "__inline") /* gcc keyword */
  33. DEF(TOK_INLINE3, "__inline__") /* gcc keyword */
  34. DEF(TOK_RESTRICT1, "restrict")
  35. DEF(TOK_RESTRICT2, "__restrict")
  36. DEF(TOK_RESTRICT3, "__restrict__")
  37. DEF(TOK_EXTENSION, "__extension__") /* gcc keyword */
  38. DEF(TOK_GENERIC, "_Generic")
  39. DEF(TOK_FLOAT, "float")
  40. DEF(TOK_DOUBLE, "double")
  41. DEF(TOK_BOOL, "_Bool")
  42. DEF(TOK_SHORT, "short")
  43. DEF(TOK_STRUCT, "struct")
  44. DEF(TOK_UNION, "union")
  45. DEF(TOK_TYPEDEF, "typedef")
  46. DEF(TOK_DEFAULT, "default")
  47. DEF(TOK_ENUM, "enum")
  48. DEF(TOK_SIZEOF, "sizeof")
  49. DEF(TOK_ATTRIBUTE1, "__attribute")
  50. DEF(TOK_ATTRIBUTE2, "__attribute__")
  51. DEF(TOK_ALIGNOF1, "__alignof")
  52. DEF(TOK_ALIGNOF2, "__alignof__")
  53. DEF(TOK_TYPEOF1, "typeof")
  54. DEF(TOK_TYPEOF2, "__typeof")
  55. DEF(TOK_TYPEOF3, "__typeof__")
  56. DEF(TOK_LABEL, "__label__")
  57. DEF(TOK_ASM1, "asm")
  58. DEF(TOK_ASM2, "__asm")
  59. DEF(TOK_ASM3, "__asm__")
  60. #ifdef TCC_TARGET_ARM64
  61. DEF(TOK_UINT128, "__uint128_t")
  62. #endif
  63. /*********************************************************************/
  64. /* the following are not keywords. They are included to ease parsing */
  65. /* preprocessor only */
  66. DEF(TOK_DEFINE, "define")
  67. DEF(TOK_INCLUDE, "include")
  68. DEF(TOK_INCLUDE_NEXT, "include_next")
  69. DEF(TOK_IFDEF, "ifdef")
  70. DEF(TOK_IFNDEF, "ifndef")
  71. DEF(TOK_ELIF, "elif")
  72. DEF(TOK_ENDIF, "endif")
  73. DEF(TOK_DEFINED, "defined")
  74. DEF(TOK_UNDEF, "undef")
  75. DEF(TOK_ERROR, "error")
  76. DEF(TOK_WARNING, "warning")
  77. DEF(TOK_LINE, "line")
  78. DEF(TOK_PRAGMA, "pragma")
  79. DEF(TOK___LINE__, "__LINE__")
  80. DEF(TOK___FILE__, "__FILE__")
  81. DEF(TOK___DATE__, "__DATE__")
  82. DEF(TOK___TIME__, "__TIME__")
  83. DEF(TOK___FUNCTION__, "__FUNCTION__")
  84. DEF(TOK___VA_ARGS__, "__VA_ARGS__")
  85. DEF(TOK___COUNTER__, "__COUNTER__")
  86. /* special identifiers */
  87. DEF(TOK___FUNC__, "__func__")
  88. /* special floating point values */
  89. DEF(TOK___NAN__, "__nan__")
  90. DEF(TOK___SNAN__, "__snan__")
  91. DEF(TOK___INF__, "__inf__")
  92. /* attribute identifiers */
  93. /* XXX: handle all tokens generically since speed is not critical */
  94. DEF(TOK_SECTION1, "section")
  95. DEF(TOK_SECTION2, "__section__")
  96. DEF(TOK_ALIGNED1, "aligned")
  97. DEF(TOK_ALIGNED2, "__aligned__")
  98. DEF(TOK_PACKED1, "packed")
  99. DEF(TOK_PACKED2, "__packed__")
  100. DEF(TOK_WEAK1, "weak")
  101. DEF(TOK_WEAK2, "__weak__")
  102. DEF(TOK_ALIAS1, "alias")
  103. DEF(TOK_ALIAS2, "__alias__")
  104. DEF(TOK_UNUSED1, "unused")
  105. DEF(TOK_UNUSED2, "__unused__")
  106. DEF(TOK_CDECL1, "cdecl")
  107. DEF(TOK_CDECL2, "__cdecl")
  108. DEF(TOK_CDECL3, "__cdecl__")
  109. DEF(TOK_STDCALL1, "stdcall")
  110. DEF(TOK_STDCALL2, "__stdcall")
  111. DEF(TOK_STDCALL3, "__stdcall__")
  112. DEF(TOK_FASTCALL1, "fastcall")
  113. DEF(TOK_FASTCALL2, "__fastcall")
  114. DEF(TOK_FASTCALL3, "__fastcall__")
  115. DEF(TOK_REGPARM1, "regparm")
  116. DEF(TOK_REGPARM2, "__regparm__")
  117. DEF(TOK_MODE, "__mode__")
  118. DEF(TOK_MODE_QI, "__QI__")
  119. DEF(TOK_MODE_DI, "__DI__")
  120. DEF(TOK_MODE_HI, "__HI__")
  121. DEF(TOK_MODE_SI, "__SI__")
  122. DEF(TOK_MODE_word, "__word__")
  123. DEF(TOK_DLLEXPORT, "dllexport")
  124. DEF(TOK_DLLIMPORT, "dllimport")
  125. DEF(TOK_NODECORATE, "nodecorate")
  126. DEF(TOK_NORETURN1, "noreturn")
  127. DEF(TOK_NORETURN2, "__noreturn__")
  128. DEF(TOK_VISIBILITY1, "visibility")
  129. DEF(TOK_VISIBILITY2, "__visibility__")
  130. DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
  131. DEF(TOK_builtin_choose_expr, "__builtin_choose_expr")
  132. DEF(TOK_builtin_constant_p, "__builtin_constant_p")
  133. DEF(TOK_builtin_frame_address, "__builtin_frame_address")
  134. DEF(TOK_builtin_return_address, "__builtin_return_address")
  135. DEF(TOK_builtin_expect, "__builtin_expect")
  136. /*DEF(TOK_builtin_va_list, "__builtin_va_list")*/
  137. #if defined TCC_TARGET_PE && defined TCC_TARGET_X86_64
  138. DEF(TOK_builtin_va_start, "__builtin_va_start")
  139. #elif defined TCC_TARGET_X86_64
  140. DEF(TOK_builtin_va_arg_types, "__builtin_va_arg_types")
  141. #elif defined TCC_TARGET_ARM64
  142. DEF(TOK___va_start, "__va_start")
  143. DEF(TOK___va_arg, "__va_arg")
  144. #endif
  145. /* pragma */
  146. DEF(TOK_pack, "pack")
  147. #if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_X86_64)
  148. /* already defined for assembler */
  149. DEF(TOK_ASM_push, "push")
  150. DEF(TOK_ASM_pop, "pop")
  151. #endif
  152. DEF(TOK_comment, "comment")
  153. DEF(TOK_lib, "lib")
  154. DEF(TOK_push_macro, "push_macro")
  155. DEF(TOK_pop_macro, "pop_macro")
  156. DEF(TOK_once, "once")
  157. DEF(TOK_option, "option")
  158. /* builtin functions or variables */
  159. #ifndef TCC_ARM_EABI
  160. DEF(TOK_memcpy, "memcpy")
  161. DEF(TOK_memmove, "memmove")
  162. DEF(TOK_memset, "memset")
  163. DEF(TOK___divdi3, "__divdi3")
  164. DEF(TOK___moddi3, "__moddi3")
  165. DEF(TOK___udivdi3, "__udivdi3")
  166. DEF(TOK___umoddi3, "__umoddi3")
  167. DEF(TOK___ashrdi3, "__ashrdi3")
  168. DEF(TOK___lshrdi3, "__lshrdi3")
  169. DEF(TOK___ashldi3, "__ashldi3")
  170. DEF(TOK___floatundisf, "__floatundisf")
  171. DEF(TOK___floatundidf, "__floatundidf")
  172. # ifndef TCC_ARM_VFP
  173. DEF(TOK___floatundixf, "__floatundixf")
  174. DEF(TOK___fixunsxfdi, "__fixunsxfdi")
  175. # endif
  176. DEF(TOK___fixunssfdi, "__fixunssfdi")
  177. DEF(TOK___fixunsdfdi, "__fixunsdfdi")
  178. #endif
  179. #if defined TCC_TARGET_ARM
  180. # ifdef TCC_ARM_EABI
  181. DEF(TOK_memcpy, "__aeabi_memcpy")
  182. DEF(TOK_memcpy4, "__aeabi_memcpy4")
  183. DEF(TOK_memcpy8, "__aeabi_memcpy8")
  184. DEF(TOK_memmove, "__aeabi_memmove")
  185. DEF(TOK_memset, "__aeabi_memset")
  186. DEF(TOK___aeabi_ldivmod, "__aeabi_ldivmod")
  187. DEF(TOK___aeabi_uldivmod, "__aeabi_uldivmod")
  188. DEF(TOK___aeabi_idivmod, "__aeabi_idivmod")
  189. DEF(TOK___aeabi_uidivmod, "__aeabi_uidivmod")
  190. DEF(TOK___divsi3, "__aeabi_idiv")
  191. DEF(TOK___udivsi3, "__aeabi_uidiv")
  192. DEF(TOK___floatdisf, "__aeabi_l2f")
  193. DEF(TOK___floatdidf, "__aeabi_l2d")
  194. DEF(TOK___fixsfdi, "__aeabi_f2lz")
  195. DEF(TOK___fixdfdi, "__aeabi_d2lz")
  196. DEF(TOK___ashrdi3, "__aeabi_lasr")
  197. DEF(TOK___lshrdi3, "__aeabi_llsr")
  198. DEF(TOK___ashldi3, "__aeabi_llsl")
  199. DEF(TOK___floatundisf, "__aeabi_ul2f")
  200. DEF(TOK___floatundidf, "__aeabi_ul2d")
  201. DEF(TOK___fixunssfdi, "__aeabi_f2ulz")
  202. DEF(TOK___fixunsdfdi, "__aeabi_d2ulz")
  203. # else
  204. DEF(TOK___modsi3, "__modsi3")
  205. DEF(TOK___umodsi3, "__umodsi3")
  206. DEF(TOK___divsi3, "__divsi3")
  207. DEF(TOK___udivsi3, "__udivsi3")
  208. DEF(TOK___floatdisf, "__floatdisf")
  209. DEF(TOK___floatdidf, "__floatdidf")
  210. # ifndef TCC_ARM_VFP
  211. DEF(TOK___floatdixf, "__floatdixf")
  212. DEF(TOK___fixunssfsi, "__fixunssfsi")
  213. DEF(TOK___fixunsdfsi, "__fixunsdfsi")
  214. DEF(TOK___fixunsxfsi, "__fixunsxfsi")
  215. DEF(TOK___fixxfdi, "__fixxfdi")
  216. # endif
  217. DEF(TOK___fixsfdi, "__fixsfdi")
  218. DEF(TOK___fixdfdi, "__fixdfdi")
  219. # endif
  220. #endif
  221. #if defined TCC_TARGET_C67
  222. DEF(TOK__divi, "_divi")
  223. DEF(TOK__divu, "_divu")
  224. DEF(TOK__divf, "_divf")
  225. DEF(TOK__divd, "_divd")
  226. DEF(TOK__remi, "_remi")
  227. DEF(TOK__remu, "_remu")
  228. #endif
  229. #if defined TCC_TARGET_I386
  230. DEF(TOK___fixsfdi, "__fixsfdi")
  231. DEF(TOK___fixdfdi, "__fixdfdi")
  232. DEF(TOK___fixxfdi, "__fixxfdi")
  233. #endif
  234. #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
  235. DEF(TOK_alloca, "alloca")
  236. #endif
  237. #if defined TCC_TARGET_PE
  238. DEF(TOK___chkstk, "__chkstk")
  239. #endif
  240. #ifdef TCC_TARGET_ARM64
  241. DEF(TOK___arm64_clear_cache, "__arm64_clear_cache")
  242. DEF(TOK___addtf3, "__addtf3")
  243. DEF(TOK___subtf3, "__subtf3")
  244. DEF(TOK___multf3, "__multf3")
  245. DEF(TOK___divtf3, "__divtf3")
  246. DEF(TOK___extendsftf2, "__extendsftf2")
  247. DEF(TOK___extenddftf2, "__extenddftf2")
  248. DEF(TOK___trunctfsf2, "__trunctfsf2")
  249. DEF(TOK___trunctfdf2, "__trunctfdf2")
  250. DEF(TOK___fixtfsi, "__fixtfsi")
  251. DEF(TOK___fixtfdi, "__fixtfdi")
  252. DEF(TOK___fixunstfsi, "__fixunstfsi")
  253. DEF(TOK___fixunstfdi, "__fixunstfdi")
  254. DEF(TOK___floatsitf, "__floatsitf")
  255. DEF(TOK___floatditf, "__floatditf")
  256. DEF(TOK___floatunsitf, "__floatunsitf")
  257. DEF(TOK___floatunditf, "__floatunditf")
  258. DEF(TOK___eqtf2, "__eqtf2")
  259. DEF(TOK___netf2, "__netf2")
  260. DEF(TOK___lttf2, "__lttf2")
  261. DEF(TOK___letf2, "__letf2")
  262. DEF(TOK___gttf2, "__gttf2")
  263. DEF(TOK___getf2, "__getf2")
  264. #endif
  265. /* bound checking symbols */
  266. #ifdef CONFIG_TCC_BCHECK
  267. DEF(TOK___bound_ptr_add, "__bound_ptr_add")
  268. DEF(TOK___bound_ptr_indir1, "__bound_ptr_indir1")
  269. DEF(TOK___bound_ptr_indir2, "__bound_ptr_indir2")
  270. DEF(TOK___bound_ptr_indir4, "__bound_ptr_indir4")
  271. DEF(TOK___bound_ptr_indir8, "__bound_ptr_indir8")
  272. DEF(TOK___bound_ptr_indir12, "__bound_ptr_indir12")
  273. DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16")
  274. DEF(TOK___bound_main_arg, "__bound_main_arg")
  275. DEF(TOK___bound_local_new, "__bound_local_new")
  276. DEF(TOK___bound_local_delete, "__bound_local_delete")
  277. # ifdef TCC_TARGET_PE
  278. DEF(TOK_malloc, "malloc")
  279. DEF(TOK_free, "free")
  280. DEF(TOK_realloc, "realloc")
  281. DEF(TOK_memalign, "memalign")
  282. DEF(TOK_calloc, "calloc")
  283. # endif
  284. DEF(TOK_strlen, "strlen")
  285. DEF(TOK_strcpy, "strcpy")
  286. #endif
  287. /* Tiny Assembler */
  288. DEF_ASMDIR(byte) /* must be first directive */
  289. DEF_ASMDIR(word)
  290. DEF_ASMDIR(align)
  291. DEF_ASMDIR(balign)
  292. DEF_ASMDIR(p2align)
  293. DEF_ASMDIR(set)
  294. DEF_ASMDIR(skip)
  295. DEF_ASMDIR(space)
  296. DEF_ASMDIR(string)
  297. DEF_ASMDIR(asciz)
  298. DEF_ASMDIR(ascii)
  299. DEF_ASMDIR(file)
  300. DEF_ASMDIR(globl)
  301. DEF_ASMDIR(global)
  302. DEF_ASMDIR(weak)
  303. DEF_ASMDIR(hidden)
  304. DEF_ASMDIR(ident)
  305. DEF_ASMDIR(size)
  306. DEF_ASMDIR(type)
  307. DEF_ASMDIR(text)
  308. DEF_ASMDIR(data)
  309. DEF_ASMDIR(bss)
  310. DEF_ASMDIR(previous)
  311. DEF_ASMDIR(pushsection)
  312. DEF_ASMDIR(popsection)
  313. DEF_ASMDIR(fill)
  314. DEF_ASMDIR(rept)
  315. DEF_ASMDIR(endr)
  316. DEF_ASMDIR(org)
  317. DEF_ASMDIR(quad)
  318. #if defined(TCC_TARGET_I386)
  319. DEF_ASMDIR(code16)
  320. DEF_ASMDIR(code32)
  321. #elif defined(TCC_TARGET_X86_64)
  322. DEF_ASMDIR(code64)
  323. #endif
  324. DEF_ASMDIR(short)
  325. DEF_ASMDIR(long)
  326. DEF_ASMDIR(int)
  327. DEF_ASMDIR(section) /* must be last directive */
  328. #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
  329. #include "i386-tok.h"
  330. #endif