gencodes.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 "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. void fatal ();
  29. int insn_code_number;
  30. void
  31. gen_insn (insn)
  32. rtx insn;
  33. {
  34. /* Don't mention instructions whose names are the null string.
  35. They are in the machine description just to be recognized. */
  36. if (strlen (XSTR (insn, 0)) != 0)
  37. printf (" CODE_FOR_%s = %d,\n", XSTR (insn, 0),
  38. insn_code_number);
  39. insn_code_number++;
  40. }
  41. xmalloc (size)
  42. {
  43. register int val = malloc (size);
  44. if (val == 0)
  45. abort ();
  46. return val;
  47. }
  48. int
  49. xrealloc (ptr, size)
  50. char *ptr;
  51. int size;
  52. {
  53. int result = realloc (ptr, size);
  54. if (!result)
  55. abort ();
  56. return result;
  57. }
  58. void
  59. fatal (s, a1, a2)
  60. {
  61. fprintf (stderr, "genflags: ");
  62. fprintf (stderr, s, a1, a2);
  63. fprintf (stderr, "\n");
  64. exit (1);
  65. }
  66. main (argc, argv)
  67. int argc;
  68. char **argv;
  69. {
  70. rtx desc;
  71. FILE *infile;
  72. extern rtx read_rtx ();
  73. register int c;
  74. obstack_begin (current_obstack, 4060);
  75. if (argc <= 1)
  76. fatal ("No input file name.");
  77. infile = fopen (argv[1], "r");
  78. if (infile == 0)
  79. {
  80. perror (argv[1]);
  81. exit (1);
  82. }
  83. init_rtl ();
  84. printf ("/* Generated automatically by the program `gencodes'\n\
  85. from the machine description file `md'. */\n\n");
  86. printf ("#ifndef MAX_INSN_CODE\n\n");
  87. /* Read the machine description. */
  88. insn_code_number = 0;
  89. printf ("enum insn_code {\n");
  90. while (1)
  91. {
  92. c = read_skip_spaces (infile);
  93. if (c == EOF)
  94. break;
  95. ungetc (c, infile);
  96. desc = read_rtx (infile);
  97. gen_insn (desc);
  98. }
  99. printf (" CODE_FOR_nothing };\n");
  100. printf ("\n#define MAX_INSN_CODE ((int) CODE_FOR_nothing)\n");
  101. printf ("#endif /* MAX_INSN_CODE */\n");
  102. return 0;
  103. }