home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / GCC 1.37.1r14 / usr / gcc-1.37.1r14 / (gcc-1.37.π) / final.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-19  |  43.1 KB  |  1,665 lines  |  [TEXT/KAHL]

  1. /* Convert RTL to assembler code and output it, for GNU compiler.
  2.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  3.    Copyright (C) 1989, 1990 Apple Computer, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* This is the final pass of the compiler.
  23.    It looks at the rtl code for a function and outputs assembler code.
  24.  
  25.    Call `final_start_function' to output the assembler code for function entry,
  26.    `final' to output assembler code for some RTL code,
  27.    `final_end_function' to output assembler code for function exit.
  28.    If a function is compiled in several pieces, each piece is
  29.    output separately with `final'.
  30.  
  31.    Some optimizations are also done at this level.
  32.    Move instructions that were made unnecessary by good register allocation
  33.    are detected and omitted from the output.  (Though most of these
  34.    are removed by the last jump pass.)
  35.  
  36.    Instructions to set the condition codes are omitted when it can be
  37.    seen that the condition codes already had the desired values.
  38.  
  39.    In some cases it is sufficient if the inherited condition codes
  40.    have related values, but this may require the following insn
  41.    (the one that tests the condition codes) to be modified.
  42.  
  43.    The code for the function prologue and epilogue are generated
  44.    directly as assembler code by the macros FUNCTION_PROLOGUE and
  45.    FUNCTION_EPILOGUE.  Those instructions never exist as rtl.  */
  46.  
  47. #include <stdio.h>
  48. #include "config.h"
  49. #include "rtl.h"
  50. #include "regs.h"
  51. #include "insn-config.h"
  52. #include "recog.h"
  53. #include "conditions.h"
  54. #include "gdbfiles.h"
  55. #include "flags.h"
  56. #include "real.h"
  57. #include "output.h"
  58.  
  59. #ifdef MPW
  60. #include <CursorCtl.h>
  61. #endif
  62.  
  63. /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist.  */
  64. #ifdef DBX_DEBUGGING_INFO
  65. #ifdef USG
  66. #include "stab.h"  /* If doing DBX on sysV, use our own stab.h.  */
  67. #else
  68. #include <stab.h>  /* On BSD, use the system's stab.h.  */
  69. #endif /* not USG */
  70. #endif /* DBX_DEBUGGING_INFO */
  71.  
  72. /* .stabd code for line number.  */
  73. #ifndef N_SLINE
  74. #define    N_SLINE    0x44
  75. #endif
  76.  
  77. /* .stabs code for included file name.  */
  78. #ifndef N_SOL
  79. #define    N_SOL 0x84
  80. #endif
  81.  
  82. #define min(A,B) ((A) < (B) ? (A) : (B))
  83.  
  84. rtx peephole ();
  85. void output_asm_insn ();
  86. rtx alter_subreg ();
  87. static int alter_cond ();
  88. void output_asm_label ();
  89. static void output_operand ();
  90. void output_address ();
  91. void output_addr_const ();
  92. static void output_source_line ();
  93. rtx final_scan_insn ();
  94.  
  95. /* the sdb debugger needs the line given as an offset from the beginning
  96.    of the current function -wfs*/
  97.  
  98. extern int sdb_begin_function_line;
  99.  
  100. /* Line number of last NOTE.  */
  101. static int last_linenum;
  102.  
  103. /* Number of basic blocks seen so far;
  104.    used if profile_block_flag is set.  */
  105. static int count_basic_blocks;
  106.  
  107. /* Nonzero while outputting an `asm' with operands.
  108.    This means that inconsistencies are the user's fault, so don't abort.
  109.    The precise value is the insn being output, to pass to error_for_asm.  */
  110. static rtx this_is_asm_operands;
  111.  
  112. /* Number of operands of this insn, for an `asm' with operands.  */
  113. static int insn_noperands;
  114.  
  115. /* File in which assembler code is being written.  */
  116.  
  117. extern FILE *asm_out_file;
  118.  
  119. /* Compare optimization flag. */
  120.  
  121. static rtx last_ignored_compare = 0;
  122.  
  123. /* Flag indicating this insn is the start of a new basic block. */
  124.  
  125. static int new_block = 1;
  126.  
  127. /* All the symbol-blocks (levels of scoping) in the compilation
  128.    are assigned sequence numbers in order of appearance of the
  129.    beginnings of the symbol-blocks.  Both final and dbxout do this,
  130.    and assume that they will both give the same number to each block.
  131.    Final uses these sequence numbers to generate assembler label names
  132.    LBBnnn and LBEnnn for the beginning and end of the symbol-block.
  133.    Dbxout uses the sequence nunbers to generate references to the same labels
  134.    from the dbx debugging information.
  135.  
  136.    Sdb records this level at the beginning
  137.    of each function, so that when it recurses down the declarations, it may
  138.    find the current level, since it outputs the block beginning and endings
  139.    at the point in the asm file, where the blocks would begin and end.  */
  140.  
  141. int next_block_index;
  142.  
  143. /* Chain of all `struct gdbfile's.  */
  144.  
  145. struct gdbfile *gdbfiles;
  146.  
  147. /* `struct gdbfile' for the last file we wrote a line number for.  */
  148.  
  149. static struct gdbfile *current_gdbfile;
  150.  
  151. /* Filenum to assign to the next distinct source file encountered.  */
  152.  
  153. static int next_gdb_filenum;
  154.  
  155. /* This variable contains machine-dependent flags (defined in tm-...h)
  156.    set and examined by output routines
  157.    that describe how to interpret the condition codes properly.  */
  158.  
  159. CC_STATUS cc_status;
  160.  
  161. /* During output of an insn, this contains a copy of cc_status
  162.    from before the insn.  */
  163.  
  164. CC_STATUS cc_prev_status;
  165.  
  166. /* Last source file name mentioned in a NOTE insn.  */
  167.  
  168. static char *lastfile;
  169.  
  170. /* Indexed by hardware reg number, is 1 if that register is ever
  171.    used in the current function.
  172.  
  173.    In life_analysis, or in stupid_life_analysis, this is set
  174.    up to record the hard regs used explicitly.  Reload adds
  175.    in the hard regs used for holding pseudo regs.  Final uses
  176.    it to generate the code in the function prologue and epilogue
  177.    to save and restore registers as needed.  */
  178.  
  179. char regs_ever_live[FIRST_PSEUDO_REGISTER];
  180.  
  181. /* Nonzero means current function must be given a frame pointer.
  182.    Set in stmt.c if anything is allocated on the stack there.
  183.    Set in reload1.c if anything is allocated on the stack there.  */
  184.  
  185. int frame_pointer_needed;
  186.  
  187. /* Assign unique numbers to labels generated for profiling.  */
  188.  
  189. int profile_label_no;
  190.  
  191. /* Length so far allocated in PENDING_BLOCKS.  */
  192.  
  193. static int max_block_depth;
  194.  
  195. /* Stack of sequence numbers of symbol-blocks of which we have seen the
  196.    beginning but not yet the end.  Sequence numbers are assigned at
  197.    the beginning; this stack allows us to find the sequence number
  198.    of a block that is ending.  */
  199.  
  200. static int *pending_blocks;
  201.  
  202. /* Number of elements currently in use in PENDING_BLOCKS.  */
  203.  
  204. static int block_depth;
  205.  
  206. /* Nonzero if have enabled APP processing of our assembler output.  */
  207.  
  208. static int app_on;
  209.  
  210. /* If we are outputting an insn sequence, this contains the sequence rtx.
  211.    Zero otherwise.  */
  212.  
  213. rtx final_sequence;
  214.  
  215. #ifdef MPW
  216. static int cursor_count;
  217. #endif
  218.  
  219. /* Initialize data in final at the beginning of a compilation.  */
  220.  
  221. void
  222. init_final (filename)
  223.      char *filename;
  224. {
  225.   next_block_index = 2;
  226.   lastfile = filename;
  227.   app_on = 0;
  228.   max_block_depth = 20;
  229.   pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
  230.   gdbfiles = 0;
  231.   next_gdb_filenum = 0;
  232.   final_sequence = 0;
  233. #ifdef MPW
  234.   cursor_count = 0;
  235. #endif
  236. }
  237.  
  238. /* Called at end of source file,
  239.    to output the block-profiling table for this entire compilation.  */
  240.  
  241. void
  242. end_final (filename)
  243.      char *filename;
  244. {
  245.   int i;
  246.  
  247.   if (profile_block_flag)
  248.     {
  249.       char name[12];
  250.  
  251.       data_section ();
  252.  
  253.       /* Output the main header, of 6 words:
  254.      0:  1 if this file's initialized, else 0.
  255.      1:  address of file name.
  256.      2:  address of table of counts.
  257.      4:  number of counts in the table.
  258.      5:  always 0, for compatibility with Sun.
  259.      6:  extra word added by GNU: address of address table
  260.           which contains addresses of basic blocks,
  261.           in parallel with the table of counts.  */
  262.       ASM_OUTPUT_ALIGN (asm_out_file,
  263.             exact_log2 (min (UNITS_PER_WORD,
  264.                      BIGGEST_ALIGNMENT / BITS_PER_UNIT)));
  265.  
  266.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
  267.       assemble_integer_zero ();
  268.  
  269.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
  270.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  271.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
  272.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  273.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (CONST_INT, VOIDmode,
  274.                          count_basic_blocks));
  275.       assemble_integer_zero ();
  276.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
  277.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  278.  
  279.       /* Output the file name.  */
  280.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
  281.       assemble_string (filename, strlen (filename) + 1);
  282.  
  283.       /* Realign data section.  */
  284.       ASM_OUTPUT_ALIGN (asm_out_file,
  285.             exact_log2 (min (UNITS_PER_WORD,
  286.                      BIGGEST_ALIGNMENT / BITS_PER_UNIT)));
  287.  
  288.       /* Make space for the table of counts.  */
  289.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
  290.       ASM_OUTPUT_SKIP (asm_out_file, UNITS_PER_WORD * count_basic_blocks);
  291.  
  292.       /* Output the table of addresses.  */
  293.       text_section ();
  294.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
  295.       for (i = 0; i < count_basic_blocks; i++)
  296.     {
  297.       char name[12];
  298.       ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
  299.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  300.     }
  301.  
  302.       /* End with the address of the table of addresses,
  303.      so we can find it easily, as the last word in the file's text.  */
  304.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
  305.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  306.     }
  307. }
  308.  
  309. /* Enable APP processing of subsequent output.
  310.    Used before the output from an `asm' statement.  */
  311.  
  312. void
  313. app_enable ()
  314. {
  315.   if (! app_on)
  316.     {
  317.       fprintf (asm_out_file, ASM_APP_ON);
  318.       app_on = 1;
  319.     }
  320. }
  321.  
  322. /* Enable APP processing of subsequent output.
  323.    Called from varasm.c before most kinds of output.  */
  324.  
  325. void
  326. app_disable ()
  327. {
  328.   if (app_on)
  329.     {
  330.       fprintf (asm_out_file, ASM_APP_OFF);
  331.       app_on = 0;
  332.     }
  333. }
  334.  
  335. /* Return the number of slots filled in the current 
  336.    delayed branch sequence. */
  337.  
  338. #ifdef HAVE_DELAYED_BRANCH
  339. int
  340. dbr_sequence_length ()
  341. {
  342.   int i;
  343.   int slots = 0;
  344.   /* It's zero if we are not scheduling or not in a sequence. 
  345.      (We never count the first insn.)                  */
  346.   if (flag_delayed_branch && final_sequence != 0)
  347.     {
  348.       for (i = 1; i < XVECLEN (final_sequence, 0); i++)
  349.     slots += DBR_INSN_SLOTS (XVECEXP (final_sequence, 0, i));
  350.     }
  351.   return slots;
  352. }
  353. #endif
  354.  
  355. /* Output assembler code for the start of a function,
  356.    and initialize some of the variables in this file
  357.    for the new function.  The label for the function and associated
  358.    assembler pseudo-ops have already been output in `assemble_function'.
  359.  
  360.    FIRST is the first insn of the rtl for the function being compiled.
  361.    FILE is the file to write assembler code to.
  362.    WRITE_SYMBOLS says which kind of debugging info to write (or none).
  363.    OPTIMIZE is nonzero if we should eliminate redundant
  364.      test and compare insns.  */
  365.  
  366. void
  367. final_start_function (first, file, write_symbols, optimize)
  368.      rtx first;
  369.      FILE *file;
  370.      enum debugger write_symbols;
  371.      int optimize;
  372. {
  373.   block_depth = 0;
  374.  
  375.   this_is_asm_operands = 0;
  376.  
  377.   /* Record beginning of the symbol-block that's the entire function.  */
  378.  
  379.   if (write_symbols == GDB_DEBUG)
  380.     {
  381.       pending_blocks[block_depth++] = next_block_index;
  382.       fprintf (file, "\t.gdbbeg %d\n", next_block_index++);
  383.     }
  384.  
  385.   /* Initial line number is supposed to be output
  386.      before the function's prologue and label
  387.      so that the function's address will not appear to be
  388.      in the last statement of the preceding function.  */
  389.   if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
  390.     output_source_line (file, first, write_symbols);
  391.  
  392. #ifdef FUNCTION_PROLOGUE
  393.   /* First output the function prologue: code to set up the stack frame.  */
  394.   FUNCTION_PROLOGUE (file, get_frame_size ());
  395. #endif
  396.  
  397. #ifdef SDB_DEBUGGING_INFO
  398.   next_block_index = 1;
  399. #endif
  400.  
  401. #ifdef FUNCTION_BLOCK_PROFILER
  402.   if (profile_block_flag)
  403.     {
  404.       FUNCTION_BLOCK_PROFILER (file, profile_label_no);
  405.     }
  406. #endif /* FUNCTION_BLOCK_PROFILER */
  407.  
  408. #ifndef APPLE_C
  409.   /* This profiling stuff is at best not very useful, so we effectively
  410.      disable it. */
  411.   if (profile_flag)
  412.     {
  413.       int align = min (BIGGEST_ALIGNMENT, BITS_PER_WORD);
  414.       extern int current_function_returns_struct;
  415.       extern int current_function_needs_context;
  416.       int sval = current_function_returns_struct;
  417.       int cxt = current_function_needs_context;
  418.  
  419.       data_section ();
  420.       ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
  421.       ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
  422.       assemble_integer_zero ();
  423.  
  424.       text_section ();
  425.  
  426. #ifdef STRUCT_VALUE_INCOMING_REGNUM
  427.       if (sval)
  428.     ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
  429. #else
  430. #ifdef STRUCT_VALUE_REGNUM
  431.       if (sval)
  432.     ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
  433. #endif
  434. #endif
  435.  
  436. #if 0
  437. #ifdef STATIC_CHAIN_INCOMING_REGNUM
  438.       if (cxt)
  439.     ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
  440. #else
  441. #ifdef STATIC_CHAIN_REGNUM
  442.       if (cxt)
  443.     ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
  444. #endif
  445. #endif
  446. #endif /* 0 */
  447.  
  448.       FUNCTION_PROFILER (file, profile_label_no);
  449.  
  450. #if 0
  451. #ifdef STATIC_CHAIN_INCOMING_REGNUM
  452.       if (cxt)
  453.     ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
  454. #else
  455. #ifdef STATIC_CHAIN_REGNUM
  456.       if (cxt)
  457.     ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
  458. #endif
  459. #endif
  460. #endif /* 0 */
  461.  
  462. #ifdef STRUCT_VALUE_INCOMING_REGNUM
  463.       if (sval)
  464.     ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
  465. #else
  466. #ifdef STRUCT_VALUE_REGNUM
  467.       if (sval)
  468.     ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
  469. #endif
  470. #endif
  471.     }
  472. #endif /* n APPLE_C */
  473.  
  474.   profile_label_no++;
  475. }
  476.  
  477. /* Output assembler code for the end of a function.
  478.    For clarity, args are same as those of `final_start_function'
  479.    even though not all of them are needed.  */
  480.  
  481. void
  482. final_end_function (first, file, write_symbols, optimize)
  483.      rtx first;
  484.      FILE *file;
  485.      enum debugger write_symbols;
  486.      int optimize;
  487. {
  488.   if (app_on)
  489.     {
  490.       fprintf (file, ASM_APP_OFF);
  491.       app_on = 0;
  492.     }
  493.  
  494. #ifndef MPW
  495.   /* MPW can't do anything with gdb symbol stuff. */
  496.   if (write_symbols == GDB_DEBUG)
  497.     fprintf (file, "\t.gdbend %d\n", pending_blocks[0]);
  498. #endif /* n MPW */
  499.  
  500. #ifdef SDB_DEBUGGING_INFO
  501.   if (write_symbols == SDB_DEBUG)
  502.     sdbout_end_function (last_linenum);
  503. #endif
  504.  
  505. #ifdef FUNCTION_EPILOGUE
  506.   /* Finally, output the function epilogue:
  507.      code to restore the stack frame and return to the caller.  */
  508.   FUNCTION_EPILOGUE (file, get_frame_size ());
  509. #endif
  510.  
  511. #ifdef SDB_DEBUGGING_INFO
  512.   if (write_symbols == SDB_DEBUG)
  513.     sdbout_end_epilogue ();
  514. #endif
  515. #ifdef APPLE_HAX
  516.   /* It is sometimes useful to be able to print something special at
  517.      the end of a function. */
  518. #ifdef ASM_FUNCTION_END
  519.   ASM_FUNCTION_END(asm_out_file);
  520. #endif
  521. #endif /* APPLE_HAX */
  522.  
  523.   /* If FUNCTION_EPILOGUE is not defined, then the function body
  524.      itself contains return instructions wherever needed.  */
  525. }
  526.  
  527. /* Output assembler code for some insns: all or part of a function.
  528.    For description of args, see `final_start_function', above.
  529.  
  530.    PRESCAN is 1 if we are not really outputting,
  531.      just scanning as if we were outputting.
  532.    Prescanning deletes and rearranges insns just like ordinary output.
  533.    PRESCAN is -2 if we are outputting after having prescanned.
  534.    In this case, don't try to delete or rearrange insns
  535.    because that has already been done.
  536.    Prescanning is done only on certain machines.  */
  537.  
  538. void
  539. final (first, file, write_symbols, optimize, prescan)
  540.      rtx first;
  541.      FILE *file;
  542.      enum debugger write_symbols;
  543.      int optimize;
  544.      int prescan;
  545. {
  546.   register rtx insn;
  547.  
  548.   last_ignored_compare = 0;
  549.   new_block = 1;
  550.  
  551.   init_recog ();
  552.  
  553.   CC_STATUS_INIT;
  554.  
  555.   for (insn = NEXT_INSN (first); insn;)
  556.     insn = final_scan_insn (insn, file, write_symbols, optimize,
  557.                 prescan, 0);
  558. }
  559.  
  560. /* The final scan for one insn, INSN.
  561.    Args are same as in `final', except that INSN
  562.    is the insn being scanned.
  563.    Value returned is the next insn to be scanned.
  564.  
  565.    NOPEEPHOLES is the flag to disallow peephole processing (currently
  566.    used for within delayed branch sequence output).  */
  567.  
  568. rtx
  569. final_scan_insn  (insn, file, write_symbols, optimize, prescan, nopeepholes)
  570.      rtx insn;
  571.      FILE *file;
  572.      enum debugger write_symbols;
  573.      int optimize;
  574.      int prescan;
  575.      int nopeepholes;
  576. {
  577.   register int i;
  578.   switch (GET_CODE (insn))
  579.     {
  580.     case NOTE:
  581.       if (prescan > 0)
  582.     break;
  583.       if (write_symbols == NO_DEBUG)
  584.     break;
  585.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
  586.     {
  587. #ifdef SDB_DEBUGGING_INFO
  588.       if (write_symbols == SDB_DEBUG)
  589.         sdbout_begin_function (last_linenum);
  590. #endif
  591.       break;
  592.     }
  593.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
  594.       || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
  595.     break;
  596.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
  597.     break;            /* An insn that was "deleted" */
  598.       if (app_on)
  599.     {
  600.       fprintf (file, ASM_APP_OFF);
  601.       app_on = 0;
  602.     }
  603.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
  604.     {
  605.       /* Beginning of a symbol-block.  Assign it a sequence number
  606.          and push the number onto the stack PENDING_BLOCKS.  */
  607.  
  608.       if (block_depth == max_block_depth)
  609.         {
  610.           /* PENDING_BLOCKS is full; make it longer.  */
  611.           max_block_depth *= 2;
  612.           pending_blocks
  613.         = (int *) xrealloc (pending_blocks,
  614.                     max_block_depth * sizeof (int));
  615.         }
  616.       pending_blocks[block_depth++] = next_block_index;
  617.  
  618.       /* Output debugging info about the symbol-block beginning.  */
  619.  
  620. #ifdef SDB_DEBUGGING_INFO
  621.       if (write_symbols == SDB_DEBUG)
  622.         sdbout_begin_block (file, last_linenum, next_block_index);
  623. #endif
  624. #ifdef DBX_DEBUGGING_INFO
  625.       if (write_symbols == DBX_DEBUG)
  626.         ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
  627. #endif
  628.       if (write_symbols == GDB_DEBUG)
  629.         fprintf (file, "\t.gdbbeg %d\n", next_block_index);
  630.  
  631.       next_block_index++;
  632.     }
  633.       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
  634.     {
  635.       /* End of a symbol-block.  Pop its sequence number off
  636.          PENDING_BLOCKS and output debugging info based on that.  */
  637.  
  638.       --block_depth;
  639.  
  640. #ifdef DBX_DEBUGGING_INFO
  641.       if (write_symbols == DBX_DEBUG && block_depth >= 0)
  642.         ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
  643.                        pending_blocks[block_depth]);
  644. #endif
  645.  
  646. #ifdef SDB_DEBUGGING_INFO
  647.       if (write_symbols == SDB_DEBUG && block_depth >= 0)
  648.         sdbout_end_block (file, last_linenum);
  649. #endif
  650.  
  651.       if (write_symbols == GDB_DEBUG)
  652.         fprintf (file, "\t.gdbend %d\n", pending_blocks[block_depth]);
  653.     }
  654.       else if (NOTE_LINE_NUMBER (insn) > 0)
  655.     /* This note is a line-number.  */
  656.     output_source_line (file, insn, write_symbols);
  657.       break;
  658.  
  659.     case BARRIER:
  660. #ifdef ASM_OUTPUT_ALIGN_CODE
  661.       ASM_OUTPUT_ALIGN_CODE (file);
  662. #endif
  663.       break;
  664.  
  665.     case CODE_LABEL:
  666.       CC_STATUS_INIT;
  667.       if (prescan > 0)
  668.     break;
  669.       new_block = 1;
  670.       if (app_on)
  671.     {
  672.       fprintf (file, ASM_APP_OFF);
  673.       app_on = 0;
  674.     }
  675. #ifdef ASM_OUTPUT_CASE_LABEL
  676.       if (NEXT_INSN (insn) != 0
  677.       && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
  678.     {
  679.       rtx nextbody = PATTERN (NEXT_INSN (insn));
  680.  
  681.       /* If this label is followed by a jump-table,
  682.          output the two of them together in a special way.  */
  683.  
  684.       if (GET_CODE (nextbody) == ADDR_VEC
  685.           || GET_CODE (nextbody) == ADDR_DIFF_VEC)
  686.         {
  687.           ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
  688.                      NEXT_INSN (insn));
  689.           break;
  690.         }
  691.     }
  692. #endif
  693.  
  694.       ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
  695.       break;
  696.  
  697.     default:
  698.       {
  699.     register rtx body = PATTERN (insn);
  700.     int insn_code_number;
  701.     char *template;
  702.  
  703.     /* An INSN, JUMP_INSN or CALL_INSN.
  704.        First check for special kinds that recog doesn't recognize.  */
  705.  
  706.     if (GET_CODE (body) == USE /* These are just declarations */
  707.         || GET_CODE (body) == CLOBBER)
  708.       break;
  709.  
  710.     if (profile_block_flag && new_block)
  711.       {
  712.         new_block = 0;
  713.         /* Enable the table of basic-block use counts
  714.            to point at the code it applies to.  */
  715.         ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
  716.         /* Before first insn of this basic block, increment the
  717.            count of times it was entered.  */
  718. #ifdef BLOCK_PROFILER
  719.         BLOCK_PROFILER (file, count_basic_blocks);
  720. #endif
  721.         count_basic_blocks++;
  722.       }
  723.  
  724.     if (GET_CODE (body) == ASM_INPUT)
  725.       {
  726.         /* There's no telling what that did to the condition codes.  */
  727.         CC_STATUS_INIT;
  728.         if (prescan > 0)
  729.           break;
  730.         if (! app_on)
  731.           {
  732.         fprintf (file, ASM_APP_ON);
  733.         app_on = 1;
  734.           }
  735.         fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
  736.         break;
  737.       }
  738.  
  739.     /* Detect `asm' construct with operands.  */
  740.     if (asm_noperands (body) >= 0)
  741.       {
  742.         int noperands = asm_noperands (body);
  743.         rtx *ops;
  744.         char *string;
  745.  
  746.         /* There's no telling what that did to the condition codes.  */
  747.         CC_STATUS_INIT;
  748.         if (prescan > 0)
  749.           break;
  750.  
  751.         /* alloca won't do here, since only return from `final'
  752.            would free it.  */
  753.         if (noperands > 0)
  754.           ops = (rtx *) xmalloc (noperands * sizeof (rtx));
  755.  
  756.         if (! app_on)
  757.           {
  758.         fprintf (file, ASM_APP_ON);
  759.         app_on = 1;
  760.           }
  761.  
  762.         /* Get out the operand values.  */
  763.         string = decode_asm_operands (body, ops, 0, 0, 0);
  764.         /* Inhibit aborts on what would otherwise be compiler bugs.  */
  765.         insn_noperands = noperands;
  766.         this_is_asm_operands = insn;
  767.         /* Output the insn using them.  */
  768.         output_asm_insn (string, ops);
  769.         this_is_asm_operands = 0;
  770.         if (noperands > 0)
  771.           free (ops);
  772.         break;
  773.       }
  774.  
  775.     if (prescan <= 0 && app_on)
  776.       {
  777.         fprintf (file, ASM_APP_OFF);
  778.         app_on = 0;
  779.       }
  780.  
  781.     /* Detect insns that are really jump-tables
  782.        and output them as such.  */
  783.  
  784.     if (GET_CODE (body) == ADDR_VEC)
  785.       {
  786.         register int vlen, idx;
  787.  
  788.         if (prescan > 0)
  789.           break;
  790.  
  791.         vlen = XVECLEN (body, 0);
  792.         for (idx = 0; idx < vlen; idx++)
  793.           ASM_OUTPUT_ADDR_VEC_ELT (file,
  794.                        CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
  795. #ifdef ASM_OUTPUT_CASE_END
  796.         ASM_OUTPUT_CASE_END (file,
  797.                  CODE_LABEL_NUMBER (PREV_INSN (insn)),
  798.                  insn);
  799. #endif
  800.         break;
  801.       }
  802.     if (GET_CODE (body) == ADDR_DIFF_VEC)
  803.       {
  804.         register int vlen, idx;
  805.  
  806.         if (prescan > 0)
  807.           break;
  808.  
  809.         vlen = XVECLEN (body, 1);
  810.         for (idx = 0; idx < vlen; idx++)
  811.           ASM_OUTPUT_ADDR_DIFF_ELT (file,
  812.                     CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
  813.                     CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
  814. #ifdef ASM_OUTPUT_CASE_END
  815.         ASM_OUTPUT_CASE_END (file,
  816.                  CODE_LABEL_NUMBER (PREV_INSN (insn)),
  817.                  insn);
  818. #endif
  819.         break;
  820.       }
  821.  
  822.     if (recog_memoized (insn) == -1
  823.         && GET_CODE (body) == SEQUENCE) /* A delayed-branch sequence */
  824.       {
  825.         register int i;
  826.         if (prescan > 0)
  827.           break;
  828.         final_sequence = body;
  829.         for (i = 0; i < XVECLEN (body, 0); i++)
  830.           final_scan_insn (XVECEXP (body, 0, i), file, write_symbols,
  831.                    optimize, prescan, 1);
  832.         final_sequence = 0;
  833. #ifdef DBR_OUTPUT_SEQEND
  834.         DBR_OUTPUT_SEQEND (file);
  835. #endif
  836.         break;
  837.       }
  838.  
  839.     /* We have a real machine instruction as rtl.  */
  840.  
  841.     body = PATTERN (insn);
  842.  
  843.     /* Check for redundant test and compare instructions
  844.        (when the condition codes are already set up as desired).
  845.        This is done only when optimizing; if not optimizing,
  846.        it should be possible for the user to alter a variable
  847.        with the debugger in between statements
  848.        and the next statement should reexamine the variable
  849.        to compute the condition codes.  */
  850.  
  851.     if (optimize
  852.         && GET_CODE (body) == SET
  853.         && GET_CODE (SET_DEST (body)) == CC0
  854.         && insn != last_ignored_compare)
  855.       {
  856.         if (GET_CODE (SET_SRC (body)) == SUBREG)
  857.           SET_SRC (body) = alter_subreg (SET_SRC (body));
  858.         if ((cc_status.value1 != 0
  859.          && rtx_equal_p (SET_SRC (body), cc_status.value1))
  860.         || (cc_status.value2 != 0
  861.             && rtx_equal_p (SET_SRC (body), cc_status.value2)))
  862.           {
  863.         /* Don't delete insn if has an addressing side-effect */
  864.         if (! find_reg_note (insn, REG_INC, 0)
  865.             /* or if anything in it is volatile.  */
  866.             && ! volatile_refs_p (PATTERN (insn)))
  867.           {
  868.             /* We don't really delete the insn; just ignore it.  */
  869.             last_ignored_compare = insn;
  870.             break;
  871.           }
  872.           }
  873.       }
  874.  
  875.     /* Following a conditional branch, we have a new basic block.  */
  876.     if (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
  877.         && GET_CODE (SET_SRC (body)) != LABEL_REF)
  878.       new_block = 1;
  879.  
  880.     /* If this is a conditional branch, maybe modify it
  881.        if the cc's are in a nonstandard state
  882.        so that it accomplishes the same thing that it would
  883.        do straightforwardly if the cc's were set up normally.  */
  884.  
  885.     if (cc_status.flags != 0
  886.         && GET_CODE (insn) == JUMP_INSN
  887.         && GET_CODE (body) == SET
  888.         && SET_DEST (body) == pc_rtx
  889.         && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
  890.         /* This is done during prescan; it is not done again
  891.            in final scan when prescan has been done.  */
  892.         && prescan >= 0)
  893.       {
  894.         /* This function may alter the contents of its argument
  895.            and clear some of the cc_status.flags bits.
  896.            It may also return 1 meaning condition now always true
  897.            or -1 meaning condition now always false
  898.            or 2 meaning condition nontrivial but altered.  */
  899.         register int result = alter_cond (XEXP (SET_SRC (body), 0));
  900.         /* If condition now has fixed value, replace the IF_THEN_ELSE
  901.            with its then-operand or its else-operand.  */
  902.         if (result == 1)
  903.           SET_SRC (body) = XEXP (SET_SRC (body), 1);
  904.         if (result == -1)
  905.           SET_SRC (body) = XEXP (SET_SRC (body), 2);
  906.         /* The jump is now either unconditional or a no-op.
  907.            If it has become a no-op, don't try to output it.
  908.            (It would not be recognized.)  */
  909.         if (SET_SRC (body) == pc_rtx)
  910.           {
  911.         PUT_CODE (insn, NOTE);
  912.         NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  913.         NOTE_SOURCE_FILE (insn) = 0;
  914.         break;
  915.           }
  916.         /* Rerecognize the instruction if it has changed.  */
  917.         if (result != 0)
  918.           INSN_CODE (insn) = -1;
  919.       }
  920.  
  921. #ifdef STORE_FLAG_VALUE
  922.     /* Make same adjustments to instructions that examine the
  923.        condition codes without jumping (if this machine has them).  */
  924.  
  925.     if (cc_status.flags != 0
  926.         && GET_CODE (body) == SET)
  927.       switch (GET_CODE (SET_SRC (body)))
  928.         {
  929.         case GTU:
  930.         case GT:
  931.         case LTU:
  932.         case LT:
  933.         case GEU:
  934.         case GE:
  935.         case LEU:
  936.         case LE:
  937.         case EQ:
  938.         case NE:
  939.           {
  940.         register int result;
  941.         if (GET_CODE (XEXP (SET_SRC (body), 0)) != CC0)
  942.           break;
  943.         result = alter_cond (SET_SRC (body));
  944.         if (result == 1)
  945.           SET_SRC (body) = gen_rtx (CONST_INT, VOIDmode,
  946.                         STORE_FLAG_VALUE);
  947.         if (result == -1)
  948.           SET_SRC (body) = const0_rtx;
  949.         if (result != 0)
  950.           INSN_CODE (insn) = -1;
  951.           }
  952.         }
  953. #endif                /* STORE_FLAG_VALUE */
  954.  
  955.     /* Do machine-specific peephole optimizations if desired.  */
  956.  
  957.     if (optimize && !flag_no_peephole && !nopeepholes)
  958.       {
  959.         rtx next = peephole (insn);
  960.         /* When peepholing, if there were notes within the peephole,
  961.            emit them before the peephole.  */
  962.         if (next != 0 && next != NEXT_INSN (insn))
  963.           {
  964.         rtx note = NEXT_INSN (insn);
  965.         rtx prev = PREV_INSN (insn);
  966.         while (note != next)
  967.           {
  968.             final_scan_insn (note, file, write_symbols, optimize,
  969.                      prescan, nopeepholes);
  970.             note = NEXT_INSN (note);
  971.           }
  972.         /* In case this is prescan, put the notes
  973.            in proper position for later rescan.  */
  974.         note = NEXT_INSN (insn);
  975.         PREV_INSN (note) = prev;
  976.         NEXT_INSN (prev) = note;
  977.         NEXT_INSN (PREV_INSN (next)) = insn;
  978.         PREV_INSN (insn) = PREV_INSN (next);
  979.         NEXT_INSN (insn) = next;
  980.         PREV_INSN (next) = insn;
  981.           }
  982.  
  983.         /* PEEPHOLE might have changed this.  */
  984.         body = PATTERN (insn);
  985.       }
  986.  
  987.     /* Try to recognize the instruction.
  988.        If successful, verify that the operands satisfy the
  989.        constraints for the instruction.  Crash if they don't,
  990.        since `reload' should have changed them so that they do.  */
  991.  
  992.     insn_code_number = recog_memoized (insn);
  993.     insn_extract (insn);
  994.     for (i = 0; i < insn_n_operands[insn_code_number]; i++)
  995.       {
  996.         if (GET_CODE (recog_operand[i]) == SUBREG)
  997.           recog_operand[i] = alter_subreg (recog_operand[i]);
  998.       }
  999.  
  1000. #ifdef REGISTER_CONSTRAINTS
  1001. #ifdef MPW
  1002.     /* A common place to visit Macsbug from... */
  1003.     if (! constrain_operands (insn_code_number)) {
  1004.       fprintf (stderr, "Register constraints violated!\n Insn was\n");
  1005.       debug_rtx (insn);
  1006.       abort ();
  1007.     }
  1008. #else
  1009.     if (! constrain_operands (insn_code_number))
  1010.       abort ();
  1011. #endif /* MPW */
  1012. #endif
  1013.  
  1014.     /* Some target machines need to prescan each insn before
  1015.        it is output.  */
  1016.  
  1017. #ifdef FINAL_PRESCAN_INSN
  1018.     FINAL_PRESCAN_INSN (insn, recog_operand,
  1019.                 insn_n_operands[insn_code_number]);
  1020. #endif
  1021.  
  1022.     cc_prev_status = cc_status;
  1023.  
  1024.     /* Update `cc_status' for this instruction.
  1025.        The instruction's output routine may change it further.
  1026.        If the output routine for a jump insn needs to depend
  1027.        on the cc status, it should look at cc_prev_status.  */
  1028.  
  1029.     NOTICE_UPDATE_CC (body, insn);
  1030.  
  1031.     /* If the proper template needs to be chosen by some C code,
  1032.        run that code and get the real template.  */
  1033.  
  1034.     template = insn_template[insn_code_number];
  1035.     if (template == 0)
  1036.       {
  1037.         template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
  1038.  
  1039.         /* If the C code returns 0, it means that it is a jump insn
  1040.            which follows a deleted test insn, and that test insn
  1041.            needs to be reinserted.  */
  1042.         if (template == 0)
  1043.           {
  1044.         if (PREV_INSN (insn) != last_ignored_compare)
  1045.           abort ();
  1046.         new_block = 0;
  1047.         return PREV_INSN (insn);
  1048.           }
  1049.       }
  1050.  
  1051.     if (prescan > 0)
  1052.       break;
  1053.  
  1054.     /* Output assembler code from the template.  */
  1055.  
  1056.     output_asm_insn (template, recog_operand);
  1057.  
  1058.     /* Mark this insn as having been output.  */
  1059.     INSN_DELETED_P (insn) = 1;
  1060.       }
  1061.     }
  1062.   return NEXT_INSN (insn);
  1063. }
  1064.  
  1065. /* Set up FILENAME as the current file for GDB line-number output.  */
  1066.  
  1067. void
  1068. set_current_gdbfile (filename)
  1069.      char *filename;
  1070. {
  1071.   register struct gdbfile *f;
  1072.   for (f = gdbfiles; f; f = f->next)
  1073.     if (!strcmp (f->name, filename))
  1074.       break;
  1075.  
  1076.   if (!f)
  1077.     {
  1078.       f = (struct gdbfile *) permalloc (sizeof (struct gdbfile));
  1079.       f->next = gdbfiles;
  1080.       gdbfiles = f;
  1081.       f->name = filename;
  1082.       f->filenum = next_gdb_filenum++;
  1083.       f->nlines = 0;
  1084.     }
  1085.   current_gdbfile = f;
  1086.   lastfile = filename;
  1087. }
  1088.  
  1089. /* Output debugging info to the assembler file FILE
  1090.    based on the NOTE-insn INSN, assumed to be a line number.  */
  1091.  
  1092. static void
  1093. output_source_line (file, insn, write_symbols)
  1094.      FILE *file;
  1095.      rtx insn;
  1096.      enum debugger write_symbols;
  1097. {
  1098.   register char *filename = NOTE_SOURCE_FILE (insn);
  1099.  
  1100.   last_linenum = NOTE_LINE_NUMBER (insn);
  1101.  
  1102.   if (write_symbols == GDB_DEBUG)
  1103.     {
  1104.       /* Output GDB-format line number info.  */
  1105.  
  1106.       /* If this is not the same source file as last time,
  1107.      find or assign a GDB-file-number to this file.  */
  1108.       if (filename && (lastfile == 0 || strcmp (filename, lastfile)
  1109.                || current_gdbfile == 0))
  1110.     set_current_gdbfile (filename);
  1111.  
  1112.       ++current_gdbfile->nlines;
  1113.       fprintf (file, "\t.gdbline %d,%d\n",
  1114.            current_gdbfile->filenum, NOTE_LINE_NUMBER (insn));
  1115.     }
  1116.  
  1117.   if (write_symbols == SDB_DEBUG || write_symbols == DBX_DEBUG)
  1118.     {
  1119. #ifdef SDB_DEBUGGING_INFO
  1120.       if (write_symbols == SDB_DEBUG
  1121. #if 0 /* People like having line numbers even in wrong file!  */
  1122.       /* COFF can't handle multiple source files--lose, lose.  */
  1123.       && !strcmp (filename, main_input_filename)
  1124. #endif
  1125.       /* COFF relative line numbers must be positive.  */
  1126.       && last_linenum > sdb_begin_function_line)
  1127.     {
  1128. #ifdef ASM_OUTPUT_SOURCE_LINE
  1129.       ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
  1130. #else
  1131.       fprintf (file, "\t.ln\t%d\n",
  1132.            (sdb_begin_function_line
  1133.             ? last_linenum - sdb_begin_function_line : 1));
  1134. #endif
  1135.     }
  1136. #endif
  1137.  
  1138. #ifdef DBX_DEBUGGING_INFO
  1139.       if (write_symbols == DBX_DEBUG)
  1140.     {
  1141.       /* Write DBX line number data.  */
  1142.  
  1143.       if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
  1144.         {
  1145. #ifdef ASM_OUTPUT_SOURCE_FILENAME
  1146.           ASM_OUTPUT_SOURCE_FILENAME (file, filename);
  1147. #else
  1148.           fprintf (file, "\t.stabs \"%s\",%d,0,0,Ltext\n",
  1149.                filename, N_SOL);
  1150. #endif
  1151.           lastfile = filename;
  1152.         }
  1153.     }
  1154.  
  1155. #ifdef ASM_OUTPUT_SOURCE_LINE
  1156.       ASM_OUTPUT_SOURCE_LINE (file, NOTE_LINE_NUMBER (insn));
  1157. #else
  1158.       fprintf (file, "\t.stabd %d,0,%d\n",
  1159.            N_SLINE, NOTE_LINE_NUMBER (insn));
  1160. #endif
  1161. #endif /* DBX_DEBUGGING_INFO */
  1162.     }
  1163. }
  1164.  
  1165. /* If X is a SUBREG, replace it with a REG or a MEM,
  1166.    based on the thing it is a subreg of.  */
  1167.  
  1168. rtx
  1169. alter_subreg (x)
  1170.      register rtx x;
  1171. {
  1172.   register rtx y = SUBREG_REG (x);
  1173.   if (GET_CODE (y) == SUBREG)
  1174.     y = alter_subreg (y);
  1175.  
  1176.   if (GET_CODE (y) == REG)
  1177.     {
  1178.       /* If the containing reg really gets a hard reg, so do we.  */
  1179.       PUT_CODE (x, REG);
  1180.       REGNO (x) = REGNO (y) + SUBREG_WORD (x);
  1181.     }
  1182.   else if (GET_CODE (y) == MEM)
  1183.     {
  1184.       register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  1185. #ifdef BYTES_BIG_ENDIAN
  1186.       offset -= (min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
  1187.          - min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
  1188. #endif
  1189.       PUT_CODE (x, MEM);
  1190.       MEM_VOLATILE_P (x) = MEM_VOLATILE_P (y);
  1191.       XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
  1192.     }
  1193.   else if (GET_CODE (y) == CONST_DOUBLE)
  1194.     return y;
  1195.  
  1196.   return x;
  1197. }
  1198.  
  1199. /* Do alter_subreg on all the SUBREGs contained in X.  */
  1200.  
  1201. static rtx
  1202. walk_alter_subreg (x)
  1203.      rtx x;
  1204. {
  1205.   switch (GET_CODE (x))
  1206.     {
  1207.     case PLUS:
  1208.     case MULT:
  1209.       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
  1210.       XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
  1211.       break;
  1212.  
  1213.     case MEM:
  1214.       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
  1215.       break;
  1216.  
  1217.     case SUBREG:
  1218.       return alter_subreg (x);
  1219.     }
  1220.  
  1221.   return x;
  1222. }
  1223.  
  1224. /* Given BODY, the body of a jump instruction, alter the jump condition
  1225.    as required by the bits that are set in cc_status.flags.
  1226.    Not all of the bits there can be handled at this level in all cases.
  1227.  
  1228.    The value is normally 0.
  1229.    1 means that the condition has become always true.
  1230.    -1 means that the condition has become always false.
  1231.    2 means that COND has been altered.  */
  1232.  
  1233. static int
  1234. alter_cond (cond)
  1235.      register rtx cond;
  1236. {
  1237.   int value = 0;
  1238.  
  1239.   if (cc_status.flags & CC_REVERSED)
  1240.     {
  1241.       value = 2;
  1242.       switch (GET_CODE (cond))
  1243.     {
  1244.     case LE:
  1245.       PUT_CODE (cond, GE);
  1246.       break;
  1247.     case GE:
  1248.       PUT_CODE (cond, LE);
  1249.       break;
  1250.     case LT:
  1251.       PUT_CODE (cond, GT);
  1252.       break;
  1253.     case GT:
  1254.       PUT_CODE (cond, LT);
  1255.       break;
  1256.     case LEU:
  1257.       PUT_CODE (cond, GEU);
  1258.       break;
  1259.     case GEU:
  1260.       PUT_CODE (cond, LEU);
  1261.       break;
  1262.     case LTU:
  1263.       PUT_CODE (cond, GTU);
  1264.       break;
  1265.     case GTU:
  1266.       PUT_CODE (cond, LTU);
  1267.       break;
  1268.     }
  1269.     }
  1270.  
  1271.   if (cc_status.flags & CC_NOT_POSITIVE)
  1272.     switch (GET_CODE (cond))
  1273.       {
  1274.       case LE:
  1275.       case LEU:
  1276.       case GEU:
  1277.     /* Jump becomes unconditional.  */
  1278.     return 1;
  1279.  
  1280.       case GT:
  1281.       case GTU:
  1282.       case LTU:
  1283.     /* Jump becomes no-op.  */
  1284.     return -1;
  1285.  
  1286.       case GE:
  1287.     PUT_CODE (cond, EQ);
  1288.     value = 2;
  1289.     break;
  1290.  
  1291.       case LT:
  1292.     PUT_CODE (cond, NE);
  1293.     value = 2;
  1294.     break;
  1295.       }
  1296.  
  1297.   if (cc_status.flags & CC_NOT_NEGATIVE)
  1298.     switch (GET_CODE (cond))
  1299.       {
  1300.       case GE:
  1301.       case GEU:
  1302.     /* Jump becomes unconditional.  */
  1303.     return 1;
  1304.  
  1305.       case LT:
  1306.       case LTU:
  1307.     /* Jump becomes no-op.  */
  1308.     return -1;
  1309.  
  1310.       case LE:
  1311.       case LEU:
  1312.     PUT_CODE (cond, EQ);
  1313.     value = 2;
  1314.     break;
  1315.  
  1316.       case GT:
  1317.       case GTU:
  1318.     PUT_CODE (cond, NE);
  1319.     value = 2;
  1320.     break;
  1321.       }
  1322.  
  1323.   if (cc_status.flags & CC_NO_OVERFLOW)
  1324.     switch (GET_CODE (cond))
  1325.       {
  1326.       case GEU:
  1327.     /* Jump becomes unconditional.  */
  1328.     return 1;
  1329.  
  1330.       case LEU:
  1331.     PUT_CODE (cond, EQ);
  1332.     value = 2;
  1333.     break;
  1334.  
  1335.       case GTU:
  1336.     PUT_CODE (cond, NE);
  1337.     value = 2;
  1338.     break;
  1339.  
  1340.       case LTU:
  1341.     /* Jump becomes no-op.  */
  1342.     return -1;
  1343.       }
  1344.  
  1345.   if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
  1346.     switch (GET_CODE (cond))
  1347.       {
  1348.       case LE:
  1349.       case LEU:
  1350.       case GE:
  1351.       case GEU:
  1352.       case LT:
  1353.       case LTU:
  1354.       case GT:
  1355.       case GTU:
  1356.     abort ();
  1357.  
  1358.       case NE:
  1359.     PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
  1360.     value = 2;
  1361.     break;
  1362.  
  1363.       case EQ:
  1364.     PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
  1365.     value = 2;
  1366.     break;
  1367.       }
  1368.   
  1369.   return value;
  1370. }
  1371.  
  1372. /* Report inconsistency between the assembler template and the operands.
  1373.    In an `asm', it's the user's fault; otherwise, the compiler's fault.  */
  1374.  
  1375. static void
  1376. output_operand_lossage (str)
  1377.      char *str;
  1378. {
  1379.   if (this_is_asm_operands)
  1380.     error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
  1381.   else
  1382. #ifdef MPW
  1383.     /* Another place where some more info is helpful in MPW debugging. */
  1384.     {
  1385.       fprintf (stderr, "Invalid asm - %s", str);
  1386.       abort ();
  1387.     }
  1388. #else
  1389.     abort ();
  1390. #endif /* MPW */
  1391. }
  1392.  
  1393. /* Output of assembler code from a template, and its subroutines.  */
  1394.  
  1395. /* Output text from TEMPLATE to the assembler output file,
  1396.    obeying %-directions to substitute operands taken from
  1397.    the vector OPERANDS.
  1398.  
  1399.    %N (for N a digit) means print operand N in usual manner.
  1400.    %lN means require operand N to be a CODE_LABEL or LABEL_REF
  1401.       and print the label name with no punctuation.
  1402.    %cN means require operand N to be a constant
  1403.       and print the constant expression with no punctuation.
  1404.    %aN means expect operand N to be a memory address
  1405.       (not a memory reference!) and print a reference
  1406.       to that address.
  1407.    %nN means expect operand N to be a constant
  1408.       and print a constant expression for minus the value
  1409.       of the operand, with no other punctuation.  */
  1410.  
  1411. void
  1412. output_asm_insn (template, operands)
  1413.      char *template;
  1414.      rtx *operands;
  1415. {
  1416.   register char *p;
  1417.   register int c;
  1418.  
  1419.   /* An insn may return a null string template
  1420.      in a case where no assembler code is needed.  */
  1421.   if (*template == 0)
  1422.     return;
  1423.  
  1424. #ifdef MPW
  1425.   cursor_count++;
  1426.   if ((cursor_count % 5) == 0)
  1427.       SpinCursor(1);
  1428. #endif
  1429.  
  1430.   p = template;
  1431.   putc ('\t', asm_out_file);
  1432.  
  1433. #ifdef ASM_OUTPUT_OPCODE
  1434.   ASM_OUTPUT_OPCODE (asm_out_file, p);
  1435. #endif
  1436.  
  1437.   while (c = *p++)
  1438.     {
  1439. #ifdef ASM_OUTPUT_OPCODE
  1440.       if (c == '\n')
  1441.     {
  1442.       putc (c, asm_out_file);
  1443.       while ((c = *p) == '\t')
  1444.         {
  1445.           putc (c, asm_out_file);
  1446.           p++;
  1447.         }
  1448.       ASM_OUTPUT_OPCODE (asm_out_file, p);
  1449.     }
  1450.       else
  1451. #endif
  1452.       if (c != '%')
  1453.     putc (c, asm_out_file);
  1454.       else
  1455.     {
  1456.       /* %% outputs a single %.  */
  1457.       if (*p == '%')
  1458.         {
  1459.           p++;
  1460.           putc (c, asm_out_file);
  1461.         }
  1462.       /* % followed by a letter and some digits
  1463.          outputs an operand in a special way depending on the letter.
  1464.          Letters `acln' are implemented here.
  1465.          Other letters are passed to `output_operand' so that
  1466.          the PRINT_OPERAND macro can define them.  */
  1467.       else if ((*p >= 'a' && *p <= 'z')
  1468.            || (*p >= 'A' && *p <= 'Z'))
  1469.         {
  1470.           int letter = *p++;
  1471.           c = atoi (p);
  1472.  
  1473.           if (! (*p >= '0' && *p <= '9'))
  1474.         output_operand_lossage ("operand number missing after %-letter");
  1475.           else if (this_is_asm_operands && c >= (unsigned) insn_noperands)
  1476.         output_operand_lossage ("operand number out of range");
  1477.           else if (letter == 'l')
  1478.         output_asm_label (operands[c]);
  1479.           else if (letter == 'a')
  1480.         output_address (operands[c]);
  1481.           else if (letter == 'c')
  1482.         {
  1483.           if (CONSTANT_ADDRESS_P (operands[c]))
  1484.             output_addr_const (asm_out_file, operands[c]);
  1485.           else
  1486.             output_operand (operands[c], 'c');
  1487.         }
  1488.           else if (letter == 'n')
  1489.         {
  1490.           if (GET_CODE (operands[c]) == CONST_INT)
  1491.             fprintf (asm_out_file, "%d", - INTVAL (operands[c]));
  1492.           else
  1493.             {
  1494.               putc ('-', asm_out_file);
  1495.               output_addr_const (asm_out_file, operands[c]);
  1496.             }
  1497.         }
  1498.           else
  1499.         output_operand (operands[c], letter);
  1500.  
  1501.           while ((c = *p) >= '0' && c <= '9') p++;
  1502.         }
  1503.       /* % followed by a digit outputs an operand the default way.  */
  1504.       else if (*p >= '0' && *p <= '9')
  1505.         {
  1506.           c = atoi (p);
  1507.           if (this_is_asm_operands && c >= (unsigned) insn_noperands)
  1508.         output_operand_lossage ("operand number out of range");
  1509.           else
  1510.         output_operand (operands[c], 0);
  1511.           while ((c = *p) >= '0' && c <= '9') p++;
  1512.         }
  1513.       /* % followed by punctuation: output something for that
  1514.          punctuation character alone, with no operand.
  1515.          The PRINT_OPERAND macro decides what is actually done.  */
  1516. #ifdef PRINT_OPERAND_PUNCT_VALID_P
  1517.       else if (PRINT_OPERAND_PUNCT_VALID_P (*p))
  1518.         output_operand (0, *p++);
  1519. #endif
  1520.       else
  1521.         output_operand_lossage ("invalid %%-code");
  1522.     }
  1523.     }
  1524.  
  1525.   putc ('\n', asm_out_file);
  1526. }
  1527.  
  1528. /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol.  */
  1529.  
  1530. void
  1531. output_asm_label (x)
  1532.      rtx x;
  1533. {
  1534.   char buf[256];
  1535.  
  1536.   if (GET_CODE (x) == LABEL_REF)
  1537.     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
  1538.   else if (GET_CODE (x) == CODE_LABEL)
  1539.     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
  1540.   else
  1541.     output_operand_lossage ("`%l' operand isn't a label");
  1542.  
  1543.   assemble_name (asm_out_file, buf);
  1544. }
  1545.  
  1546. /* Print operand X using machine-dependent assembler syntax.
  1547.    The macro PRINT_OPERAND is defined just to control this function.
  1548.    CODE is a non-digit that preceded the operand-number in the % spec,
  1549.    such as 'z' if the spec was `%z3'.  CODE is 0 if there was no char
  1550.    between the % and the digits.
  1551.    When CODE is a non-letter, X is 0.
  1552.  
  1553.    The meanings of the letters are machine-dependent and controlled
  1554.    by PRINT_OPERAND.  */
  1555.  
  1556. static void
  1557. output_operand (x, code)
  1558.      rtx x;
  1559.      int code;
  1560. {
  1561.   if (x && GET_CODE (x) == SUBREG)
  1562.     x = alter_subreg (x);
  1563.   PRINT_OPERAND (asm_out_file, x, code);
  1564. }
  1565.  
  1566. /* Print a memory reference operand for address X
  1567.    using machine-dependent assembler syntax.
  1568.    The macro PRINT_OPERAND_ADDRESS exists just to control this function.  */
  1569.  
  1570. void
  1571. output_address (x)
  1572.      rtx x;
  1573. {
  1574.   walk_alter_subreg (x);
  1575.   PRINT_OPERAND_ADDRESS (asm_out_file, x);
  1576. }
  1577.  
  1578. /* Print an integer constant expression in assembler syntax.
  1579.    Addition and subtraction are the only arithmetic
  1580.    that may appear in these expressions.  */
  1581.  
  1582. void
  1583. output_addr_const (file, x)
  1584.      FILE *file;
  1585.      rtx x;
  1586. {
  1587.   char buf[256];
  1588.  
  1589.  restart:
  1590.   switch (GET_CODE (x))
  1591.     {
  1592.     case SYMBOL_REF:
  1593.       assemble_name (file, XSTR (x, 0));
  1594.       break;
  1595.  
  1596.     case LABEL_REF:
  1597.       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
  1598.       assemble_name (asm_out_file, buf);
  1599.       break;
  1600.  
  1601.     case CODE_LABEL:
  1602.       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
  1603.       assemble_name (asm_out_file, buf);
  1604.       break;
  1605.  
  1606.     case CONST_INT:
  1607.       fprintf (file, "%d", INTVAL (x));
  1608.       break;
  1609.  
  1610.     case CONST:
  1611.       x = XEXP (x, 0);
  1612.       goto restart;
  1613.  
  1614.     case CONST_DOUBLE:
  1615.       if (GET_MODE (x) == DImode)
  1616.     {
  1617.       /* We can use %d if the number is <32 bits and positive.  */
  1618.       if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
  1619.         fprintf (file, "0x%x%08x",
  1620.              CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
  1621.       else
  1622.         fprintf (file, "%d", CONST_DOUBLE_LOW (x));
  1623.     }
  1624.       else
  1625.     /* We can't handle floating point constants;
  1626.        PRINT_OPERAND must handle them.  */
  1627.     output_operand_lossage ("floating constant misused");
  1628.       break;
  1629.  
  1630.     case PLUS:
  1631.       /* Some assemblers need integer constants to appear last (eg masm).  */
  1632.       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
  1633.     {
  1634.       output_addr_const (file, XEXP (x, 1));
  1635.       if (INTVAL (XEXP (x, 0)) >= 0)
  1636.         fprintf (file, "+");
  1637.       output_addr_const (file, XEXP (x, 0));
  1638.     }
  1639.       else
  1640.     {
  1641.       output_addr_const (file, XEXP (x, 0));
  1642.       if (INTVAL (XEXP (x, 1)) >= 0)
  1643.         fprintf (file, "+");
  1644.       output_addr_const (file, XEXP (x, 1));
  1645.     }
  1646.       break;
  1647.  
  1648.     case MINUS:
  1649.       output_addr_const (file, XEXP (x, 0));
  1650.       fprintf (file, "-");
  1651.       output_addr_const (file, XEXP (x, 1));
  1652.       break;
  1653.  
  1654.     default:
  1655.       output_operand_lossage ("invalid expression as operand");
  1656.     }
  1657. }
  1658.  
  1659.  
  1660. init_final2()
  1661. {
  1662. #define INIT_FINAL
  1663. #include "init.c"
  1664. }
  1665.