laag-nasm 2.13.03.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (455) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +57 -0
  3. data/LICENSE.txt +29 -0
  4. data/README.org +34 -0
  5. data/ext/laag/nasm/extconf.rb +16 -0
  6. data/laag-nasm.gemspec +20 -0
  7. data/lib/laag/nasm.rb +29 -0
  8. data/patches/Makefile.in.patch +13 -0
  9. data/vendor/repo.or.cz/nasm/.gitignore +102 -0
  10. data/vendor/repo.or.cz/nasm/AUTHORS +137 -0
  11. data/vendor/repo.or.cz/nasm/CHANGES +2 -0
  12. data/vendor/repo.or.cz/nasm/ChangeLog +2905 -0
  13. data/vendor/repo.or.cz/nasm/INSTALL +102 -0
  14. data/vendor/repo.or.cz/nasm/LICENSE +29 -0
  15. data/vendor/repo.or.cz/nasm/Makefile.in +855 -0
  16. data/vendor/repo.or.cz/nasm/Mkfiles/README +46 -0
  17. data/vendor/repo.or.cz/nasm/Mkfiles/msvc.mak +732 -0
  18. data/vendor/repo.or.cz/nasm/Mkfiles/openwcom.mak +706 -0
  19. data/vendor/repo.or.cz/nasm/README +23 -0
  20. data/vendor/repo.or.cz/nasm/SubmittingPatches +116 -0
  21. data/vendor/repo.or.cz/nasm/TODO +376 -0
  22. data/vendor/repo.or.cz/nasm/aclocal.m4 +139 -0
  23. data/vendor/repo.or.cz/nasm/asm/assemble.c +2957 -0
  24. data/vendor/repo.or.cz/nasm/asm/assemble.h +54 -0
  25. data/vendor/repo.or.cz/nasm/asm/directiv.c +566 -0
  26. data/vendor/repo.or.cz/nasm/asm/directiv.dat +92 -0
  27. data/vendor/repo.or.cz/nasm/asm/error.c +202 -0
  28. data/vendor/repo.or.cz/nasm/asm/eval.c +1014 -0
  29. data/vendor/repo.or.cz/nasm/asm/eval.h +49 -0
  30. data/vendor/repo.or.cz/nasm/asm/exprdump.c +79 -0
  31. data/vendor/repo.or.cz/nasm/asm/exprlib.c +200 -0
  32. data/vendor/repo.or.cz/nasm/asm/float.c +952 -0
  33. data/vendor/repo.or.cz/nasm/asm/float.h +54 -0
  34. data/vendor/repo.or.cz/nasm/asm/labels.c +540 -0
  35. data/vendor/repo.or.cz/nasm/asm/listing.c +346 -0
  36. data/vendor/repo.or.cz/nasm/asm/listing.h +113 -0
  37. data/vendor/repo.or.cz/nasm/asm/nasm.c +1855 -0
  38. data/vendor/repo.or.cz/nasm/asm/parser.c +1167 -0
  39. data/vendor/repo.or.cz/nasm/asm/parser.h +45 -0
  40. data/vendor/repo.or.cz/nasm/asm/phash.pl +109 -0
  41. data/vendor/repo.or.cz/nasm/asm/pptok.dat +96 -0
  42. data/vendor/repo.or.cz/nasm/asm/pptok.pl +271 -0
  43. data/vendor/repo.or.cz/nasm/asm/pragma.c +218 -0
  44. data/vendor/repo.or.cz/nasm/asm/preproc-nop.c +188 -0
  45. data/vendor/repo.or.cz/nasm/asm/preproc.c +5459 -0
  46. data/vendor/repo.or.cz/nasm/asm/preproc.h +55 -0
  47. data/vendor/repo.or.cz/nasm/asm/quote.c +479 -0
  48. data/vendor/repo.or.cz/nasm/asm/quote.h +44 -0
  49. data/vendor/repo.or.cz/nasm/asm/rdstrnum.c +68 -0
  50. data/vendor/repo.or.cz/nasm/asm/segalloc.c +51 -0
  51. data/vendor/repo.or.cz/nasm/asm/stdscan.c +345 -0
  52. data/vendor/repo.or.cz/nasm/asm/stdscan.h +49 -0
  53. data/vendor/repo.or.cz/nasm/asm/strfunc.c +359 -0
  54. data/vendor/repo.or.cz/nasm/asm/tokens.dat +135 -0
  55. data/vendor/repo.or.cz/nasm/asm/tokhash.pl +284 -0
  56. data/vendor/repo.or.cz/nasm/autogen.sh +9 -0
  57. data/vendor/repo.or.cz/nasm/common/common.c +122 -0
  58. data/vendor/repo.or.cz/nasm/config/msvc.h +192 -0
  59. data/vendor/repo.or.cz/nasm/config/unknown.h +51 -0
  60. data/vendor/repo.or.cz/nasm/config/watcom.h +74 -0
  61. data/vendor/repo.or.cz/nasm/configure.ac +253 -0
  62. data/vendor/repo.or.cz/nasm/contrib/MSVC6.txt +25 -0
  63. data/vendor/repo.or.cz/nasm/contrib/VSrules/nasm.README +16 -0
  64. data/vendor/repo.or.cz/nasm/contrib/VSrules/nasm.rules +79 -0
  65. data/vendor/repo.or.cz/nasm/disasm/disasm.c +1735 -0
  66. data/vendor/repo.or.cz/nasm/disasm/disasm.h +49 -0
  67. data/vendor/repo.or.cz/nasm/disasm/ndisasm.c +397 -0
  68. data/vendor/repo.or.cz/nasm/disasm/sync.c +132 -0
  69. data/vendor/repo.or.cz/nasm/disasm/sync.h +45 -0
  70. data/vendor/repo.or.cz/nasm/doc/Makefile.in +86 -0
  71. data/vendor/repo.or.cz/nasm/doc/README +20 -0
  72. data/vendor/repo.or.cz/nasm/doc/afmmetrics.ph +102 -0
  73. data/vendor/repo.or.cz/nasm/doc/changes.src +2588 -0
  74. data/vendor/repo.or.cz/nasm/doc/findfont.ph +180 -0
  75. data/vendor/repo.or.cz/nasm/doc/genps.pl +1294 -0
  76. data/vendor/repo.or.cz/nasm/doc/inslist.pl +108 -0
  77. data/vendor/repo.or.cz/nasm/doc/internal.doc +290 -0
  78. data/vendor/repo.or.cz/nasm/doc/local.css +1 -0
  79. data/vendor/repo.or.cz/nasm/doc/nasmdoc.css +150 -0
  80. data/vendor/repo.or.cz/nasm/doc/nasmdoc.src +8309 -0
  81. data/vendor/repo.or.cz/nasm/doc/nasmlogo.eps +212 -0
  82. data/vendor/repo.or.cz/nasm/doc/nasmlogw.png +0 -0
  83. data/vendor/repo.or.cz/nasm/doc/psfonts.ph +53 -0
  84. data/vendor/repo.or.cz/nasm/doc/pspdf.pl +98 -0
  85. data/vendor/repo.or.cz/nasm/doc/pswidth.ph +25 -0
  86. data/vendor/repo.or.cz/nasm/doc/rdsrc.pl +1111 -0
  87. data/vendor/repo.or.cz/nasm/doc/ttfmetrics.ph +63 -0
  88. data/vendor/repo.or.cz/nasm/headers/c +33 -0
  89. data/vendor/repo.or.cz/nasm/headers/doc +33 -0
  90. data/vendor/repo.or.cz/nasm/headers/mac +33 -0
  91. data/vendor/repo.or.cz/nasm/headers/perl +33 -0
  92. data/vendor/repo.or.cz/nasm/include/compiler.h +277 -0
  93. data/vendor/repo.or.cz/nasm/include/disp8.h +45 -0
  94. data/vendor/repo.or.cz/nasm/include/error.h +135 -0
  95. data/vendor/repo.or.cz/nasm/include/hashtbl.h +85 -0
  96. data/vendor/repo.or.cz/nasm/include/iflag.h +173 -0
  97. data/vendor/repo.or.cz/nasm/include/insns.h +76 -0
  98. data/vendor/repo.or.cz/nasm/include/labels.h +60 -0
  99. data/vendor/repo.or.cz/nasm/include/md5.h +21 -0
  100. data/vendor/repo.or.cz/nasm/include/nasm.h +1246 -0
  101. data/vendor/repo.or.cz/nasm/include/nasmint.h +219 -0
  102. data/vendor/repo.or.cz/nasm/include/nasmlib.h +524 -0
  103. data/vendor/repo.or.cz/nasm/include/opflags.h +271 -0
  104. data/vendor/repo.or.cz/nasm/include/perfhash.h +52 -0
  105. data/vendor/repo.or.cz/nasm/include/raa.h +46 -0
  106. data/vendor/repo.or.cz/nasm/include/rbtree.h +51 -0
  107. data/vendor/repo.or.cz/nasm/include/rdoff.h +169 -0
  108. data/vendor/repo.or.cz/nasm/include/saa.h +94 -0
  109. data/vendor/repo.or.cz/nasm/include/strlist.h +55 -0
  110. data/vendor/repo.or.cz/nasm/include/tables.h +70 -0
  111. data/vendor/repo.or.cz/nasm/include/ver.h +47 -0
  112. data/vendor/repo.or.cz/nasm/install-sh +250 -0
  113. data/vendor/repo.or.cz/nasm/macros/altreg.mac +107 -0
  114. data/vendor/repo.or.cz/nasm/macros/fp.mac +54 -0
  115. data/vendor/repo.or.cz/nasm/macros/ifunc.mac +48 -0
  116. data/vendor/repo.or.cz/nasm/macros/macros.pl +294 -0
  117. data/vendor/repo.or.cz/nasm/macros/smartalign.mac +189 -0
  118. data/vendor/repo.or.cz/nasm/macros/standard.mac +226 -0
  119. data/vendor/repo.or.cz/nasm/misc/Doxyfile +752 -0
  120. data/vendor/repo.or.cz/nasm/misc/Nindent +18 -0
  121. data/vendor/repo.or.cz/nasm/misc/README +2 -0
  122. data/vendor/repo.or.cz/nasm/misc/c16.mac +82 -0
  123. data/vendor/repo.or.cz/nasm/misc/c32.mac +52 -0
  124. data/vendor/repo.or.cz/nasm/misc/crcgen.c +44 -0
  125. data/vendor/repo.or.cz/nasm/misc/exebin.mac +57 -0
  126. data/vendor/repo.or.cz/nasm/misc/exebin2.mac +114 -0
  127. data/vendor/repo.or.cz/nasm/misc/fmtinsns.pl +40 -0
  128. data/vendor/repo.or.cz/nasm/misc/genfma.pl +63 -0
  129. data/vendor/repo.or.cz/nasm/misc/hints.txt +26 -0
  130. data/vendor/repo.or.cz/nasm/misc/magic +6 -0
  131. data/vendor/repo.or.cz/nasm/misc/myC32.mac +121 -0
  132. data/vendor/repo.or.cz/nasm/misc/nasm.sl +320 -0
  133. data/vendor/repo.or.cz/nasm/misc/nasmstab +296 -0
  134. data/vendor/repo.or.cz/nasm/misc/omfdump.c +517 -0
  135. data/vendor/repo.or.cz/nasm/misc/pmw.bat +9 -0
  136. data/vendor/repo.or.cz/nasm/misc/proc32.ash +441 -0
  137. data/vendor/repo.or.cz/nasm/misc/scitech.mac +1223 -0
  138. data/vendor/repo.or.cz/nasm/misc/xcrcgen.c +80 -0
  139. data/vendor/repo.or.cz/nasm/nasm.spec.in +83 -0
  140. data/vendor/repo.or.cz/nasm/nasm.spec.sed +3 -0
  141. data/vendor/repo.or.cz/nasm/nasm.txt +306 -0
  142. data/vendor/repo.or.cz/nasm/nasmlib/badenum.c +43 -0
  143. data/vendor/repo.or.cz/nasm/nasmlib/bsi.c +77 -0
  144. data/vendor/repo.or.cz/nasm/nasmlib/crc64.c +189 -0
  145. data/vendor/repo.or.cz/nasm/nasmlib/file.c +259 -0
  146. data/vendor/repo.or.cz/nasm/nasmlib/file.h +128 -0
  147. data/vendor/repo.or.cz/nasm/nasmlib/filename.c +69 -0
  148. data/vendor/repo.or.cz/nasm/nasmlib/hashtbl.c +232 -0
  149. data/vendor/repo.or.cz/nasm/nasmlib/ilog2.c +168 -0
  150. data/vendor/repo.or.cz/nasm/nasmlib/malloc.c +108 -0
  151. data/vendor/repo.or.cz/nasm/nasmlib/md5c.c +247 -0
  152. data/vendor/repo.or.cz/nasm/nasmlib/mmap.c +139 -0
  153. data/vendor/repo.or.cz/nasm/nasmlib/path.c +186 -0
  154. data/vendor/repo.or.cz/nasm/nasmlib/perfhash.c +55 -0
  155. data/vendor/repo.or.cz/nasm/nasmlib/perfhash.pl +362 -0
  156. data/vendor/repo.or.cz/nasm/nasmlib/raa.c +173 -0
  157. data/vendor/repo.or.cz/nasm/nasmlib/rbtree.c +119 -0
  158. data/vendor/repo.or.cz/nasm/nasmlib/readnum.c +172 -0
  159. data/vendor/repo.or.cz/nasm/nasmlib/realpath.c +135 -0
  160. data/vendor/repo.or.cz/nasm/nasmlib/saa.c +431 -0
  161. data/vendor/repo.or.cz/nasm/nasmlib/srcfile.c +128 -0
  162. data/vendor/repo.or.cz/nasm/nasmlib/string.c +242 -0
  163. data/vendor/repo.or.cz/nasm/nasmlib/strlist.c +100 -0
  164. data/vendor/repo.or.cz/nasm/nasmlib/ver.c +51 -0
  165. data/vendor/repo.or.cz/nasm/nasmlib/zerobuf.c +42 -0
  166. data/vendor/repo.or.cz/nasm/ndisasm.txt +94 -0
  167. data/vendor/repo.or.cz/nasm/nsis/NASMMultiUser.nsh +478 -0
  168. data/vendor/repo.or.cz/nasm/nsis/getpearch.pl +76 -0
  169. data/vendor/repo.or.cz/nasm/nsis/nasm-un.ico +0 -0
  170. data/vendor/repo.or.cz/nasm/nsis/nasm.ico +0 -0
  171. data/vendor/repo.or.cz/nasm/nsis/nasm.nsi +241 -0
  172. data/vendor/repo.or.cz/nasm/output/codeview.c +814 -0
  173. data/vendor/repo.or.cz/nasm/output/dwarf.h +566 -0
  174. data/vendor/repo.or.cz/nasm/output/elf.h +537 -0
  175. data/vendor/repo.or.cz/nasm/output/legacy.c +112 -0
  176. data/vendor/repo.or.cz/nasm/output/nulldbg.c +93 -0
  177. data/vendor/repo.or.cz/nasm/output/nullout.c +51 -0
  178. data/vendor/repo.or.cz/nasm/output/outaout.c +954 -0
  179. data/vendor/repo.or.cz/nasm/output/outaout.mac +37 -0
  180. data/vendor/repo.or.cz/nasm/output/outas86.c +650 -0
  181. data/vendor/repo.or.cz/nasm/output/outas86.mac +37 -0
  182. data/vendor/repo.or.cz/nasm/output/outbin.c +1713 -0
  183. data/vendor/repo.or.cz/nasm/output/outbin.mac +40 -0
  184. data/vendor/repo.or.cz/nasm/output/outcoff.c +1242 -0
  185. data/vendor/repo.or.cz/nasm/output/outcoff.mac +43 -0
  186. data/vendor/repo.or.cz/nasm/output/outdbg.c +425 -0
  187. data/vendor/repo.or.cz/nasm/output/outelf.c +3370 -0
  188. data/vendor/repo.or.cz/nasm/output/outelf.h +156 -0
  189. data/vendor/repo.or.cz/nasm/output/outelf.mac +41 -0
  190. data/vendor/repo.or.cz/nasm/output/outform.c +120 -0
  191. data/vendor/repo.or.cz/nasm/output/outform.h +379 -0
  192. data/vendor/repo.or.cz/nasm/output/outieee.c +1528 -0
  193. data/vendor/repo.or.cz/nasm/output/outlib.c +58 -0
  194. data/vendor/repo.or.cz/nasm/output/outlib.h +63 -0
  195. data/vendor/repo.or.cz/nasm/output/outmacho.c +2387 -0
  196. data/vendor/repo.or.cz/nasm/output/outmacho.mac +49 -0
  197. data/vendor/repo.or.cz/nasm/output/outobj.c +2725 -0
  198. data/vendor/repo.or.cz/nasm/output/outobj.mac +49 -0
  199. data/vendor/repo.or.cz/nasm/output/outrdf.mac +40 -0
  200. data/vendor/repo.or.cz/nasm/output/outrdf2.c +791 -0
  201. data/vendor/repo.or.cz/nasm/output/outrdf2.mac +43 -0
  202. data/vendor/repo.or.cz/nasm/output/pecoff.h +532 -0
  203. data/vendor/repo.or.cz/nasm/output/stabs.h +144 -0
  204. data/vendor/repo.or.cz/nasm/perllib/crc64.ph +158 -0
  205. data/vendor/repo.or.cz/nasm/perllib/gensv.pl +34 -0
  206. data/vendor/repo.or.cz/nasm/perllib/phash.ph +200 -0
  207. data/vendor/repo.or.cz/nasm/perllib/random_sv_vectors.ph +67 -0
  208. data/vendor/repo.or.cz/nasm/rdoff/README +185 -0
  209. data/vendor/repo.or.cz/nasm/rdoff/collectn.c +44 -0
  210. data/vendor/repo.or.cz/nasm/rdoff/collectn.h +22 -0
  211. data/vendor/repo.or.cz/nasm/rdoff/doc/Makefile +37 -0
  212. data/vendor/repo.or.cz/nasm/rdoff/doc/rdoff.texi +137 -0
  213. data/vendor/repo.or.cz/nasm/rdoff/doc/v1-v2.txt +62 -0
  214. data/vendor/repo.or.cz/nasm/rdoff/hash.c +122 -0
  215. data/vendor/repo.or.cz/nasm/rdoff/hash.h +17 -0
  216. data/vendor/repo.or.cz/nasm/rdoff/ldrdf.1 +41 -0
  217. data/vendor/repo.or.cz/nasm/rdoff/ldrdf.c +1395 -0
  218. data/vendor/repo.or.cz/nasm/rdoff/ldsegs.h +59 -0
  219. data/vendor/repo.or.cz/nasm/rdoff/rdf2bin.1 +65 -0
  220. data/vendor/repo.or.cz/nasm/rdoff/rdf2bin.c +431 -0
  221. data/vendor/repo.or.cz/nasm/rdoff/rdf2com.1 +1 -0
  222. data/vendor/repo.or.cz/nasm/rdoff/rdf2ihx.1 +1 -0
  223. data/vendor/repo.or.cz/nasm/rdoff/rdf2ith.1 +1 -0
  224. data/vendor/repo.or.cz/nasm/rdoff/rdf2srec.1 +1 -0
  225. data/vendor/repo.or.cz/nasm/rdoff/rdfdump.1 +24 -0
  226. data/vendor/repo.or.cz/nasm/rdoff/rdfdump.c +347 -0
  227. data/vendor/repo.or.cz/nasm/rdoff/rdflib.1 +39 -0
  228. data/vendor/repo.or.cz/nasm/rdoff/rdflib.c +434 -0
  229. data/vendor/repo.or.cz/nasm/rdoff/rdfload.c +213 -0
  230. data/vendor/repo.or.cz/nasm/rdoff/rdfload.h +29 -0
  231. data/vendor/repo.or.cz/nasm/rdoff/rdfutils.h +165 -0
  232. data/vendor/repo.or.cz/nasm/rdoff/rdlar.c +492 -0
  233. data/vendor/repo.or.cz/nasm/rdoff/rdlar.h +34 -0
  234. data/vendor/repo.or.cz/nasm/rdoff/rdlib.c +290 -0
  235. data/vendor/repo.or.cz/nasm/rdoff/rdlib.h +62 -0
  236. data/vendor/repo.or.cz/nasm/rdoff/rdoff.c +621 -0
  237. data/vendor/repo.or.cz/nasm/rdoff/rdx.1 +21 -0
  238. data/vendor/repo.or.cz/nasm/rdoff/rdx.c +90 -0
  239. data/vendor/repo.or.cz/nasm/rdoff/segtab.c +172 -0
  240. data/vendor/repo.or.cz/nasm/rdoff/segtab.h +45 -0
  241. data/vendor/repo.or.cz/nasm/rdoff/symtab.c +159 -0
  242. data/vendor/repo.or.cz/nasm/rdoff/symtab.h +55 -0
  243. data/vendor/repo.or.cz/nasm/rdoff/test/Makefile +10 -0
  244. data/vendor/repo.or.cz/nasm/rdoff/test/makelib.sh +14 -0
  245. data/vendor/repo.or.cz/nasm/rdoff/test/rdfseg.asm +20 -0
  246. data/vendor/repo.or.cz/nasm/rdoff/test/rdfseg2.asm +12 -0
  247. data/vendor/repo.or.cz/nasm/rdoff/test/rdftest1.asm +54 -0
  248. data/vendor/repo.or.cz/nasm/rdoff/test/rdftest2.asm +33 -0
  249. data/vendor/repo.or.cz/nasm/rdoff/test/rdtlib.asm +48 -0
  250. data/vendor/repo.or.cz/nasm/rdoff/test/rdtmain.asm +47 -0
  251. data/vendor/repo.or.cz/nasm/rdoff/test/testlib.asm +18 -0
  252. data/vendor/repo.or.cz/nasm/stdlib/snprintf.c +29 -0
  253. data/vendor/repo.or.cz/nasm/stdlib/strlcpy.c +51 -0
  254. data/vendor/repo.or.cz/nasm/stdlib/strnlen.c +46 -0
  255. data/vendor/repo.or.cz/nasm/stdlib/vsnprintf.c +51 -0
  256. data/vendor/repo.or.cz/nasm/test/Makefile +106 -0
  257. data/vendor/repo.or.cz/nasm/test/_file_.asm +5 -0
  258. data/vendor/repo.or.cz/nasm/test/_version.asm +2 -0
  259. data/vendor/repo.or.cz/nasm/test/a32offs.asm +9 -0
  260. data/vendor/repo.or.cz/nasm/test/absolute.asm +40 -0
  261. data/vendor/repo.or.cz/nasm/test/addr64x.asm +18 -0
  262. data/vendor/repo.or.cz/nasm/test/align13.asm +19 -0
  263. data/vendor/repo.or.cz/nasm/test/align13s.asm +20 -0
  264. data/vendor/repo.or.cz/nasm/test/alonesym-obj.asm +166 -0
  265. data/vendor/repo.or.cz/nasm/test/andbyte.asm +15 -0
  266. data/vendor/repo.or.cz/nasm/test/aoutso.asm +99 -0
  267. data/vendor/repo.or.cz/nasm/test/aouttest.asm +86 -0
  268. data/vendor/repo.or.cz/nasm/test/aouttest.c +36 -0
  269. data/vendor/repo.or.cz/nasm/test/avx.asm +46 -0
  270. data/vendor/repo.or.cz/nasm/test/avx005.asm +529 -0
  271. data/vendor/repo.or.cz/nasm/test/avx2.asm +1608 -0
  272. data/vendor/repo.or.cz/nasm/test/avx512cd.asm +106 -0
  273. data/vendor/repo.or.cz/nasm/test/avx512er.asm +144 -0
  274. data/vendor/repo.or.cz/nasm/test/avx512f.asm +7000 -0
  275. data/vendor/repo.or.cz/nasm/test/avx512pf.asm +88 -0
  276. data/vendor/repo.or.cz/nasm/test/bcd.asm +23 -0
  277. data/vendor/repo.or.cz/nasm/test/binexe.asm +35 -0
  278. data/vendor/repo.or.cz/nasm/test/bintest.asm +59 -0
  279. data/vendor/repo.or.cz/nasm/test/bisect.sh +22 -0
  280. data/vendor/repo.or.cz/nasm/test/br1879590.asm +25 -0
  281. data/vendor/repo.or.cz/nasm/test/br2003451.asm +17 -0
  282. data/vendor/repo.or.cz/nasm/test/br2030823.asm +7 -0
  283. data/vendor/repo.or.cz/nasm/test/br2148476.asm +221 -0
  284. data/vendor/repo.or.cz/nasm/test/br2222615.asm +19 -0
  285. data/vendor/repo.or.cz/nasm/test/br2496848.asm +42 -0
  286. data/vendor/repo.or.cz/nasm/test/br3005117.asm +26 -0
  287. data/vendor/repo.or.cz/nasm/test/br3026808.asm +20 -0
  288. data/vendor/repo.or.cz/nasm/test/br3028880.asm +8 -0
  289. data/vendor/repo.or.cz/nasm/test/br3041451.asm +59 -0
  290. data/vendor/repo.or.cz/nasm/test/br3058845.asm +14 -0
  291. data/vendor/repo.or.cz/nasm/test/br3066383.asm +70 -0
  292. data/vendor/repo.or.cz/nasm/test/br3074517.asm +12 -0
  293. data/vendor/repo.or.cz/nasm/test/br3092924.asm +25 -0
  294. data/vendor/repo.or.cz/nasm/test/br3104312.asm +11 -0
  295. data/vendor/repo.or.cz/nasm/test/br3109604.asm +9 -0
  296. data/vendor/repo.or.cz/nasm/test/br3174983.asm +9 -0
  297. data/vendor/repo.or.cz/nasm/test/br3187743.asm +7 -0
  298. data/vendor/repo.or.cz/nasm/test/br3189064.asm +7 -0
  299. data/vendor/repo.or.cz/nasm/test/br3200749.asm +9 -0
  300. data/vendor/repo.or.cz/nasm/test/br3385573.asm +11 -0
  301. data/vendor/repo.or.cz/nasm/test/br3392252.asm +43 -0
  302. data/vendor/repo.or.cz/nasm/test/br3392259.asm +8 -0
  303. data/vendor/repo.or.cz/nasm/test/br3392363.asm +4 -0
  304. data/vendor/repo.or.cz/nasm/test/br3392392.asm +16 -0
  305. data/vendor/repo.or.cz/nasm/test/br3392396.asm +5 -0
  306. data/vendor/repo.or.cz/nasm/test/br3392411.asm +22 -0
  307. data/vendor/repo.or.cz/nasm/test/br3392418.asm +3 -0
  308. data/vendor/repo.or.cz/nasm/test/br3392439.asm +25 -0
  309. data/vendor/repo.or.cz/nasm/test/br3392442.asm +6 -0
  310. data/vendor/repo.or.cz/nasm/test/br560575.asm +17 -0
  311. data/vendor/repo.or.cz/nasm/test/br560873.asm +27 -0
  312. data/vendor/repo.or.cz/nasm/test/br890790.asm +7 -0
  313. data/vendor/repo.or.cz/nasm/test/br890790_i.asm +1 -0
  314. data/vendor/repo.or.cz/nasm/test/br978756.asm +7 -0
  315. data/vendor/repo.or.cz/nasm/test/changed.asm +383 -0
  316. data/vendor/repo.or.cz/nasm/test/cofftest.asm +85 -0
  317. data/vendor/repo.or.cz/nasm/test/cofftest.c +35 -0
  318. data/vendor/repo.or.cz/nasm/test/crc32.asm +37 -0
  319. data/vendor/repo.or.cz/nasm/test/cv8struc.asm +14 -0
  320. data/vendor/repo.or.cz/nasm/test/dtbcd.asm +72 -0
  321. data/vendor/repo.or.cz/nasm/test/elf64so.asm +118 -0
  322. data/vendor/repo.or.cz/nasm/test/elfso.asm +100 -0
  323. data/vendor/repo.or.cz/nasm/test/elftest.asm +87 -0
  324. data/vendor/repo.or.cz/nasm/test/elftest.c +38 -0
  325. data/vendor/repo.or.cz/nasm/test/elftest64.c +43 -0
  326. data/vendor/repo.or.cz/nasm/test/elif.asm +39 -0
  327. data/vendor/repo.or.cz/nasm/test/expimp.asm +90 -0
  328. data/vendor/repo.or.cz/nasm/test/far64.asm +10 -0
  329. data/vendor/repo.or.cz/nasm/test/float.asm +186 -0
  330. data/vendor/repo.or.cz/nasm/test/float8.asm +135 -0
  331. data/vendor/repo.or.cz/nasm/test/floatb.asm +35 -0
  332. data/vendor/repo.or.cz/nasm/test/floatexp.asm +382 -0
  333. data/vendor/repo.or.cz/nasm/test/floatize.asm +19 -0
  334. data/vendor/repo.or.cz/nasm/test/floattest.asm +28 -0
  335. data/vendor/repo.or.cz/nasm/test/floatx.asm +525 -0
  336. data/vendor/repo.or.cz/nasm/test/fpu.asm +127 -0
  337. data/vendor/repo.or.cz/nasm/test/fwdopt.asm +133 -0
  338. data/vendor/repo.or.cz/nasm/test/fwdoptpp.asm +150 -0
  339. data/vendor/repo.or.cz/nasm/test/gas2nasm.py +104 -0
  340. data/vendor/repo.or.cz/nasm/test/gather.asm +11 -0
  341. data/vendor/repo.or.cz/nasm/test/gotoff64.asm +25 -0
  342. data/vendor/repo.or.cz/nasm/test/hexfp.asm +25 -0
  343. data/vendor/repo.or.cz/nasm/test/hle.asm +19 -0
  344. data/vendor/repo.or.cz/nasm/test/ifelse.asm +46 -0
  345. data/vendor/repo.or.cz/nasm/test/ifenv.asm +31 -0
  346. data/vendor/repo.or.cz/nasm/test/ifmacro.asm +413 -0
  347. data/vendor/repo.or.cz/nasm/test/iftoken.asm +317 -0
  348. data/vendor/repo.or.cz/nasm/test/iftoken.pl +32 -0
  349. data/vendor/repo.or.cz/nasm/test/ilog2.asm +271 -0
  350. data/vendor/repo.or.cz/nasm/test/imacro.asm +8 -0
  351. data/vendor/repo.or.cz/nasm/test/imm.asm +23 -0
  352. data/vendor/repo.or.cz/nasm/test/imm64.asm +61 -0
  353. data/vendor/repo.or.cz/nasm/test/immwarn.asm +91 -0
  354. data/vendor/repo.or.cz/nasm/test/imul.asm +117 -0
  355. data/vendor/repo.or.cz/nasm/test/inc1.asm +6 -0
  356. data/vendor/repo.or.cz/nasm/test/inc2.asm +8 -0
  357. data/vendor/repo.or.cz/nasm/test/incbin.asm +7 -0
  358. data/vendor/repo.or.cz/nasm/test/incbin.data +2 -0
  359. data/vendor/repo.or.cz/nasm/test/inctest.asm +15 -0
  360. data/vendor/repo.or.cz/nasm/test/insnlbl.asm +12 -0
  361. data/vendor/repo.or.cz/nasm/test/invlpga.asm +11 -0
  362. data/vendor/repo.or.cz/nasm/test/jmp64.asm +19 -0
  363. data/vendor/repo.or.cz/nasm/test/lar_lsl.asm +124 -0
  364. data/vendor/repo.or.cz/nasm/test/larlsl.asm +23 -0
  365. data/vendor/repo.or.cz/nasm/test/lnxhello.asm +54 -0
  366. data/vendor/repo.or.cz/nasm/test/local.asm +19 -0
  367. data/vendor/repo.or.cz/nasm/test/loopoffs.asm +12 -0
  368. data/vendor/repo.or.cz/nasm/test/lwp.asm +213 -0
  369. data/vendor/repo.or.cz/nasm/test/macro-defaults.asm +64 -0
  370. data/vendor/repo.or.cz/nasm/test/macroerr.asm +12 -0
  371. data/vendor/repo.or.cz/nasm/test/macroerr.inc +3 -0
  372. data/vendor/repo.or.cz/nasm/test/mmxsize.asm +38 -0
  373. data/vendor/repo.or.cz/nasm/test/movd.asm +12 -0
  374. data/vendor/repo.or.cz/nasm/test/movd64.asm +15 -0
  375. data/vendor/repo.or.cz/nasm/test/movimm.asm +28 -0
  376. data/vendor/repo.or.cz/nasm/test/movnti.asm +10 -0
  377. data/vendor/repo.or.cz/nasm/test/mpx-64.asm +120 -0
  378. data/vendor/repo.or.cz/nasm/test/mpx.asm +89 -0
  379. data/vendor/repo.or.cz/nasm/test/multisection.asm +96 -0
  380. data/vendor/repo.or.cz/nasm/test/nasmformat.asm +17 -0
  381. data/vendor/repo.or.cz/nasm/test/new +9 -0
  382. data/vendor/repo.or.cz/nasm/test/newrdwr.asm +24 -0
  383. data/vendor/repo.or.cz/nasm/test/nop.asm +17 -0
  384. data/vendor/repo.or.cz/nasm/test/nullfile.asm +4 -0
  385. data/vendor/repo.or.cz/nasm/test/objexe.asm +30 -0
  386. data/vendor/repo.or.cz/nasm/test/objlink.c +33 -0
  387. data/vendor/repo.or.cz/nasm/test/objtest.asm +85 -0
  388. data/vendor/repo.or.cz/nasm/test/optimization.asm +104 -0
  389. data/vendor/repo.or.cz/nasm/test/org.asm +18 -0
  390. data/vendor/repo.or.cz/nasm/test/paste.asm +12 -0
  391. data/vendor/repo.or.cz/nasm/test/pcrel.asm +52 -0
  392. data/vendor/repo.or.cz/nasm/test/perf/label.pl +18 -0
  393. data/vendor/repo.or.cz/nasm/test/perf/macro.pl +18 -0
  394. data/vendor/repo.or.cz/nasm/test/perf/token.pl +23 -0
  395. data/vendor/repo.or.cz/nasm/test/performtest.pl +192 -0
  396. data/vendor/repo.or.cz/nasm/test/pextrw.asm +3 -0
  397. data/vendor/repo.or.cz/nasm/test/pinsr16.asm +53 -0
  398. data/vendor/repo.or.cz/nasm/test/pinsr32.asm +53 -0
  399. data/vendor/repo.or.cz/nasm/test/pinsr64.asm +68 -0
  400. data/vendor/repo.or.cz/nasm/test/popcnt.asm +32 -0
  401. data/vendor/repo.or.cz/nasm/test/ppindirect.asm +42 -0
  402. data/vendor/repo.or.cz/nasm/test/pragma.asm +12 -0
  403. data/vendor/repo.or.cz/nasm/test/prefix66.asm +28 -0
  404. data/vendor/repo.or.cz/nasm/test/ptr.asm +4 -0
  405. data/vendor/repo.or.cz/nasm/test/pushseg.asm +17 -0
  406. data/vendor/repo.or.cz/nasm/test/r13.asm +15 -0
  407. data/vendor/repo.or.cz/nasm/test/radix.asm +54 -0
  408. data/vendor/repo.or.cz/nasm/test/rdpid.asm +21 -0
  409. data/vendor/repo.or.cz/nasm/test/reldef.asm +57 -0
  410. data/vendor/repo.or.cz/nasm/test/relocs.asm +20 -0
  411. data/vendor/repo.or.cz/nasm/test/riprel.asm +5357 -0
  412. data/vendor/repo.or.cz/nasm/test/riprel.pl +29 -0
  413. data/vendor/repo.or.cz/nasm/test/riprel2.asm +11 -0
  414. data/vendor/repo.or.cz/nasm/test/sha-64.asm +30 -0
  415. data/vendor/repo.or.cz/nasm/test/sha.asm +31 -0
  416. data/vendor/repo.or.cz/nasm/test/smartalign16.asm +36 -0
  417. data/vendor/repo.or.cz/nasm/test/smartalign32.asm +36 -0
  418. data/vendor/repo.or.cz/nasm/test/smartalign64.asm +36 -0
  419. data/vendor/repo.or.cz/nasm/test/splitea.asm +11 -0
  420. data/vendor/repo.or.cz/nasm/test/sreg.asm +65 -0
  421. data/vendor/repo.or.cz/nasm/test/strlen.asm +5 -0
  422. data/vendor/repo.or.cz/nasm/test/struc.asm +33 -0
  423. data/vendor/repo.or.cz/nasm/test/test67.asm +38 -0
  424. data/vendor/repo.or.cz/nasm/test/testdos.asm +13 -0
  425. data/vendor/repo.or.cz/nasm/test/testnos3.asm +973 -0
  426. data/vendor/repo.or.cz/nasm/test/time.asm +11 -0
  427. data/vendor/repo.or.cz/nasm/test/times.asm +21 -0
  428. data/vendor/repo.or.cz/nasm/test/timesneg.asm +3 -0
  429. data/vendor/repo.or.cz/nasm/test/tmap.nas +1447 -0
  430. data/vendor/repo.or.cz/nasm/test/uscore.asm +15 -0
  431. data/vendor/repo.or.cz/nasm/test/utf.asm +82 -0
  432. data/vendor/repo.or.cz/nasm/test/vaesenc.asm +22 -0
  433. data/vendor/repo.or.cz/nasm/test/vex.asm +9 -0
  434. data/vendor/repo.or.cz/nasm/test/vgather.asm +76 -0
  435. data/vendor/repo.or.cz/nasm/test/vmread.asm +26 -0
  436. data/vendor/repo.or.cz/nasm/test/weirdpaste.asm +29 -0
  437. data/vendor/repo.or.cz/nasm/test/xchg.asm +96 -0
  438. data/vendor/repo.or.cz/nasm/test/xcrypt.asm +24 -0
  439. data/vendor/repo.or.cz/nasm/test/xmm0.asm +12 -0
  440. data/vendor/repo.or.cz/nasm/test/zerobyte.asm +22 -0
  441. data/vendor/repo.or.cz/nasm/tools/cleanfile +176 -0
  442. data/vendor/repo.or.cz/nasm/tools/cleanpatch +258 -0
  443. data/vendor/repo.or.cz/nasm/tools/mkdep.pl +261 -0
  444. data/vendor/repo.or.cz/nasm/tools/release +105 -0
  445. data/vendor/repo.or.cz/nasm/tools/syncfiles.pl +137 -0
  446. data/vendor/repo.or.cz/nasm/tools/tag-release +58 -0
  447. data/vendor/repo.or.cz/nasm/version +1 -0
  448. data/vendor/repo.or.cz/nasm/version.pl +189 -0
  449. data/vendor/repo.or.cz/nasm/x86/disp8.c +131 -0
  450. data/vendor/repo.or.cz/nasm/x86/insns-iflags.ph +280 -0
  451. data/vendor/repo.or.cz/nasm/x86/insns.dat +5371 -0
  452. data/vendor/repo.or.cz/nasm/x86/insns.pl +1043 -0
  453. data/vendor/repo.or.cz/nasm/x86/regs.dat +138 -0
  454. data/vendor/repo.or.cz/nasm/x86/regs.pl +204 -0
  455. metadata +520 -0
@@ -0,0 +1,1855 @@
1
+ /* ----------------------------------------------------------------------- *
2
+ *
3
+ * Copyright 1996-2017 The NASM Authors - All Rights Reserved
4
+ * See the file AUTHORS included with the NASM distribution for
5
+ * the specific copyright holders.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following
9
+ * conditions are met:
10
+ *
11
+ * * Redistributions of source code must retain the above copyright
12
+ * notice, this list of conditions and the following disclaimer.
13
+ * * Redistributions in binary form must reproduce the above
14
+ * copyright notice, this list of conditions and the following
15
+ * disclaimer in the documentation and/or other materials provided
16
+ * with the distribution.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ * ----------------------------------------------------------------------- */
33
+
34
+ /*
35
+ * The Netwide Assembler main program module
36
+ */
37
+
38
+ #include "compiler.h"
39
+
40
+ #include <stdio.h>
41
+ #include <stdarg.h>
42
+ #include <stdlib.h>
43
+ #include <string.h>
44
+ #include <ctype.h>
45
+ #include <limits.h>
46
+
47
+ #include "nasm.h"
48
+ #include "nasmlib.h"
49
+ #include "error.h"
50
+ #include "saa.h"
51
+ #include "raa.h"
52
+ #include "float.h"
53
+ #include "stdscan.h"
54
+ #include "insns.h"
55
+ #include "preproc.h"
56
+ #include "parser.h"
57
+ #include "eval.h"
58
+ #include "assemble.h"
59
+ #include "labels.h"
60
+ #include "outform.h"
61
+ #include "listing.h"
62
+ #include "iflag.h"
63
+ #include "ver.h"
64
+
65
+ /*
66
+ * This is the maximum number of optimization passes to do. If we ever
67
+ * find a case where the optimizer doesn't naturally converge, we might
68
+ * have to drop this value so the assembler doesn't appear to just hang.
69
+ */
70
+ #define MAX_OPTIMIZE (INT_MAX >> 1)
71
+
72
+ struct forwrefinfo { /* info held on forward refs. */
73
+ int lineno;
74
+ int operand;
75
+ };
76
+
77
+ static void parse_cmdline(int, char **, int);
78
+ static void assemble_file(char *, StrList **);
79
+ static bool is_suppressed_warning(int severity);
80
+ static bool skip_this_pass(int severity);
81
+ static void nasm_verror_gnu(int severity, const char *fmt, va_list args);
82
+ static void nasm_verror_vc(int severity, const char *fmt, va_list args);
83
+ static void nasm_verror_common(int severity, const char *fmt, va_list args);
84
+ static void usage(void);
85
+
86
+ static bool using_debug_info, opt_verbose_info;
87
+ static const char *debug_format;
88
+
89
+ bool tasm_compatible_mode = false;
90
+ int pass0, passn;
91
+ static int pass1, pass2; /* XXX: Get rid of these, they are redundant */
92
+ int globalrel = 0;
93
+ int globalbnd = 0;
94
+
95
+ struct compile_time official_compile_time;
96
+
97
+ static char inname[FILENAME_MAX];
98
+ static char outname[FILENAME_MAX];
99
+ static char listname[FILENAME_MAX];
100
+ static char errname[FILENAME_MAX];
101
+ static int globallineno; /* for forward-reference tracking */
102
+ /* static int pass = 0; */
103
+ const struct ofmt *ofmt = &OF_DEFAULT;
104
+ const struct ofmt_alias *ofmt_alias = NULL;
105
+ const struct dfmt *dfmt;
106
+
107
+ static FILE *error_file; /* Where to write error messages */
108
+
109
+ FILE *ofile = NULL;
110
+ int optimizing = MAX_OPTIMIZE; /* number of optimization passes to take */
111
+ static int cmd_sb = 16; /* by default */
112
+
113
+ iflag_t cpu;
114
+ static iflag_t cmd_cpu;
115
+
116
+ struct location location;
117
+ bool in_absolute; /* Flag we are in ABSOLUTE seg */
118
+ struct location absolute; /* Segment/offset inside ABSOLUTE */
119
+
120
+ static struct RAA *offsets;
121
+
122
+ static struct SAA *forwrefs; /* keep track of forward references */
123
+ static const struct forwrefinfo *forwref;
124
+
125
+ static const struct preproc_ops *preproc;
126
+
127
+ #define OP_NORMAL (1u << 0)
128
+ #define OP_PREPROCESS (1u << 1)
129
+ #define OP_DEPEND (1u << 2)
130
+
131
+ static unsigned int operating_mode;
132
+
133
+ /* Dependency flags */
134
+ static bool depend_emit_phony = false;
135
+ static bool depend_missing_ok = false;
136
+ static const char *depend_target = NULL;
137
+ static const char *depend_file = NULL;
138
+ StrList *depend_list;
139
+
140
+ static bool want_usage;
141
+ static bool terminate_after_phase;
142
+ bool user_nolist = false;
143
+
144
+ static char *quote_for_pmake(const char *str);
145
+ static char *quote_for_wmake(const char *str);
146
+ static char *(*quote_for_make)(const char *) = quote_for_pmake;
147
+
148
+ static int64_t get_curr_offs(void)
149
+ {
150
+ return in_absolute ? absolute.offset : raa_read(offsets, location.segment);
151
+ }
152
+
153
+ static void set_curr_offs(int64_t l_off)
154
+ {
155
+ if (in_absolute)
156
+ absolute.offset = l_off;
157
+ else
158
+ offsets = raa_write(offsets, location.segment, l_off);
159
+ }
160
+
161
+ static void nasm_fputs(const char *line, FILE * outfile)
162
+ {
163
+ if (outfile) {
164
+ fputs(line, outfile);
165
+ putc('\n', outfile);
166
+ } else
167
+ puts(line);
168
+ }
169
+
170
+ static void define_macros_early(void)
171
+ {
172
+ const struct compile_time * const oct = &official_compile_time;
173
+ char temp[128];
174
+
175
+ if (oct->have_local) {
176
+ strftime(temp, sizeof temp, "__DATE__=\"%Y-%m-%d\"", &oct->local);
177
+ preproc->pre_define(temp);
178
+ strftime(temp, sizeof temp, "__DATE_NUM__=%Y%m%d", &oct->local);
179
+ preproc->pre_define(temp);
180
+ strftime(temp, sizeof temp, "__TIME__=\"%H:%M:%S\"", &oct->local);
181
+ preproc->pre_define(temp);
182
+ strftime(temp, sizeof temp, "__TIME_NUM__=%H%M%S", &oct->local);
183
+ preproc->pre_define(temp);
184
+ }
185
+
186
+ if (oct->have_gm) {
187
+ strftime(temp, sizeof temp, "__UTC_DATE__=\"%Y-%m-%d\"", &oct->gm);
188
+ preproc->pre_define(temp);
189
+ strftime(temp, sizeof temp, "__UTC_DATE_NUM__=%Y%m%d", &oct->gm);
190
+ preproc->pre_define(temp);
191
+ strftime(temp, sizeof temp, "__UTC_TIME__=\"%H:%M:%S\"", &oct->gm);
192
+ preproc->pre_define(temp);
193
+ strftime(temp, sizeof temp, "__UTC_TIME_NUM__=%H%M%S", &oct->gm);
194
+ preproc->pre_define(temp);
195
+ }
196
+
197
+ if (oct->have_posix) {
198
+ snprintf(temp, sizeof temp, "__POSIX_TIME__=%"PRId64, oct->posix);
199
+ preproc->pre_define(temp);
200
+ }
201
+ }
202
+
203
+ static void define_macros_late(void)
204
+ {
205
+ char temp[128];
206
+
207
+ /*
208
+ * In case if output format is defined by alias
209
+ * we have to put shortname of the alias itself here
210
+ * otherwise ABI backward compatibility gets broken.
211
+ */
212
+ snprintf(temp, sizeof(temp), "__OUTPUT_FORMAT__=%s",
213
+ ofmt_alias ? ofmt_alias->shortname : ofmt->shortname);
214
+ preproc->pre_define(temp);
215
+ }
216
+
217
+ static void emit_dependencies(StrList *list)
218
+ {
219
+ FILE *deps;
220
+ int linepos, len;
221
+ StrList *l, *nl;
222
+ bool wmake = (quote_for_make == quote_for_wmake);
223
+ const char *wrapstr, *nulltarget;
224
+
225
+ wrapstr = wmake ? " &\n " : " \\\n ";
226
+ nulltarget = wmake ? "\t%null\n" : "";
227
+
228
+ if (depend_file && strcmp(depend_file, "-")) {
229
+ deps = nasm_open_write(depend_file, NF_TEXT);
230
+ if (!deps) {
231
+ nasm_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE,
232
+ "unable to write dependency file `%s'", depend_file);
233
+ return;
234
+ }
235
+ } else {
236
+ deps = stdout;
237
+ }
238
+
239
+ linepos = fprintf(deps, "%s :", depend_target);
240
+ list_for_each(l, list) {
241
+ char *file = quote_for_make(l->str);
242
+ len = strlen(file);
243
+ if (linepos + len > 62 && linepos > 1) {
244
+ fputs(wrapstr, deps);
245
+ linepos = 1;
246
+ }
247
+ fprintf(deps, " %s", file);
248
+ linepos += len+1;
249
+ nasm_free(file);
250
+ }
251
+ fprintf(deps, "\n\n");
252
+
253
+ list_for_each_safe(l, nl, list) {
254
+ if (depend_emit_phony) {
255
+ char *file = quote_for_make(l->str);
256
+ fprintf(deps, "%s :\n%s\n", file, nulltarget);
257
+ nasm_free(file);
258
+ }
259
+ nasm_free(l);
260
+ }
261
+
262
+ if (deps != stdout)
263
+ fclose(deps);
264
+ }
265
+
266
+ /* Convert a struct tm to a POSIX-style time constant */
267
+ static int64_t make_posix_time(const struct tm *tm)
268
+ {
269
+ int64_t t;
270
+ int64_t y = tm->tm_year;
271
+
272
+ /* See IEEE 1003.1:2004, section 4.14 */
273
+
274
+ t = (y-70)*365 + (y-69)/4 - (y-1)/100 + (y+299)/400;
275
+ t += tm->tm_yday;
276
+ t *= 24;
277
+ t += tm->tm_hour;
278
+ t *= 60;
279
+ t += tm->tm_min;
280
+ t *= 60;
281
+ t += tm->tm_sec;
282
+
283
+ return t;
284
+ }
285
+
286
+ static void timestamp(void)
287
+ {
288
+ struct compile_time * const oct = &official_compile_time;
289
+ const struct tm *tp, *best_gm;
290
+
291
+ time(&oct->t);
292
+
293
+ best_gm = NULL;
294
+
295
+ tp = localtime(&oct->t);
296
+ if (tp) {
297
+ oct->local = *tp;
298
+ best_gm = &oct->local;
299
+ oct->have_local = true;
300
+ }
301
+
302
+ tp = gmtime(&oct->t);
303
+ if (tp) {
304
+ oct->gm = *tp;
305
+ best_gm = &oct->gm;
306
+ oct->have_gm = true;
307
+ if (!oct->have_local)
308
+ oct->local = oct->gm;
309
+ } else {
310
+ oct->gm = oct->local;
311
+ }
312
+
313
+ if (best_gm) {
314
+ oct->posix = make_posix_time(best_gm);
315
+ oct->have_posix = true;
316
+ }
317
+ }
318
+
319
+ int main(int argc, char **argv)
320
+ {
321
+ StrList **depend_ptr;
322
+
323
+ timestamp();
324
+
325
+ iflag_set_default_cpu(&cpu);
326
+ iflag_set_default_cpu(&cmd_cpu);
327
+
328
+ pass0 = 0;
329
+ want_usage = terminate_after_phase = false;
330
+ nasm_set_verror(nasm_verror_gnu);
331
+
332
+ error_file = stderr;
333
+
334
+ tolower_init();
335
+ src_init();
336
+
337
+ offsets = raa_init();
338
+ forwrefs = saa_init((int32_t)sizeof(struct forwrefinfo));
339
+
340
+ preproc = &nasmpp;
341
+ operating_mode = OP_NORMAL;
342
+
343
+ parse_cmdline(argc, argv, 1);
344
+ if (terminate_after_phase) {
345
+ if (want_usage)
346
+ usage();
347
+ return 1;
348
+ }
349
+
350
+ /*
351
+ * Define some macros dependent on the runtime, but not
352
+ * on the command line (as those are scanned in cmdline pass 2.)
353
+ */
354
+ preproc->init();
355
+ define_macros_early();
356
+
357
+ parse_cmdline(argc, argv, 2);
358
+ if (terminate_after_phase) {
359
+ if (want_usage)
360
+ usage();
361
+ return 1;
362
+ }
363
+
364
+ /* Save away the default state of warnings */
365
+ memcpy(warning_state_init, warning_state, sizeof warning_state);
366
+
367
+ if (!using_debug_info) {
368
+ /* No debug info, redirect to the null backend (empty stubs) */
369
+ dfmt = &null_debug_form;
370
+ } else if (!debug_format) {
371
+ /* Default debug format for this backend */
372
+ dfmt = ofmt->default_dfmt;
373
+ } else {
374
+ dfmt = dfmt_find(ofmt, debug_format);
375
+ if (!dfmt) {
376
+ nasm_fatal(ERR_NOFILE | ERR_USAGE,
377
+ "unrecognized debug format `%s' for"
378
+ " output format `%s'",
379
+ debug_format, ofmt->shortname);
380
+ }
381
+ }
382
+
383
+ if (ofmt->stdmac)
384
+ preproc->extra_stdmac(ofmt->stdmac);
385
+
386
+ /* define some macros dependent of command-line */
387
+ define_macros_late();
388
+
389
+ depend_ptr = (depend_file || (operating_mode & OP_DEPEND)) ? &depend_list : NULL;
390
+
391
+ if (!depend_target)
392
+ depend_target = quote_for_make(outname);
393
+
394
+ if (operating_mode & OP_DEPEND) {
395
+ char *line;
396
+
397
+ if (depend_missing_ok)
398
+ preproc->include_path(NULL); /* "assume generated" */
399
+
400
+ preproc->reset(inname, 0, depend_ptr);
401
+ if (outname[0] == '\0')
402
+ ofmt->filename(inname, outname);
403
+ ofile = NULL;
404
+ while ((line = preproc->getline()))
405
+ nasm_free(line);
406
+ preproc->cleanup(0);
407
+ } else if (operating_mode & OP_PREPROCESS) {
408
+ char *line;
409
+ const char *file_name = NULL;
410
+ int32_t prior_linnum = 0;
411
+ int lineinc = 0;
412
+
413
+ if (*outname) {
414
+ ofile = nasm_open_write(outname, NF_TEXT);
415
+ if (!ofile)
416
+ nasm_fatal(ERR_NOFILE,
417
+ "unable to open output file `%s'",
418
+ outname);
419
+ } else
420
+ ofile = NULL;
421
+
422
+ location.known = false;
423
+
424
+ /* pass = 1; */
425
+ preproc->reset(inname, 3, depend_ptr);
426
+
427
+ /* Revert all warnings to the default state */
428
+ memcpy(warning_state, warning_state_init, sizeof warning_state);
429
+
430
+ while ((line = preproc->getline())) {
431
+ /*
432
+ * We generate %line directives if needed for later programs
433
+ */
434
+ int32_t linnum = prior_linnum += lineinc;
435
+ int altline = src_get(&linnum, &file_name);
436
+ if (altline) {
437
+ if (altline == 1 && lineinc == 1)
438
+ nasm_fputs("", ofile);
439
+ else {
440
+ lineinc = (altline != -1 || lineinc != 1);
441
+ fprintf(ofile ? ofile : stdout,
442
+ "%%line %"PRId32"+%d %s\n", linnum, lineinc,
443
+ file_name);
444
+ }
445
+ prior_linnum = linnum;
446
+ }
447
+ nasm_fputs(line, ofile);
448
+ nasm_free(line);
449
+ }
450
+ preproc->cleanup(0);
451
+ if (ofile)
452
+ fclose(ofile);
453
+ if (ofile && terminate_after_phase)
454
+ remove(outname);
455
+ ofile = NULL;
456
+ }
457
+
458
+ if (operating_mode & OP_NORMAL) {
459
+ /*
460
+ * We must call ofmt->filename _anyway_, even if the user
461
+ * has specified their own output file, because some
462
+ * formats (eg OBJ and COFF) use ofmt->filename to find out
463
+ * the name of the input file and then put that inside the
464
+ * file.
465
+ */
466
+ ofmt->filename(inname, outname);
467
+
468
+ ofile = nasm_open_write(outname, (ofmt->flags & OFMT_TEXT) ? NF_TEXT : NF_BINARY);
469
+ if (!ofile)
470
+ nasm_fatal(ERR_NOFILE,
471
+ "unable to open output file `%s'", outname);
472
+
473
+ /*
474
+ * We must call init_labels() before ofmt->init() since
475
+ * some object formats will want to define labels in their
476
+ * init routines. (eg OS/2 defines the FLAT group)
477
+ */
478
+ init_labels();
479
+
480
+ ofmt->init();
481
+ dfmt->init();
482
+
483
+ assemble_file(inname, depend_ptr);
484
+
485
+ if (!terminate_after_phase) {
486
+ ofmt->cleanup();
487
+ cleanup_labels();
488
+ fflush(ofile);
489
+ if (ferror(ofile)) {
490
+ nasm_error(ERR_NONFATAL|ERR_NOFILE,
491
+ "write error on output file `%s'", outname);
492
+ terminate_after_phase = true;
493
+ }
494
+ }
495
+
496
+ if (ofile) {
497
+ fclose(ofile);
498
+ if (terminate_after_phase)
499
+ remove(outname);
500
+ ofile = NULL;
501
+ }
502
+ }
503
+
504
+ if (depend_list && !terminate_after_phase)
505
+ emit_dependencies(depend_list);
506
+
507
+ if (want_usage)
508
+ usage();
509
+
510
+ raa_free(offsets);
511
+ saa_free(forwrefs);
512
+ eval_cleanup();
513
+ stdscan_cleanup();
514
+ src_free();
515
+
516
+ return terminate_after_phase;
517
+ }
518
+
519
+ /*
520
+ * Get a parameter for a command line option.
521
+ * First arg must be in the form of e.g. -f...
522
+ */
523
+ static char *get_param(char *p, char *q, bool *advance)
524
+ {
525
+ *advance = false;
526
+ if (p[2]) /* the parameter's in the option */
527
+ return nasm_skip_spaces(p + 2);
528
+ if (q && q[0]) {
529
+ *advance = true;
530
+ return q;
531
+ }
532
+ nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
533
+ "option `-%c' requires an argument", p[1]);
534
+ return NULL;
535
+ }
536
+
537
+ /*
538
+ * Copy a filename
539
+ */
540
+ static void copy_filename(char *dst, const char *src)
541
+ {
542
+ size_t len = strlen(src);
543
+
544
+ if (len >= (size_t)FILENAME_MAX) {
545
+ nasm_fatal(ERR_NOFILE, "file name too long");
546
+ return;
547
+ }
548
+ strncpy(dst, src, FILENAME_MAX);
549
+ }
550
+
551
+ /*
552
+ * Convert a string to a POSIX make-safe form
553
+ */
554
+ static char *quote_for_pmake(const char *str)
555
+ {
556
+ const char *p;
557
+ char *os, *q;
558
+
559
+ size_t n = 1; /* Terminating zero */
560
+ size_t nbs = 0;
561
+
562
+ if (!str)
563
+ return NULL;
564
+
565
+ for (p = str; *p; p++) {
566
+ switch (*p) {
567
+ case ' ':
568
+ case '\t':
569
+ /* Convert N backslashes + ws -> 2N+1 backslashes + ws */
570
+ n += nbs + 2;
571
+ nbs = 0;
572
+ break;
573
+ case '$':
574
+ case '#':
575
+ nbs = 0;
576
+ n += 2;
577
+ break;
578
+ case '\\':
579
+ nbs++;
580
+ n++;
581
+ break;
582
+ default:
583
+ nbs = 0;
584
+ n++;
585
+ break;
586
+ }
587
+ }
588
+
589
+ /* Convert N backslashes at the end of filename to 2N backslashes */
590
+ if (nbs)
591
+ n += nbs;
592
+
593
+ os = q = nasm_malloc(n);
594
+
595
+ nbs = 0;
596
+ for (p = str; *p; p++) {
597
+ switch (*p) {
598
+ case ' ':
599
+ case '\t':
600
+ while (nbs--)
601
+ *q++ = '\\';
602
+ *q++ = '\\';
603
+ *q++ = *p;
604
+ break;
605
+ case '$':
606
+ *q++ = *p;
607
+ *q++ = *p;
608
+ nbs = 0;
609
+ break;
610
+ case '#':
611
+ *q++ = '\\';
612
+ *q++ = *p;
613
+ nbs = 0;
614
+ break;
615
+ case '\\':
616
+ *q++ = *p;
617
+ nbs++;
618
+ break;
619
+ default:
620
+ *q++ = *p;
621
+ nbs = 0;
622
+ break;
623
+ }
624
+ }
625
+ while (nbs--)
626
+ *q++ = '\\';
627
+
628
+ *q = '\0';
629
+
630
+ return os;
631
+ }
632
+
633
+ /*
634
+ * Convert a string to a Watcom make-safe form
635
+ */
636
+ static char *quote_for_wmake(const char *str)
637
+ {
638
+ const char *p;
639
+ char *os, *q;
640
+ bool quote = false;
641
+
642
+ size_t n = 1; /* Terminating zero */
643
+
644
+ if (!str)
645
+ return NULL;
646
+
647
+ for (p = str; *p; p++) {
648
+ switch (*p) {
649
+ case ' ':
650
+ case '\t':
651
+ case '&':
652
+ quote = true;
653
+ n++;
654
+ break;
655
+ case '\"':
656
+ quote = true;
657
+ n += 2;
658
+ break;
659
+ case '$':
660
+ case '#':
661
+ n += 2;
662
+ break;
663
+ default:
664
+ n++;
665
+ break;
666
+ }
667
+ }
668
+
669
+ if (quote)
670
+ n += 2;
671
+
672
+ os = q = nasm_malloc(n);
673
+
674
+ if (quote)
675
+ *q++ = '\"';
676
+
677
+ for (p = str; *p; p++) {
678
+ switch (*p) {
679
+ case '$':
680
+ case '#':
681
+ *q++ = '$';
682
+ *q++ = *p;
683
+ break;
684
+ case '\"':
685
+ *q++ = *p;
686
+ *q++ = *p;
687
+ break;
688
+ default:
689
+ *q++ = *p;
690
+ break;
691
+ }
692
+ }
693
+
694
+ if (quote)
695
+ *q++ = '\"';
696
+
697
+ *q = '\0';
698
+
699
+ return os;
700
+ }
701
+
702
+ struct textargs {
703
+ const char *label;
704
+ int value;
705
+ };
706
+
707
+ enum text_options {
708
+ OPT_PREFIX,
709
+ OPT_POSTFIX
710
+ };
711
+ static const struct textargs textopts[] = {
712
+ {"prefix", OPT_PREFIX},
713
+ {"postfix", OPT_POSTFIX},
714
+ {NULL, 0}
715
+ };
716
+
717
+ static void show_version(void)
718
+ {
719
+ printf("NASM version %s compiled on %s%s\n",
720
+ nasm_version, nasm_date, nasm_compile_options);
721
+ exit(0);
722
+ }
723
+
724
+ static bool stopoptions = false;
725
+ static bool process_arg(char *p, char *q, int pass)
726
+ {
727
+ char *param;
728
+ int i;
729
+ bool advance = false;
730
+
731
+ if (!p || !p[0])
732
+ return false;
733
+
734
+ if (p[0] == '-' && !stopoptions) {
735
+ if (strchr("oOfpPdDiIlFXuUZwW", p[1])) {
736
+ /* These parameters take values */
737
+ if (!(param = get_param(p, q, &advance)))
738
+ return advance;
739
+ }
740
+
741
+ switch (p[1]) {
742
+ case 's':
743
+ if (pass == 1)
744
+ error_file = stdout;
745
+ break;
746
+
747
+ case 'o': /* output file */
748
+ if (pass == 2)
749
+ copy_filename(outname, param);
750
+ break;
751
+
752
+ case 'f': /* output format */
753
+ if (pass == 1) {
754
+ ofmt = ofmt_find(param, &ofmt_alias);
755
+ if (!ofmt) {
756
+ nasm_fatal(ERR_NOFILE | ERR_USAGE,
757
+ "unrecognised output format `%s' - "
758
+ "use -hf for a list", param);
759
+ }
760
+ }
761
+ break;
762
+
763
+ case 'O': /* Optimization level */
764
+ if (pass == 2) {
765
+ int opt;
766
+
767
+ if (!*param) {
768
+ /* Naked -O == -Ox */
769
+ optimizing = MAX_OPTIMIZE;
770
+ } else {
771
+ while (*param) {
772
+ switch (*param) {
773
+ case '0': case '1': case '2': case '3': case '4':
774
+ case '5': case '6': case '7': case '8': case '9':
775
+ opt = strtoul(param, &param, 10);
776
+
777
+ /* -O0 -> optimizing == -1, 0.98 behaviour */
778
+ /* -O1 -> optimizing == 0, 0.98.09 behaviour */
779
+ if (opt < 2)
780
+ optimizing = opt - 1;
781
+ else
782
+ optimizing = opt;
783
+ break;
784
+
785
+ case 'v':
786
+ case '+':
787
+ param++;
788
+ opt_verbose_info = true;
789
+ break;
790
+
791
+ case 'x':
792
+ param++;
793
+ optimizing = MAX_OPTIMIZE;
794
+ break;
795
+
796
+ default:
797
+ nasm_fatal(0,
798
+ "unknown optimization option -O%c\n",
799
+ *param);
800
+ break;
801
+ }
802
+ }
803
+ if (optimizing > MAX_OPTIMIZE)
804
+ optimizing = MAX_OPTIMIZE;
805
+ }
806
+ }
807
+ break;
808
+
809
+ case 'p': /* pre-include */
810
+ case 'P':
811
+ if (pass == 2)
812
+ preproc->pre_include(param);
813
+ break;
814
+
815
+ case 'd': /* pre-define */
816
+ case 'D':
817
+ if (pass == 2)
818
+ preproc->pre_define(param);
819
+ break;
820
+
821
+ case 'u': /* un-define */
822
+ case 'U':
823
+ if (pass == 2)
824
+ preproc->pre_undefine(param);
825
+ break;
826
+
827
+ case 'i': /* include search path */
828
+ case 'I':
829
+ if (pass == 2)
830
+ preproc->include_path(param);
831
+ break;
832
+
833
+ case 'l': /* listing file */
834
+ if (pass == 2)
835
+ copy_filename(listname, param);
836
+ break;
837
+
838
+ case 'Z': /* error messages file */
839
+ if (pass == 1)
840
+ copy_filename(errname, param);
841
+ break;
842
+
843
+ case 'F': /* specify debug format */
844
+ if (pass == 2) {
845
+ using_debug_info = true;
846
+ debug_format = param;
847
+ }
848
+ break;
849
+
850
+ case 'X': /* specify error reporting format */
851
+ if (pass == 1) {
852
+ if (nasm_stricmp("vc", param) == 0)
853
+ nasm_set_verror(nasm_verror_vc);
854
+ else if (nasm_stricmp("gnu", param) == 0)
855
+ nasm_set_verror(nasm_verror_gnu);
856
+ else
857
+ nasm_fatal(ERR_NOFILE | ERR_USAGE,
858
+ "unrecognized error reporting format `%s'",
859
+ param);
860
+ }
861
+ break;
862
+
863
+ case 'g':
864
+ if (pass == 2) {
865
+ using_debug_info = true;
866
+ if (p[2])
867
+ debug_format = nasm_skip_spaces(p + 2);
868
+ }
869
+ break;
870
+
871
+ case 'h':
872
+ printf
873
+ ("usage: nasm [-@ response file] [-o outfile] [-f format] "
874
+ "[-l listfile]\n"
875
+ " [options...] [--] filename\n"
876
+ " or nasm -v (or --v) for version info\n\n"
877
+ " -t assemble in SciTech TASM compatible mode\n");
878
+ printf
879
+ (" -E (or -e) preprocess only (writes output to stdout by default)\n"
880
+ " -a don't preprocess (assemble only)\n"
881
+ " -M generate Makefile dependencies on stdout\n"
882
+ " -MG d:o, missing files assumed generated\n"
883
+ " -MF <file> set Makefile dependency file\n"
884
+ " -MD <file> assemble and generate dependencies\n"
885
+ " -MT <file> dependency target name\n"
886
+ " -MQ <file> dependency target name (quoted)\n"
887
+ " -MP emit phony target\n\n"
888
+ " -Z<file> redirect error messages to file\n"
889
+ " -s redirect error messages to stdout\n\n"
890
+ " -g generate debugging information\n\n"
891
+ " -F format select a debugging format\n\n"
892
+ " -gformat same as -g -F format\n\n"
893
+ " -o outfile write output to an outfile\n\n"
894
+ " -f format select an output format\n\n"
895
+ " -l listfile write listing to a listfile\n\n"
896
+ " -I<path> adds a pathname to the include file path\n");
897
+ printf
898
+ (" -O<digit> optimize branch offsets\n"
899
+ " -O0: No optimization\n"
900
+ " -O1: Minimal optimization\n"
901
+ " -Ox: Multipass optimization (default)\n\n"
902
+ " -P<file> pre-includes a file\n"
903
+ " -D<macro>[=<value>] pre-defines a macro\n"
904
+ " -U<macro> undefines a macro\n"
905
+ " -X<format> specifies error reporting format (gnu or vc)\n"
906
+ " -w+foo enables warning foo (equiv. -Wfoo)\n"
907
+ " -w-foo disable warning foo (equiv. -Wno-foo)\n\n"
908
+ " -w[+-]error[=foo] can be used to promote warnings to errors\n"
909
+ " -h show invocation summary and exit\n\n"
910
+ "--prefix,--postfix\n"
911
+ " these options prepend or append the given string\n"
912
+ " to all extern and global variables\n"
913
+ "\n"
914
+ "Response files should contain command line parameters,\n"
915
+ "one per line.\n"
916
+ "\n"
917
+ "Warnings for the -W/-w options:\n");
918
+ for (i = 0; i <= ERR_WARN_ALL; i++)
919
+ printf(" %-23s %s%s\n",
920
+ warnings[i].name, warnings[i].help,
921
+ i == ERR_WARN_ALL ? "\n" :
922
+ warnings[i].enabled ? " (default on)" :
923
+ " (default off)");
924
+ if (p[2] == 'f') {
925
+ printf("valid output formats for -f are"
926
+ " (`*' denotes default):\n");
927
+ ofmt_list(ofmt, stdout);
928
+ } else {
929
+ printf("For a list of valid output formats, use -hf.\n");
930
+ printf("For a list of debug formats, use -f <form> -y.\n");
931
+ }
932
+ exit(0); /* never need usage message here */
933
+ break;
934
+
935
+ case 'y':
936
+ printf("\nvalid debug formats for '%s' output format are"
937
+ " ('*' denotes default):\n", ofmt->shortname);
938
+ dfmt_list(ofmt, stdout);
939
+ exit(0);
940
+ break;
941
+
942
+ case 't':
943
+ if (pass == 2)
944
+ tasm_compatible_mode = true;
945
+ break;
946
+
947
+ case 'v':
948
+ show_version();
949
+ break;
950
+
951
+ case 'e': /* preprocess only */
952
+ case 'E':
953
+ if (pass == 1)
954
+ operating_mode = OP_PREPROCESS;
955
+ break;
956
+
957
+ case 'a': /* assemble only - don't preprocess */
958
+ if (pass == 1)
959
+ preproc = &preproc_nop;
960
+ break;
961
+
962
+ case 'w':
963
+ case 'W':
964
+ if (pass == 2) {
965
+ if (!set_warning_status(param)) {
966
+ nasm_error(ERR_WARNING|ERR_NOFILE|ERR_WARN_UNK_WARNING,
967
+ "unknown warning option: %s", param);
968
+ }
969
+ }
970
+ break;
971
+
972
+ case 'M':
973
+ if (pass == 1) {
974
+ switch (p[2]) {
975
+ case 'W':
976
+ quote_for_make = quote_for_wmake;
977
+ break;
978
+ case 'D':
979
+ case 'F':
980
+ case 'T':
981
+ case 'Q':
982
+ advance = true;
983
+ break;
984
+ default:
985
+ break;
986
+ }
987
+ } else {
988
+ switch (p[2]) {
989
+ case 0:
990
+ operating_mode = OP_DEPEND;
991
+ break;
992
+ case 'G':
993
+ operating_mode = OP_DEPEND;
994
+ depend_missing_ok = true;
995
+ break;
996
+ case 'P':
997
+ depend_emit_phony = true;
998
+ break;
999
+ case 'D':
1000
+ operating_mode = OP_NORMAL;
1001
+ depend_file = q;
1002
+ advance = true;
1003
+ break;
1004
+ case 'F':
1005
+ depend_file = q;
1006
+ advance = true;
1007
+ break;
1008
+ case 'T':
1009
+ depend_target = q;
1010
+ advance = true;
1011
+ break;
1012
+ case 'Q':
1013
+ depend_target = quote_for_make(q);
1014
+ advance = true;
1015
+ break;
1016
+ case 'W':
1017
+ /* handled in pass 1 */
1018
+ break;
1019
+ default:
1020
+ nasm_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE,
1021
+ "unknown dependency option `-M%c'", p[2]);
1022
+ break;
1023
+ }
1024
+ }
1025
+ if (advance && (!q || !q[0])) {
1026
+ nasm_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE,
1027
+ "option `-M%c' requires a parameter", p[2]);
1028
+ break;
1029
+ }
1030
+ break;
1031
+
1032
+ case '-':
1033
+ {
1034
+ int s;
1035
+
1036
+ if (p[2] == 0) { /* -- => stop processing options */
1037
+ stopoptions = 1;
1038
+ break;
1039
+ }
1040
+
1041
+ if (!nasm_stricmp(p, "--v"))
1042
+ show_version();
1043
+
1044
+ if (!nasm_stricmp(p, "--version"))
1045
+ show_version();
1046
+
1047
+ for (s = 0; textopts[s].label; s++) {
1048
+ if (!nasm_stricmp(p + 2, textopts[s].label)) {
1049
+ break;
1050
+ }
1051
+ }
1052
+
1053
+ switch (s) {
1054
+ case OPT_PREFIX:
1055
+ case OPT_POSTFIX:
1056
+ {
1057
+ if (!q) {
1058
+ nasm_error(ERR_NONFATAL | ERR_NOFILE |
1059
+ ERR_USAGE,
1060
+ "option `--%s' requires an argument",
1061
+ p + 2);
1062
+ break;
1063
+ } else {
1064
+ advance = 1, param = q;
1065
+ }
1066
+
1067
+ switch (s) {
1068
+ case OPT_PREFIX:
1069
+ if (pass == 2)
1070
+ strlcpy(lprefix, param, PREFIX_MAX);
1071
+ break;
1072
+ case OPT_POSTFIX:
1073
+ if (pass == 2)
1074
+ strlcpy(lpostfix, param, POSTFIX_MAX);
1075
+ break;
1076
+ default:
1077
+ panic();
1078
+ break;
1079
+ }
1080
+ break;
1081
+ }
1082
+
1083
+ default:
1084
+ {
1085
+ nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
1086
+ "unrecognised option `--%s'", p + 2);
1087
+ break;
1088
+ }
1089
+ }
1090
+ break;
1091
+ }
1092
+
1093
+ default:
1094
+ nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
1095
+ "unrecognised option `-%c'", p[1]);
1096
+ break;
1097
+ }
1098
+ } else if (pass == 2) {
1099
+ if (*inname) {
1100
+ nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
1101
+ "more than one input file specified");
1102
+ } else {
1103
+ copy_filename(inname, p);
1104
+ }
1105
+ }
1106
+
1107
+ return advance;
1108
+ }
1109
+
1110
+ #define ARG_BUF_DELTA 128
1111
+
1112
+ static void process_respfile(FILE * rfile, int pass)
1113
+ {
1114
+ char *buffer, *p, *q, *prevarg;
1115
+ int bufsize, prevargsize;
1116
+
1117
+ bufsize = prevargsize = ARG_BUF_DELTA;
1118
+ buffer = nasm_malloc(ARG_BUF_DELTA);
1119
+ prevarg = nasm_malloc(ARG_BUF_DELTA);
1120
+ prevarg[0] = '\0';
1121
+
1122
+ while (1) { /* Loop to handle all lines in file */
1123
+ p = buffer;
1124
+ while (1) { /* Loop to handle long lines */
1125
+ q = fgets(p, bufsize - (p - buffer), rfile);
1126
+ if (!q)
1127
+ break;
1128
+ p += strlen(p);
1129
+ if (p > buffer && p[-1] == '\n')
1130
+ break;
1131
+ if (p - buffer > bufsize - 10) {
1132
+ int offset;
1133
+ offset = p - buffer;
1134
+ bufsize += ARG_BUF_DELTA;
1135
+ buffer = nasm_realloc(buffer, bufsize);
1136
+ p = buffer + offset;
1137
+ }
1138
+ }
1139
+
1140
+ if (!q && p == buffer) {
1141
+ if (prevarg[0])
1142
+ process_arg(prevarg, NULL, pass);
1143
+ nasm_free(buffer);
1144
+ nasm_free(prevarg);
1145
+ return;
1146
+ }
1147
+
1148
+ /*
1149
+ * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
1150
+ * them are present at the end of the line.
1151
+ */
1152
+ *(p = &buffer[strcspn(buffer, "\r\n\032")]) = '\0';
1153
+
1154
+ while (p > buffer && nasm_isspace(p[-1]))
1155
+ *--p = '\0';
1156
+
1157
+ p = nasm_skip_spaces(buffer);
1158
+
1159
+ if (process_arg(prevarg, p, pass))
1160
+ *p = '\0';
1161
+
1162
+ if ((int) strlen(p) > prevargsize - 10) {
1163
+ prevargsize += ARG_BUF_DELTA;
1164
+ prevarg = nasm_realloc(prevarg, prevargsize);
1165
+ }
1166
+ strncpy(prevarg, p, prevargsize);
1167
+ }
1168
+ }
1169
+
1170
+ /* Function to process args from a string of args, rather than the
1171
+ * argv array. Used by the environment variable and response file
1172
+ * processing.
1173
+ */
1174
+ static void process_args(char *args, int pass)
1175
+ {
1176
+ char *p, *q, *arg, *prevarg;
1177
+ char separator = ' ';
1178
+
1179
+ p = args;
1180
+ if (*p && *p != '-')
1181
+ separator = *p++;
1182
+ arg = NULL;
1183
+ while (*p) {
1184
+ q = p;
1185
+ while (*p && *p != separator)
1186
+ p++;
1187
+ while (*p == separator)
1188
+ *p++ = '\0';
1189
+ prevarg = arg;
1190
+ arg = q;
1191
+ if (process_arg(prevarg, arg, pass))
1192
+ arg = NULL;
1193
+ }
1194
+ if (arg)
1195
+ process_arg(arg, NULL, pass);
1196
+ }
1197
+
1198
+ static void process_response_file(const char *file, int pass)
1199
+ {
1200
+ char str[2048];
1201
+ FILE *f = nasm_open_read(file, NF_TEXT);
1202
+ if (!f) {
1203
+ perror(file);
1204
+ exit(-1);
1205
+ }
1206
+ while (fgets(str, sizeof str, f)) {
1207
+ process_args(str, pass);
1208
+ }
1209
+ fclose(f);
1210
+ }
1211
+
1212
+ static void parse_cmdline(int argc, char **argv, int pass)
1213
+ {
1214
+ FILE *rfile;
1215
+ char *envreal, *envcopy = NULL, *p;
1216
+ int i;
1217
+
1218
+ *inname = *outname = *listname = *errname = '\0';
1219
+
1220
+ /* Initialize all the warnings to their default state */
1221
+ for (i = 0; i < ERR_WARN_ALL; i++) {
1222
+ warning_state_init[i] = warning_state[i] =
1223
+ warnings[i].enabled ? WARN_ST_ENABLED : 0;
1224
+ }
1225
+
1226
+ /*
1227
+ * First, process the NASMENV environment variable.
1228
+ */
1229
+ envreal = getenv("NASMENV");
1230
+ if (envreal) {
1231
+ envcopy = nasm_strdup(envreal);
1232
+ process_args(envcopy, pass);
1233
+ nasm_free(envcopy);
1234
+ }
1235
+
1236
+ /*
1237
+ * Now process the actual command line.
1238
+ */
1239
+ while (--argc) {
1240
+ bool advance;
1241
+ argv++;
1242
+ if (argv[0][0] == '@') {
1243
+ /*
1244
+ * We have a response file, so process this as a set of
1245
+ * arguments like the environment variable. This allows us
1246
+ * to have multiple arguments on a single line, which is
1247
+ * different to the -@resp file processing below for regular
1248
+ * NASM.
1249
+ */
1250
+ process_response_file(argv[0]+1, pass);
1251
+ argc--;
1252
+ argv++;
1253
+ }
1254
+ if (!stopoptions && argv[0][0] == '-' && argv[0][1] == '@') {
1255
+ p = get_param(argv[0], argc > 1 ? argv[1] : NULL, &advance);
1256
+ if (p) {
1257
+ rfile = nasm_open_read(p, NF_TEXT);
1258
+ if (rfile) {
1259
+ process_respfile(rfile, pass);
1260
+ fclose(rfile);
1261
+ } else
1262
+ nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
1263
+ "unable to open response file `%s'", p);
1264
+ }
1265
+ } else
1266
+ advance = process_arg(argv[0], argc > 1 ? argv[1] : NULL, pass);
1267
+ argv += advance, argc -= advance;
1268
+ }
1269
+
1270
+ /*
1271
+ * Look for basic command line typos. This definitely doesn't
1272
+ * catch all errors, but it might help cases of fumbled fingers.
1273
+ */
1274
+ if (pass != 2)
1275
+ return;
1276
+
1277
+ if (!*inname)
1278
+ nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
1279
+ "no input file specified");
1280
+ else if (!strcmp(inname, errname) ||
1281
+ !strcmp(inname, outname) ||
1282
+ !strcmp(inname, listname) ||
1283
+ (depend_file && !strcmp(inname, depend_file)))
1284
+ nasm_fatal(ERR_NOFILE | ERR_USAGE,
1285
+ "file `%s' is both input and output file",
1286
+ inname);
1287
+
1288
+ if (*errname) {
1289
+ error_file = nasm_open_write(errname, NF_TEXT);
1290
+ if (!error_file) {
1291
+ error_file = stderr; /* Revert to default! */
1292
+ nasm_fatal(ERR_NOFILE | ERR_USAGE,
1293
+ "cannot open file `%s' for error messages",
1294
+ errname);
1295
+ }
1296
+ }
1297
+ }
1298
+
1299
+ static void assemble_file(char *fname, StrList **depend_ptr)
1300
+ {
1301
+ char *line;
1302
+ insn output_ins;
1303
+ int i;
1304
+ int64_t offs;
1305
+ int pass_max;
1306
+ uint64_t prev_offset_changed;
1307
+ unsigned int stall_count = 0; /* Make sure we make forward progress... */
1308
+
1309
+ switch (cmd_sb) {
1310
+ case 16:
1311
+ break;
1312
+ case 32:
1313
+ if (!iflag_cpu_level_ok(&cmd_cpu, IF_386))
1314
+ nasm_fatal(0, "command line: 32-bit segment size requires a higher cpu");
1315
+ break;
1316
+ case 64:
1317
+ if (!iflag_cpu_level_ok(&cmd_cpu, IF_X86_64))
1318
+ nasm_fatal(0, "command line: 64-bit segment size requires a higher cpu");
1319
+ break;
1320
+ default:
1321
+ panic();
1322
+ break;
1323
+ }
1324
+
1325
+ pass_max = prev_offset_changed = (INT_MAX >> 1) + 2; /* Almost unlimited */
1326
+ for (passn = 1; pass0 <= 2; passn++) {
1327
+ ldfunc def_label;
1328
+
1329
+ pass1 = pass0 == 2 ? 2 : 1; /* 1, 1, 1, ..., 1, 2 */
1330
+ pass2 = passn > 1 ? 2 : 1; /* 1, 2, 2, ..., 2, 2 */
1331
+ /* pass0 0, 0, 0, ..., 1, 2 */
1332
+
1333
+ def_label = passn > 1 ? redefine_label : define_label;
1334
+
1335
+ globalbits = cmd_sb; /* set 'bits' to command line default */
1336
+ cpu = cmd_cpu;
1337
+ if (pass0 == 2) {
1338
+ lfmt->init(listname);
1339
+ } else if (passn == 1 && *listname) {
1340
+ /* Remove the list file in case we die before the output pass */
1341
+ remove(listname);
1342
+ }
1343
+ in_absolute = false;
1344
+ global_offset_changed = 0; /* set by redefine_label */
1345
+ location.segment = ofmt->section(NULL, pass2, &globalbits);
1346
+ if (passn > 1) {
1347
+ saa_rewind(forwrefs);
1348
+ forwref = saa_rstruct(forwrefs);
1349
+ raa_free(offsets);
1350
+ offsets = raa_init();
1351
+ }
1352
+ preproc->reset(fname, pass1, pass1 == 2 ? depend_ptr : NULL);
1353
+
1354
+ /* Revert all warnings to the default state */
1355
+ memcpy(warning_state, warning_state_init, sizeof warning_state);
1356
+
1357
+ globallineno = 0;
1358
+ if (passn == 1)
1359
+ location.known = true;
1360
+ location.offset = offs = get_curr_offs();
1361
+
1362
+ while ((line = preproc->getline())) {
1363
+ globallineno++;
1364
+
1365
+ /*
1366
+ * Here we parse our directives; this is not handled by the
1367
+ * main parser.
1368
+ */
1369
+ if (process_directives(line))
1370
+ goto end_of_line; /* Just do final cleanup */
1371
+
1372
+ /* Not a directive, or even something that starts with [ */
1373
+
1374
+ parse_line(pass1, line, &output_ins, def_label);
1375
+
1376
+ if (optimizing > 0) {
1377
+ if (forwref != NULL && globallineno == forwref->lineno) {
1378
+ output_ins.forw_ref = true;
1379
+ do {
1380
+ output_ins.oprs[forwref->operand].opflags |= OPFLAG_FORWARD;
1381
+ forwref = saa_rstruct(forwrefs);
1382
+ } while (forwref != NULL
1383
+ && forwref->lineno == globallineno);
1384
+ } else
1385
+ output_ins.forw_ref = false;
1386
+
1387
+ if (output_ins.forw_ref) {
1388
+ if (passn == 1) {
1389
+ for (i = 0; i < output_ins.operands; i++) {
1390
+ if (output_ins.oprs[i].opflags & OPFLAG_FORWARD) {
1391
+ struct forwrefinfo *fwinf = (struct forwrefinfo *)saa_wstruct(forwrefs);
1392
+ fwinf->lineno = globallineno;
1393
+ fwinf->operand = i;
1394
+ }
1395
+ }
1396
+ }
1397
+ }
1398
+ }
1399
+
1400
+ /* forw_ref */
1401
+ if (output_ins.opcode == I_EQU) {
1402
+ if (pass1 == 1) {
1403
+ /*
1404
+ * Special `..' EQUs get processed in pass two,
1405
+ * except `..@' macro-processor EQUs which are done
1406
+ * in the normal place.
1407
+ */
1408
+ if (!output_ins.label)
1409
+ nasm_error(ERR_NONFATAL,
1410
+ "EQU not preceded by label");
1411
+
1412
+ else if (output_ins.label[0] != '.' ||
1413
+ output_ins.label[1] != '.' ||
1414
+ output_ins.label[2] == '@') {
1415
+ if (output_ins.operands == 1 &&
1416
+ (output_ins.oprs[0].type & IMMEDIATE) &&
1417
+ output_ins.oprs[0].wrt == NO_SEG) {
1418
+ bool isext = !!(output_ins.oprs[0].opflags & OPFLAG_EXTERN);
1419
+ def_label(output_ins.label,
1420
+ output_ins.oprs[0].segment,
1421
+ output_ins.oprs[0].offset, NULL,
1422
+ false, isext);
1423
+ } else if (output_ins.operands == 2
1424
+ && (output_ins.oprs[0].type & IMMEDIATE)
1425
+ && (output_ins.oprs[0].type & COLON)
1426
+ && output_ins.oprs[0].segment == NO_SEG
1427
+ && output_ins.oprs[0].wrt == NO_SEG
1428
+ && (output_ins.oprs[1].type & IMMEDIATE)
1429
+ && output_ins.oprs[1].segment == NO_SEG
1430
+ && output_ins.oprs[1].wrt == NO_SEG) {
1431
+ def_label(output_ins.label,
1432
+ output_ins.oprs[0].offset | SEG_ABS,
1433
+ output_ins.oprs[1].offset,
1434
+ NULL, false, false);
1435
+ } else
1436
+ nasm_error(ERR_NONFATAL,
1437
+ "bad syntax for EQU");
1438
+ }
1439
+ } else {
1440
+ /*
1441
+ * Special `..' EQUs get processed here, except
1442
+ * `..@' macro processor EQUs which are done above.
1443
+ */
1444
+ if (output_ins.label[0] == '.' &&
1445
+ output_ins.label[1] == '.' &&
1446
+ output_ins.label[2] != '@') {
1447
+ if (output_ins.operands == 1 &&
1448
+ (output_ins.oprs[0].type & IMMEDIATE)) {
1449
+ define_label(output_ins.label,
1450
+ output_ins.oprs[0].segment,
1451
+ output_ins.oprs[0].offset,
1452
+ NULL, false, false);
1453
+ } else if (output_ins.operands == 2
1454
+ && (output_ins.oprs[0].type & IMMEDIATE)
1455
+ && (output_ins.oprs[0].type & COLON)
1456
+ && output_ins.oprs[0].segment == NO_SEG
1457
+ && (output_ins.oprs[1].type & IMMEDIATE)
1458
+ && output_ins.oprs[1].segment == NO_SEG) {
1459
+ define_label(output_ins.label,
1460
+ output_ins.oprs[0].offset | SEG_ABS,
1461
+ output_ins.oprs[1].offset,
1462
+ NULL, false, false);
1463
+ } else
1464
+ nasm_error(ERR_NONFATAL,
1465
+ "bad syntax for EQU");
1466
+ }
1467
+ }
1468
+ } else { /* instruction isn't an EQU */
1469
+ int32_t n;
1470
+
1471
+ nasm_assert(output_ins.times >= 0);
1472
+
1473
+ for (n = 1; n <= output_ins.times; n++) {
1474
+ if (pass1 == 1) {
1475
+ int64_t l = insn_size(location.segment, offs,
1476
+ globalbits, &output_ins);
1477
+
1478
+ /* if (using_debug_info) && output_ins.opcode != -1) */
1479
+ if (using_debug_info)
1480
+ { /* fbk 03/25/01 */
1481
+ /* this is done here so we can do debug type info */
1482
+ int32_t typeinfo =
1483
+ TYS_ELEMENTS(output_ins.operands);
1484
+ switch (output_ins.opcode) {
1485
+ case I_RESB:
1486
+ typeinfo =
1487
+ TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_BYTE;
1488
+ break;
1489
+ case I_RESW:
1490
+ typeinfo =
1491
+ TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_WORD;
1492
+ break;
1493
+ case I_RESD:
1494
+ typeinfo =
1495
+ TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_DWORD;
1496
+ break;
1497
+ case I_RESQ:
1498
+ typeinfo =
1499
+ TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_QWORD;
1500
+ break;
1501
+ case I_REST:
1502
+ typeinfo =
1503
+ TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_TBYTE;
1504
+ break;
1505
+ case I_RESO:
1506
+ typeinfo =
1507
+ TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_OWORD;
1508
+ break;
1509
+ case I_RESY:
1510
+ typeinfo =
1511
+ TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_YWORD;
1512
+ break;
1513
+ case I_RESZ:
1514
+ typeinfo =
1515
+ TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_ZWORD;
1516
+ break;
1517
+ case I_DB:
1518
+ typeinfo |= TY_BYTE;
1519
+ break;
1520
+ case I_DW:
1521
+ typeinfo |= TY_WORD;
1522
+ break;
1523
+ case I_DD:
1524
+ if (output_ins.eops_float)
1525
+ typeinfo |= TY_FLOAT;
1526
+ else
1527
+ typeinfo |= TY_DWORD;
1528
+ break;
1529
+ case I_DQ:
1530
+ typeinfo |= TY_QWORD;
1531
+ break;
1532
+ case I_DT:
1533
+ typeinfo |= TY_TBYTE;
1534
+ break;
1535
+ case I_DO:
1536
+ typeinfo |= TY_OWORD;
1537
+ break;
1538
+ case I_DY:
1539
+ typeinfo |= TY_YWORD;
1540
+ break;
1541
+ case I_DZ:
1542
+ typeinfo |= TY_ZWORD;
1543
+ break;
1544
+ default:
1545
+ typeinfo = TY_LABEL;
1546
+ break;
1547
+ }
1548
+
1549
+ dfmt->debug_typevalue(typeinfo);
1550
+ }
1551
+
1552
+ /*
1553
+ * For INCBIN, let the code in assemble
1554
+ * handle TIMES, so we don't have to read the
1555
+ * input file over and over.
1556
+ */
1557
+ if (l != -1) {
1558
+ offs += l;
1559
+ set_curr_offs(offs);
1560
+ }
1561
+ /*
1562
+ * else l == -1 => invalid instruction, which will be
1563
+ * flagged as an error on pass 2
1564
+ */
1565
+ } else {
1566
+ if (n == 2)
1567
+ lfmt->uplevel(LIST_TIMES);
1568
+ offs += assemble(location.segment, offs,
1569
+ globalbits, &output_ins);
1570
+ set_curr_offs(offs);
1571
+ }
1572
+ } /* not an EQU */
1573
+ }
1574
+ if (output_ins.times > 1)
1575
+ lfmt->downlevel(LIST_TIMES);
1576
+
1577
+ cleanup_insn(&output_ins);
1578
+
1579
+ end_of_line:
1580
+ nasm_free(line);
1581
+ location.offset = offs = get_curr_offs();
1582
+ } /* end while (line = preproc->getline... */
1583
+
1584
+ if (pass0 == 2 && global_offset_changed && !terminate_after_phase)
1585
+ nasm_error(ERR_NONFATAL,
1586
+ "phase error detected at end of assembly.");
1587
+
1588
+ if (pass1 == 1)
1589
+ preproc->cleanup(1);
1590
+
1591
+ if ((passn > 1 && !global_offset_changed) || pass0 == 2) {
1592
+ pass0++;
1593
+ } else if (global_offset_changed &&
1594
+ global_offset_changed < prev_offset_changed) {
1595
+ prev_offset_changed = global_offset_changed;
1596
+ stall_count = 0;
1597
+ } else {
1598
+ stall_count++;
1599
+ }
1600
+
1601
+ if (terminate_after_phase)
1602
+ break;
1603
+
1604
+ if ((stall_count > 997U) || (passn >= pass_max)) {
1605
+ /* We get here if the labels don't converge
1606
+ * Example: FOO equ FOO + 1
1607
+ */
1608
+ nasm_error(ERR_NONFATAL,
1609
+ "Can't find valid values for all labels "
1610
+ "after %d passes, giving up.", passn);
1611
+ nasm_error(ERR_NONFATAL,
1612
+ "Possible causes: recursive EQUs, macro abuse.");
1613
+ break;
1614
+ }
1615
+ }
1616
+
1617
+ preproc->cleanup(0);
1618
+ lfmt->cleanup();
1619
+ if (!terminate_after_phase && opt_verbose_info) {
1620
+ /* -On and -Ov switches */
1621
+ fprintf(stdout, "info: assembly required 1+%d+1 passes\n", passn-3);
1622
+ }
1623
+ }
1624
+
1625
+ /**
1626
+ * gnu style error reporting
1627
+ * This function prints an error message to error_file in the
1628
+ * style used by GNU. An example would be:
1629
+ * file.asm:50: error: blah blah blah
1630
+ * where file.asm is the name of the file, 50 is the line number on
1631
+ * which the error occurs (or is detected) and "error:" is one of
1632
+ * the possible optional diagnostics -- it can be "error" or "warning"
1633
+ * or something else. Finally the line terminates with the actual
1634
+ * error message.
1635
+ *
1636
+ * @param severity the severity of the warning or error
1637
+ * @param fmt the printf style format string
1638
+ */
1639
+ static void nasm_verror_gnu(int severity, const char *fmt, va_list ap)
1640
+ {
1641
+ const char *currentfile = NULL;
1642
+ int32_t lineno = 0;
1643
+
1644
+ if (is_suppressed_warning(severity))
1645
+ return;
1646
+
1647
+ if (!(severity & ERR_NOFILE))
1648
+ src_get(&lineno, &currentfile);
1649
+
1650
+ if (!skip_this_pass(severity)) {
1651
+ if (currentfile) {
1652
+ fprintf(error_file, "%s:%"PRId32": ", currentfile, lineno);
1653
+ } else {
1654
+ fputs("nasm: ", error_file);
1655
+ }
1656
+ }
1657
+
1658
+ nasm_verror_common(severity, fmt, ap);
1659
+ }
1660
+
1661
+ /**
1662
+ * MS style error reporting
1663
+ * This function prints an error message to error_file in the
1664
+ * style used by Visual C and some other Microsoft tools. An example
1665
+ * would be:
1666
+ * file.asm(50) : error: blah blah blah
1667
+ * where file.asm is the name of the file, 50 is the line number on
1668
+ * which the error occurs (or is detected) and "error:" is one of
1669
+ * the possible optional diagnostics -- it can be "error" or "warning"
1670
+ * or something else. Finally the line terminates with the actual
1671
+ * error message.
1672
+ *
1673
+ * @param severity the severity of the warning or error
1674
+ * @param fmt the printf style format string
1675
+ */
1676
+ static void nasm_verror_vc(int severity, const char *fmt, va_list ap)
1677
+ {
1678
+ const char *currentfile = NULL;
1679
+ int32_t lineno = 0;
1680
+
1681
+ if (is_suppressed_warning(severity))
1682
+ return;
1683
+
1684
+ if (!(severity & ERR_NOFILE))
1685
+ src_get(&lineno, &currentfile);
1686
+
1687
+ if (!skip_this_pass(severity)) {
1688
+ if (currentfile) {
1689
+ fprintf(error_file, "%s(%"PRId32") : ", currentfile, lineno);
1690
+ } else {
1691
+ fputs("nasm: ", error_file);
1692
+ }
1693
+ }
1694
+
1695
+ nasm_verror_common(severity, fmt, ap);
1696
+ }
1697
+
1698
+ /*
1699
+ * check to see if this is a suppressable warning
1700
+ */
1701
+ static inline bool is_valid_warning(int severity)
1702
+ {
1703
+ /* Not a warning at all */
1704
+ if ((severity & ERR_MASK) != ERR_WARNING)
1705
+ return false;
1706
+
1707
+ return WARN_IDX(severity) < ERR_WARN_ALL;
1708
+ }
1709
+
1710
+ /**
1711
+ * check for suppressed warning
1712
+ * checks for suppressed warning or pass one only warning and we're
1713
+ * not in pass 1
1714
+ *
1715
+ * @param severity the severity of the warning or error
1716
+ * @return true if we should abort error/warning printing
1717
+ */
1718
+ static bool is_suppressed_warning(int severity)
1719
+ {
1720
+ /* Might be a warning but suppresed explicitly */
1721
+ if (is_valid_warning(severity))
1722
+ return !(warning_state[WARN_IDX(severity)] & WARN_ST_ENABLED);
1723
+ else
1724
+ return false;
1725
+ }
1726
+
1727
+ static bool warning_is_error(int severity)
1728
+ {
1729
+ if (is_valid_warning(severity))
1730
+ return !!(warning_state[WARN_IDX(severity)] & WARN_ST_ERROR);
1731
+ else
1732
+ return false;
1733
+ }
1734
+
1735
+ static bool skip_this_pass(int severity)
1736
+ {
1737
+ /*
1738
+ * See if it's a pass-specific error or warning which should be skipped.
1739
+ * We cannot skip errors stronger than ERR_NONFATAL as by definition
1740
+ * they cannot be resumed from.
1741
+ */
1742
+ if ((severity & ERR_MASK) > ERR_NONFATAL)
1743
+ return false;
1744
+
1745
+ /*
1746
+ * passn is 1 on the very first pass only.
1747
+ * pass0 is 2 on the code-generation (final) pass only.
1748
+ * These are the passes we care about in this case.
1749
+ */
1750
+ return (((severity & ERR_PASS1) && passn != 1) ||
1751
+ ((severity & ERR_PASS2) && pass0 != 2));
1752
+ }
1753
+
1754
+ /**
1755
+ * common error reporting
1756
+ * This is the common back end of the error reporting schemes currently
1757
+ * implemented. It prints the nature of the warning and then the
1758
+ * specific error message to error_file and may or may not return. It
1759
+ * doesn't return if the error severity is a "panic" or "debug" type.
1760
+ *
1761
+ * @param severity the severity of the warning or error
1762
+ * @param fmt the printf style format string
1763
+ */
1764
+ static void nasm_verror_common(int severity, const char *fmt, va_list args)
1765
+ {
1766
+ char msg[1024];
1767
+ const char *pfx;
1768
+
1769
+ switch (severity & (ERR_MASK|ERR_NO_SEVERITY)) {
1770
+ case ERR_WARNING:
1771
+ pfx = "warning: ";
1772
+ break;
1773
+ case ERR_NONFATAL:
1774
+ pfx = "error: ";
1775
+ break;
1776
+ case ERR_FATAL:
1777
+ pfx = "fatal: ";
1778
+ break;
1779
+ case ERR_PANIC:
1780
+ pfx = "panic: ";
1781
+ break;
1782
+ case ERR_DEBUG:
1783
+ pfx = "debug: ";
1784
+ break;
1785
+ default:
1786
+ pfx = "";
1787
+ break;
1788
+ }
1789
+
1790
+ vsnprintf(msg, sizeof msg - 64, fmt, args);
1791
+ if (is_valid_warning(severity) && WARN_IDX(severity) != ERR_WARN_OTHER) {
1792
+ char *p = strchr(msg, '\0');
1793
+ snprintf(p, 64, " [-w+%s]", warnings[WARN_IDX(severity)].name);
1794
+ }
1795
+
1796
+ if (!skip_this_pass(severity))
1797
+ fprintf(error_file, "%s%s\n", pfx, msg);
1798
+
1799
+ /* Are we recursing from error_list_macros? */
1800
+ if (severity & ERR_PP_LISTMACRO)
1801
+ return;
1802
+
1803
+ /*
1804
+ * Don't suppress this with skip_this_pass(), or we don't get
1805
+ * pass1 or preprocessor warnings in the list file
1806
+ */
1807
+ lfmt->error(severity, pfx, msg);
1808
+
1809
+ if (skip_this_pass(severity))
1810
+ return;
1811
+
1812
+ if (severity & ERR_USAGE)
1813
+ want_usage = true;
1814
+
1815
+ preproc->error_list_macros(severity);
1816
+
1817
+ switch (severity & ERR_MASK) {
1818
+ case ERR_DEBUG:
1819
+ /* no further action, by definition */
1820
+ break;
1821
+ case ERR_WARNING:
1822
+ /* Treat warnings as errors */
1823
+ if (warning_is_error(severity))
1824
+ terminate_after_phase = true;
1825
+ break;
1826
+ case ERR_NONFATAL:
1827
+ terminate_after_phase = true;
1828
+ break;
1829
+ case ERR_FATAL:
1830
+ if (ofile) {
1831
+ fclose(ofile);
1832
+ remove(outname);
1833
+ ofile = NULL;
1834
+ }
1835
+ if (want_usage)
1836
+ usage();
1837
+ exit(1); /* instantly die */
1838
+ break; /* placate silly compilers */
1839
+ case ERR_PANIC:
1840
+ fflush(NULL);
1841
+ /* abort(); */ /* halt, catch fire, and dump core */
1842
+ if (ofile) {
1843
+ fclose(ofile);
1844
+ remove(outname);
1845
+ ofile = NULL;
1846
+ }
1847
+ exit(3);
1848
+ break;
1849
+ }
1850
+ }
1851
+
1852
+ static void usage(void)
1853
+ {
1854
+ fputs("type `nasm -h' for help\n", error_file);
1855
+ }