options.c 5.1 KB

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