genconfig.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* Generate from machine description:
  2. - some #define configuration flags.
  3. Copyright (C) 1987 Free Software Foundation, Inc.
  4. This file is part of GNU CC.
  5. GNU CC is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY. No author or distributor
  7. accepts responsibility to anyone for the consequences of using it
  8. or for whether it serves any particular purpose or works at all,
  9. unless he says so in writing. Refer to the GNU CC General Public
  10. License for full details.
  11. Everyone is granted permission to copy, modify and redistribute
  12. GNU CC, but only under the conditions described in the
  13. GNU CC General Public License. A copy of this license is
  14. supposed to have been given to you along with GNU CC so you
  15. can know your rights and responsibilities. It should be in a
  16. file named COPYING. Among other things, the copyright notice
  17. and this notice must be preserved on all copies. */
  18. #include <stdio.h>
  19. #include "config.h"
  20. #include "rtl.h"
  21. #include "obstack.h"
  22. struct obstack obstack;
  23. struct obstack *rtl_obstack = &obstack;
  24. #define obstack_chunk_alloc xmalloc
  25. #define obstack_chunk_free free
  26. extern int xmalloc ();
  27. extern void free ();
  28. /* flags to determine output of machine description dependent #define's. */
  29. int max_recog_operands_flag;
  30. int max_dup_operands_flag;
  31. int max_sets_per_insn_flag;
  32. int max_clobbers_per_insn_flag;
  33. int register_constraint_flag;
  34. int sets_seen_this_insn;
  35. int clobbers_seen_this_insn;
  36. int dup_operands_seen_this_insn;
  37. void fatal ();
  38. void
  39. walk_insn_part (part)
  40. rtx part;
  41. {
  42. register int i, j;
  43. register RTX_CODE code;
  44. register char *format_ptr;
  45. if (part == 0)
  46. return;
  47. code = GET_CODE (part);
  48. switch (code)
  49. {
  50. case SET:
  51. sets_seen_this_insn++;
  52. break;
  53. case CLOBBER:
  54. clobbers_seen_this_insn++;
  55. break;
  56. case MATCH_OPERAND:
  57. if (XINT (part, 0) > max_recog_operands_flag)
  58. max_recog_operands_flag = XINT (part, 0);
  59. if (XSTR (part, 2) && *XSTR (part, 2))
  60. register_constraint_flag = 1;
  61. return;
  62. case LABEL_REF:
  63. if (GET_CODE (XEXP (part, 0)) == MATCH_OPERAND)
  64. break;
  65. return;
  66. case MATCH_DUP:
  67. ++dup_operands_seen_this_insn;
  68. if (XINT (part, 0) > max_recog_operands_flag)
  69. max_recog_operands_flag = XINT (part, 0);
  70. case REG: case CONST_INT: case SYMBOL_REF:
  71. case PC: case CC0:
  72. return;
  73. }
  74. format_ptr = GET_RTX_FORMAT (GET_CODE (part));
  75. for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
  76. switch (*format_ptr++)
  77. {
  78. case 'e':
  79. case 'u':
  80. walk_insn_part (XEXP (part, i));
  81. break;
  82. case 'E':
  83. if (XVEC (part, i) != NULL)
  84. for (j = 0; j < XVECLEN (part, i); j++)
  85. walk_insn_part (XVECEXP (part, i, j));
  86. break;
  87. }
  88. }
  89. void
  90. gen_insn (insn)
  91. rtx insn;
  92. {
  93. int i;
  94. /* Walk the insn pattern to gather the #define's status. */
  95. sets_seen_this_insn = 0;
  96. clobbers_seen_this_insn = 0;
  97. dup_operands_seen_this_insn = 0;
  98. if (XVEC (insn, 1) != 0)
  99. for (i = 0; i < XVECLEN (insn, 1); i++)
  100. walk_insn_part (XVECEXP (insn, 1, i));
  101. if (sets_seen_this_insn > max_sets_per_insn_flag)
  102. max_sets_per_insn_flag = sets_seen_this_insn;
  103. if (clobbers_seen_this_insn > max_clobbers_per_insn_flag)
  104. max_clobbers_per_insn_flag = clobbers_seen_this_insn;
  105. if (dup_operands_seen_this_insn > max_dup_operands_flag)
  106. max_dup_operands_flag = dup_operands_seen_this_insn;
  107. }
  108. /* Similar but scan a define_expand. */
  109. void
  110. gen_expand (insn)
  111. rtx insn;
  112. {
  113. int i;
  114. /* Walk the insn pattern to gather the #define's status. */
  115. /* Note that we don't bother recording the number of MATCH_DUPs
  116. that occur in a gen_expand, because only reload cares about that. */
  117. if (XVEC (insn, 1) != 0)
  118. for (i = 0; i < XVECLEN (insn, 1); i++)
  119. {
  120. /* Compute the maximum SETs and CLOBBERS
  121. in any one of the sub-insns;
  122. don't sum across all of them. */
  123. sets_seen_this_insn = 0;
  124. clobbers_seen_this_insn = 0;
  125. walk_insn_part (XVECEXP (insn, 1, i));
  126. if (sets_seen_this_insn > max_sets_per_insn_flag)
  127. max_sets_per_insn_flag = sets_seen_this_insn;
  128. if (clobbers_seen_this_insn > max_clobbers_per_insn_flag)
  129. max_clobbers_per_insn_flag = clobbers_seen_this_insn;
  130. }
  131. }
  132. void
  133. gen_peephole (peep)
  134. rtx peep;
  135. {
  136. int i;
  137. /* Look through the patterns that are matched
  138. to compute the maximum operand number. */
  139. for (i = 0; i < XVECLEN (peep, 0); i++)
  140. walk_insn_part (XVECEXP (peep, 0, i));
  141. }
  142. int
  143. xmalloc (size)
  144. {
  145. register int val = malloc (size);
  146. if (val == 0)
  147. fatal ("virtual memory exhausted");
  148. return val;
  149. }
  150. int
  151. xrealloc (ptr, size)
  152. char *ptr;
  153. int size;
  154. {
  155. int result = realloc (ptr, size);
  156. if (!result)
  157. fatal ("virtual memory exhausted");
  158. return result;
  159. }
  160. void
  161. fatal (s, a1, a2)
  162. {
  163. fprintf (stderr, "genconfig: ");
  164. fprintf (stderr, s, a1, a2);
  165. fprintf (stderr, "\n");
  166. exit (FATAL_EXIT_CODE);
  167. }
  168. int
  169. main (argc, argv)
  170. int argc;
  171. char **argv;
  172. {
  173. rtx desc;
  174. FILE *infile;
  175. extern rtx read_rtx ();
  176. register int c;
  177. obstack_init (rtl_obstack);
  178. if (argc <= 1)
  179. fatal ("No input file name.");
  180. infile = fopen (argv[1], "r");
  181. if (infile == 0)
  182. {
  183. perror (argv[1]);
  184. exit (FATAL_EXIT_CODE);
  185. }
  186. init_rtl ();
  187. printf ("/* Generated automatically by the program `genconfig'\n\
  188. from the machine description file `md'. */\n\n");
  189. /* Read the machine description. */
  190. while (1)
  191. {
  192. c = read_skip_spaces (infile);
  193. if (c == EOF)
  194. break;
  195. ungetc (c, infile);
  196. desc = read_rtx (infile);
  197. if (GET_CODE (desc) == DEFINE_INSN)
  198. gen_insn (desc);
  199. if (GET_CODE (desc) == DEFINE_EXPAND)
  200. gen_expand (desc);
  201. if (GET_CODE (desc) == DEFINE_PEEPHOLE)
  202. gen_peephole (desc);
  203. }
  204. printf ("\n#define MAX_RECOG_OPERANDS %d\n", max_recog_operands_flag + 1);
  205. if (max_dup_operands_flag == 0)
  206. max_dup_operands_flag = 1;
  207. printf ("\n#define MAX_DUP_OPERANDS %d\n", max_dup_operands_flag);
  208. printf ("#define MAX_SETS_PER_INSN %d\n", max_sets_per_insn_flag);
  209. printf ("#define MAX_CLOBBERS_PER_INSN %d\n", max_clobbers_per_insn_flag);
  210. if (register_constraint_flag)
  211. printf ("#define REGISTER_CONSTRAINTS\n");
  212. fflush (stdout);
  213. exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
  214. }