options.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Header$ */
  6. /* U S E R O P T I O N - H A N D L I N G */
  7. #include "botch_free.h"
  8. #include <alloc.h>
  9. #include "nofloat.h"
  10. #include "nopp.h"
  11. #include "idfsize.h"
  12. #include "maxincl.h"
  13. #include "nobitfield.h"
  14. #include "class.h"
  15. #include "macro.h"
  16. #include "idf.h"
  17. #include "arith.h"
  18. #include "sizes.h"
  19. #include "align.h"
  20. #include "use_tmp.h"
  21. #include "dataflow.h"
  22. #include "noRoption.h"
  23. #ifndef NOPP
  24. extern char *inctable[MAXINCL];
  25. extern int inc_pos;
  26. #endif NOPP
  27. extern char options[];
  28. extern int idfsize;
  29. #ifdef USE_TMP
  30. extern char *tmpfdir; /* main.c */
  31. #endif USE_TMP
  32. int txt2int();
  33. do_option(text)
  34. char *text;
  35. {
  36. switch(*text++) {
  37. default:
  38. fatal("illegal option: %c", *--text);
  39. case '-':
  40. options[*text] = 1; /* flags, debug options etc. */
  41. break;
  42. #ifdef DATAFLOW
  43. case 'd':
  44. #endif DATAFLOW
  45. case 'p': /* procentry/procexit */
  46. case 'L' : /* no fil/lin */
  47. case 'n': /* use no registers */
  48. case 'w': /* no warnings will be given */
  49. #ifndef NOROPTION
  50. case 'R': /* strict version */
  51. #endif
  52. options[*(text-1)] = 1;
  53. break;
  54. #ifdef NOROPTION
  55. case 'R':
  56. warning("-R option not implemented");
  57. break;
  58. #endif
  59. #ifdef ___XXX___
  60. deleted, is now a debug-flag
  61. case 'C' : /* E option + comment output */
  62. #ifndef NOPP
  63. options['E'] = 1;
  64. warning("-C: comment is not output");
  65. #else NOPP
  66. warning("-C option ignored");
  67. #endif NOPP
  68. break;
  69. #endif ___XXX___
  70. case 'D' : { /* -Dname : predefine name */
  71. #ifndef NOPP
  72. register char *cp = text, *name, *mactext;
  73. if (class(*cp) != STIDF) {
  74. error("identifier missing in -D%s", text);
  75. break;
  76. }
  77. name = cp;
  78. while (*cp && in_idf(*cp)) {
  79. ++cp;
  80. }
  81. if (!*cp) { /* -Dname */
  82. mactext = "1";
  83. }
  84. else
  85. if (*cp == '=') { /* -Dname=text */
  86. *cp++ = '\0'; /* end of name */
  87. mactext = cp;
  88. }
  89. else { /* -Dname?? */
  90. error("malformed option -D%s", text);
  91. break;
  92. }
  93. macro_def(str2idf(name), mactext, -1, strlen(mactext),
  94. NOFLAG);
  95. #else NOPP
  96. warning("-D option ignored");
  97. #endif NOPP
  98. break;
  99. }
  100. #ifdef ___XXX___
  101. case 'E' : /* run preprocessor only, with #<int> */
  102. #ifndef NOPP
  103. options['E'] = 1;
  104. #else NOPP
  105. warning("-E option ignored");
  106. #endif NOPP
  107. break;
  108. #endif ___XXX___
  109. case 'I' : /* -Ipath : insert "path" into include list */
  110. #ifndef NOPP
  111. if (*text) {
  112. int i = inc_pos++;
  113. register char *new = text;
  114. while (new) {
  115. char *tmp = inctable[i];
  116. inctable[i++] = new;
  117. if (i == MAXINCL)
  118. fatal("too many -I options");
  119. new = tmp;
  120. }
  121. }
  122. else inctable[inc_pos] = 0;
  123. #else NOPP
  124. warning("-I option ignored");
  125. #endif NOPP
  126. break;
  127. case 'M': /* maximum identifier length */
  128. idfsize = txt2int(&text);
  129. if (*text || idfsize <= 0)
  130. fatal("malformed -M option");
  131. if (idfsize > IDFSIZE)
  132. fatal("maximum identifier length is %d", IDFSIZE);
  133. break;
  134. case 'N' :
  135. #ifdef USE_TMP
  136. options['N'] = 1;
  137. #else USE_TMP
  138. warning("-N option ignored");
  139. #endif USE_TMP
  140. break;
  141. #ifdef ___XXX___
  142. case 'P' : /* run preprocessor stand-alone, without #'s */
  143. #ifndef NOPP
  144. options['E'] = 1;
  145. options['P'] = 1;
  146. #else NOPP
  147. warning("-P option ignored");
  148. #endif NOPP
  149. break;
  150. #endif ___XXX___
  151. #ifdef USE_TMP
  152. case 'T' :
  153. if (*text)
  154. tmpfdir = text;
  155. else
  156. tmpfdir = ".";
  157. #else USE_TMP
  158. warning("-T option ignored");
  159. #endif USE_TMP
  160. break;
  161. case 'U' : { /* -Uname : undefine predefined */
  162. #ifndef NOPP
  163. register struct idf *idef;
  164. if (*text) {
  165. if ((idef = str2idf(text))->id_macro) {
  166. free_macro(idef->id_macro);
  167. idef->id_macro = (struct macro *) 0;
  168. }
  169. }
  170. #else NOPP
  171. warning("-U option ignored");
  172. #endif NOPP
  173. break;
  174. }
  175. case 'V' : /* set object sizes and alignment requirements */
  176. #ifdef NOCROSS
  177. warning("-V option ignored");
  178. break;
  179. #else NOCROSS
  180. {
  181. register arith size, align;
  182. char c;
  183. while (c = *text++) {
  184. size = txt2int(&text);
  185. align = 0;
  186. if (*text == '.') {
  187. text++;
  188. align = txt2int(&text);
  189. }
  190. switch (c) {
  191. case 's': /* short */
  192. if (size != (arith)0)
  193. short_size = size;
  194. if (align != 0)
  195. short_align = align;
  196. break;
  197. case 'w': /* word */
  198. if (size != (arith)0)
  199. dword_size = (word_size = size) << 1;
  200. if (align != 0)
  201. word_align = align;
  202. break;
  203. case 'i': /* int */
  204. if (size != (arith)0)
  205. int_size = size;
  206. if (align != 0)
  207. int_align = align;
  208. break;
  209. case 'l': /* long */
  210. if (size != (arith)0)
  211. long_size = size;
  212. if (align != 0)
  213. long_align = align;
  214. break;
  215. case 'f': /* float */
  216. #ifndef NOFLOAT
  217. if (size != (arith)0)
  218. float_size = size;
  219. if (align != 0)
  220. float_align = align;
  221. #endif NOFLOAT
  222. break;
  223. case 'd': /* double */
  224. #ifndef NOFLOAT
  225. if (size != (arith)0)
  226. double_size = size;
  227. if (align != 0)
  228. double_align = align;
  229. #endif NOFLOAT
  230. break;
  231. case 'p': /* pointer */
  232. if (size != (arith)0)
  233. pointer_size = size;
  234. if (align != 0)
  235. pointer_align = align;
  236. break;
  237. case 'r': /* adjust bitfields right */
  238. #ifndef NOBITFIELD
  239. options['r'] = 1;
  240. #else NOBITFIELD
  241. warning("bitfields are not implemented");
  242. #endif NOBITFIELD
  243. break;
  244. case 'S': /* initial struct alignment */
  245. if (size != (arith)0)
  246. struct_align = size;
  247. break;
  248. case 'U': /* initial union alignment */
  249. if (size != (arith)0)
  250. union_align = size;
  251. break;
  252. default:
  253. error("-V: bad type indicator %c\n", c);
  254. }
  255. }
  256. break;
  257. }
  258. #endif NOCROSS
  259. }
  260. }
  261. int
  262. txt2int(tp)
  263. register char **tp;
  264. {
  265. /* the integer pointed to by *tp is read, while increasing
  266. *tp; the resulting value is yielded.
  267. */
  268. register int val = 0, ch;
  269. while (ch = **tp, ch >= '0' && ch <= '9') {
  270. val = val * 10 + ch - '0';
  271. (*tp)++;
  272. }
  273. return val;
  274. }