tcc 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +35 -0
  3. data/README.md +196 -0
  4. data/ext/tcc/extconf.rb +25 -0
  5. data/ext/tcc/tcc-0.9.26.patch +30 -0
  6. data/ext/tcc/tcc-0.9.26/COPYING +504 -0
  7. data/ext/tcc/tcc-0.9.26/Changelog +396 -0
  8. data/ext/tcc/tcc-0.9.26/Makefile +349 -0
  9. data/ext/tcc/tcc-0.9.26/README +101 -0
  10. data/ext/tcc/tcc-0.9.26/TODO +93 -0
  11. data/ext/tcc/tcc-0.9.26/VERSION +1 -0
  12. data/ext/tcc/tcc-0.9.26/arm-gen.c +2005 -0
  13. data/ext/tcc/tcc-0.9.26/c67-gen.c +2560 -0
  14. data/ext/tcc/tcc-0.9.26/coff.h +446 -0
  15. data/ext/tcc/tcc-0.9.26/config.h +8 -0
  16. data/ext/tcc/tcc-0.9.26/config.mak +28 -0
  17. data/ext/tcc/tcc-0.9.26/config.texi +1 -0
  18. data/ext/tcc/tcc-0.9.26/configure +540 -0
  19. data/ext/tcc/tcc-0.9.26/conftest.c +71 -0
  20. data/ext/tcc/tcc-0.9.26/elf.h +1731 -0
  21. data/ext/tcc/tcc-0.9.26/examples/ex1.c +8 -0
  22. data/ext/tcc/tcc-0.9.26/examples/ex2.c +98 -0
  23. data/ext/tcc/tcc-0.9.26/examples/ex3.c +24 -0
  24. data/ext/tcc/tcc-0.9.26/examples/ex4.c +26 -0
  25. data/ext/tcc/tcc-0.9.26/examples/ex5.c +8 -0
  26. data/ext/tcc/tcc-0.9.26/i386-asm.c +1498 -0
  27. data/ext/tcc/tcc-0.9.26/i386-asm.h +473 -0
  28. data/ext/tcc/tcc-0.9.26/i386-gen.c +1096 -0
  29. data/ext/tcc/tcc-0.9.26/i386-tok.h +243 -0
  30. data/ext/tcc/tcc-0.9.26/il-gen.c +667 -0
  31. data/ext/tcc/tcc-0.9.26/il-opcodes.h +251 -0
  32. data/ext/tcc/tcc-0.9.26/include/float.h +57 -0
  33. data/ext/tcc/tcc-0.9.26/include/stdarg.h +41 -0
  34. data/ext/tcc/tcc-0.9.26/include/stdbool.h +10 -0
  35. data/ext/tcc/tcc-0.9.26/include/stddef.h +28 -0
  36. data/ext/tcc/tcc-0.9.26/include/tcclib.h +78 -0
  37. data/ext/tcc/tcc-0.9.26/include/varargs.h +12 -0
  38. data/ext/tcc/tcc-0.9.26/lib/Makefile +102 -0
  39. data/ext/tcc/tcc-0.9.26/lib/alloca86-bt.S +47 -0
  40. data/ext/tcc/tcc-0.9.26/lib/alloca86.S +35 -0
  41. data/ext/tcc/tcc-0.9.26/lib/alloca86_64.S +42 -0
  42. data/ext/tcc/tcc-0.9.26/lib/bcheck.c +875 -0
  43. data/ext/tcc/tcc-0.9.26/lib/libtcc1.c +691 -0
  44. data/ext/tcc/tcc-0.9.26/libtcc.c +1941 -0
  45. data/ext/tcc/tcc-0.9.26/libtcc.h +103 -0
  46. data/ext/tcc/tcc-0.9.26/stab.def +234 -0
  47. data/ext/tcc/tcc-0.9.26/stab.h +17 -0
  48. data/ext/tcc/tcc-0.9.26/tcc-doc.html +2332 -0
  49. data/ext/tcc/tcc-0.9.26/tcc-doc.info +1151 -0
  50. data/ext/tcc/tcc-0.9.26/tcc-doc.texi +1268 -0
  51. data/ext/tcc/tcc-0.9.26/tcc.1 +415 -0
  52. data/ext/tcc/tcc-0.9.26/tcc.c +352 -0
  53. data/ext/tcc/tcc-0.9.26/tcc.h +1379 -0
  54. data/ext/tcc/tcc-0.9.26/tccasm.c +1118 -0
  55. data/ext/tcc/tcc-0.9.26/tcccoff.c +948 -0
  56. data/ext/tcc/tcc-0.9.26/tccelf.c +3129 -0
  57. data/ext/tcc/tcc-0.9.26/tccgen.c +5841 -0
  58. data/ext/tcc/tcc-0.9.26/tccpe.c +1887 -0
  59. data/ext/tcc/tcc-0.9.26/tccpp.c +3128 -0
  60. data/ext/tcc/tcc-0.9.26/tccrun.c +737 -0
  61. data/ext/tcc/tcc-0.9.26/tcctok.h +278 -0
  62. data/ext/tcc/tcc-0.9.26/tests/Makefile +199 -0
  63. data/ext/tcc/tcc-0.9.26/tests/asmtest.S +609 -0
  64. data/ext/tcc/tcc-0.9.26/tests/boundtest.c +233 -0
  65. data/ext/tcc/tcc-0.9.26/tests/gcctestsuite.sh +33 -0
  66. data/ext/tcc/tcc-0.9.26/tests/libtcc_test.c +76 -0
  67. data/ext/tcc/tcc-0.9.26/tests/tcctest.c +2713 -0
  68. data/ext/tcc/tcc-0.9.26/tests/tests2/00_assignment.c +18 -0
  69. data/ext/tcc/tcc-0.9.26/tests/tests2/00_assignment.expect +3 -0
  70. data/ext/tcc/tcc-0.9.26/tests/tests2/01_comment.c +14 -0
  71. data/ext/tcc/tcc-0.9.26/tests/tests2/01_comment.expect +5 -0
  72. data/ext/tcc/tcc-0.9.26/tests/tests2/02_printf.c +18 -0
  73. data/ext/tcc/tcc-0.9.26/tests/tests2/02_printf.expect +15 -0
  74. data/ext/tcc/tcc-0.9.26/tests/tests2/03_struct.c +31 -0
  75. data/ext/tcc/tcc-0.9.26/tests/tests2/03_struct.expect +6 -0
  76. data/ext/tcc/tcc-0.9.26/tests/tests2/04_for.c +15 -0
  77. data/ext/tcc/tcc-0.9.26/tests/tests2/04_for.expect +10 -0
  78. data/ext/tcc/tcc-0.9.26/tests/tests2/05_array.c +21 -0
  79. data/ext/tcc/tcc-0.9.26/tests/tests2/05_array.expect +10 -0
  80. data/ext/tcc/tcc-0.9.26/tests/tests2/06_case.c +29 -0
  81. data/ext/tcc/tcc-0.9.26/tests/tests2/06_case.expect +8 -0
  82. data/ext/tcc/tcc-0.9.26/tests/tests2/07_function.c +30 -0
  83. data/ext/tcc/tcc-0.9.26/tests/tests2/07_function.expect +4 -0
  84. data/ext/tcc/tcc-0.9.26/tests/tests2/08_while.c +24 -0
  85. data/ext/tcc/tcc-0.9.26/tests/tests2/08_while.expect +11 -0
  86. data/ext/tcc/tcc-0.9.26/tests/tests2/09_do_while.c +24 -0
  87. data/ext/tcc/tcc-0.9.26/tests/tests2/09_do_while.expect +11 -0
  88. data/ext/tcc/tcc-0.9.26/tests/tests2/10_pointer.c +40 -0
  89. data/ext/tcc/tcc-0.9.26/tests/tests2/10_pointer.expect +8 -0
  90. data/ext/tcc/tcc-0.9.26/tests/tests2/11_precedence.c +40 -0
  91. data/ext/tcc/tcc-0.9.26/tests/tests2/11_precedence.expect +15 -0
  92. data/ext/tcc/tcc-0.9.26/tests/tests2/12_hashdefine.c +14 -0
  93. data/ext/tcc/tcc-0.9.26/tests/tests2/12_hashdefine.expect +2 -0
  94. data/ext/tcc/tcc-0.9.26/tests/tests2/13_integer_literals.c +20 -0
  95. data/ext/tcc/tcc-0.9.26/tests/tests2/13_integer_literals.expect +5 -0
  96. data/ext/tcc/tcc-0.9.26/tests/tests2/14_if.c +21 -0
  97. data/ext/tcc/tcc-0.9.26/tests/tests2/14_if.expect +2 -0
  98. data/ext/tcc/tcc-0.9.26/tests/tests2/15_recursion.c +21 -0
  99. data/ext/tcc/tcc-0.9.26/tests/tests2/15_recursion.expect +10 -0
  100. data/ext/tcc/tcc-0.9.26/tests/tests2/16_nesting.c +21 -0
  101. data/ext/tcc/tcc-0.9.26/tests/tests2/16_nesting.expect +18 -0
  102. data/ext/tcc/tcc-0.9.26/tests/tests2/17_enum.c +29 -0
  103. data/ext/tcc/tcc-0.9.26/tests/tests2/17_enum.expect +3 -0
  104. data/ext/tcc/tcc-0.9.26/tests/tests2/18_include.c +12 -0
  105. data/ext/tcc/tcc-0.9.26/tests/tests2/18_include.expect +3 -0
  106. data/ext/tcc/tcc-0.9.26/tests/tests2/18_include.h +1 -0
  107. data/ext/tcc/tcc-0.9.26/tests/tests2/19_pointer_arithmetic.c +28 -0
  108. data/ext/tcc/tcc-0.9.26/tests/tests2/19_pointer_arithmetic.expect +3 -0
  109. data/ext/tcc/tcc-0.9.26/tests/tests2/20_pointer_comparison.c +24 -0
  110. data/ext/tcc/tcc-0.9.26/tests/tests2/20_pointer_comparison.expect +6 -0
  111. data/ext/tcc/tcc-0.9.26/tests/tests2/21_char_array.c +33 -0
  112. data/ext/tcc/tcc-0.9.26/tests/tests2/21_char_array.expect +7 -0
  113. data/ext/tcc/tcc-0.9.26/tests/tests2/22_floating_point.c +50 -0
  114. data/ext/tcc/tcc-0.9.26/tests/tests2/22_floating_point.expect +16 -0
  115. data/ext/tcc/tcc-0.9.26/tests/tests2/23_type_coercion.c +54 -0
  116. data/ext/tcc/tcc-0.9.26/tests/tests2/23_type_coercion.expect +12 -0
  117. data/ext/tcc/tcc-0.9.26/tests/tests2/24_math_library.c +28 -0
  118. data/ext/tcc/tcc-0.9.26/tests/tests2/24_math_library.expect +18 -0
  119. data/ext/tcc/tcc-0.9.26/tests/tests2/25_quicksort.c +83 -0
  120. data/ext/tcc/tcc-0.9.26/tests/tests2/25_quicksort.expect +2 -0
  121. data/ext/tcc/tcc-0.9.26/tests/tests2/26_character_constants.c +17 -0
  122. data/ext/tcc/tcc-0.9.26/tests/tests2/26_character_constants.expect +8 -0
  123. data/ext/tcc/tcc-0.9.26/tests/tests2/27_sizeof.c +16 -0
  124. data/ext/tcc/tcc-0.9.26/tests/tests2/27_sizeof.expect +3 -0
  125. data/ext/tcc/tcc-0.9.26/tests/tests2/28_strings.c +46 -0
  126. data/ext/tcc/tcc-0.9.26/tests/tests2/28_strings.expect +19 -0
  127. data/ext/tcc/tcc-0.9.26/tests/tests2/29_array_address.c +13 -0
  128. data/ext/tcc/tcc-0.9.26/tests/tests2/29_array_address.expect +1 -0
  129. data/ext/tcc/tcc-0.9.26/tests/tests2/30_hanoi.c +122 -0
  130. data/ext/tcc/tcc-0.9.26/tests/tests2/30_hanoi.expect +71 -0
  131. data/ext/tcc/tcc-0.9.26/tests/tests2/31_args.c +14 -0
  132. data/ext/tcc/tcc-0.9.26/tests/tests2/31_args.expect +7 -0
  133. data/ext/tcc/tcc-0.9.26/tests/tests2/32_led.c +266 -0
  134. data/ext/tcc/tcc-0.9.26/tests/tests2/32_led.expect +4 -0
  135. data/ext/tcc/tcc-0.9.26/tests/tests2/33_ternary_op.c +15 -0
  136. data/ext/tcc/tcc-0.9.26/tests/tests2/33_ternary_op.expect +10 -0
  137. data/ext/tcc/tcc-0.9.26/tests/tests2/34_array_assignment.c +23 -0
  138. data/ext/tcc/tcc-0.9.26/tests/tests2/34_array_assignment.expect +2 -0
  139. data/ext/tcc/tcc-0.9.26/tests/tests2/35_sizeof.c +14 -0
  140. data/ext/tcc/tcc-0.9.26/tests/tests2/35_sizeof.expect +2 -0
  141. data/ext/tcc/tcc-0.9.26/tests/tests2/36_array_initialisers.c +21 -0
  142. data/ext/tcc/tcc-0.9.26/tests/tests2/36_array_initialisers.expect +20 -0
  143. data/ext/tcc/tcc-0.9.26/tests/tests2/37_sprintf.c +17 -0
  144. data/ext/tcc/tcc-0.9.26/tests/tests2/37_sprintf.expect +20 -0
  145. data/ext/tcc/tcc-0.9.26/tests/tests2/38_multiple_array_index.c +32 -0
  146. data/ext/tcc/tcc-0.9.26/tests/tests2/38_multiple_array_index.expect +4 -0
  147. data/ext/tcc/tcc-0.9.26/tests/tests2/39_typedef.c +31 -0
  148. data/ext/tcc/tcc-0.9.26/tests/tests2/39_typedef.expect +3 -0
  149. data/ext/tcc/tcc-0.9.26/tests/tests2/40_stdio.c +52 -0
  150. data/ext/tcc/tcc-0.9.26/tests/tests2/40_stdio.expect +27 -0
  151. data/ext/tcc/tcc-0.9.26/tests/tests2/41_hashif.c +85 -0
  152. data/ext/tcc/tcc-0.9.26/tests/tests2/41_hashif.expect +6 -0
  153. data/ext/tcc/tcc-0.9.26/tests/tests2/42_function_pointer.c +18 -0
  154. data/ext/tcc/tcc-0.9.26/tests/tests2/42_function_pointer.expect +2 -0
  155. data/ext/tcc/tcc-0.9.26/tests/tests2/43_void_param.c +15 -0
  156. data/ext/tcc/tcc-0.9.26/tests/tests2/43_void_param.expect +1 -0
  157. data/ext/tcc/tcc-0.9.26/tests/tests2/44_scoped_declarations.c +17 -0
  158. data/ext/tcc/tcc-0.9.26/tests/tests2/44_scoped_declarations.expect +1 -0
  159. data/ext/tcc/tcc-0.9.26/tests/tests2/45_empty_for.c +18 -0
  160. data/ext/tcc/tcc-0.9.26/tests/tests2/45_empty_for.expect +10 -0
  161. data/ext/tcc/tcc-0.9.26/tests/tests2/46_grep.c +564 -0
  162. data/ext/tcc/tcc-0.9.26/tests/tests2/47_switch_return.c +24 -0
  163. data/ext/tcc/tcc-0.9.26/tests/tests2/47_switch_return.expect +4 -0
  164. data/ext/tcc/tcc-0.9.26/tests/tests2/48_nested_break.c +26 -0
  165. data/ext/tcc/tcc-0.9.26/tests/tests2/48_nested_break.expect +1 -0
  166. data/ext/tcc/tcc-0.9.26/tests/tests2/49_bracket_evaluation.c +23 -0
  167. data/ext/tcc/tcc-0.9.26/tests/tests2/49_bracket_evaluation.expect +1 -0
  168. data/ext/tcc/tcc-0.9.26/tests/tests2/50_logical_second_arg.c +29 -0
  169. data/ext/tcc/tcc-0.9.26/tests/tests2/50_logical_second_arg.expect +20 -0
  170. data/ext/tcc/tcc-0.9.26/tests/tests2/51_static.c +30 -0
  171. data/ext/tcc/tcc-0.9.26/tests/tests2/51_static.expect +8 -0
  172. data/ext/tcc/tcc-0.9.26/tests/tests2/52_unnamed_enum.c +27 -0
  173. data/ext/tcc/tcc-0.9.26/tests/tests2/52_unnamed_enum.expect +9 -0
  174. data/ext/tcc/tcc-0.9.26/tests/tests2/54_goto.c +56 -0
  175. data/ext/tcc/tcc-0.9.26/tests/tests2/54_goto.expect +8 -0
  176. data/ext/tcc/tcc-0.9.26/tests/tests2/55_lshift_type.c +52 -0
  177. data/ext/tcc/tcc-0.9.26/tests/tests2/55_lshift_type.expect +1 -0
  178. data/ext/tcc/tcc-0.9.26/tests/tests2/LICENSE +37 -0
  179. data/ext/tcc/tcc-0.9.26/tests/tests2/Makefile +98 -0
  180. data/ext/tcc/tcc-0.9.26/texi2pod.pl +427 -0
  181. data/ext/tcc/tcc-0.9.26/win32/build-tcc.bat +60 -0
  182. data/ext/tcc/tcc-0.9.26/win32/examples/dll.c +12 -0
  183. data/ext/tcc/tcc-0.9.26/win32/examples/fib.c +23 -0
  184. data/ext/tcc/tcc-0.9.26/win32/examples/hello_dll.c +19 -0
  185. data/ext/tcc/tcc-0.9.26/win32/examples/hello_win.c +163 -0
  186. data/ext/tcc/tcc-0.9.26/win32/include/_mingw.h +139 -0
  187. data/ext/tcc/tcc-0.9.26/win32/include/assert.h +54 -0
  188. data/ext/tcc/tcc-0.9.26/win32/include/conio.h +409 -0
  189. data/ext/tcc/tcc-0.9.26/win32/include/ctype.h +281 -0
  190. data/ext/tcc/tcc-0.9.26/win32/include/dir.h +31 -0
  191. data/ext/tcc/tcc-0.9.26/win32/include/direct.h +68 -0
  192. data/ext/tcc/tcc-0.9.26/win32/include/dirent.h +135 -0
  193. data/ext/tcc/tcc-0.9.26/win32/include/dos.h +55 -0
  194. data/ext/tcc/tcc-0.9.26/win32/include/errno.h +75 -0
  195. data/ext/tcc/tcc-0.9.26/win32/include/excpt.h +123 -0
  196. data/ext/tcc/tcc-0.9.26/win32/include/fcntl.h +52 -0
  197. data/ext/tcc/tcc-0.9.26/win32/include/fenv.h +108 -0
  198. data/ext/tcc/tcc-0.9.26/win32/include/inttypes.h +297 -0
  199. data/ext/tcc/tcc-0.9.26/win32/include/io.h +418 -0
  200. data/ext/tcc/tcc-0.9.26/win32/include/limits.h +111 -0
  201. data/ext/tcc/tcc-0.9.26/win32/include/locale.h +91 -0
  202. data/ext/tcc/tcc-0.9.26/win32/include/malloc.h +175 -0
  203. data/ext/tcc/tcc-0.9.26/win32/include/math.h +777 -0
  204. data/ext/tcc/tcc-0.9.26/win32/include/mem.h +13 -0
  205. data/ext/tcc/tcc-0.9.26/win32/include/memory.h +40 -0
  206. data/ext/tcc/tcc-0.9.26/win32/include/process.h +176 -0
  207. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/conio_s.h +42 -0
  208. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/crtdbg_s.h +19 -0
  209. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/io_s.h +33 -0
  210. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/mbstring_s.h +52 -0
  211. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/search_s.h +25 -0
  212. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/stdio_s.h +145 -0
  213. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/stdlib_s.h +67 -0
  214. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/stralign_s.h +30 -0
  215. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/string_s.h +41 -0
  216. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/sys/timeb_s.h +34 -0
  217. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/tchar_s.h +266 -0
  218. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/time_s.h +61 -0
  219. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/wchar_s.h +128 -0
  220. data/ext/tcc/tcc-0.9.26/win32/include/setjmp.h +160 -0
  221. data/ext/tcc/tcc-0.9.26/win32/include/share.h +28 -0
  222. data/ext/tcc/tcc-0.9.26/win32/include/signal.h +63 -0
  223. data/ext/tcc/tcc-0.9.26/win32/include/stdint.h +209 -0
  224. data/ext/tcc/tcc-0.9.26/win32/include/stdio.h +429 -0
  225. data/ext/tcc/tcc-0.9.26/win32/include/stdlib.h +580 -0
  226. data/ext/tcc/tcc-0.9.26/win32/include/string.h +164 -0
  227. data/ext/tcc/tcc-0.9.26/win32/include/sys/fcntl.h +13 -0
  228. data/ext/tcc/tcc-0.9.26/win32/include/sys/file.h +14 -0
  229. data/ext/tcc/tcc-0.9.26/win32/include/sys/locking.h +30 -0
  230. data/ext/tcc/tcc-0.9.26/win32/include/sys/stat.h +290 -0
  231. data/ext/tcc/tcc-0.9.26/win32/include/sys/time.h +69 -0
  232. data/ext/tcc/tcc-0.9.26/win32/include/sys/timeb.h +133 -0
  233. data/ext/tcc/tcc-0.9.26/win32/include/sys/types.h +118 -0
  234. data/ext/tcc/tcc-0.9.26/win32/include/sys/unistd.h +14 -0
  235. data/ext/tcc/tcc-0.9.26/win32/include/sys/utime.h +146 -0
  236. data/ext/tcc/tcc-0.9.26/win32/include/tchar.h +1102 -0
  237. data/ext/tcc/tcc-0.9.26/win32/include/time.h +287 -0
  238. data/ext/tcc/tcc-0.9.26/win32/include/vadefs.h +11 -0
  239. data/ext/tcc/tcc-0.9.26/win32/include/values.h +4 -0
  240. data/ext/tcc/tcc-0.9.26/win32/include/wchar.h +871 -0
  241. data/ext/tcc/tcc-0.9.26/win32/include/wctype.h +172 -0
  242. data/ext/tcc/tcc-0.9.26/win32/include/winapi/basetsd.h +149 -0
  243. data/ext/tcc/tcc-0.9.26/win32/include/winapi/basetyps.h +85 -0
  244. data/ext/tcc/tcc-0.9.26/win32/include/winapi/guiddef.h +151 -0
  245. data/ext/tcc/tcc-0.9.26/win32/include/winapi/intrin.h +11 -0
  246. data/ext/tcc/tcc-0.9.26/win32/include/winapi/poppack.h +8 -0
  247. data/ext/tcc/tcc-0.9.26/win32/include/winapi/pshpack1.h +8 -0
  248. data/ext/tcc/tcc-0.9.26/win32/include/winapi/pshpack2.h +8 -0
  249. data/ext/tcc/tcc-0.9.26/win32/include/winapi/pshpack4.h +8 -0
  250. data/ext/tcc/tcc-0.9.26/win32/include/winapi/pshpack8.h +8 -0
  251. data/ext/tcc/tcc-0.9.26/win32/include/winapi/reason.h +80 -0
  252. data/ext/tcc/tcc-0.9.26/win32/include/winapi/specstrings.h +7 -0
  253. data/ext/tcc/tcc-0.9.26/win32/include/winapi/stralign.h +154 -0
  254. data/ext/tcc/tcc-0.9.26/win32/include/winapi/tvout.h +79 -0
  255. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winbase.h +2951 -0
  256. data/ext/tcc/tcc-0.9.26/win32/include/winapi/wincon.h +301 -0
  257. data/ext/tcc/tcc-0.9.26/win32/include/winapi/windef.h +293 -0
  258. data/ext/tcc/tcc-0.9.26/win32/include/winapi/windows.h +123 -0
  259. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winerror.h +3166 -0
  260. data/ext/tcc/tcc-0.9.26/win32/include/winapi/wingdi.h +4080 -0
  261. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winnetwk.h +476 -0
  262. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winnls.h +765 -0
  263. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winnt.h +5770 -0
  264. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winreg.h +272 -0
  265. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winuser.h +5651 -0
  266. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winver.h +160 -0
  267. data/ext/tcc/tcc-0.9.26/win32/lib/chkstk.S +191 -0
  268. data/ext/tcc/tcc-0.9.26/win32/lib/crt1.c +34 -0
  269. data/ext/tcc/tcc-0.9.26/win32/lib/dllcrt1.c +13 -0
  270. data/ext/tcc/tcc-0.9.26/win32/lib/dllmain.c +9 -0
  271. data/ext/tcc/tcc-0.9.26/win32/lib/gdi32.def +337 -0
  272. data/ext/tcc/tcc-0.9.26/win32/lib/kernel32.def +765 -0
  273. data/ext/tcc/tcc-0.9.26/win32/lib/msvcrt.def +1399 -0
  274. data/ext/tcc/tcc-0.9.26/win32/lib/user32.def +654 -0
  275. data/ext/tcc/tcc-0.9.26/win32/lib/wincrt1.c +64 -0
  276. data/ext/tcc/tcc-0.9.26/win32/tcc-win32.txt +156 -0
  277. data/ext/tcc/tcc-0.9.26/win32/tools/tiny_impdef.c +243 -0
  278. data/ext/tcc/tcc-0.9.26/win32/tools/tiny_libmaker.c +258 -0
  279. data/ext/tcc/tcc-0.9.26/x86_64-asm.h +448 -0
  280. data/ext/tcc/tcc-0.9.26/x86_64-gen.c +1701 -0
  281. data/lib/tcc.rb +291 -0
  282. data/tcc.gemspec +15 -0
  283. metadata +343 -0
@@ -0,0 +1,1096 @@
1
+ /*
2
+ * X86 code generator for TCC
3
+ *
4
+ * Copyright (c) 2001-2004 Fabrice Bellard
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ */
20
+
21
+ #ifdef TARGET_DEFS_ONLY
22
+
23
+ /* number of available registers */
24
+ #define NB_REGS 4
25
+ #define NB_ASM_REGS 8
26
+
27
+ /* a register can belong to several classes. The classes must be
28
+ sorted from more general to more precise (see gv2() code which does
29
+ assumptions on it). */
30
+ #define RC_INT 0x0001 /* generic integer register */
31
+ #define RC_FLOAT 0x0002 /* generic float register */
32
+ #define RC_EAX 0x0004
33
+ #define RC_ST0 0x0008
34
+ #define RC_ECX 0x0010
35
+ #define RC_EDX 0x0020
36
+ #define RC_IRET RC_EAX /* function return: integer register */
37
+ #define RC_LRET RC_EDX /* function return: second integer register */
38
+ #define RC_FRET RC_ST0 /* function return: float register */
39
+
40
+ /* pretty names for the registers */
41
+ enum {
42
+ TREG_EAX = 0,
43
+ TREG_ECX,
44
+ TREG_EDX,
45
+ TREG_ST0,
46
+ };
47
+
48
+ /* return registers for function */
49
+ #define REG_IRET TREG_EAX /* single word int return register */
50
+ #define REG_LRET TREG_EDX /* second word return register (for long long) */
51
+ #define REG_FRET TREG_ST0 /* float return register */
52
+
53
+ /* defined if function parameters must be evaluated in reverse order */
54
+ #define INVERT_FUNC_PARAMS
55
+
56
+ /* defined if structures are passed as pointers. Otherwise structures
57
+ are directly pushed on stack. */
58
+ //#define FUNC_STRUCT_PARAM_AS_PTR
59
+
60
+ /* pointer size, in bytes */
61
+ #define PTR_SIZE 4
62
+
63
+ /* long double size and alignment, in bytes */
64
+ #define LDOUBLE_SIZE 12
65
+ #define LDOUBLE_ALIGN 4
66
+ /* maximum alignment (for aligned attribute support) */
67
+ #define MAX_ALIGN 8
68
+
69
+
70
+ #define psym oad
71
+
72
+ /******************************************************/
73
+ /* ELF defines */
74
+
75
+ #define EM_TCC_TARGET EM_386
76
+
77
+ /* relocation type for 32 bit data relocation */
78
+ #define R_DATA_32 R_386_32
79
+ #define R_DATA_PTR R_386_32
80
+ #define R_JMP_SLOT R_386_JMP_SLOT
81
+ #define R_COPY R_386_COPY
82
+
83
+ #define ELF_START_ADDR 0x08048000
84
+ #define ELF_PAGE_SIZE 0x1000
85
+
86
+ /******************************************************/
87
+ #else /* ! TARGET_DEFS_ONLY */
88
+ /******************************************************/
89
+ #include "tcc.h"
90
+
91
+ ST_DATA const int reg_classes[NB_REGS] = {
92
+ /* eax */ RC_INT | RC_EAX,
93
+ /* ecx */ RC_INT | RC_ECX,
94
+ /* edx */ RC_INT | RC_EDX,
95
+ /* st0 */ RC_FLOAT | RC_ST0,
96
+ };
97
+
98
+ static unsigned long func_sub_sp_offset;
99
+ static int func_ret_sub;
100
+ #ifdef CONFIG_TCC_BCHECK
101
+ static unsigned long func_bound_offset;
102
+ #endif
103
+
104
+ /* XXX: make it faster ? */
105
+ ST_FUNC void g(int c)
106
+ {
107
+ int ind1;
108
+ ind1 = ind + 1;
109
+ if (ind1 > cur_text_section->data_allocated)
110
+ section_realloc(cur_text_section, ind1);
111
+ cur_text_section->data[ind] = c;
112
+ ind = ind1;
113
+ }
114
+
115
+ ST_FUNC void o(unsigned int c)
116
+ {
117
+ while (c) {
118
+ g(c);
119
+ c = c >> 8;
120
+ }
121
+ }
122
+
123
+ ST_FUNC void gen_le16(int v)
124
+ {
125
+ g(v);
126
+ g(v >> 8);
127
+ }
128
+
129
+ ST_FUNC void gen_le32(int c)
130
+ {
131
+ g(c);
132
+ g(c >> 8);
133
+ g(c >> 16);
134
+ g(c >> 24);
135
+ }
136
+
137
+ /* output a symbol and patch all calls to it */
138
+ ST_FUNC void gsym_addr(int t, int a)
139
+ {
140
+ int n, *ptr;
141
+ while (t) {
142
+ ptr = (int *)(cur_text_section->data + t);
143
+ n = *ptr; /* next value */
144
+ *ptr = a - t - 4;
145
+ t = n;
146
+ }
147
+ }
148
+
149
+ ST_FUNC void gsym(int t)
150
+ {
151
+ gsym_addr(t, ind);
152
+ }
153
+
154
+ /* psym is used to put an instruction with a data field which is a
155
+ reference to a symbol. It is in fact the same as oad ! */
156
+ #define psym oad
157
+
158
+ /* instruction + 4 bytes data. Return the address of the data */
159
+ ST_FUNC int oad(int c, int s)
160
+ {
161
+ int ind1;
162
+
163
+ o(c);
164
+ ind1 = ind + 4;
165
+ if (ind1 > cur_text_section->data_allocated)
166
+ section_realloc(cur_text_section, ind1);
167
+ *(int *)(cur_text_section->data + ind) = s;
168
+ s = ind;
169
+ ind = ind1;
170
+ return s;
171
+ }
172
+
173
+ /* output constant with relocation if 'r & VT_SYM' is true */
174
+ ST_FUNC void gen_addr32(int r, Sym *sym, int c)
175
+ {
176
+ if (r & VT_SYM)
177
+ greloc(cur_text_section, sym, ind, R_386_32);
178
+ gen_le32(c);
179
+ }
180
+
181
+ ST_FUNC void gen_addrpc32(int r, Sym *sym, int c)
182
+ {
183
+ if (r & VT_SYM)
184
+ greloc(cur_text_section, sym, ind, R_386_PC32);
185
+ gen_le32(c - 4);
186
+ }
187
+
188
+ /* generate a modrm reference. 'op_reg' contains the addtionnal 3
189
+ opcode bits */
190
+ static void gen_modrm(int op_reg, int r, Sym *sym, int c)
191
+ {
192
+ op_reg = op_reg << 3;
193
+ if ((r & VT_VALMASK) == VT_CONST) {
194
+ /* constant memory reference */
195
+ o(0x05 | op_reg);
196
+ gen_addr32(r, sym, c);
197
+ } else if ((r & VT_VALMASK) == VT_LOCAL) {
198
+ /* currently, we use only ebp as base */
199
+ if (c == (char)c) {
200
+ /* short reference */
201
+ o(0x45 | op_reg);
202
+ g(c);
203
+ } else {
204
+ oad(0x85 | op_reg, c);
205
+ }
206
+ } else {
207
+ g(0x00 | op_reg | (r & VT_VALMASK));
208
+ }
209
+ }
210
+
211
+ /* load 'r' from value 'sv' */
212
+ ST_FUNC void load(int r, SValue *sv)
213
+ {
214
+ int v, t, ft, fc, fr;
215
+ SValue v1;
216
+
217
+ #ifdef TCC_TARGET_PE
218
+ SValue v2;
219
+ sv = pe_getimport(sv, &v2);
220
+ #endif
221
+
222
+ fr = sv->r;
223
+ ft = sv->type.t;
224
+ fc = sv->c.ul;
225
+
226
+ v = fr & VT_VALMASK;
227
+ if (fr & VT_LVAL) {
228
+ if (v == VT_LLOCAL) {
229
+ v1.type.t = VT_INT;
230
+ v1.r = VT_LOCAL | VT_LVAL;
231
+ v1.c.ul = fc;
232
+ fr = r;
233
+ if (!(reg_classes[fr] & RC_INT))
234
+ fr = get_reg(RC_INT);
235
+ load(fr, &v1);
236
+ }
237
+ if ((ft & VT_BTYPE) == VT_FLOAT) {
238
+ o(0xd9); /* flds */
239
+ r = 0;
240
+ } else if ((ft & VT_BTYPE) == VT_DOUBLE) {
241
+ o(0xdd); /* fldl */
242
+ r = 0;
243
+ } else if ((ft & VT_BTYPE) == VT_LDOUBLE) {
244
+ o(0xdb); /* fldt */
245
+ r = 5;
246
+ } else if ((ft & VT_TYPE) == VT_BYTE) {
247
+ o(0xbe0f); /* movsbl */
248
+ } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) {
249
+ o(0xb60f); /* movzbl */
250
+ } else if ((ft & VT_TYPE) == VT_SHORT) {
251
+ o(0xbf0f); /* movswl */
252
+ } else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) {
253
+ o(0xb70f); /* movzwl */
254
+ } else {
255
+ o(0x8b); /* movl */
256
+ }
257
+ gen_modrm(r, fr, sv->sym, fc);
258
+ } else {
259
+ if (v == VT_CONST) {
260
+ o(0xb8 + r); /* mov $xx, r */
261
+ gen_addr32(fr, sv->sym, fc);
262
+ } else if (v == VT_LOCAL) {
263
+ if (fc) {
264
+ o(0x8d); /* lea xxx(%ebp), r */
265
+ gen_modrm(r, VT_LOCAL, sv->sym, fc);
266
+ } else {
267
+ o(0x89);
268
+ o(0xe8 + r); /* mov %ebp, r */
269
+ }
270
+ } else if (v == VT_CMP) {
271
+ oad(0xb8 + r, 0); /* mov $0, r */
272
+ o(0x0f); /* setxx %br */
273
+ o(fc);
274
+ o(0xc0 + r);
275
+ } else if (v == VT_JMP || v == VT_JMPI) {
276
+ t = v & 1;
277
+ oad(0xb8 + r, t); /* mov $1, r */
278
+ o(0x05eb); /* jmp after */
279
+ gsym(fc);
280
+ oad(0xb8 + r, t ^ 1); /* mov $0, r */
281
+ } else if (v != r) {
282
+ o(0x89);
283
+ o(0xc0 + r + v * 8); /* mov v, r */
284
+ }
285
+ }
286
+ }
287
+
288
+ /* store register 'r' in lvalue 'v' */
289
+ ST_FUNC void store(int r, SValue *v)
290
+ {
291
+ int fr, bt, ft, fc;
292
+
293
+ #ifdef TCC_TARGET_PE
294
+ SValue v2;
295
+ v = pe_getimport(v, &v2);
296
+ #endif
297
+
298
+ ft = v->type.t;
299
+ fc = v->c.ul;
300
+ fr = v->r & VT_VALMASK;
301
+ bt = ft & VT_BTYPE;
302
+ /* XXX: incorrect if float reg to reg */
303
+ if (bt == VT_FLOAT) {
304
+ o(0xd9); /* fsts */
305
+ r = 2;
306
+ } else if (bt == VT_DOUBLE) {
307
+ o(0xdd); /* fstpl */
308
+ r = 2;
309
+ } else if (bt == VT_LDOUBLE) {
310
+ o(0xc0d9); /* fld %st(0) */
311
+ o(0xdb); /* fstpt */
312
+ r = 7;
313
+ } else {
314
+ if (bt == VT_SHORT)
315
+ o(0x66);
316
+ if (bt == VT_BYTE || bt == VT_BOOL)
317
+ o(0x88);
318
+ else
319
+ o(0x89);
320
+ }
321
+ if (fr == VT_CONST ||
322
+ fr == VT_LOCAL ||
323
+ (v->r & VT_LVAL)) {
324
+ gen_modrm(r, v->r, v->sym, fc);
325
+ } else if (fr != r) {
326
+ o(0xc0 + fr + r * 8); /* mov r, fr */
327
+ }
328
+ }
329
+
330
+ static void gadd_sp(int val)
331
+ {
332
+ if (val == (char)val) {
333
+ o(0xc483);
334
+ g(val);
335
+ } else {
336
+ oad(0xc481, val); /* add $xxx, %esp */
337
+ }
338
+ }
339
+
340
+ /* 'is_jmp' is '1' if it is a jump */
341
+ static void gcall_or_jmp(int is_jmp)
342
+ {
343
+ int r;
344
+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
345
+ /* constant case */
346
+ if (vtop->r & VT_SYM) {
347
+ /* relocation case */
348
+ greloc(cur_text_section, vtop->sym,
349
+ ind + 1, R_386_PC32);
350
+ } else {
351
+ /* put an empty PC32 relocation */
352
+ put_elf_reloc(symtab_section, cur_text_section,
353
+ ind + 1, R_386_PC32, 0);
354
+ }
355
+ oad(0xe8 + is_jmp, vtop->c.ul - 4); /* call/jmp im */
356
+ } else {
357
+ /* otherwise, indirect call */
358
+ r = gv(RC_INT);
359
+ o(0xff); /* call/jmp *r */
360
+ o(0xd0 + r + (is_jmp << 4));
361
+ }
362
+ }
363
+
364
+ static uint8_t fastcall_regs[3] = { TREG_EAX, TREG_EDX, TREG_ECX };
365
+ static uint8_t fastcallw_regs[2] = { TREG_ECX, TREG_EDX };
366
+
367
+ /* Generate function call. The function address is pushed first, then
368
+ all the parameters in call order. This functions pops all the
369
+ parameters and the function address. */
370
+ ST_FUNC void gfunc_call(int nb_args)
371
+ {
372
+ int size, align, r, args_size, i, func_call;
373
+ Sym *func_sym;
374
+
375
+ args_size = 0;
376
+ for(i = 0;i < nb_args; i++) {
377
+ if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
378
+ size = type_size(&vtop->type, &align);
379
+ /* align to stack align size */
380
+ size = (size + 3) & ~3;
381
+ /* allocate the necessary size on stack */
382
+ oad(0xec81, size); /* sub $xxx, %esp */
383
+ /* generate structure store */
384
+ r = get_reg(RC_INT);
385
+ o(0x89); /* mov %esp, r */
386
+ o(0xe0 + r);
387
+ vset(&vtop->type, r | VT_LVAL, 0);
388
+ vswap();
389
+ vstore();
390
+ args_size += size;
391
+ } else if (is_float(vtop->type.t)) {
392
+ gv(RC_FLOAT); /* only one float register */
393
+ if ((vtop->type.t & VT_BTYPE) == VT_FLOAT)
394
+ size = 4;
395
+ else if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE)
396
+ size = 8;
397
+ else
398
+ size = 12;
399
+ oad(0xec81, size); /* sub $xxx, %esp */
400
+ if (size == 12)
401
+ o(0x7cdb);
402
+ else
403
+ o(0x5cd9 + size - 4); /* fstp[s|l] 0(%esp) */
404
+ g(0x24);
405
+ g(0x00);
406
+ args_size += size;
407
+ } else {
408
+ /* simple type (currently always same size) */
409
+ /* XXX: implicit cast ? */
410
+ r = gv(RC_INT);
411
+ if ((vtop->type.t & VT_BTYPE) == VT_LLONG) {
412
+ size = 8;
413
+ o(0x50 + vtop->r2); /* push r */
414
+ } else {
415
+ size = 4;
416
+ }
417
+ o(0x50 + r); /* push r */
418
+ args_size += size;
419
+ }
420
+ vtop--;
421
+ }
422
+ save_regs(0); /* save used temporary registers */
423
+ func_sym = vtop->type.ref;
424
+ func_call = FUNC_CALL(func_sym->r);
425
+ /* fast call case */
426
+ if ((func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) ||
427
+ func_call == FUNC_FASTCALLW) {
428
+ int fastcall_nb_regs;
429
+ uint8_t *fastcall_regs_ptr;
430
+ if (func_call == FUNC_FASTCALLW) {
431
+ fastcall_regs_ptr = fastcallw_regs;
432
+ fastcall_nb_regs = 2;
433
+ } else {
434
+ fastcall_regs_ptr = fastcall_regs;
435
+ fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1;
436
+ }
437
+ for(i = 0;i < fastcall_nb_regs; i++) {
438
+ if (args_size <= 0)
439
+ break;
440
+ o(0x58 + fastcall_regs_ptr[i]); /* pop r */
441
+ /* XXX: incorrect for struct/floats */
442
+ args_size -= 4;
443
+ }
444
+ }
445
+ gcall_or_jmp(0);
446
+
447
+ #ifdef TCC_TARGET_PE
448
+ if ((func_sym->type.t & VT_BTYPE) == VT_STRUCT)
449
+ args_size -= 4;
450
+ #endif
451
+ if (args_size && func_call != FUNC_STDCALL)
452
+ gadd_sp(args_size);
453
+ vtop--;
454
+ }
455
+
456
+ #ifdef TCC_TARGET_PE
457
+ #define FUNC_PROLOG_SIZE 10
458
+ #else
459
+ #define FUNC_PROLOG_SIZE 9
460
+ #endif
461
+
462
+ /* generate function prolog of type 't' */
463
+ ST_FUNC void gfunc_prolog(CType *func_type)
464
+ {
465
+ int addr, align, size, func_call, fastcall_nb_regs;
466
+ int param_index, param_addr;
467
+ uint8_t *fastcall_regs_ptr;
468
+ Sym *sym;
469
+ CType *type;
470
+
471
+ sym = func_type->ref;
472
+ func_call = FUNC_CALL(sym->r);
473
+ addr = 8;
474
+ loc = 0;
475
+ func_vc = 0;
476
+
477
+ if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) {
478
+ fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1;
479
+ fastcall_regs_ptr = fastcall_regs;
480
+ } else if (func_call == FUNC_FASTCALLW) {
481
+ fastcall_nb_regs = 2;
482
+ fastcall_regs_ptr = fastcallw_regs;
483
+ } else {
484
+ fastcall_nb_regs = 0;
485
+ fastcall_regs_ptr = NULL;
486
+ }
487
+ param_index = 0;
488
+
489
+ ind += FUNC_PROLOG_SIZE;
490
+ func_sub_sp_offset = ind;
491
+ /* if the function returns a structure, then add an
492
+ implicit pointer parameter */
493
+ func_vt = sym->type;
494
+ if ((func_vt.t & VT_BTYPE) == VT_STRUCT) {
495
+ /* XXX: fastcall case ? */
496
+ func_vc = addr;
497
+ addr += 4;
498
+ param_index++;
499
+ }
500
+ /* define parameters */
501
+ while ((sym = sym->next) != NULL) {
502
+ type = &sym->type;
503
+ size = type_size(type, &align);
504
+ size = (size + 3) & ~3;
505
+ #ifdef FUNC_STRUCT_PARAM_AS_PTR
506
+ /* structs are passed as pointer */
507
+ if ((type->t & VT_BTYPE) == VT_STRUCT) {
508
+ size = 4;
509
+ }
510
+ #endif
511
+ if (param_index < fastcall_nb_regs) {
512
+ /* save FASTCALL register */
513
+ loc -= 4;
514
+ o(0x89); /* movl */
515
+ gen_modrm(fastcall_regs_ptr[param_index], VT_LOCAL, NULL, loc);
516
+ param_addr = loc;
517
+ } else {
518
+ param_addr = addr;
519
+ addr += size;
520
+ }
521
+ sym_push(sym->v & ~SYM_FIELD, type,
522
+ VT_LOCAL | lvalue_type(type->t), param_addr);
523
+ param_index++;
524
+ }
525
+ func_ret_sub = 0;
526
+ /* pascal type call ? */
527
+ if (func_call == FUNC_STDCALL)
528
+ func_ret_sub = addr - 8;
529
+ #ifdef TCC_TARGET_PE
530
+ else if (func_vc)
531
+ func_ret_sub = 4;
532
+ #endif
533
+
534
+ #ifdef CONFIG_TCC_BCHECK
535
+ /* leave some room for bound checking code */
536
+ if (tcc_state->do_bounds_check) {
537
+ oad(0xb8, 0); /* lbound section pointer */
538
+ oad(0xb8, 0); /* call to function */
539
+ func_bound_offset = lbounds_section->data_offset;
540
+ }
541
+ #endif
542
+ }
543
+
544
+ /* generate function epilog */
545
+ ST_FUNC void gfunc_epilog(void)
546
+ {
547
+ int v, saved_ind;
548
+
549
+ #ifdef CONFIG_TCC_BCHECK
550
+ if (tcc_state->do_bounds_check
551
+ && func_bound_offset != lbounds_section->data_offset) {
552
+ int saved_ind;
553
+ int *bounds_ptr;
554
+ Sym *sym, *sym_data;
555
+ /* add end of table info */
556
+ bounds_ptr = section_ptr_add(lbounds_section, sizeof(int));
557
+ *bounds_ptr = 0;
558
+ /* generate bound local allocation */
559
+ saved_ind = ind;
560
+ ind = func_sub_sp_offset;
561
+ sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
562
+ func_bound_offset, lbounds_section->data_offset);
563
+ greloc(cur_text_section, sym_data,
564
+ ind + 1, R_386_32);
565
+ oad(0xb8, 0); /* mov %eax, xxx */
566
+ sym = external_global_sym(TOK___bound_local_new, &func_old_type, 0);
567
+ greloc(cur_text_section, sym,
568
+ ind + 1, R_386_PC32);
569
+ oad(0xe8, -4);
570
+ ind = saved_ind;
571
+ /* generate bound check local freeing */
572
+ o(0x5250); /* save returned value, if any */
573
+ greloc(cur_text_section, sym_data,
574
+ ind + 1, R_386_32);
575
+ oad(0xb8, 0); /* mov %eax, xxx */
576
+ sym = external_global_sym(TOK___bound_local_delete, &func_old_type, 0);
577
+ greloc(cur_text_section, sym,
578
+ ind + 1, R_386_PC32);
579
+ oad(0xe8, -4);
580
+ o(0x585a); /* restore returned value, if any */
581
+ }
582
+ #endif
583
+ o(0xc9); /* leave */
584
+ if (func_ret_sub == 0) {
585
+ o(0xc3); /* ret */
586
+ } else {
587
+ o(0xc2); /* ret n */
588
+ g(func_ret_sub);
589
+ g(func_ret_sub >> 8);
590
+ }
591
+ /* align local size to word & save local variables */
592
+
593
+ v = (-loc + 3) & -4;
594
+ saved_ind = ind;
595
+ ind = func_sub_sp_offset - FUNC_PROLOG_SIZE;
596
+ #ifdef TCC_TARGET_PE
597
+ if (v >= 4096) {
598
+ Sym *sym = external_global_sym(TOK___chkstk, &func_old_type, 0);
599
+ oad(0xb8, v); /* mov stacksize, %eax */
600
+ oad(0xe8, -4); /* call __chkstk, (does the stackframe too) */
601
+ greloc(cur_text_section, sym, ind-4, R_386_PC32);
602
+ } else
603
+ #endif
604
+ {
605
+ o(0xe58955); /* push %ebp, mov %esp, %ebp */
606
+ o(0xec81); /* sub esp, stacksize */
607
+ gen_le32(v);
608
+ #if FUNC_PROLOG_SIZE == 10
609
+ o(0x90); /* adjust to FUNC_PROLOG_SIZE */
610
+ #endif
611
+ }
612
+ ind = saved_ind;
613
+ }
614
+
615
+ /* generate a jump to a label */
616
+ ST_FUNC int gjmp(int t)
617
+ {
618
+ return psym(0xe9, t);
619
+ }
620
+
621
+ /* generate a jump to a fixed address */
622
+ ST_FUNC void gjmp_addr(int a)
623
+ {
624
+ int r;
625
+ r = a - ind - 2;
626
+ if (r == (char)r) {
627
+ g(0xeb);
628
+ g(r);
629
+ } else {
630
+ oad(0xe9, a - ind - 5);
631
+ }
632
+ }
633
+
634
+ /* generate a test. set 'inv' to invert test. Stack entry is popped */
635
+ ST_FUNC int gtst(int inv, int t)
636
+ {
637
+ int v, *p;
638
+
639
+ v = vtop->r & VT_VALMASK;
640
+ if (v == VT_CMP) {
641
+ /* fast case : can jump directly since flags are set */
642
+ g(0x0f);
643
+ t = psym((vtop->c.i - 16) ^ inv, t);
644
+ } else if (v == VT_JMP || v == VT_JMPI) {
645
+ /* && or || optimization */
646
+ if ((v & 1) == inv) {
647
+ /* insert vtop->c jump list in t */
648
+ p = &vtop->c.i;
649
+ while (*p != 0)
650
+ p = (int *)(cur_text_section->data + *p);
651
+ *p = t;
652
+ t = vtop->c.i;
653
+ } else {
654
+ t = gjmp(t);
655
+ gsym(vtop->c.i);
656
+ }
657
+ } else {
658
+ if (is_float(vtop->type.t) ||
659
+ (vtop->type.t & VT_BTYPE) == VT_LLONG) {
660
+ vpushi(0);
661
+ gen_op(TOK_NE);
662
+ }
663
+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
664
+ /* constant jmp optimization */
665
+ if ((vtop->c.i != 0) != inv)
666
+ t = gjmp(t);
667
+ } else {
668
+ v = gv(RC_INT);
669
+ o(0x85);
670
+ o(0xc0 + v * 9);
671
+ g(0x0f);
672
+ t = psym(0x85 ^ inv, t);
673
+ }
674
+ }
675
+ vtop--;
676
+ return t;
677
+ }
678
+
679
+ /* generate an integer binary operation */
680
+ ST_FUNC void gen_opi(int op)
681
+ {
682
+ int r, fr, opc, c;
683
+
684
+ switch(op) {
685
+ case '+':
686
+ case TOK_ADDC1: /* add with carry generation */
687
+ opc = 0;
688
+ gen_op8:
689
+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
690
+ /* constant case */
691
+ vswap();
692
+ r = gv(RC_INT);
693
+ vswap();
694
+ c = vtop->c.i;
695
+ if (c == (char)c) {
696
+ /* generate inc and dec for smaller code */
697
+ if (c==1 && opc==0) {
698
+ o (0x40 | r); // inc
699
+ } else if (c==1 && opc==5) {
700
+ o (0x48 | r); // dec
701
+ } else {
702
+ o(0x83);
703
+ o(0xc0 | (opc << 3) | r);
704
+ g(c);
705
+ }
706
+ } else {
707
+ o(0x81);
708
+ oad(0xc0 | (opc << 3) | r, c);
709
+ }
710
+ } else {
711
+ gv2(RC_INT, RC_INT);
712
+ r = vtop[-1].r;
713
+ fr = vtop[0].r;
714
+ o((opc << 3) | 0x01);
715
+ o(0xc0 + r + fr * 8);
716
+ }
717
+ vtop--;
718
+ if (op >= TOK_ULT && op <= TOK_GT) {
719
+ vtop->r = VT_CMP;
720
+ vtop->c.i = op;
721
+ }
722
+ break;
723
+ case '-':
724
+ case TOK_SUBC1: /* sub with carry generation */
725
+ opc = 5;
726
+ goto gen_op8;
727
+ case TOK_ADDC2: /* add with carry use */
728
+ opc = 2;
729
+ goto gen_op8;
730
+ case TOK_SUBC2: /* sub with carry use */
731
+ opc = 3;
732
+ goto gen_op8;
733
+ case '&':
734
+ opc = 4;
735
+ goto gen_op8;
736
+ case '^':
737
+ opc = 6;
738
+ goto gen_op8;
739
+ case '|':
740
+ opc = 1;
741
+ goto gen_op8;
742
+ case '*':
743
+ gv2(RC_INT, RC_INT);
744
+ r = vtop[-1].r;
745
+ fr = vtop[0].r;
746
+ vtop--;
747
+ o(0xaf0f); /* imul fr, r */
748
+ o(0xc0 + fr + r * 8);
749
+ break;
750
+ case TOK_SHL:
751
+ opc = 4;
752
+ goto gen_shift;
753
+ case TOK_SHR:
754
+ opc = 5;
755
+ goto gen_shift;
756
+ case TOK_SAR:
757
+ opc = 7;
758
+ gen_shift:
759
+ opc = 0xc0 | (opc << 3);
760
+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
761
+ /* constant case */
762
+ vswap();
763
+ r = gv(RC_INT);
764
+ vswap();
765
+ c = vtop->c.i & 0x1f;
766
+ o(0xc1); /* shl/shr/sar $xxx, r */
767
+ o(opc | r);
768
+ g(c);
769
+ } else {
770
+ /* we generate the shift in ecx */
771
+ gv2(RC_INT, RC_ECX);
772
+ r = vtop[-1].r;
773
+ o(0xd3); /* shl/shr/sar %cl, r */
774
+ o(opc | r);
775
+ }
776
+ vtop--;
777
+ break;
778
+ case '/':
779
+ case TOK_UDIV:
780
+ case TOK_PDIV:
781
+ case '%':
782
+ case TOK_UMOD:
783
+ case TOK_UMULL:
784
+ /* first operand must be in eax */
785
+ /* XXX: need better constraint for second operand */
786
+ gv2(RC_EAX, RC_ECX);
787
+ r = vtop[-1].r;
788
+ fr = vtop[0].r;
789
+ vtop--;
790
+ save_reg(TREG_EDX);
791
+ if (op == TOK_UMULL) {
792
+ o(0xf7); /* mul fr */
793
+ o(0xe0 + fr);
794
+ vtop->r2 = TREG_EDX;
795
+ r = TREG_EAX;
796
+ } else {
797
+ if (op == TOK_UDIV || op == TOK_UMOD) {
798
+ o(0xf7d231); /* xor %edx, %edx, div fr, %eax */
799
+ o(0xf0 + fr);
800
+ } else {
801
+ o(0xf799); /* cltd, idiv fr, %eax */
802
+ o(0xf8 + fr);
803
+ }
804
+ if (op == '%' || op == TOK_UMOD)
805
+ r = TREG_EDX;
806
+ else
807
+ r = TREG_EAX;
808
+ }
809
+ vtop->r = r;
810
+ break;
811
+ default:
812
+ opc = 7;
813
+ goto gen_op8;
814
+ }
815
+ }
816
+
817
+ /* generate a floating point operation 'v = t1 op t2' instruction. The
818
+ two operands are guaranted to have the same floating point type */
819
+ /* XXX: need to use ST1 too */
820
+ ST_FUNC void gen_opf(int op)
821
+ {
822
+ int a, ft, fc, swapped, r;
823
+
824
+ /* convert constants to memory references */
825
+ if ((vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
826
+ vswap();
827
+ gv(RC_FLOAT);
828
+ vswap();
829
+ }
830
+ if ((vtop[0].r & (VT_VALMASK | VT_LVAL)) == VT_CONST)
831
+ gv(RC_FLOAT);
832
+
833
+ /* must put at least one value in the floating point register */
834
+ if ((vtop[-1].r & VT_LVAL) &&
835
+ (vtop[0].r & VT_LVAL)) {
836
+ vswap();
837
+ gv(RC_FLOAT);
838
+ vswap();
839
+ }
840
+ swapped = 0;
841
+ /* swap the stack if needed so that t1 is the register and t2 is
842
+ the memory reference */
843
+ if (vtop[-1].r & VT_LVAL) {
844
+ vswap();
845
+ swapped = 1;
846
+ }
847
+ if (op >= TOK_ULT && op <= TOK_GT) {
848
+ /* load on stack second operand */
849
+ load(TREG_ST0, vtop);
850
+ save_reg(TREG_EAX); /* eax is used by FP comparison code */
851
+ if (op == TOK_GE || op == TOK_GT)
852
+ swapped = !swapped;
853
+ else if (op == TOK_EQ || op == TOK_NE)
854
+ swapped = 0;
855
+ if (swapped)
856
+ o(0xc9d9); /* fxch %st(1) */
857
+ o(0xe9da); /* fucompp */
858
+ o(0xe0df); /* fnstsw %ax */
859
+ if (op == TOK_EQ) {
860
+ o(0x45e480); /* and $0x45, %ah */
861
+ o(0x40fC80); /* cmp $0x40, %ah */
862
+ } else if (op == TOK_NE) {
863
+ o(0x45e480); /* and $0x45, %ah */
864
+ o(0x40f480); /* xor $0x40, %ah */
865
+ op = TOK_NE;
866
+ } else if (op == TOK_GE || op == TOK_LE) {
867
+ o(0x05c4f6); /* test $0x05, %ah */
868
+ op = TOK_EQ;
869
+ } else {
870
+ o(0x45c4f6); /* test $0x45, %ah */
871
+ op = TOK_EQ;
872
+ }
873
+ vtop--;
874
+ vtop->r = VT_CMP;
875
+ vtop->c.i = op;
876
+ } else {
877
+ /* no memory reference possible for long double operations */
878
+ if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
879
+ load(TREG_ST0, vtop);
880
+ swapped = !swapped;
881
+ }
882
+
883
+ switch(op) {
884
+ default:
885
+ case '+':
886
+ a = 0;
887
+ break;
888
+ case '-':
889
+ a = 4;
890
+ if (swapped)
891
+ a++;
892
+ break;
893
+ case '*':
894
+ a = 1;
895
+ break;
896
+ case '/':
897
+ a = 6;
898
+ if (swapped)
899
+ a++;
900
+ break;
901
+ }
902
+ ft = vtop->type.t;
903
+ fc = vtop->c.ul;
904
+ if ((ft & VT_BTYPE) == VT_LDOUBLE) {
905
+ o(0xde); /* fxxxp %st, %st(1) */
906
+ o(0xc1 + (a << 3));
907
+ } else {
908
+ /* if saved lvalue, then we must reload it */
909
+ r = vtop->r;
910
+ if ((r & VT_VALMASK) == VT_LLOCAL) {
911
+ SValue v1;
912
+ r = get_reg(RC_INT);
913
+ v1.type.t = VT_INT;
914
+ v1.r = VT_LOCAL | VT_LVAL;
915
+ v1.c.ul = fc;
916
+ load(r, &v1);
917
+ fc = 0;
918
+ }
919
+
920
+ if ((ft & VT_BTYPE) == VT_DOUBLE)
921
+ o(0xdc);
922
+ else
923
+ o(0xd8);
924
+ gen_modrm(a, r, vtop->sym, fc);
925
+ }
926
+ vtop--;
927
+ }
928
+ }
929
+
930
+ /* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
931
+ and 'long long' cases. */
932
+ ST_FUNC void gen_cvt_itof(int t)
933
+ {
934
+ save_reg(TREG_ST0);
935
+ gv(RC_INT);
936
+ if ((vtop->type.t & VT_BTYPE) == VT_LLONG) {
937
+ /* signed long long to float/double/long double (unsigned case
938
+ is handled generically) */
939
+ o(0x50 + vtop->r2); /* push r2 */
940
+ o(0x50 + (vtop->r & VT_VALMASK)); /* push r */
941
+ o(0x242cdf); /* fildll (%esp) */
942
+ o(0x08c483); /* add $8, %esp */
943
+ } else if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) ==
944
+ (VT_INT | VT_UNSIGNED)) {
945
+ /* unsigned int to float/double/long double */
946
+ o(0x6a); /* push $0 */
947
+ g(0x00);
948
+ o(0x50 + (vtop->r & VT_VALMASK)); /* push r */
949
+ o(0x242cdf); /* fildll (%esp) */
950
+ o(0x08c483); /* add $8, %esp */
951
+ } else {
952
+ /* int to float/double/long double */
953
+ o(0x50 + (vtop->r & VT_VALMASK)); /* push r */
954
+ o(0x2404db); /* fildl (%esp) */
955
+ o(0x04c483); /* add $4, %esp */
956
+ }
957
+ vtop->r = TREG_ST0;
958
+ }
959
+
960
+ /* convert fp to int 't' type */
961
+ /* XXX: handle long long case */
962
+ ST_FUNC void gen_cvt_ftoi(int t)
963
+ {
964
+ int r, r2, size;
965
+ Sym *sym;
966
+ CType ushort_type;
967
+
968
+ ushort_type.t = VT_SHORT | VT_UNSIGNED;
969
+ ushort_type.ref = 0;
970
+
971
+ gv(RC_FLOAT);
972
+ if (t != VT_INT)
973
+ size = 8;
974
+ else
975
+ size = 4;
976
+
977
+ o(0x2dd9); /* ldcw xxx */
978
+ sym = external_global_sym(TOK___tcc_int_fpu_control,
979
+ &ushort_type, VT_LVAL);
980
+ greloc(cur_text_section, sym,
981
+ ind, R_386_32);
982
+ gen_le32(0);
983
+
984
+ oad(0xec81, size); /* sub $xxx, %esp */
985
+ if (size == 4)
986
+ o(0x1cdb); /* fistpl */
987
+ else
988
+ o(0x3cdf); /* fistpll */
989
+ o(0x24);
990
+ o(0x2dd9); /* ldcw xxx */
991
+ sym = external_global_sym(TOK___tcc_fpu_control,
992
+ &ushort_type, VT_LVAL);
993
+ greloc(cur_text_section, sym,
994
+ ind, R_386_32);
995
+ gen_le32(0);
996
+
997
+ r = get_reg(RC_INT);
998
+ o(0x58 + r); /* pop r */
999
+ if (size == 8) {
1000
+ if (t == VT_LLONG) {
1001
+ vtop->r = r; /* mark reg as used */
1002
+ r2 = get_reg(RC_INT);
1003
+ o(0x58 + r2); /* pop r2 */
1004
+ vtop->r2 = r2;
1005
+ } else {
1006
+ o(0x04c483); /* add $4, %esp */
1007
+ }
1008
+ }
1009
+ vtop->r = r;
1010
+ }
1011
+
1012
+ /* convert from one floating point type to another */
1013
+ ST_FUNC void gen_cvt_ftof(int t)
1014
+ {
1015
+ /* all we have to do on i386 is to put the float in a register */
1016
+ gv(RC_FLOAT);
1017
+ }
1018
+
1019
+ /* computed goto support */
1020
+ ST_FUNC void ggoto(void)
1021
+ {
1022
+ gcall_or_jmp(1);
1023
+ vtop--;
1024
+ }
1025
+
1026
+ /* bound check support functions */
1027
+ #ifdef CONFIG_TCC_BCHECK
1028
+
1029
+ /* generate a bounded pointer addition */
1030
+ ST_FUNC void gen_bounded_ptr_add(void)
1031
+ {
1032
+ Sym *sym;
1033
+
1034
+ /* prepare fast i386 function call (args in eax and edx) */
1035
+ gv2(RC_EAX, RC_EDX);
1036
+ /* save all temporary registers */
1037
+ vtop -= 2;
1038
+ save_regs(0);
1039
+ /* do a fast function call */
1040
+ sym = external_global_sym(TOK___bound_ptr_add, &func_old_type, 0);
1041
+ greloc(cur_text_section, sym,
1042
+ ind + 1, R_386_PC32);
1043
+ oad(0xe8, -4);
1044
+ /* returned pointer is in eax */
1045
+ vtop++;
1046
+ vtop->r = TREG_EAX | VT_BOUNDED;
1047
+ /* address of bounding function call point */
1048
+ vtop->c.ul = (cur_text_section->reloc->data_offset - sizeof(Elf32_Rel));
1049
+ }
1050
+
1051
+ /* patch pointer addition in vtop so that pointer dereferencing is
1052
+ also tested */
1053
+ ST_FUNC void gen_bounded_ptr_deref(void)
1054
+ {
1055
+ int func;
1056
+ int size, align;
1057
+ Elf32_Rel *rel;
1058
+ Sym *sym;
1059
+
1060
+ size = 0;
1061
+ /* XXX: put that code in generic part of tcc */
1062
+ if (!is_float(vtop->type.t)) {
1063
+ if (vtop->r & VT_LVAL_BYTE)
1064
+ size = 1;
1065
+ else if (vtop->r & VT_LVAL_SHORT)
1066
+ size = 2;
1067
+ }
1068
+ if (!size)
1069
+ size = type_size(&vtop->type, &align);
1070
+ switch(size) {
1071
+ case 1: func = TOK___bound_ptr_indir1; break;
1072
+ case 2: func = TOK___bound_ptr_indir2; break;
1073
+ case 4: func = TOK___bound_ptr_indir4; break;
1074
+ case 8: func = TOK___bound_ptr_indir8; break;
1075
+ case 12: func = TOK___bound_ptr_indir12; break;
1076
+ case 16: func = TOK___bound_ptr_indir16; break;
1077
+ default:
1078
+ tcc_error("unhandled size when dereferencing bounded pointer");
1079
+ func = 0;
1080
+ break;
1081
+ }
1082
+
1083
+ /* patch relocation */
1084
+ /* XXX: find a better solution ? */
1085
+ rel = (Elf32_Rel *)(cur_text_section->reloc->data + vtop->c.ul);
1086
+ sym = external_global_sym(func, &func_old_type, 0);
1087
+ if (!sym->c)
1088
+ put_extern_sym(sym, NULL, 0, 0);
1089
+ rel->r_info = ELF32_R_INFO(sym->c, ELF32_R_TYPE(rel->r_info));
1090
+ }
1091
+ #endif
1092
+
1093
+ /* end of X86 code generator */
1094
+ /*************************************************************/
1095
+ #endif
1096
+ /*************************************************************/