genflags.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 "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. 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. return;
  38. printf ("#define HAVE_%s %s\n", XSTR (insn, 0),
  39. strlen (XSTR (insn, 2)) ? XSTR (insn, 2) : "1");
  40. printf ("extern rtx gen_%s ();\n", XSTR (insn, 0));
  41. }
  42. int
  43. xmalloc (size)
  44. {
  45. register int val = malloc (size);
  46. if (val == 0)
  47. fatal ("virtual memory exhausted");
  48. return val;
  49. }
  50. int
  51. xrealloc (ptr, size)
  52. char *ptr;
  53. int size;
  54. {
  55. int result = realloc (ptr, size);
  56. if (!result)
  57. fatal ("virtual memory exhausted");
  58. return result;
  59. }
  60. void
  61. fatal (s, a1, a2)
  62. {
  63. fprintf (stderr, "genflags: ");
  64. fprintf (stderr, s, a1, a2);
  65. fprintf (stderr, "\n");
  66. exit (FATAL_EXIT_CODE);
  67. }
  68. int
  69. main (argc, argv)
  70. int argc;
  71. char **argv;
  72. {
  73. rtx desc;
  74. FILE *infile;
  75. extern rtx read_rtx ();
  76. register int c;
  77. obstack_init (rtl_obstack);
  78. if (argc <= 1)
  79. fatal ("No input file name.");
  80. infile = fopen (argv[1], "r");
  81. if (infile == 0)
  82. {
  83. perror (argv[1]);
  84. exit (FATAL_EXIT_CODE);
  85. }
  86. init_rtl ();
  87. printf ("/* Generated automatically by the program `genflags'\n\
  88. from the machine description file `md'. */\n\n");
  89. /* Read the machine description. */
  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. if (GET_CODE (desc) == DEFINE_INSN || GET_CODE (desc) == DEFINE_EXPAND)
  98. gen_insn (desc);
  99. }
  100. fflush (stdout);
  101. exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
  102. }