gencodes.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* Generate from machine description:
  2. - some macros CODE_FOR_... giving the insn_code_number value
  3. for each of the defined standard insn names.
  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 "config.h"
  21. #include "rtl.h"
  22. #include "obstack.h"
  23. struct obstack obstack;
  24. struct obstack *rtl_obstack = &obstack;
  25. #define obstack_chunk_alloc xmalloc
  26. #define obstack_chunk_free free
  27. extern int xmalloc ();
  28. extern void free ();
  29. void fatal ();
  30. int insn_code_number;
  31. void
  32. gen_insn (insn)
  33. rtx insn;
  34. {
  35. /* Don't mention instructions whose names are the null string.
  36. They are in the machine description just to be recognized. */
  37. if (strlen (XSTR (insn, 0)) != 0)
  38. printf (" CODE_FOR_%s = %d,\n", XSTR (insn, 0),
  39. insn_code_number);
  40. }
  41. int
  42. xmalloc (size)
  43. {
  44. register int val = malloc (size);
  45. if (val == 0)
  46. fatal ("virtual memory exhausted");
  47. return val;
  48. }
  49. int
  50. xrealloc (ptr, size)
  51. char *ptr;
  52. int size;
  53. {
  54. int result = realloc (ptr, size);
  55. if (!result)
  56. fatal ("virtual memory exhausted");
  57. return result;
  58. }
  59. void
  60. fatal (s, a1, a2)
  61. {
  62. fprintf (stderr, "gencodes: ");
  63. fprintf (stderr, s, a1, a2);
  64. fprintf (stderr, "\n");
  65. exit (FATAL_EXIT_CODE);
  66. }
  67. int
  68. main (argc, argv)
  69. int argc;
  70. char **argv;
  71. {
  72. rtx desc;
  73. FILE *infile;
  74. extern rtx read_rtx ();
  75. register int c;
  76. obstack_init (rtl_obstack);
  77. if (argc <= 1)
  78. fatal ("No input file name.");
  79. infile = fopen (argv[1], "r");
  80. if (infile == 0)
  81. {
  82. perror (argv[1]);
  83. exit (FATAL_EXIT_CODE);
  84. }
  85. init_rtl ();
  86. printf ("/* Generated automatically by the program `gencodes'\n\
  87. from the machine description file `md'. */\n\n");
  88. printf ("#ifndef MAX_INSN_CODE\n\n");
  89. /* Read the machine description. */
  90. insn_code_number = 0;
  91. printf ("enum insn_code {\n");
  92. while (1)
  93. {
  94. c = read_skip_spaces (infile);
  95. if (c == EOF)
  96. break;
  97. ungetc (c, infile);
  98. desc = read_rtx (infile);
  99. if (GET_CODE (desc) == DEFINE_INSN || GET_CODE (desc) == DEFINE_EXPAND)
  100. {
  101. gen_insn (desc);
  102. insn_code_number++;
  103. }
  104. if (GET_CODE (desc) == DEFINE_PEEPHOLE)
  105. {
  106. insn_code_number++;
  107. }
  108. }
  109. printf (" CODE_FOR_nothing };\n");
  110. printf ("\n#define MAX_INSN_CODE ((int) CODE_FOR_nothing)\n");
  111. printf ("#endif /* MAX_INSN_CODE */\n");
  112. fflush (stdout);
  113. exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
  114. }