home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / gcc-2.3.3-src.lha / GNU / src / amiga / gcc-2.3.3 / genoutput.c < prev    next >
C/C++ Source or Header  |  1994-02-06  |  27KB  |  991 lines

  1. /* Generate code from to output assembler insns as recognized from rtl.
  2.    Copyright (C) 1987, 1988, 1992 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. /* This program reads the machine description for the compiler target machine
  22.    and produces a file containing these things:
  23.  
  24.    1. An array of strings `insn_template' which is indexed by insn code number
  25.    and contains the template for output of that insn,
  26.  
  27.    2. An array of functions `insn_outfun' which, indexed by the insn code
  28.    number, gives the function that returns a template to use for output of
  29.    that insn.  This is used only in the cases where the template is not
  30.    constant.  These cases are specified by a * or @ at the beginning of the
  31.    template string in the machine description.  They are identified for the
  32.    sake of other parts of the compiler by a zero element in `insn_template'.
  33.   
  34.    3. An array of functions `insn_gen_function' which, indexed
  35.    by insn code number, gives the function to generate a body
  36.    for that pattern, given operands as arguments.
  37.  
  38.    4. An array of strings `insn_name' which, indexed by insn code number,
  39.    gives the name for that pattern.  Nameless patterns are given a name.
  40.  
  41.    5. An array of ints `insn_n_operands' which is indexed by insn code number
  42.    and contains the number of distinct operands in the pattern for that insn,
  43.  
  44.    6. An array of ints `insn_n_dups' which is indexed by insn code number
  45.    and contains the number of match_dup's that appear in the insn's pattern.
  46.    This says how many elements of `recog_dup_loc' are significant
  47.    after an insn has been recognized.
  48.  
  49.    7. An array of arrays of operand constraint strings,
  50.    `insn_operand_constraint',
  51.    indexed first by insn code number and second by operand number,
  52.    containing the constraint for that operand.
  53.  
  54.    This array is generated only if register constraints appear in 
  55.    match_operand rtx's.
  56.  
  57.    8. An array of arrays of chars which indicate which operands of
  58.    which insn patterns appear within ADDRESS rtx's.  This array is
  59.    called `insn_operand_address_p' and is generated only if there
  60.    are *no* register constraints in the match_operand rtx's.
  61.  
  62.    9. An array of arrays of machine modes, `insn_operand_mode',
  63.    indexed first by insn code number and second by operand number,
  64.    containing the machine mode that that operand is supposed to have.
  65.    Also `insn_operand_strict_low', which is nonzero for operands
  66.    contained in a STRICT_LOW_PART.
  67.  
  68.    10. An array of arrays of int-valued functions, `insn_operand_predicate',
  69.    indexed first by insn code number and second by operand number,
  70.    containing the match_operand predicate for this operand.
  71.  
  72.    11. An array of ints, `insn_n_alternatives', that gives the number
  73.    of alternatives in the constraints of each pattern.
  74.  
  75. The code number of an insn is simply its position in the machine description;
  76. code numbers are assigned sequentially to entries in the description,
  77. starting with code number 0.
  78.  
  79. Thus, the following entry in the machine description
  80.  
  81.     (define_insn "clrdf"
  82.       [(set (match_operand:DF 0 "general_operand" "")
  83.         (const_int 0))]
  84.       ""
  85.       "clrd %0")
  86.  
  87. assuming it is the 25th entry present, would cause
  88. insn_template[24] to be "clrd %0", and insn_n_operands[24] to be 1.
  89. It would not make an case in output_insn_hairy because the template
  90. given in the entry is a constant (it does not start with `*').  */
  91.  
  92. #include <stdio.h>
  93. #include "hconfig.h"
  94. #include "rtl.h"
  95. #include "obstack.h"
  96.  
  97. /* No instruction can have more operands than this.
  98.    Sorry for this arbitrary limit, but what machine will
  99.    have an instruction with this many operands?  */
  100.  
  101. #define MAX_MAX_OPERANDS 40
  102.  
  103. static struct obstack obstack;
  104. struct obstack *rtl_obstack = &obstack;
  105.  
  106. #define obstack_chunk_alloc xmalloc
  107. #define obstack_chunk_free free
  108.  
  109. extern void free ();
  110. extern rtx read_rtx ();
  111.  
  112. char *xmalloc ();
  113. static void fatal ();
  114. void fancy_abort ();
  115. static void error ();
  116. static void mybcopy ();
  117. static void mybzero ();
  118. static int n_occurrences ();
  119.  
  120. /* insns in the machine description are assigned sequential code numbers
  121.    that are used by insn-recog.c (produced by genrecog) to communicate
  122.    to insn-output.c (produced by this program).  */
  123.  
  124. static int next_code_number;
  125.  
  126. /* This counts all definitions in the md file,
  127.    for the sake of error messages.  */
  128.  
  129. static int next_index_number;
  130.  
  131. /* Record in this chain all information that we will output,
  132.    associated with the code number of the insn.  */
  133.  
  134. struct data
  135. {
  136.   int code_number;
  137.   int index_number;
  138.   char *name;
  139.   char *template;        /* string such as "movl %1,%0" */
  140.   int n_operands;        /* Number of operands this insn recognizes */
  141.   int n_dups;            /* Number times match_dup appears in pattern */
  142.   int n_alternatives;        /* Number of alternatives in each constraint */
  143.   struct data *next;
  144.   char *constraints[MAX_MAX_OPERANDS];
  145.   /* Number of alternatives in constraints of operand N.  */
  146.   int op_n_alternatives[MAX_MAX_OPERANDS];
  147.   char *predicates[MAX_MAX_OPERANDS];
  148.   char address_p[MAX_MAX_OPERANDS];
  149.   enum machine_mode modes[MAX_MAX_OPERANDS];
  150.   char strict_low[MAX_MAX_OPERANDS];
  151.   char outfun;            /* Nonzero means this has an output function */
  152. };
  153.  
  154. /* This variable points to the first link in the chain.  */
  155.  
  156. struct data *insn_data;
  157.  
  158. /* Pointer to the last link in the chain, so new elements
  159.    can be added at the end.  */
  160.  
  161. struct data *end_of_insn_data;
  162.  
  163. /* Nonzero if any match_operand has a constraint string;
  164.    implies that REGISTER_CONSTRAINTS will be defined
  165.    for this machine description.  */
  166.  
  167. int have_constraints;
  168.  
  169. static void
  170. output_prologue ()
  171. {
  172.  
  173.   printf ("/* Generated automatically by the program `genoutput'\n\
  174. from the machine description file `md'.  */\n\n");
  175.  
  176.   printf ("#include \"config.h\"\n");
  177.   printf ("#include \"rtl.h\"\n");
  178.   printf ("#include \"regs.h\"\n");
  179.   printf ("#include \"hard-reg-set.h\"\n");
  180.   printf ("#include \"real.h\"\n");
  181.   printf ("#include \"insn-config.h\"\n\n");
  182.   printf ("#include \"conditions.h\"\n");
  183.   printf ("#include \"insn-flags.h\"\n");
  184.   printf ("#include \"insn-attr.h\"\n\n");
  185.   printf ("#include \"insn-codes.h\"\n\n");
  186.   printf ("#include \"recog.h\"\n\n");
  187.  
  188.   printf ("#include <stdio.h>\n");
  189.   printf ("#include \"output.h\"\n");
  190. }
  191.  
  192. static void
  193. output_epilogue ()
  194. {
  195.   register struct data *d;
  196.  
  197.   printf ("\nchar * const insn_template[] =\n  {\n");
  198.   for (d = insn_data; d; d = d->next)
  199.     {
  200.       if (d->template)
  201.     printf ("    \"%s\",\n", d->template);
  202.       else
  203.     printf ("    0,\n");
  204.     }
  205.   printf ("  };\n");
  206.  
  207.   printf ("\nchar *(*const insn_outfun[])() =\n  {\n");
  208.   for (d = insn_data; d; d = d->next)
  209.     {
  210.       if (d->outfun)
  211.     printf ("    output_%d,\n", d->code_number);
  212.       else
  213.     printf ("    0,\n");
  214.     }
  215.   printf ("  };\n");
  216.  
  217.   printf ("\nrtx (*const insn_gen_function[]) () =\n  {\n");
  218.   for (d = insn_data; d; d = d->next)
  219.     {
  220.       if (d->name)
  221.     printf ("    gen_%s,\n", d->name);
  222.       else
  223.     printf ("    0,\n");
  224.     }
  225.   printf ("  };\n");
  226.  
  227.   printf ("\nchar *insn_name[] =\n  {\n");
  228.   {
  229.     int offset = 0;
  230.     int next;
  231.     char * last_name = 0;
  232.     char * next_name;
  233.     register struct data *n;
  234.  
  235.     for (n = insn_data, next = 0; n; n = n->next, next++)
  236.       if (n->name)
  237.     {
  238.       next_name = n->name;
  239.       break;
  240.     }
  241.  
  242.     for (d = insn_data; d; d = d->next)
  243.       {
  244.     if (d->name)
  245.       {
  246.         printf ("    \"%s\",\n", d->name);
  247.         offset = 0;
  248.         last_name = d->name;
  249.         next_name = 0;
  250.         for (n = d->next, next = 1; n; n = n->next, next++)
  251.           if (n->name)
  252.         {
  253.           next_name = n-