tcctok.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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_FLOAT, "float")
  39. DEF(TOK_DOUBLE, "double")
  40. DEF(TOK_BOOL, "_Bool")
  41. DEF(TOK_SHORT, "short")
  42. DEF(TOK_STRUCT, "struct")
  43. DEF(TOK_UNION, "union")
  44. DEF(TOK_TYPEDEF, "typedef")
  45. DEF(TOK_DEFAULT, "default")
  46. DEF(TOK_ENUM, "enum")
  47. DEF(TOK_SIZEOF, "sizeof")
  48. DEF(TOK_ATTRIBUTE1, "__attribute")
  49. DEF(TOK_ATTRIBUTE2, "__attribute__")
  50. DEF(TOK_ALIGNOF1, "__alignof")
  51. DEF(TOK_ALIGNOF2, "__alignof__")
  52. DEF(TOK_TYPEOF1, "typeof")
  53. DEF(TOK_TYPEOF2, "__typeof")
  54. DEF(TOK_TYPEOF3, "__typeof__")
  55. DEF(TOK_LABEL, "__label__")
  56. DEF(TOK_ASM1, "asm")
  57. DEF(TOK_ASM2, "__asm")
  58. DEF(TOK_ASM3, "__asm__")
  59. /*********************************************************************/
  60. /* the following are not keywords. They are included to ease parsing */
  61. /* preprocessor only */
  62. DEF(TOK_DEFINE, "define")
  63. DEF(TOK_INCLUDE, "include")
  64. DEF(TOK_INCLUDE_NEXT, "include_next")
  65. DEF(TOK_IFDEF, "ifdef")
  66. DEF(TOK_IFNDEF, "ifndef")
  67. DEF(TOK_ELIF, "elif")
  68. DEF(TOK_ENDIF, "endif")
  69. DEF(TOK_DEFINED, "defined")
  70. DEF(TOK_UNDEF, "undef")
  71. DEF(TOK_ERROR, "error")
  72. DEF(TOK_WARNING, "warning")
  73. DEF(TOK_LINE, "line")
  74. DEF(TOK_PRAGMA, "pragma")
  75. DEF(TOK___LINE__, "__LINE__")
  76. DEF(TOK___FILE__, "__FILE__")
  77. DEF(TOK___DATE__, "__DATE__")
  78. DEF(TOK___TIME__, "__TIME__")
  79. DEF(TOK___FUNCTION__, "__FUNCTION__")
  80. DEF(TOK___VA_ARGS__, "__VA_ARGS__")
  81. /* special identifiers */
  82. DEF(TOK___FUNC__, "__func__")
  83. /* attribute identifiers */
  84. /* XXX: handle all tokens generically since speed is not critical */
  85. DEF(TOK_SECTION1, "section")
  86. DEF(TOK_SECTION2, "__section__")
  87. DEF(TOK_ALIGNED1, "aligned")
  88. DEF(TOK_ALIGNED2, "__aligned__")
  89. DEF(TOK_PACKED1, "packed")
  90. DEF(TOK_PACKED2, "__packed__")
  91. DEF(TOK_UNUSED1, "unused")
  92. DEF(TOK_UNUSED2, "__unused__")
  93. DEF(TOK_CDECL1, "cdecl")
  94. DEF(TOK_CDECL2, "__cdecl")
  95. DEF(TOK_CDECL3, "__cdecl__")
  96. DEF(TOK_STDCALL1, "stdcall")
  97. DEF(TOK_STDCALL2, "__stdcall")
  98. DEF(TOK_STDCALL3, "__stdcall__")
  99. DEF(TOK_FASTCALL1, "fastcall")
  100. DEF(TOK_FASTCALL2, "__fastcall")
  101. DEF(TOK_FASTCALL3, "__fastcall__")
  102. DEF(TOK_DLLEXPORT, "dllexport")
  103. DEF(TOK_NORETURN1, "noreturn")
  104. DEF(TOK_NORETURN2, "__noreturn__")
  105. DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
  106. DEF(TOK_builtin_constant_p, "__builtin_constant_p")
  107. DEF(TOK_builtin_frame_address, "__builtin_frame_address")
  108. #ifdef TCC_TARGET_X86_64
  109. DEF(TOK_builtin_malloc, "__builtin_malloc")
  110. DEF(TOK_builtin_free, "__builtin_free")
  111. DEF(TOK_malloc, "malloc")
  112. DEF(TOK_free, "free")
  113. #endif
  114. DEF(TOK_REGPARM1, "regparm")
  115. DEF(TOK_REGPARM2, "__regparm__")
  116. /* pragma */
  117. DEF(TOK_pack, "pack")
  118. #if !defined(TCC_TARGET_I386)
  119. /* already defined for assembler */
  120. DEF(TOK_ASM_push, "push")
  121. DEF(TOK_ASM_pop, "pop")
  122. #endif
  123. /* builtin functions or variables */
  124. #ifdef TCC_ARM_EABI
  125. DEF(TOK_memcpy, "__aeabi_memcpy")
  126. DEF(TOK_memcpy4, "__aeabi_memcpy4")
  127. DEF(TOK_memcpy8, "__aeabi_memcpy8")
  128. DEF(TOK_memset, "__aeabi_memset")
  129. DEF(TOK___aeabi_ldivmod, "__aeabi_ldivmod")
  130. DEF(TOK___aeabi_uldivmod, "__aeabi_uldivmod")
  131. #else
  132. DEF(TOK_memcpy, "memcpy")
  133. DEF(TOK_memset, "memset")
  134. DEF(TOK___divdi3, "__divdi3")
  135. DEF(TOK___moddi3, "__moddi3")
  136. DEF(TOK___udivdi3, "__udivdi3")
  137. DEF(TOK___umoddi3, "__umoddi3")
  138. #endif
  139. #if defined(TCC_TARGET_ARM)
  140. #ifdef TCC_ARM_EABI
  141. DEF(TOK___aeabi_idivmod, "__aeabi_idivmod")
  142. DEF(TOK___aeabi_uidivmod, "__aeabi_uidivmod")
  143. DEF(TOK___divsi3, "__aeabi_idiv")
  144. DEF(TOK___udivsi3, "__aeabi_uidiv")
  145. DEF(TOK___floatdisf, "__aeabi_l2f")
  146. DEF(TOK___floatdidf, "__aeabi_l2d")
  147. DEF(TOK___fixsfdi, "__aeabi_f2lz")
  148. DEF(TOK___fixdfdi, "__aeabi_d2lz")
  149. #else
  150. DEF(TOK___modsi3, "__modsi3")
  151. DEF(TOK___umodsi3, "__umodsi3")
  152. DEF(TOK___divsi3, "__divsi3")
  153. DEF(TOK___udivsi3, "__udivsi3")
  154. DEF(TOK___floatdisf, "__floatdisf")
  155. DEF(TOK___floatdidf, "__floatdidf")
  156. #ifndef TCC_ARM_VFP
  157. DEF(TOK___floatdixf, "__floatdixf")
  158. DEF(TOK___fixunssfsi, "__fixunssfsi")
  159. DEF(TOK___fixunsdfsi, "__fixunsdfsi")
  160. DEF(TOK___fixunsxfsi, "__fixunsxfsi")
  161. DEF(TOK___fixxfdi, "__fixxfdi")
  162. #endif
  163. DEF(TOK___fixsfdi, "__fixsfdi")
  164. DEF(TOK___fixdfdi, "__fixdfdi")
  165. #endif
  166. #elif defined(TCC_TARGET_C67)
  167. DEF(TOK__divi, "_divi")
  168. DEF(TOK__divu, "_divu")
  169. DEF(TOK__divf, "_divf")
  170. DEF(TOK__divd, "_divd")
  171. DEF(TOK__remi, "_remi")
  172. DEF(TOK__remu, "_remu")
  173. #endif
  174. #ifdef TCC_TARGET_I386
  175. DEF(TOK___tcc_int_fpu_control, "__tcc_int_fpu_control")
  176. DEF(TOK___tcc_fpu_control, "__tcc_fpu_control")
  177. #endif
  178. #ifdef TCC_ARM_EABI
  179. DEF(TOK___ashrdi3, "__aeabi_lasr")
  180. DEF(TOK___lshrdi3, "__aeabi_llsr")
  181. DEF(TOK___ashldi3, "__aeabi_llsl")
  182. DEF(TOK___floatundisf, "__aeabi_ul2f")
  183. DEF(TOK___floatundidf, "__aeabi_ul2d")
  184. DEF(TOK___fixunssfdi, "__aeabi_f2ulz")
  185. DEF(TOK___fixunsdfdi, "__aeabi_d2ulz")
  186. #else
  187. DEF(TOK___ashrdi3, "__ashrdi3")
  188. DEF(TOK___lshrdi3, "__lshrdi3")
  189. DEF(TOK___ashldi3, "__ashldi3")
  190. DEF(TOK___floatundisf, "__floatundisf")
  191. DEF(TOK___floatundidf, "__floatundidf")
  192. #ifndef TCC_ARM_VFP
  193. DEF(TOK___floatundixf, "__floatundixf")
  194. DEF(TOK___fixunsxfdi, "__fixunsxfdi")
  195. #endif
  196. DEF(TOK___fixunssfdi, "__fixunssfdi")
  197. DEF(TOK___fixunsdfdi, "__fixunsdfdi")
  198. #endif
  199. #ifdef TCC_TARGET_PE
  200. DEF(TOK___chkstk, "__chkstk")
  201. #endif
  202. /* bound checking symbols */
  203. #ifdef CONFIG_TCC_BCHECK
  204. DEF(TOK___bound_ptr_add, "__bound_ptr_add")
  205. DEF(TOK___bound_ptr_indir1, "__bound_ptr_indir1")
  206. DEF(TOK___bound_ptr_indir2, "__bound_ptr_indir2")
  207. DEF(TOK___bound_ptr_indir4, "__bound_ptr_indir4")
  208. DEF(TOK___bound_ptr_indir8, "__bound_ptr_indir8")
  209. DEF(TOK___bound_ptr_indir12, "__bound_ptr_indir12")
  210. DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16")
  211. DEF(TOK___bound_local_new, "__bound_local_new")
  212. DEF(TOK___bound_local_delete, "__bound_local_delete")
  213. #if 0
  214. DEF(TOK_malloc, "malloc")
  215. DEF(TOK_free, "free")
  216. DEF(TOK_realloc, "realloc")
  217. DEF(TOK_memalign, "memalign")
  218. DEF(TOK_calloc, "calloc")
  219. #endif
  220. DEF(TOK_memmove, "memmove")
  221. DEF(TOK_strlen, "strlen")
  222. DEF(TOK_strcpy, "strcpy")
  223. DEF(TOK_alloca, "alloca")
  224. #endif
  225. /* Tiny Assembler */
  226. DEF_ASM(byte)
  227. DEF_ASM(align)
  228. DEF_ASM(skip)
  229. DEF_ASM(space)
  230. DEF_ASM(string)
  231. DEF_ASM(asciz)
  232. DEF_ASM(ascii)
  233. DEF_ASM(globl)
  234. DEF_ASM(global)
  235. DEF_ASM(text)
  236. DEF_ASM(data)
  237. DEF_ASM(bss)
  238. DEF_ASM(previous)
  239. DEF_ASM(fill)
  240. DEF_ASM(org)
  241. DEF_ASM(quad)
  242. #ifdef TCC_TARGET_I386
  243. /* WARNING: relative order of tokens is important. */
  244. DEF_ASM(al)
  245. DEF_ASM(cl)
  246. DEF_ASM(dl)
  247. DEF_ASM(bl)
  248. DEF_ASM(ah)
  249. DEF_ASM(ch)
  250. DEF_ASM(dh)
  251. DEF_ASM(bh)
  252. DEF_ASM(ax)
  253. DEF_ASM(cx)
  254. DEF_ASM(dx)
  255. DEF_ASM(bx)
  256. DEF_ASM(sp)
  257. DEF_ASM(bp)
  258. DEF_ASM(si)
  259. DEF_ASM(di)
  260. DEF_ASM(eax)
  261. DEF_ASM(ecx)
  262. DEF_ASM(edx)
  263. DEF_ASM(ebx)
  264. DEF_ASM(esp)
  265. DEF_ASM(ebp)
  266. DEF_ASM(esi)
  267. DEF_ASM(edi)
  268. DEF_ASM(mm0)
  269. DEF_ASM(mm1)
  270. DEF_ASM(mm2)
  271. DEF_ASM(mm3)
  272. DEF_ASM(mm4)
  273. DEF_ASM(mm5)
  274. DEF_ASM(mm6)
  275. DEF_ASM(mm7)
  276. DEF_ASM(xmm0)
  277. DEF_ASM(xmm1)
  278. DEF_ASM(xmm2)
  279. DEF_ASM(xmm3)
  280. DEF_ASM(xmm4)
  281. DEF_ASM(xmm5)
  282. DEF_ASM(xmm6)
  283. DEF_ASM(xmm7)
  284. DEF_ASM(cr0)
  285. DEF_ASM(cr1)
  286. DEF_ASM(cr2)
  287. DEF_ASM(cr3)
  288. DEF_ASM(cr4)
  289. DEF_ASM(cr5)
  290. DEF_ASM(cr6)
  291. DEF_ASM(cr7)
  292. DEF_ASM(tr0)
  293. DEF_ASM(tr1)
  294. DEF_ASM(tr2)
  295. DEF_ASM(tr3)
  296. DEF_ASM(tr4)
  297. DEF_ASM(tr5)
  298. DEF_ASM(tr6)
  299. DEF_ASM(tr7)
  300. DEF_ASM(db0)
  301. DEF_ASM(db1)
  302. DEF_ASM(db2)
  303. DEF_ASM(db3)
  304. DEF_ASM(db4)
  305. DEF_ASM(db5)
  306. DEF_ASM(db6)
  307. DEF_ASM(db7)
  308. DEF_ASM(dr0)
  309. DEF_ASM(dr1)
  310. DEF_ASM(dr2)
  311. DEF_ASM(dr3)
  312. DEF_ASM(dr4)
  313. DEF_ASM(dr5)
  314. DEF_ASM(dr6)
  315. DEF_ASM(dr7)
  316. DEF_ASM(es)
  317. DEF_ASM(cs)
  318. DEF_ASM(ss)
  319. DEF_ASM(ds)
  320. DEF_ASM(fs)
  321. DEF_ASM(gs)
  322. DEF_ASM(st)
  323. DEF_BWL(mov)
  324. /* generic two operands */
  325. DEF_BWL(add)
  326. DEF_BWL(or)
  327. DEF_BWL(adc)
  328. DEF_BWL(sbb)
  329. DEF_BWL(and)
  330. DEF_BWL(sub)
  331. DEF_BWL(xor)
  332. DEF_BWL(cmp)
  333. /* unary ops */
  334. DEF_BWL(inc)
  335. DEF_BWL(dec)
  336. DEF_BWL(not)
  337. DEF_BWL(neg)
  338. DEF_BWL(mul)
  339. DEF_BWL(imul)
  340. DEF_BWL(div)
  341. DEF_BWL(idiv)
  342. DEF_BWL(xchg)
  343. DEF_BWL(test)
  344. /* shifts */
  345. DEF_BWL(rol)
  346. DEF_BWL(ror)
  347. DEF_BWL(rcl)
  348. DEF_BWL(rcr)
  349. DEF_BWL(shl)
  350. DEF_BWL(shr)
  351. DEF_BWL(sar)
  352. DEF_ASM(shldw)
  353. DEF_ASM(shldl)
  354. DEF_ASM(shld)
  355. DEF_ASM(shrdw)
  356. DEF_ASM(shrdl)
  357. DEF_ASM(shrd)
  358. DEF_ASM(pushw)
  359. DEF_ASM(pushl)
  360. DEF_ASM(push)
  361. DEF_ASM(popw)
  362. DEF_ASM(popl)
  363. DEF_ASM(pop)
  364. DEF_BWL(in)
  365. DEF_BWL(out)
  366. DEF_WL(movzb)
  367. DEF_ASM(movzwl)
  368. DEF_ASM(movsbw)
  369. DEF_ASM(movsbl)
  370. DEF_ASM(movswl)
  371. DEF_WL(lea)
  372. DEF_ASM(les)
  373. DEF_ASM(lds)
  374. DEF_ASM(lss)
  375. DEF_ASM(lfs)
  376. DEF_ASM(lgs)
  377. DEF_ASM(call)
  378. DEF_ASM(jmp)
  379. DEF_ASM(lcall)
  380. DEF_ASM(ljmp)
  381. DEF_ASMTEST(j)
  382. DEF_ASMTEST(set)
  383. DEF_ASMTEST(cmov)
  384. DEF_WL(bsf)
  385. DEF_WL(bsr)
  386. DEF_WL(bt)
  387. DEF_WL(bts)
  388. DEF_WL(btr)
  389. DEF_WL(btc)
  390. DEF_WL(lsl)
  391. /* generic FP ops */
  392. DEF_FP(add)
  393. DEF_FP(mul)
  394. DEF_ASM(fcom)
  395. DEF_ASM(fcom_1) /* non existent op, just to have a regular table */
  396. DEF_FP1(com)
  397. DEF_FP(comp)
  398. DEF_FP(sub)
  399. DEF_FP(subr)
  400. DEF_FP(div)
  401. DEF_FP(divr)
  402. DEF_BWL(xadd)
  403. DEF_BWL(cmpxchg)
  404. /* string ops */
  405. DEF_BWL(cmps)
  406. DEF_BWL(scmp)
  407. DEF_BWL(ins)
  408. DEF_BWL(outs)
  409. DEF_BWL(lods)
  410. DEF_BWL(slod)
  411. DEF_BWL(movs)
  412. DEF_BWL(smov)
  413. DEF_BWL(scas)
  414. DEF_BWL(ssca)
  415. DEF_BWL(stos)
  416. DEF_BWL(ssto)
  417. /* generic asm ops */
  418. #define ALT(x)
  419. #define DEF_ASM_OP0(name, opcode) DEF_ASM(name)
  420. #define DEF_ASM_OP0L(name, opcode, group, instr_type)
  421. #define DEF_ASM_OP1(name, opcode, group, instr_type, op0)
  422. #define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1)
  423. #define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2)
  424. #include "i386-asm.h"
  425. #define ALT(x)
  426. #define DEF_ASM_OP0(name, opcode)
  427. #define DEF_ASM_OP0L(name, opcode, group, instr_type) DEF_ASM(name)
  428. #define DEF_ASM_OP1(name, opcode, group, instr_type, op0) DEF_ASM(name)
  429. #define DEF_ASM_OP2(name, opcode, group, instr_type, op0, op1) DEF_ASM(name)
  430. #define DEF_ASM_OP3(name, opcode, group, instr_type, op0, op1, op2) DEF_ASM(name)
  431. #include "i386-asm.h"
  432. #endif