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,737 @@
1
+ /*
2
+ * TCC - Tiny C Compiler - Support for -run switch
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
+ #include "tcc.h"
22
+
23
+ /* only native compiler supports -run */
24
+ #ifdef TCC_IS_NATIVE
25
+
26
+ #ifdef CONFIG_TCC_BACKTRACE
27
+ ST_DATA int rt_num_callers = 6;
28
+ ST_DATA const char **rt_bound_error_msg;
29
+ ST_DATA void *rt_prog_main;
30
+ #endif
31
+
32
+ #ifdef _WIN32
33
+ #define ucontext_t CONTEXT
34
+ #endif
35
+
36
+ static void set_pages_executable(void *ptr, unsigned long length);
37
+ static void set_exception_handler(void);
38
+ static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level);
39
+ static void rt_error(ucontext_t *uc, const char *fmt, ...);
40
+ static int tcc_relocate_ex(TCCState *s1, void *ptr);
41
+
42
+ #ifdef _WIN64
43
+ static void win64_add_function_table(TCCState *s1);
44
+ #endif
45
+
46
+ /* ------------------------------------------------------------- */
47
+ /* Do all relocations (needed before using tcc_get_symbol())
48
+ Returns -1 on error. */
49
+
50
+ LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr)
51
+ {
52
+ int ret;
53
+
54
+ if (TCC_RELOCATE_AUTO != ptr)
55
+ return tcc_relocate_ex(s1, ptr);
56
+
57
+ ret = tcc_relocate_ex(s1, NULL);
58
+ if (ret < 0)
59
+ return ret;
60
+
61
+ #ifdef HAVE_SELINUX
62
+ { /* Use mmap instead of malloc for Selinux. Ref:
63
+ http://www.gnu.org/s/libc/manual/html_node/File-Size.html */
64
+
65
+ char tmpfname[] = "/tmp/.tccrunXXXXXX";
66
+ int fd = mkstemp (tmpfname);
67
+
68
+ s1->mem_size = ret;
69
+ unlink (tmpfname);
70
+ ftruncate (fd, s1->mem_size);
71
+
72
+ s1->write_mem = mmap (NULL, ret, PROT_READ|PROT_WRITE,
73
+ MAP_SHARED, fd, 0);
74
+ if (s1->write_mem == MAP_FAILED)
75
+ tcc_error("/tmp not writeable");
76
+
77
+ s1->runtime_mem = mmap (NULL, ret, PROT_READ|PROT_EXEC,
78
+ MAP_SHARED, fd, 0);
79
+ if (s1->runtime_mem == MAP_FAILED)
80
+ tcc_error("/tmp not executable");
81
+
82
+ ret = tcc_relocate_ex(s1, s1->write_mem);
83
+ }
84
+ #else
85
+ s1->runtime_mem = tcc_malloc(ret);
86
+ ret = tcc_relocate_ex(s1, s1->runtime_mem);
87
+ #endif
88
+ return ret;
89
+ }
90
+
91
+ /* Same as `tcc_relocate(s1, TCC_RELOCATE_AUTO)` */
92
+ LIBTCCAPI int tcc_relocate_auto(TCCState *s1) {
93
+ return tcc_relocate(s1, TCC_RELOCATE_AUTO);
94
+ }
95
+
96
+ /* launch the compiled program with the given arguments */
97
+ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv)
98
+ {
99
+ int (*prog_main)(int, char **);
100
+ int ret;
101
+
102
+ if (tcc_relocate(s1, TCC_RELOCATE_AUTO) < 0)
103
+ return -1;
104
+
105
+ prog_main = tcc_get_symbol_err(s1, "main");
106
+
107
+ #ifdef CONFIG_TCC_BACKTRACE
108
+ if (s1->do_debug) {
109
+ set_exception_handler();
110
+ rt_prog_main = prog_main;
111
+ }
112
+ #endif
113
+
114
+ #ifdef CONFIG_TCC_BCHECK
115
+ if (s1->do_bounds_check) {
116
+ void (*bound_init)(void);
117
+ void (*bound_exit)(void);
118
+ /* set error function */
119
+ rt_bound_error_msg = tcc_get_symbol_err(s1, "__bound_error_msg");
120
+ /* XXX: use .init section so that it also work in binary ? */
121
+ bound_init = tcc_get_symbol_err(s1, "__bound_init");
122
+ bound_exit = tcc_get_symbol_err(s1, "__bound_exit");
123
+ bound_init();
124
+ ret = (*prog_main)(argc, argv);
125
+ bound_exit();
126
+ } else
127
+ #endif
128
+ ret = (*prog_main)(argc, argv);
129
+ return ret;
130
+ }
131
+
132
+ /* relocate code. Return -1 on error, required size if ptr is NULL,
133
+ otherwise copy code into buffer passed by the caller */
134
+ static int tcc_relocate_ex(TCCState *s1, void *ptr)
135
+ {
136
+ Section *s;
137
+ unsigned long offset, length;
138
+ addr_t mem;
139
+ int i;
140
+
141
+ if (NULL == ptr) {
142
+ s1->nb_errors = 0;
143
+ #ifdef TCC_TARGET_PE
144
+ pe_output_file(s1, NULL);
145
+ #else
146
+ tcc_add_runtime(s1);
147
+ relocate_common_syms();
148
+ tcc_add_linker_symbols(s1);
149
+ build_got_entries(s1);
150
+ #endif
151
+ if (s1->nb_errors)
152
+ return -1;
153
+ }
154
+
155
+ offset = 0, mem = (addr_t)ptr;
156
+ for(i = 1; i < s1->nb_sections; i++) {
157
+ s = s1->sections[i];
158
+ if (0 == (s->sh_flags & SHF_ALLOC))
159
+ continue;
160
+ length = s->data_offset;
161
+ s->sh_addr = mem ? (mem + offset + 15) & ~15 : 0;
162
+ offset = (offset + length + 15) & ~15;
163
+ }
164
+ offset += 16;
165
+
166
+ /* relocate symbols */
167
+ relocate_syms(s1, 1);
168
+ if (s1->nb_errors)
169
+ return -1;
170
+
171
+ #ifdef TCC_HAS_RUNTIME_PLTGOT
172
+ s1->runtime_plt_and_got_offset = 0;
173
+ s1->runtime_plt_and_got = (char *)(mem + offset);
174
+ /* double the size of the buffer for got and plt entries
175
+ XXX: calculate exact size for them? */
176
+ offset *= 2;
177
+ #endif
178
+
179
+ if (0 == mem)
180
+ return offset;
181
+
182
+ /* relocate each section */
183
+ for(i = 1; i < s1->nb_sections; i++) {
184
+ s = s1->sections[i];
185
+ if (s->reloc)
186
+ relocate_section(s1, s);
187
+ }
188
+
189
+ for(i = 1; i < s1->nb_sections; i++) {
190
+ s = s1->sections[i];
191
+ if (0 == (s->sh_flags & SHF_ALLOC))
192
+ continue;
193
+ length = s->data_offset;
194
+ // printf("%-12s %08x %04x\n", s->name, s->sh_addr, length);
195
+ ptr = (void*)s->sh_addr;
196
+ if (NULL == s->data || s->sh_type == SHT_NOBITS)
197
+ memset(ptr, 0, length);
198
+ else
199
+ memcpy(ptr, s->data, length);
200
+ /* mark executable sections as executable in memory */
201
+ if (s->sh_flags & SHF_EXECINSTR)
202
+ set_pages_executable(ptr, length);
203
+ }
204
+
205
+ #ifdef TCC_HAS_RUNTIME_PLTGOT
206
+ set_pages_executable(s1->runtime_plt_and_got,
207
+ s1->runtime_plt_and_got_offset);
208
+ #endif
209
+
210
+ #ifdef _WIN64
211
+ win64_add_function_table(s1);
212
+ #endif
213
+ return 0;
214
+ }
215
+
216
+ /* ------------------------------------------------------------- */
217
+ /* allow to run code in memory */
218
+
219
+ static void set_pages_executable(void *ptr, unsigned long length)
220
+ {
221
+ #ifdef _WIN32
222
+ unsigned long old_protect;
223
+ VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect);
224
+ #else
225
+ #ifndef PAGESIZE
226
+ # define PAGESIZE 4096
227
+ #endif
228
+ addr_t start, end;
229
+ start = (addr_t)ptr & ~(PAGESIZE - 1);
230
+ end = (addr_t)ptr + length;
231
+ end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
232
+ mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
233
+ #endif
234
+ }
235
+
236
+ /* ------------------------------------------------------------- */
237
+ #ifdef CONFIG_TCC_BACKTRACE
238
+
239
+ ST_FUNC void tcc_set_num_callers(int n)
240
+ {
241
+ rt_num_callers = n;
242
+ }
243
+
244
+ /* print the position in the source file of PC value 'pc' by reading
245
+ the stabs debug information */
246
+ static addr_t rt_printline(addr_t wanted_pc, const char *msg)
247
+ {
248
+ char func_name[128], last_func_name[128];
249
+ addr_t func_addr, last_pc, pc;
250
+ const char *incl_files[INCLUDE_STACK_SIZE];
251
+ int incl_index, len, last_line_num, i;
252
+ const char *str, *p;
253
+
254
+ Stab_Sym *stab_sym = NULL, *stab_sym_end, *sym;
255
+ int stab_len = 0;
256
+ char *stab_str = NULL;
257
+
258
+ if (stab_section) {
259
+ stab_len = stab_section->data_offset;
260
+ stab_sym = (Stab_Sym *)stab_section->data;
261
+ stab_str = stabstr_section->data;
262
+ }
263
+
264
+ func_name[0] = '\0';
265
+ func_addr = 0;
266
+ incl_index = 0;
267
+ last_func_name[0] = '\0';
268
+ last_pc = (addr_t)-1;
269
+ last_line_num = 1;
270
+
271
+ if (!stab_sym)
272
+ goto no_stabs;
273
+
274
+ stab_sym_end = (Stab_Sym*)((char*)stab_sym + stab_len);
275
+ for (sym = stab_sym + 1; sym < stab_sym_end; ++sym) {
276
+ switch(sym->n_type) {
277
+ /* function start or end */
278
+ case N_FUN:
279
+ if (sym->n_strx == 0) {
280
+ /* we test if between last line and end of function */
281
+ pc = sym->n_value + func_addr;
282
+ if (wanted_pc >= last_pc && wanted_pc < pc)
283
+ goto found;
284
+ func_name[0] = '\0';
285
+ func_addr = 0;
286
+ } else {
287
+ str = stab_str + sym->n_strx;
288
+ p = strchr(str, ':');
289
+ if (!p) {
290
+ pstrcpy(func_name, sizeof(func_name), str);
291
+ } else {
292
+ len = p - str;
293
+ if (len > sizeof(func_name) - 1)
294
+ len = sizeof(func_name) - 1;
295
+ memcpy(func_name, str, len);
296
+ func_name[len] = '\0';
297
+ }
298
+ func_addr = sym->n_value;
299
+ }
300
+ break;
301
+ /* line number info */
302
+ case N_SLINE:
303
+ pc = sym->n_value + func_addr;
304
+ if (wanted_pc >= last_pc && wanted_pc < pc)
305
+ goto found;
306
+ last_pc = pc;
307
+ last_line_num = sym->n_desc;
308
+ /* XXX: slow! */
309
+ strcpy(last_func_name, func_name);
310
+ break;
311
+ /* include files */
312
+ case N_BINCL:
313
+ str = stab_str + sym->n_strx;
314
+ add_incl:
315
+ if (incl_index < INCLUDE_STACK_SIZE) {
316
+ incl_files[incl_index++] = str;
317
+ }
318
+ break;
319
+ case N_EINCL:
320
+ if (incl_index > 1)
321
+ incl_index--;
322
+ break;
323
+ case N_SO:
324
+ if (sym->n_strx == 0) {
325
+ incl_index = 0; /* end of translation unit */
326
+ } else {
327
+ str = stab_str + sym->n_strx;
328
+ /* do not add path */
329
+ len = strlen(str);
330
+ if (len > 0 && str[len - 1] != '/')
331
+ goto add_incl;
332
+ }
333
+ break;
334
+ }
335
+ }
336
+
337
+ no_stabs:
338
+ /* second pass: we try symtab symbols (no line number info) */
339
+ incl_index = 0;
340
+ if (symtab_section)
341
+ {
342
+ ElfW(Sym) *sym, *sym_end;
343
+ int type;
344
+
345
+ sym_end = (ElfW(Sym) *)(symtab_section->data + symtab_section->data_offset);
346
+ for(sym = (ElfW(Sym) *)symtab_section->data + 1;
347
+ sym < sym_end;
348
+ sym++) {
349
+ type = ELFW(ST_TYPE)(sym->st_info);
350
+ if (type == STT_FUNC || type == STT_GNU_IFUNC) {
351
+ if (wanted_pc >= sym->st_value &&
352
+ wanted_pc < sym->st_value + sym->st_size) {
353
+ pstrcpy(last_func_name, sizeof(last_func_name),
354
+ strtab_section->data + sym->st_name);
355
+ func_addr = sym->st_value;
356
+ goto found;
357
+ }
358
+ }
359
+ }
360
+ }
361
+ /* did not find any info: */
362
+ fprintf(stderr, "%s %p ???\n", msg, (void*)wanted_pc);
363
+ fflush(stderr);
364
+ return 0;
365
+ found:
366
+ i = incl_index;
367
+ if (i > 0)
368
+ fprintf(stderr, "%s:%d: ", incl_files[--i], last_line_num);
369
+ fprintf(stderr, "%s %p", msg, (void*)wanted_pc);
370
+ if (last_func_name[0] != '\0')
371
+ fprintf(stderr, " %s()", last_func_name);
372
+ if (--i >= 0) {
373
+ fprintf(stderr, " (included from ");
374
+ for (;;) {
375
+ fprintf(stderr, "%s", incl_files[i]);
376
+ if (--i < 0)
377
+ break;
378
+ fprintf(stderr, ", ");
379
+ }
380
+ fprintf(stderr, ")");
381
+ }
382
+ fprintf(stderr, "\n");
383
+ fflush(stderr);
384
+ return func_addr;
385
+ }
386
+
387
+ /* emit a run time error at position 'pc' */
388
+ static void rt_error(ucontext_t *uc, const char *fmt, ...)
389
+ {
390
+ va_list ap;
391
+ addr_t pc;
392
+ int i;
393
+
394
+ fprintf(stderr, "Runtime error: ");
395
+ va_start(ap, fmt);
396
+ vfprintf(stderr, fmt, ap);
397
+ va_end(ap);
398
+ fprintf(stderr, "\n");
399
+
400
+ for(i=0;i<rt_num_callers;i++) {
401
+ if (rt_get_caller_pc(&pc, uc, i) < 0)
402
+ break;
403
+ pc = rt_printline(pc, i ? "by" : "at");
404
+ if (pc == (addr_t)rt_prog_main && pc)
405
+ break;
406
+ }
407
+ }
408
+
409
+ /* ------------------------------------------------------------- */
410
+ #ifndef _WIN32
411
+
412
+ /* signal handler for fatal errors */
413
+ static void sig_error(int signum, siginfo_t *siginf, void *puc)
414
+ {
415
+ ucontext_t *uc = puc;
416
+
417
+ switch(signum) {
418
+ case SIGFPE:
419
+ switch(siginf->si_code) {
420
+ case FPE_INTDIV:
421
+ case FPE_FLTDIV:
422
+ rt_error(uc, "division by zero");
423
+ break;
424
+ default:
425
+ rt_error(uc, "floating point exception");
426
+ break;
427
+ }
428
+ break;
429
+ case SIGBUS:
430
+ case SIGSEGV:
431
+ if (rt_bound_error_msg && *rt_bound_error_msg)
432
+ rt_error(uc, *rt_bound_error_msg);
433
+ else
434
+ rt_error(uc, "dereferencing invalid pointer");
435
+ break;
436
+ case SIGILL:
437
+ rt_error(uc, "illegal instruction");
438
+ break;
439
+ case SIGABRT:
440
+ rt_error(uc, "abort() called");
441
+ break;
442
+ default:
443
+ rt_error(uc, "caught signal %d", signum);
444
+ break;
445
+ }
446
+ exit(255);
447
+ }
448
+
449
+ #ifndef SA_SIGINFO
450
+ # define SA_SIGINFO 0x00000004u
451
+ #endif
452
+
453
+ /* Generate a stack backtrace when a CPU exception occurs. */
454
+ static void set_exception_handler(void)
455
+ {
456
+ struct sigaction sigact;
457
+ /* install TCC signal handlers to print debug info on fatal
458
+ runtime errors */
459
+ sigact.sa_flags = SA_SIGINFO | SA_RESETHAND;
460
+ sigact.sa_sigaction = sig_error;
461
+ sigemptyset(&sigact.sa_mask);
462
+ sigaction(SIGFPE, &sigact, NULL);
463
+ sigaction(SIGILL, &sigact, NULL);
464
+ sigaction(SIGSEGV, &sigact, NULL);
465
+ sigaction(SIGBUS, &sigact, NULL);
466
+ sigaction(SIGABRT, &sigact, NULL);
467
+ }
468
+
469
+ /* ------------------------------------------------------------- */
470
+ #ifdef __i386__
471
+
472
+ /* fix for glibc 2.1 */
473
+ #ifndef REG_EIP
474
+ #define REG_EIP EIP
475
+ #define REG_EBP EBP
476
+ #endif
477
+
478
+ /* return the PC at frame level 'level'. Return negative if not found */
479
+ static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
480
+ {
481
+ addr_t fp;
482
+ int i;
483
+
484
+ if (level == 0) {
485
+ #if defined(__APPLE__)
486
+ *paddr = uc->uc_mcontext->__ss.__eip;
487
+ #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
488
+ *paddr = uc->uc_mcontext.mc_eip;
489
+ #elif defined(__dietlibc__)
490
+ *paddr = uc->uc_mcontext.eip;
491
+ #else
492
+ *paddr = uc->uc_mcontext.gregs[REG_EIP];
493
+ #endif
494
+ return 0;
495
+ } else {
496
+ #if defined(__APPLE__)
497
+ fp = uc->uc_mcontext->__ss.__ebp;
498
+ #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
499
+ fp = uc->uc_mcontext.mc_ebp;
500
+ #elif defined(__dietlibc__)
501
+ fp = uc->uc_mcontext.ebp;
502
+ #else
503
+ fp = uc->uc_mcontext.gregs[REG_EBP];
504
+ #endif
505
+ for(i=1;i<level;i++) {
506
+ /* XXX: check address validity with program info */
507
+ if (fp <= 0x1000 || fp >= 0xc0000000)
508
+ return -1;
509
+ fp = ((addr_t *)fp)[0];
510
+ }
511
+ *paddr = ((addr_t *)fp)[1];
512
+ return 0;
513
+ }
514
+ }
515
+
516
+ /* ------------------------------------------------------------- */
517
+ #elif defined(__x86_64__)
518
+
519
+ /* return the PC at frame level 'level'. Return negative if not found */
520
+ static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
521
+ {
522
+ addr_t fp;
523
+ int i;
524
+
525
+ if (level == 0) {
526
+ /* XXX: only support linux */
527
+ #if defined(__APPLE__)
528
+ *paddr = uc->uc_mcontext->__ss.__rip;
529
+ #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
530
+ *paddr = uc->uc_mcontext.mc_rip;
531
+ #else
532
+ *paddr = uc->uc_mcontext.gregs[REG_RIP];
533
+ #endif
534
+ return 0;
535
+ } else {
536
+ #if defined(__APPLE__)
537
+ fp = uc->uc_mcontext->__ss.__rbp;
538
+ #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
539
+ fp = uc->uc_mcontext.mc_rbp;
540
+ #else
541
+ fp = uc->uc_mcontext.gregs[REG_RBP];
542
+ #endif
543
+ for(i=1;i<level;i++) {
544
+ /* XXX: check address validity with program info */
545
+ if (fp <= 0x1000)
546
+ return -1;
547
+ fp = ((addr_t *)fp)[0];
548
+ }
549
+ *paddr = ((addr_t *)fp)[1];
550
+ return 0;
551
+ }
552
+ }
553
+
554
+ /* ------------------------------------------------------------- */
555
+ #elif defined(__arm__)
556
+
557
+ /* return the PC at frame level 'level'. Return negative if not found */
558
+ static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
559
+ {
560
+ addr_t fp, sp;
561
+ int i;
562
+
563
+ if (level == 0) {
564
+ /* XXX: only supports linux */
565
+ #if defined(__linux__)
566
+ *paddr = uc->uc_mcontext.arm_pc;
567
+ #else
568
+ return -1;
569
+ #endif
570
+ return 0;
571
+ } else {
572
+ #if defined(__linux__)
573
+ fp = uc->uc_mcontext.arm_fp;
574
+ sp = uc->uc_mcontext.arm_sp;
575
+ if (sp < 0x1000)
576
+ sp = 0x1000;
577
+ #else
578
+ return -1;
579
+ #endif
580
+ /* XXX: specific to tinycc stack frames */
581
+ if (fp < sp + 12 || fp & 3)
582
+ return -1;
583
+ for(i = 1; i < level; i++) {
584
+ sp = ((addr_t *)fp)[-2];
585
+ if (sp < fp || sp - fp > 16 || sp & 3)
586
+ return -1;
587
+ fp = ((addr_t *)fp)[-3];
588
+ if (fp <= sp || fp - sp < 12 || fp & 3)
589
+ return -1;
590
+ }
591
+ /* XXX: check address validity with program info */
592
+ *paddr = ((addr_t *)fp)[-1];
593
+ return 0;
594
+ }
595
+ }
596
+
597
+ /* ------------------------------------------------------------- */
598
+ #else
599
+
600
+ #warning add arch specific rt_get_caller_pc()
601
+ static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
602
+ {
603
+ return -1;
604
+ }
605
+
606
+ #endif /* !__i386__ */
607
+
608
+ /* ------------------------------------------------------------- */
609
+ #else /* WIN32 */
610
+
611
+ static long __stdcall cpu_exception_handler(EXCEPTION_POINTERS *ex_info)
612
+ {
613
+ EXCEPTION_RECORD *er = ex_info->ExceptionRecord;
614
+ CONTEXT *uc = ex_info->ContextRecord;
615
+ switch (er->ExceptionCode) {
616
+ case EXCEPTION_ACCESS_VIOLATION:
617
+ if (rt_bound_error_msg && *rt_bound_error_msg)
618
+ rt_error(uc, *rt_bound_error_msg);
619
+ else
620
+ rt_error(uc, "access violation");
621
+ break;
622
+ case EXCEPTION_STACK_OVERFLOW:
623
+ rt_error(uc, "stack overflow");
624
+ break;
625
+ case EXCEPTION_INT_DIVIDE_BY_ZERO:
626
+ rt_error(uc, "division by zero");
627
+ break;
628
+ default:
629
+ rt_error(uc, "exception caught");
630
+ break;
631
+ }
632
+ return EXCEPTION_EXECUTE_HANDLER;
633
+ }
634
+
635
+ /* Generate a stack backtrace when a CPU exception occurs. */
636
+ static void set_exception_handler(void)
637
+ {
638
+ SetUnhandledExceptionFilter(cpu_exception_handler);
639
+ }
640
+
641
+ #ifdef _WIN64
642
+ static void win64_add_function_table(TCCState *s1)
643
+ {
644
+ RtlAddFunctionTable(
645
+ (RUNTIME_FUNCTION*)s1->uw_pdata->sh_addr,
646
+ s1->uw_pdata->data_offset / sizeof (RUNTIME_FUNCTION),
647
+ text_section->sh_addr
648
+ );
649
+ }
650
+ #endif
651
+
652
+ /* return the PC at frame level 'level'. Return non zero if not found */
653
+ static int rt_get_caller_pc(addr_t *paddr, CONTEXT *uc, int level)
654
+ {
655
+ addr_t fp, pc;
656
+ int i;
657
+ #ifdef _WIN64
658
+ pc = uc->Rip;
659
+ fp = uc->Rbp;
660
+ #else
661
+ pc = uc->Eip;
662
+ fp = uc->Ebp;
663
+ #endif
664
+ if (level > 0) {
665
+ for(i=1;i<level;i++) {
666
+ /* XXX: check address validity with program info */
667
+ if (fp <= 0x1000 || fp >= 0xc0000000)
668
+ return -1;
669
+ fp = ((addr_t*)fp)[0];
670
+ }
671
+ pc = ((addr_t*)fp)[1];
672
+ }
673
+ *paddr = pc;
674
+ return 0;
675
+ }
676
+
677
+ #endif /* _WIN32 */
678
+ #endif /* CONFIG_TCC_BACKTRACE */
679
+ /* ------------------------------------------------------------- */
680
+ #ifdef CONFIG_TCC_STATIC
681
+
682
+ /* dummy function for profiling */
683
+ ST_FUNC void *dlopen(const char *filename, int flag)
684
+ {
685
+ return NULL;
686
+ }
687
+
688
+ ST_FUNC void dlclose(void *p)
689
+ {
690
+ }
691
+
692
+ ST_FUNC const char *dlerror(void)
693
+ {
694
+ return "error";
695
+ }
696
+
697
+ typedef struct TCCSyms {
698
+ char *str;
699
+ void *ptr;
700
+ } TCCSyms;
701
+
702
+
703
+ /* add the symbol you want here if no dynamic linking is done */
704
+ static TCCSyms tcc_syms[] = {
705
+ #if !defined(CONFIG_TCCBOOT)
706
+ #define TCCSYM(a) { #a, &a, },
707
+ TCCSYM(printf)
708
+ TCCSYM(fprintf)
709
+ TCCSYM(fopen)
710
+ TCCSYM(fclose)
711
+ #undef TCCSYM
712
+ #endif
713
+ { NULL, NULL },
714
+ };
715
+
716
+ ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol)
717
+ {
718
+ TCCSyms *p;
719
+ p = tcc_syms;
720
+ while (p->str != NULL) {
721
+ if (!strcmp(p->str, symbol))
722
+ return p->ptr;
723
+ p++;
724
+ }
725
+ return NULL;
726
+ }
727
+
728
+ #elif !defined(_WIN32)
729
+
730
+ ST_FUNC void *resolve_sym(TCCState *s1, const char *sym)
731
+ {
732
+ return dlsym(RTLD_DEFAULT, sym);
733
+ }
734
+
735
+ #endif /* CONFIG_TCC_STATIC */
736
+ #endif /* TCC_IS_NATIVE */
737
+ /* ------------------------------------------------------------- */