genflags.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* Generate from machine description:
  2. - some flags HAVE_... saying which simple standard instructions are
  3. available for this machine.
  4. Copyright (C) 1987 Free Software Foundation, Inc.
  5. This file is part of GNU CC.
  6. GNU CC is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY. No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing. Refer to the GNU CC General Public
  11. License for full details.
  12. Everyone is granted permission to copy, modify and redistribute
  13. GNU CC, but only under the conditions described in the
  14. GNU CC General Public License. A copy of this license is
  15. supposed to have been given to you along with GNU CC so you
  16. can know your rights and responsibilities. It should be in a
  17. file named COPYING. Among other things, the copyright notice
  18. and this notice must be preserved on all copies. */
  19. #include <stdio.h>
  20. #include "rtl.h"
  21. #include <obstack.h>
  22. struct obstack obstack;
  23. struct obstack *current_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 register_constraint_flag;
  33. int sets_seen_this_insn;
  34. int dup_operands_seen_this_insn;
  35. void fatal ();
  36. void
  37. walk_insn_part (part)
  38. rtx part;
  39. {
  40. register int i, j;
  41. register RTX_CODE code = GET_CODE (part);
  42. register char *format_ptr;
  43. switch (code)
  44. {
  45. case SET:
  46. sets_seen_this_insn++;
  47. break;
  48. case MATCH_OPERAND:
  49. if (XINT (part, 0) > max_recog_operands_flag)
  50. max_recog_operands_flag = XINT (part, 0);
  51. if (XSTR (part, 2) && *XSTR (part, 2))
  52. register_constraint_flag = 1;
  53. return;
  54. case MATCH_DUP:
  55. ++dup_operands_seen_this_insn;
  56. case REG: case CONST_INT: case SYMBOL_REF:
  57. case LABEL_REF: case PC: case CC0:
  58. return;
  59. }
  60. format_ptr = GET_RTX_FORMAT (GET_CODE (part));
  61. for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
  62. switch (*format_ptr++)
  63. {
  64. case 'e':
  65. walk_insn_part (XEXP (part, i));
  66. break;
  67. case 'E':
  68. if (XVEC (part, i) != NULL)
  69. for (j = 0; j < XVECLEN (part, i); j++)
  70. walk_insn_part (XVECEXP (part, i, j));
  71. break;
  72. }
  73. }
  74. void
  75. gen_insn (insn)
  76. rtx insn;
  77. {
  78. int i;
  79. /* Walk the insn pattern to gather the #define's status. */
  80. sets_seen_this_insn = 0;
  81. dup_operands_seen_this_insn = 0;
  82. for (i = 0; i < XVECLEN (insn, 1); i++) {
  83. walk_insn_part (XVECEXP (insn, 1, i));
  84. }
  85. if (sets_seen_this_insn > max_sets_per_insn_flag)
  86. max_sets_per_insn_flag = sets_seen_this_insn;
  87. if (dup_operands_seen_this_insn > max_dup_operands_flag)
  88. max_dup_operands_flag = dup_operands_seen_this_insn;
  89. /* Don't mention instructions whose names are the null string.
  90. They are in the machine description just to be recognized. */
  91. if (strlen (XSTR (insn, 0)) == 0)
  92. return;
  93. printf ("#define HAVE_%s %s\n", XSTR (insn, 0),
  94. strlen (XSTR (insn, 2)) ? XSTR (insn, 2) : "1");
  95. printf ("extern rtx gen_%s ();\n", XSTR (insn, 0));
  96. }
  97. xmalloc (size)
  98. {
  99. register int val = malloc (size);
  100. if (val == 0)
  101. abort ();
  102. return val;
  103. }
  104. int
  105. xrealloc (ptr, size)
  106. char *ptr;
  107. int size;
  108. {
  109. int result = realloc (ptr, size);
  110. if (!result)
  111. abort ();
  112. return result;
  113. }
  114. void
  115. fatal (s, a1, a2)
  116. {
  117. fprintf (stderr, "genflags: ");
  118. fprintf (stderr, s, a1, a2);
  119. fprintf (stderr, "\n");
  120. exit (1);
  121. }
  122. main (argc, argv)
  123. int argc;
  124. char **argv;
  125. {
  126. rtx desc;
  127. FILE *infile;
  128. extern rtx read_rtx ();
  129. register int c;
  130. obstack_begin (current_obstack, 4060);
  131. if (argc <= 1)
  132. fatal ("No input file name.");
  133. infile = fopen (argv[1], "r");
  134. if (infile == 0)
  135. {
  136. perror (argv[1]);
  137. exit (1);
  138. }
  139. init_rtl ();
  140. printf ("/* Generated automatically by the program `genflags'\n\
  141. from the machine description file `md'. */\n\n");
  142. /* Read the machine description. */
  143. while (1)
  144. {
  145. c = read_skip_spaces (infile);
  146. if (c == EOF)
  147. break;
  148. ungetc (c, infile);
  149. desc = read_rtx (infile);
  150. gen_insn (desc);
  151. }
  152. return 0;
  153. }