home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / rtl.c < prev    next >
C/C++ Source or Header  |  1991-06-03  |  25KB  |  1,020 lines

  1. /* Allocate, read and print RTL for C-Compiler
  2.    Copyright (C) 1987-1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include "config.h"
  22. #include <ctype.h>
  23. #include <stdio.h>
  24. #include "rtl.h"
  25.  
  26. #include "obstack.h"
  27. #define    obstack_chunk_alloc    xmalloc
  28. #define    obstack_chunk_free    free
  29. extern int xmalloc ();
  30. extern void free ();
  31.  
  32. /* Obstack used for allocating RTL objects.
  33.    Between functions, this is the permanent_obstack.
  34.    While parsing and expanding a function, this is maybepermanent_obstack
  35.    so we can save it if it is an inline function.
  36.    During optimization and output, this is function_obstack.  */
  37.  
  38. extern struct obstack *rtl_obstack;
  39.  
  40. #define MIN(x,y) ((x < y) ? x : y)
  41.  
  42. extern long ftell();
  43.  
  44. /* Indexed by rtx code, gives number of operands for an rtx with that code.
  45.    Does NOT include rtx header data (code and links).
  46.    This array is initialized in init_rtl.  */
  47.  
  48. int rtx_length[NUM_RTX_CODE + 1];
  49.  
  50. /* Indexed by rtx code, gives the name of that kind of rtx, as a C string.  */
  51.  
  52. #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS)   NAME ,
  53.  
  54. char *rtx_name[] = {
  55. #include "rtl.def"        /* rtl expressions are documented here */
  56. };
  57.  
  58. #undef DEF_RTL_EXPR
  59.  
  60. /* Indexed by machine mode, gives the name of that machine mode.
  61.    This name does not include the letters "mode".  */
  62.  
  63. #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER)  NAME,
  64.  
  65. char *mode_name[(int) MAX_MACHINE_MODE] = {
  66. #include "machmode.def"
  67.  
  68. #ifdef EXTRA_CC_MODES
  69.   EXTRA_CC_NAMES
  70. #endif
  71.  
  72. };
  73.  
  74. #undef DEF_MACHMODE
  75.  
  76. /* Indexed by machine mode, gives the length of the mode, in bytes.
  77.    GET_MODE_CLASS uses this.  */
  78.  
  79. #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER)  CLASS,
  80.  
  81. enum mode_class mode_class[(int) MAX_MACHINE_MODE] = {
  82. #include "machmode.def"
  83. };
  84.  
  85. #undef DEF_MACHMODE
  86.  
  87. /* Indexed by machine mode, gives the length of the mode, in bytes.
  88.    GET_MODE_SIZE uses this.  */
  89.  
  90. #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER)  SIZE,
  91.  
  92. int mode_size[(int) MAX_MACHINE_MODE] = {
  93. #include "machmode.def"
  94. };
  95.  
  96. #undef DEF_MACHMODE
  97.  
  98. /* Indexed by machine mode, gives the length of the mode's subunit.
  99.    GET_MODE_UNIT_SIZE uses this.  */
  100.  
  101. #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER)  UNIT,
  102.  
  103. int mode_unit_size[(int) MAX_MACHINE_MODE] = {
  104. #include "machmode.def"        /* machine modes are documented here */
  105. };
  106.  
  107. #undef DEF_MACHMODE
  108.  
  109. /* Indexed by machine mode, gives next wider natural mode
  110.    (QI -> HI -> SI -> DI, etc.)  Widening multiply instructions
  111.    use this.  */
  112.  
  113. #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER)  \
  114.   (enum machine_mode) WIDER,
  115.  
  116. enum machine_mode mode_wider_mode[(int) MAX_MACHINE_MODE] = {
  117. #include "machmode.def"        /* machine modes are documented here */
  118. };
  119.  
  120. #undef DEF_MACHMODE
  121.  
  122. /* Indexed by rtx code, gives a sequence of operand-types for
  123.    rtx's of that code.  The sequence is a C string in which
  124.    each charcter describes one operand.  */
  125.  
  126. char *rtx_format[] = {
  127.   /* "*" undefined.
  128.          can cause a warning message
  129.      "0" field is unused (or used in a phase-dependent manner)
  130.          prints nothing
  131.      "i" an integer
  132.          prints the integer
  133.      "n" like "i", but prints entries from `note_insn_name'
  134.      "s" a pointer to a string
  135.          prints the string
  136.      "S" like "s", but optional:
  137.      the containing rtx may end before this operand
  138.      "e" a pointer to an rtl expression
  139.          prints the expression
  140.      "E" a pointer to a vector that points to a number of rtl expressions
  141.          prints a list of the rtl expressions
  142.      "V" like "E", but optional:
  143.      the containing rtx may end before this operand
  144.      "u" a pointer to another insn
  145.          prints the uid of the insn.  */
  146.  
  147. #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS)   FORMAT ,
  148. #include "rtl.def"        /* rtl expressions are defined here */
  149. #undef DEF_RTL_EXPR
  150. };
  151.  
  152. /* Indexed by rtx code, gives a character representing the "class" of
  153.    that rtx code.  See rtl.def for documentation on the defined classes.  */
  154.  
  155. char rtx_class[] = {
  156. #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS)   CLASS, 
  157. #include "rtl.def"        /* rtl expressions are defined here */
  158. #undef DEF_RTL_EXPR
  159. };
  160.  
  161. /* Names for kinds of NOTEs and REG_NOTEs.  */
  162.  
  163. char *note_insn_name[] = { "NOTE_INSN_FUNCTION_BEG", "NOTE_INSN_DELETED",
  164.                "NOTE_INSN_BLOCK_BEG", "NOTE_INSN_BLOCK_END",
  165.                "NOTE_INSN_LOOP_BEG", "NOTE_INSN_LOOP_END",
  166.                "NOTE_INSN_FUNCTION_END", "NOTE_INSN_SETJMP",
  167.                "NOTE_INSN_LOOP_CONT", "NOTE_INSN_LOOP_VTOP" };
  168.  
  169. char *reg_note_name[] = { "", "REG_DEAD", "REG_INC", "REG_EQUIV", "REG_WAS_0",
  170.               "REG_EQUAL", "REG_RETVAL", "REG_LIBCALL",
  171.               "REG_NONNEG", "REG_NO_CONFLICT", "REG_UNUSED",
  172.               "REG_CC_SETTER", "REG_CC_USER", "REG_LABEL" };
  173.  
  174. /* Names for patterns.  Non-zero only when linked with insn-output.c.  */
  175.  
  176. char **insn_name_ptr;
  177.  
  178. /* Allocate an rtx vector of N elements.
  179.    Store the length, and initialize all elements to zero.  */
  180.  
  181. rtvec
  182. rtvec_alloc (n)
  183.      int n;
  184. {
  185.   rtvec rt;
  186.   int i;
  187.  
  188.   rt = (rtvec) obstack_alloc (rtl_obstack,
  189.                   sizeof (struct rtvec_def)
  190.                   + (( n - 1) * sizeof (rtunion)));
  191.  
  192.   /* clear out the vector */
  193.   PUT_NUM_ELEM(rt, n);
  194.   for (i=0; i < n; i++)
  195.     rt->elem[i].rtvec = NULL;    /* @@ not portable due to rtunion */
  196.  
  197.   return rt;
  198. }
  199.  
  200. /* Allocate an rtx of code CODE.  The CODE is stored in the rtx;
  201.    all the rest is initialized to zero.  */
  202.  
  203. rtx
  204. rtx_alloc (code)
  205.   RTX_CODE code;
  206. {
  207.   rtx rt;
  208.   register struct obstack *ob = rtl_obstack;
  209.   register int nelts = GET_RTX_LENGTH (code);
  210.   register int length = sizeof (struct rtx_def)
  211.     + (nelts - 1) * sizeof (rtunion);
  212.  
  213.   /* This function is called more than any other in GCC,
  214.      so we manipulate the obstack directly.
  215.  
  216.      Even though rtx objects are word aligned, we may be sharing an obstack
  217.      with tree nodes, which may have to be double-word aligned.  So align
  218.      our length to the alignment mask in the obstack.  */
  219.  
  220.   length = (length + ob->alignment_mask) & ~ ob->alignment_mask;
  221.  
  222.   if (ob->chunk_limit - ob->next_free < length)
  223.     _obstack_newchunk (ob, length);
  224.   rt = (rtx)ob->object_base;
  225.   ob->next_free += length;
  226.   ob->object_base = ob->next_free;
  227.  
  228.   * (int *) rt = 0;
  229.   PUT_CODE (rt, code);
  230.  
  231.   return rt;
  232. }
  233.  
  234. /* Create a new copy of an rtx.
  235.    Recursively copies the operands of the rtx,
  236.    except for those few rtx codes that are sharable.  */
  237.  
  238. rtx
  239. copy_rtx (orig)
  240.      register rtx orig;
  241. {
  242.   register rtx copy;
  243.   register int i, j;
  244.   register RTX_CODE code;
  245.   register char *format_ptr;
  246.  
  247.   code = GET_CODE (orig);
  248.  
  249.   switch (code)
  250.     {
  251.     case REG:
  252.     case QUEUED:
  253.     case CONST_INT:
  254.     case CONST_DOUBLE:
  255.     case SYMBOL_REF:
  256.     case CODE_LABEL:
  257.     case PC:
  258.     case CC0:
  259.       return orig;
  260.     }
  261.  
  262.   copy = rtx_alloc (code);
  263.   PUT_MODE (copy, GET_MODE (orig));
  264.   copy->in_struct = orig->in_struct;
  265.   copy->volatil = orig->volatil;
  266.   copy->unchanging = orig->unchanging;
  267.   copy->integrated = orig->integrated;
  268.   
  269.   format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
  270.  
  271.   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
  272.     {
  273.       switch (*format_ptr++)
  274.     {
  275.     case 'e':
  276.       XEXP (copy, i) = XEXP (orig, i);
  277.       if (XEXP (orig, i) != NULL)
  278.         XEXP (copy, i) = copy_rtx (XEXP (orig, i));
  279.       break;
  280.  
  281.     case 'E':
  282.     case 'V':
  283.       XVEC (copy, i) = XVEC (orig, i);
  284.       if (XVEC (orig, i) != NULL)
  285.         {
  286.           XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
  287.           for (j = 0; j < XVECLEN (copy, i); j++)
  288.         XVECEXP (copy, i, j) = copy_rtx (XVECEXP (orig, i, j));
  289.         }
  290.       break;
  291.  
  292.     default:
  293.       XINT (copy, i) = XINT (orig, i);
  294.       break;
  295.     }
  296.     }
  297.   return copy;
  298. }
  299.  
  300. /* Similar to `copy_rtx' except that if MAY_SHARE is present, it is
  301.    placed in the result directly, rather than being copied.  */
  302.  
  303. rtx
  304. copy_most_rtx (orig, may_share)
  305.      register rtx orig;
  306.      register rtx may_share;
  307. {
  308.   register rtx copy;
  309.   register int i, j;
  310.   register RTX_CODE code;
  311.   register char *format_ptr;
  312.  
  313.   if (orig == may_share)
  314.     return orig;
  315.  
  316.   code = GET_CODE (orig);
  317.  
  318.   switch (code)
  319.     {
  320.     case REG:
  321.     case QUEUED:
  322.     case CONST_INT:
  323.     case CONST_DOUBLE:
  324.     case SYMBOL_REF:
  325.     case CODE_LABEL:
  326.     case PC:
  327.     case CC0:
  328.       return orig;
  329.     }
  330.  
  331.   copy = rtx_alloc (code);
  332.   PUT_MODE (copy, GET_MODE (orig));
  333.   copy->in_struct = orig->in_struct;
  334.   copy->volatil = orig->volatil;
  335.   copy->unchanging = orig->unchanging;
  336.   copy->integrated = orig->integrated;
  337.   
  338.   format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
  339.  
  340.   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
  341.     {
  342.       switch (*format_ptr++)
  343.     {
  344.     case 'e':
  345.       XEXP (copy, i) = XEXP (orig, i);
  346.       if (XEXP (orig, i) != NULL && XEXP (orig, i) != may_share)
  347.         XEXP (copy, i) = copy_most_rtx (XEXP (orig, i), may_share);
  348.       break;
  349.  
  350.     case 'E':
  351.     case 'V':
  352.       XVEC (copy, i) = XVEC (orig, i);
  353.       if (XVEC (orig, i) != NULL)
  354.         {
  355.           XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
  356.           for (j = 0; j < XVECLEN (copy, i); j++)
  357.         XVECEXP (copy, i, j)
  358.           = copy_most_rtx (XVECEXP (orig, i, j), may_share);
  359.         }
  360.       break;
  361.  
  362.     default:
  363.       XINT (copy, i) = XINT (orig, i);
  364.       break;
  365.     }
  366.     }
  367.   return copy;
  368. }
  369.  
  370. /* Helper functions for instruction scheduling.  */
  371.  
  372. /* Add ELEM wrapped in an INSN_LIST to the LOG_LINKS of INSN,
  373.    if not already there.  Return nonzero iff ELEM was added
  374.    to INSN's LOG_LINKS by this call.  */
  375. int
  376. add_dependence (insn, elem)
  377.      rtx insn;
  378.      rtx elem;
  379. {
  380.   rtx link;
  381.  
  382.   /* Don't depend an insn on itself.  */
  383.   if (insn == elem)
  384.     return 0;
  385.  
  386.   /* If elem is part of a sequence that must be scheduled together, then
  387.      make the dependence point to the last insn of the sequence.  */
  388.   if (NEXT_INSN (elem) && RTX_UNCHANGING_P (NEXT_INSN (elem)))
  389.     {
  390.       while (NEXT_INSN (elem) && RTX_UNCHANGING_P (NEXT_INSN (elem)))
  391.     elem = NEXT_INSN (elem);
  392.       /* Again, don't depend an insn of itself.  */
  393.       if (insn == elem)
  394.     return 0;
  395.     }
  396.  
  397.   /* Check that we don't already have this dependence.  */
  398.   for (link = LOG_LINKS (insn); link; link = XEXP (link, 1))
  399.     if (XEXP (link, 0) == elem)
  400.       return 0;
  401.   /* Might want to check one level of transitivity to save conses.  */
  402.  
  403.   link = rtx_alloc (INSN_LIST);
  404.   /* Insn dependency, not data dependency.  */
  405.   PUT_MODE (link, QImode);
  406.   XEXP (link, 0) = elem;
  407.   XEXP (link, 1) = LOG_LINKS (insn);
  408.   LOG_LINKS (insn) = link;
  409.   return 1;
  410. }
  411.  
  412. /* Remove ELEM wrapped in an INSN_LIST from the LOG_LINKS
  413.    of INSN.  Abort if not found.  */
  414. void
  415. remove_dependence (insn, elem)
  416.      rtx insn;
  417.      rtx elem;
  418. {
  419.   rtx prev, link;
  420.   int found = 0;
  421.  
  422.   for (prev = 0, link = LOG_LINKS (insn); link;
  423.        prev = link, link = XEXP (link, 1))
  424.     {
  425.       if (XEXP (link, 0) == elem)
  426.     {
  427.       if (prev)
  428.         XEXP (prev, 1) = XEXP (link, 1);
  429.       else
  430.         LOG_LINKS (insn) = XEXP (link, 1);
  431.       found = 1;
  432.     }
  433.     }
  434.  
  435.   if (! found)
  436.     abort ();
  437.   return;
  438. }
  439.  
  440. /* Printing rtl for debugging dumps.  */
  441.  
  442. static FILE *outfile;
  443.  
  444. char spaces[] = "                                                                                                                                                                ";
  445.  
  446. static int sawclose = 0;
  447.  
  448. /* Print IN_RTX onto OUTFILE.  This is the recursive part of printing.  */
  449.  
  450. static void
  451. print_rtx (in_rtx)
  452.      register rtx in_rtx;
  453. {
  454.   static int indent;
  455.   register int i, j;
  456.   register char *format_ptr;
  457.   register int is_insn;
  458.  
  459.   if (sawclose)
  460.     {
  461.       fprintf (outfile, "\n%s",
  462.            (spaces + (sizeof spaces - indent * 2)));
  463.       sawclose = 0;
  464.     }
  465.  
  466.   if (in_rtx == 0)
  467.     {
  468.       fprintf (outfile, "(nil)");
  469.       sawclose = 1;
  470.       return;
  471.     }
  472.  
  473.   /* print name of expression code */
  474.   fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
  475.  
  476.   if (in_rtx->in_struct)
  477.     fprintf (outfile, "/s");
  478.  
  479.   if (in_rtx->volatil)
  480.     fprintf (outfile, "/v");
  481.  
  482.   if (in_rtx->unchanging)
  483.     fprintf (outfile, "/u");
  484.  
  485.   if (in_rtx->integrated)
  486.     fprintf (outfile, "/i");
  487.  
  488.   if (GET_MODE (in_rtx) != VOIDmode)
  489.     {
  490.       /* Print REG_NOTE names for EXPR_LIST and INSN_LIST.  */
  491.       if (GET_CODE (in_rtx) == EXPR_LIST || GET_CODE (in_rtx) == INSN_LIST)
  492.     fprintf (outfile, ":%s", GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
  493.       else
  494.     fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
  495.     }
  496.  
  497.   is_insn = (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i');
  498.   format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
  499.  
  500.   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
  501.     switch (*format_ptr++)
  502.       {
  503.       case 'S':
  504.       case 's':
  505.     if (XSTR (in_rtx, i) == 0)
  506.       fprintf (outfile, " \"\"");
  507.     else
  508.       fprintf (outfile, " (\"%s\")", XSTR (in_rtx, i));
  509.     sawclose = 1;
  510.     break;
  511.  
  512.     /* 0 indicates a field for internal use that should not be printed.  */
  513.       case '0':
  514.     break;
  515.  
  516.       case 'e':
  517.     indent += 2;
  518.     if (!sawclose)
  519.       fprintf (outfile, " ");
  520.     print_rtx (XEXP (in_rtx, i));
  521.     indent -= 2;
  522.     break;
  523.  
  524.       case 'E':
  525.       case 'V':
  526.     indent += 2;
  527.     if (sawclose)
  528.       {
  529.         fprintf (outfile, "\n%s",
  530.              (spaces + (sizeof spaces - indent * 2)));
  531.         sawclose = 0;
  532.       }
  533.     fprintf (outfile, "[ ");
  534.     if (NULL != XVEC (in_rtx, i))
  535.       {
  536.         indent += 2;
  537.         if (XVECLEN (in_rtx, i))
  538.           sawclose = 1;
  539.  
  540.         for (j = 0; j < XVECLEN (in_rtx, i); j++)
  541.           print_rtx (XVECEXP (in_rtx, i, j));
  542.  
  543.         indent -= 2;
  544.       }
  545.     if (sawclose)
  546.       fprintf (outfile, "\n%s",
  547.            (spaces + (sizeof spaces - indent * 2)));
  548.  
  549.     fprintf (outfile, "] ");
  550.     sawclose = 1;
  551.     indent -= 2;
  552.     break;
  553.  
  554.       case 'i':
  555.     fprintf (outfile, " %d", XINT (in_rtx, i));
  556.     if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
  557.         && insn_name_ptr
  558.         && XINT (in_rtx, i) >= 0)
  559.         fprintf (outfile, " {%s}", insn_name_ptr[XINT (in_rtx, i)]);
  560.     sawclose = 0;
  561.     break;
  562.  
  563.       /* Print NOTE_INSN names rather than integer codes.  */
  564.  
  565.       case 'n':
  566.     if (XINT (in_rtx, i) <= 0)
  567.       fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
  568.     else
  569.       fprintf (outfile, " %d", XINT (in_rtx, i));
  570.     sawclose = 0;
  571.     break;
  572.  
  573.       case 'u':
  574.     if (XEXP (in_rtx, i) != NULL)
  575.       fprintf(outfile, " %d", INSN_UID (XEXP (in_rtx, i)));
  576.     else
  577.       fprintf(outfile, " 0");
  578.     sawclose = 0;
  579.     break;
  580.  
  581.       default:
  582.     fprintf (stderr,
  583.          "switch format wrong in rtl.print_rtx(). format was: %c.\n",
  584.          format_ptr[-1]);
  585.     abort ();
  586.       }
  587.  
  588.   fprintf (outfile, ")");
  589.   sawclose = 1;
  590. }
  591.  
  592. /* Call this function from the debugger to see what X looks like.  */
  593.  
  594. void
  595. debug_rtx (x)
  596.      rtx x;
  597. {
  598.   outfile = stderr;
  599.   print_rtx (x);
  600.   fprintf (stderr, "\n");
  601. }
  602.  
  603. /* External entry point for printing a chain of insns
  604.    starting with RTX_FIRST onto file OUTF.
  605.    A blank line separates insns.
  606.  
  607.    If RTX_FIRST is not an insn, then it alone is printed, with no newline.  */
  608.  
  609. void
  610. print_rtl (outf, rtx_first)
  611.      FILE *outf;
  612.      rtx rtx_first;
  613. {
  614.   register rtx tmp_rtx;
  615.  
  616.   outfile = outf;
  617.   sawclose = 0;
  618.  
  619.   if (rtx_first == 0)
  620.     fprintf (outf, "(nil)\n");
  621.   else
  622.     switch (GET_CODE (rtx_first))
  623.       {
  624.       case INSN:
  625.       case JUMP_INSN:
  626.       case CALL_INSN:
  627.       case NOTE:
  628.       case CODE_LABEL:
  629.       case BARRIER:
  630.     for (tmp_rtx = rtx_first; NULL != tmp_rtx; tmp_rtx = NEXT_INSN (tmp_rtx))
  631.       {
  632.         print_rtx (tmp_rtx);
  633.         fprintf (outfile, "\n");
  634.       }
  635.     break;
  636.  
  637.       default:
  638.     print_rtx (rtx_first);
  639.       }
  640. }
  641.  
  642. /* Subroutines of read_rtx.  */
  643.  
  644. /* Dump code after printing a message.  Used when read_rtx finds
  645.    invalid data.  */
  646.  
  647. static void
  648. dump_and_abort (expected_c, actual_c, infile)
  649.      int expected_c, actual_c;
  650.      FILE *infile;
  651. {
  652.   int c, i;
  653.  
  654.   if (expected_c >= 0)
  655.     fprintf (stderr,
  656.          "Expected character %c.  Found character %c.",
  657.          expected_c, actual_c);
  658.   fprintf (stderr, "  At file position: %ld\n", ftell (infile));
  659.   fprintf (stderr, "Following characters are:\n\t");
  660.   for (i = 0; i < 200; i++)
  661.     {
  662.       c = getc (infile);
  663.       if (EOF == c) break;
  664.       putc (c, stderr);
  665.     }
  666.   fprintf (stderr, "Aborting.\n");
  667.   abort ();
  668. }
  669.  
  670. /* Read chars from INFILE until a non-whitespace char
  671.    and return that.  Comments, both Lisp style and C style,
  672.    are treated as whitespace.
  673.    Tools such as genflags use this function.  */
  674.  
  675. int
  676. read_skip_spaces (infile)
  677.      FILE *infile;
  678. {
  679.   register int c;
  680.   while (c = getc (infile))
  681.     {
  682.       if (c == ' ' || c == '\n' || c == '\t' || c == '\f')
  683.     ;
  684.       else if (c == ';')
  685.     {
  686.       while ((c = getc (infile)) && c != '\n') ;
  687.     }
  688.       else if (c == '/')
  689.     {
  690.       register int prevc;
  691.       c = getc (infile);
  692.       if (c != '*')
  693.         dump_and_abort ('*', c, infile);
  694.       
  695.       prevc = 0;
  696.       while (c = getc (infile))
  697.         {
  698.           if (prevc == '*' && c == '/')
  699.         break;
  700.           prevc = c;
  701.         }
  702.     }
  703.       else break;
  704.     }
  705.   return c;
  706. }
  707.  
  708. /* Read an rtx code name into the buffer STR[].
  709.    It is terminated by any of the punctuation chars of rtx printed syntax.  */
  710.  
  711. static void
  712. read_name (str, infile)
  713.      char *str;
  714.      FILE *infile;
  715. {
  716.   register char *p;
  717.   register int c;
  718.  
  719.   c = read_skip_spaces(infile);
  720.  
  721.   p = str;
  722.   while (1)
  723.     {
  724.       if (c == ' ' || c == '\n' || c == '\t' || c == '\f')
  725.     break;
  726.       if (c == ':' || c == ')' || c == ']' || c == '"' || c == '/'
  727.       || c == '(' || c == '[')
  728.     {
  729.       ungetc (c, infile);
  730.       break;
  731.     }
  732.       *p++ = c;
  733.       c = getc (infile);
  734.     }
  735.   if (p == str)
  736.     {
  737.       fprintf (stderr, "missing name or number");
  738.       dump_and_abort (-1, -1, infile);
  739.     }
  740.  
  741.   *p = 0;
  742. }
  743.  
  744. /* Read an rtx in printed representation from INFILE
  745.    and return an actual rtx in core constructed accordingly.
  746.    read_rtx is not used in the compiler proper, but rather in
  747.    the utilities gen*.c that construct C code from machine descriptions.  */
  748.  
  749. rtx
  750. read_rtx (infile)
  751.      FILE *infile;
  752. {
  753.   register int i, j, list_counter;
  754.   RTX_CODE tmp_code;
  755.   register char *format_ptr;
  756.   /* tmp_char is a buffer used for reading decimal integers
  757.      and names of rtx types and machine modes.
  758.      Therefore, 256 must be enough.  */
  759.   char tmp_char[256];
  760.   rtx return_rtx;
  761.   register int c;
  762.   int tmp_int;
  763.  
  764.   /* Linked list structure for making RTXs: */
  765.   struct rtx_list
  766.     {
  767.       struct rtx_list *next;
  768.       rtx value;        /* Value of this node...        */
  769.     };
  770.  
  771.   c = read_skip_spaces (infile); /* Should be open paren.  */
  772.   if (c != '(')
  773.     dump_and_abort ('(', c, infile);
  774.  
  775.   read_name (tmp_char, infile);
  776.  
  777.   tmp_code = UNKNOWN;
  778.  
  779.   for (i=0; i < NUM_RTX_CODE; i++) /* @@ might speed this search up */
  780.     {
  781.       if (!(strcmp (tmp_char, GET_RTX_NAME (i))))
  782.     {
  783.       tmp_code = (RTX_CODE) i;    /* get value for name */
  784.       break;
  785.     }
  786.     }
  787.   if (tmp_code == UNKNOWN)
  788.     {
  789.       fprintf (stderr,
  790.            "Unknown rtx read in rtl.read_rtx(). Code name was %s .",
  791.            tmp_char);
  792.     }
  793.   /* (NIL) stands for an expression that isn't there.  */
  794.   if (tmp_code == NIL)
  795.     {
  796.       /* Discard the closeparen.  */
  797.       while ((c = getc (infile)) && c != ')');
  798.       return 0;
  799.     }
  800.  
  801.   return_rtx = rtx_alloc (tmp_code); /* if we end up with an insn expression
  802.                        then we free this space below.  */
  803.   format_ptr = GET_RTX_FORMAT (GET_CODE (return_rtx));
  804.  
  805.   /* If what follows is `: mode ', read it and
  806.      store the mode in the rtx.  */
  807.  
  808.   i = read_skip_spaces (infile);
  809.   if (i == ':')
  810.     {
  811.       register int k;
  812.       read_name (tmp_char, infile);
  813.       for (k = 0; k < NUM_MACHINE_MODES; k++)
  814.     if (!strcmp (GET_MODE_NAME (k), tmp_char))
  815.       break;
  816.  
  817.       PUT_MODE (return_rtx, (enum machine_mode) k );
  818.     }
  819.   else
  820.     ungetc (i, infile);
  821.  
  822.   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (return_rtx)); i++)
  823.     switch (*format_ptr++)
  824.       {
  825.     /* 0 means a field for internal use only.
  826.        Don't expect it to be present in the input.  */
  827.       case '0':
  828.     break;
  829.  
  830.       case 'e':
  831.       case 'u':
  832.     XEXP (return_rtx, i) = read_rtx (infile);
  833.     break;
  834.  
  835.       case 'V':
  836.     /* 'V' is an optional vector: if a closeparen follows,
  837.        just store NULL for this element.  */
  838.     c = read_skip_spaces (infile);
  839.     ungetc (c, infile);
  840.     if (c == ')')
  841.       {
  842.         XVEC (return_rtx, i) = 0;
  843.         break;
  844.        }
  845.     /* Now process the vector.  */
  846.   
  847.       case 'E':
  848.     {
  849.       register struct rtx_list *next_rtx, *rtx_list_link;
  850.       struct rtx_list *list_rtx;
  851.  
  852.       c = read_skip_spaces (infile);
  853.       if (c != '[')
  854.         dump_and_abort ('[', c, infile);
  855.  
  856.       /* add expressions to a list, while keeping a count */
  857.       next_rtx = NULL;
  858.       list_counter = 0;
  859.       while ((c = read_skip_spaces (infile)) && c != ']')
  860.         {
  861.           ungetc (c, infile);
  862.           list_counter++;
  863.           rtx_list_link = (struct rtx_list *)
  864.         alloca (sizeof (struct rtx_list));
  865.           rtx_list_link->value = read_rtx (infile);
  866.           if (next_rtx == 0)
  867.         list_rtx = rtx_list_link;
  868.           else
  869.         next_rtx->next = rtx_list_link;
  870.           next_rtx = rtx_list_link;
  871.           rtx_list_link->next = 0;
  872.         }
  873.       /* get vector length and allocate it */
  874.       XVEC (return_rtx, i) = (list_counter
  875.                   ? rtvec_alloc (list_counter)
  876.                   : (struct rtvec_def *) NULL);
  877.       if (list_counter > 0)
  878.         {
  879.           next_rtx = list_rtx;
  880.           for (j = 0; j < list_counter; j++,
  881.            next_rtx = next_rtx->next)
  882.         XVECEXP (return_rtx, i, j) = next_rtx->value;
  883.         }
  884.       /* close bracket gotten */
  885.     }
  886.     break;
  887.  
  888.       case 'S':
  889.     /* 'S' is an optional string: if a closeparen follows,
  890.        just store NULL for this element.  */
  891.     c = read_skip_spaces (infile);
  892.     ungetc (c, infile);
  893.     if (c == ')')
  894.       {
  895.         XSTR (return_rtx, i) = 0;
  896.         break;
  897.       }
  898.  
  899.       case 's':
  900.     {
  901.       int saw_paren = 0;
  902.       register char *stringbuf;
  903.       int stringbufsize;
  904.  
  905.       c = read_skip_spaces (infile);
  906.       if (c == '(')
  907.         {
  908.           saw_paren = 1;
  909.           c = read_skip_spaces (infile);
  910.         }
  911.       if (c != '"')
  912.         dump_and_abort ('"', c, infile);
  913.       j = 0;
  914.       stringbufsize = 10;
  915.       stringbuf = (char *) xmalloc (stringbufsize + 1);
  916.  
  917.       while (1)
  918.         {
  919.           if (j >= stringbufsize - 4)
  920.         {
  921.           stringbufsize *= 2;
  922.           stringbuf = (char *) xrealloc (stringbuf, stringbufsize + 1);
  923.         }
  924.           stringbuf[j] = getc (infile); /* Read the string  */
  925.           if (stringbuf[j] == '\\')
  926.         {
  927.           stringbuf[j] = getc (infile);    /* Read the string  */
  928.           /* \; makes stuff for a C string constant containing
  929.              newline and tab.  */
  930.           if (stringbuf[j] == ';')
  931.             {
  932.               strcpy (&stringbuf[j], "\\n\\t");
  933.               j += 3;
  934.             }
  935.         }
  936.           else if (stringbuf[j] == '"')
  937.         break;
  938.           j++;
  939.         }
  940.  
  941.       stringbuf[j] = 0;    /* NUL terminate the string  */
  942.       stringbuf = (char *) xrealloc (stringbuf, j + 1);
  943.  
  944.       if (saw_paren)
  945.         {
  946.           c = read_skip_spaces (infile);
  947.           if (c != ')')
  948.         dump_and_abort (')', c, infile);
  949.         }
  950.       XSTR (return_rtx, i) = stringbuf;
  951.     }
  952.     break;
  953.  
  954.       case 'i':
  955.       case 'n':
  956.     read_name (tmp_char, infile);
  957.     tmp_int = atoi (tmp_char);
  958.     XINT (return_rtx, i) = tmp_int;
  959.     break;
  960.  
  961.       default:
  962.     fprintf (stderr,
  963.          "switch format wrong in rtl.read_rtx(). format was: %c.\n",
  964.          format_ptr[-1]);
  965.     fprintf (stderr, "\tfile position: %ld\n", ftell (infile));
  966.     abort ();
  967.       }
  968.  
  969.   c = read_skip_spaces (infile);
  970.   if (c != ')')
  971.     dump_and_abort (')', c, infile);
  972.  
  973.   return return_rtx;
  974. }
  975.  
  976. /* This is called once per compilation, before any rtx's are constructed.
  977.    It initializes the vector `rtx_length' and the extra CC modes, if any.  */
  978.  
  979. void
  980. init_rtl ()
  981. {
  982.   int i;
  983.  
  984.   for (i = 0; i < NUM_RTX_CODE; i++)
  985.     rtx_length[i] = strlen (rtx_format[i]);
  986.  
  987.   /* Make CONST_DOUBLE bigger, if real values are bigger than
  988.      it normally expects to have room for.
  989.      Note that REAL_VALUE_TYPE is not defined by default,
  990.      since tree.h is not included.  But the default dfn as `double'
  991.      would do no harm.  */
  992. #ifdef REAL_VALUE_TYPE
  993.   i = sizeof (REAL_VALUE_TYPE) / sizeof (rtunion) + 2;
  994.   if (rtx_length[(int) CONST_DOUBLE] < i)
  995.     {
  996.       char *s = (char *) xmalloc (i + 1);
  997.       rtx_length[(int) CONST_DOUBLE] = i;
  998.       rtx_format[(int) CONST_DOUBLE] = s;
  999.       *s++ = 'e';
  1000.       *s++ = '0';
  1001.       /* Set the GET_RTX_FORMAT of CONST_DOUBLE to a string
  1002.      of as many `i's as we now have elements.  */
  1003.       for (i = 0; i < rtx_length[(int) CONST_DOUBLE]; i++)
  1004.     *s++ = 'i';
  1005.       *s++ = 0;
  1006.     }
  1007. #endif
  1008.  
  1009. #ifdef EXTRA_CC_MODES
  1010.   for (i = (int) CCmode + 1; i < (int) MAX_MACHINE_MODE; i++)
  1011.     {
  1012.       mode_class[i] = MODE_CC;
  1013.       mode_size[i] = mode_size[(int) CCmode];
  1014.       mode_unit_size[i] = mode_unit_size[(int) CCmode];
  1015.       mode_wider_mode[i - 1] = (enum machine_mode) i;
  1016.       mode_wider_mode[i] = VOIDmode;
  1017.     }
  1018. #endif
  1019. }
  1020.