Annotation of gcc/final.c, revision 1.1.1.11

1.1       root        1: /* Convert RTL to assembler code and output it, for GNU compiler.
1.1.1.2   root        2:    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
1.1       root        3: 
                      4: This file is part of GNU CC.
                      5: 
                      6: GNU CC is distributed in the hope that it will be useful,
                      7: but WITHOUT ANY WARRANTY.  No author or distributor
                      8: accepts responsibility to anyone for the consequences of using it
                      9: or for whether it serves any particular purpose or works at all,
                     10: unless he says so in writing.  Refer to the GNU CC General Public
                     11: License for full details.
                     12: 
                     13: Everyone is granted permission to copy, modify and redistribute
                     14: GNU CC, but only under the conditions described in the
                     15: GNU CC General Public License.   A copy of this license is
                     16: supposed to have been given to you along with GNU CC so you
                     17: can know your rights and responsibilities.  It should be in a
                     18: file named COPYING.  Among other things, the copyright notice
                     19: and this notice must be preserved on all copies.  */
                     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: 
1.1.1.2   root       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'.
1.1       root       30: 
                     31:    Some optimizations are also done at this level.
                     32:    Move instructions that were made unnecessary by good register allocation
1.1.1.2   root       33:    are detected and omitted from the output.  (Though most of these
                     34:    are removed by the last jump pass.)
                     35: 
1.1       root       36:    Instructions to set the condition codes are omitted when it can be
                     37:    seen that the condition codes already had the desired values.
1.1.1.2   root       38: 
1.1       root       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"
1.1.1.2   root       54: #include "gdbfiles.h"
1.1.1.4   root       55: #include "flags.h"
1.1.1.2   root       56: 
1.1.1.3   root       57: /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist.  */
1.1.1.4   root       58: #ifdef DBX_DEBUGGING_INFO
1.1.1.3   root       59: #include <stab.h>
                     60: #endif
                     61: 
1.1.1.2   root       62: /* .stabd code for line number.  */
                     63: #ifndef N_SLINE
                     64: #define        N_SLINE 0x44
                     65: #endif
                     66: 
                     67: /* .stabs code for included file name.  */
                     68: #ifndef N_SOL
                     69: #define        N_SOL 0x84
                     70: #endif
1.1       root       71: 
                     72: #define min(A,B) ((A) < (B) ? (A) : (B))
                     73: 
                     74: void output_asm_insn ();
1.1.1.10  root       75: rtx alter_subreg ();
1.1       root       76: static int alter_cond ();
1.1.1.3   root       77: void output_asm_label ();
1.1       root       78: static void output_operand ();
1.1.1.2   root       79: void output_address ();
1.1       root       80: void output_addr_const ();
1.1.1.2   root       81: static void output_source_line ();
1.1       root       82: 
1.1.1.4   root       83: /* the sdb debugger needs the line given as an offset from the beginning
                     84:    of the current function -wfs*/
                     85: 
                     86: extern int sdb_begin_function_line;
                     87: 
                     88: /* Line number of last NOTE.  */
                     89: static int last_linenum;
                     90: 
1.1.1.9   root       91: /* Nonzero while outputting an `asm' with operands.
1.1.1.10  root       92:    This means that inconsistencies are the user's fault, so don't abort.
                     93:    The precise value is the insn being output, to pass to error_for_asm.  */
                     94: static rtx this_is_asm_operands;
1.1.1.9   root       95: 
                     96: /* Number of operands of this insn, for an `asm' with operands.  */
                     97: static int insn_noperands;
                     98: 
1.1.1.4   root       99: /* Indexed by hard register, the name of the register for assembler code.  */
                    100: 
1.1       root      101: static char *reg_name[] = REGISTER_NAMES;
                    102: 
                    103: /* File in which assembler code is being written.  */
                    104: 
1.1.1.2   root      105: extern FILE *asm_out_file;
1.1       root      106: 
                    107: /* All the symbol-blocks (levels of scoping) in the compilation
                    108:    are assigned sequence numbers in order of appearance of the
                    109:    beginnings of the symbol-blocks.  Both final and dbxout do this,
                    110:    and assume that they will both give the same number to each block.
                    111:    Final uses these sequence numbers to generate assembler label names
                    112:    LBBnnn and LBEnnn for the beginning and end of the symbol-block.
                    113:    Dbxout uses the sequence nunbers to generate references to the same labels
1.1.1.4   root      114:    from the dbx debugging information.
                    115: 
                    116:    Sdb records this level at the beginning
                    117:    of each function, so that when it recurses down the declarations, it may
                    118:    find the current level, since it outputs the block beginning and endings
                    119:    at the point in the asm file, where the blocks would begin and end.  */
1.1       root      120: 
1.1.1.4   root      121: int next_block_index;
1.1       root      122: 
1.1.1.2   root      123: /* Chain of all `struct gdbfile's.  */
                    124: 
                    125: struct gdbfile *gdbfiles;
                    126: 
                    127: /* `struct gdbfile' for the last file we wrote a line number for.  */
                    128: 
                    129: static struct gdbfile *current_gdbfile;
                    130: 
                    131: /* Filenum to assign to the next distinct source file encountered.  */
                    132: 
                    133: static int next_gdb_filenum;
                    134: 
1.1       root      135: /* This variable contains machine-dependent flags (defined in tm-...h)
                    136:    set and examined by output routines
                    137:    that describe how to interpret the condition codes properly.  */
                    138: 
                    139: CC_STATUS cc_status;
                    140: 
1.1.1.2   root      141: /* During output of an insn, this contains a copy of cc_status
                    142:    from before the insn.  */
                    143: 
                    144: CC_STATUS cc_prev_status;
                    145: 
1.1       root      146: /* Last source file name mentioned in a NOTE insn.  */
                    147: 
                    148: static char *lastfile;
                    149: 
                    150: /* Indexed by hardware reg number, is 1 if that register is ever
                    151:    used in the current function.
                    152: 
                    153:    In life_analysis, or in stupid_life_analysis, this is set
                    154:    up to record the hard regs used explicitly.  Reload adds
                    155:    in the hard regs used for holding pseudo regs.  Final uses
                    156:    it to generate the code in the function prologue and epilogue
                    157:    to save and restore registers as needed.  */
                    158: 
                    159: char regs_ever_live[FIRST_PSEUDO_REGISTER];
                    160: 
1.1.1.2   root      161: /* Nonzero means current function must be given a frame pointer.
                    162:    Set in stmt.c if anything is allocated on the stack there.
                    163:    Set in reload1.c if anything is allocated on the stack there.  */
                    164: 
                    165: int frame_pointer_needed;
                    166: 
                    167: /* Assign unique numbers to labels generated for profiling.  */
                    168: 
                    169: int profile_label_no;
                    170: 
                    171: /* Length so far allocated in PENDING_BLOCKS.  */
                    172: 
                    173: static int max_block_depth;
                    174: 
                    175: /* Stack of sequence numbers of symbol-blocks of which we have seen the
                    176:    beginning but not yet the end.  Sequence numbers are assigned at
                    177:    the beginning; this stack allows us to find the sequence number
                    178:    of a block that is ending.  */
1.1       root      179: 
1.1.1.2   root      180: static int *pending_blocks;
                    181: 
                    182: /* Number of elements currently in use in PENDING_BLOCKS.  */
                    183: 
                    184: static int block_depth;
                    185: 
                    186: /* Nonzero if have enabled APP processing of our assembler output.  */
                    187: 
                    188: static int app_on;
1.1       root      189: 
                    190: /* Initialize data in final at the beginning of a compilation.  */
                    191: 
                    192: void
                    193: init_final (filename)
                    194:      char *filename;
                    195: {
                    196:   next_block_index = 2;
                    197:   lastfile = filename;
1.1.1.2   root      198:   app_on = 0;
                    199:   max_block_depth = 20;
                    200:   pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
                    201:   gdbfiles = 0;
                    202:   next_gdb_filenum = 0;
1.1       root      203: }
                    204: 
1.1.1.2   root      205: /* Enable APP processing of subsequent output.
                    206:    Used before the output from an `asm' statement.  */
                    207: 
                    208: void
                    209: app_enable ()
                    210: {
                    211:   if (! app_on)
                    212:     {
                    213:       fprintf (asm_out_file, ASM_APP_ON);
                    214:       app_on = 1;
                    215:     }
                    216: }
                    217: 
                    218: /* Enable APP processing of subsequent output.
                    219:    Called from varasm.c before most kinds of output.  */
                    220: 
                    221: void
                    222: app_disable ()
                    223: {
                    224:   if (app_on)
                    225:     {
                    226:       fprintf (asm_out_file, ASM_APP_OFF);
                    227:       app_on = 0;
                    228:     }
                    229: }
                    230: 
                    231: /* Output assembler code for the start of a function,
                    232:    and initialize some of the variables in this file
                    233:    for the new function.  The label for the function and associated
                    234:    assembler pseudo-ops have already been output in `assemble_function'.
                    235: 
1.1       root      236:    FIRST is the first insn of the rtl for the function being compiled.
                    237:    FILE is the file to write assembler code to.
1.1.1.4   root      238:    WRITE_SYMBOLS says which kind of debugging info to write (or none).
1.1       root      239:    OPTIMIZE is nonzero if we should eliminate redundant
                    240:      test and compare insns.  */
                    241: 
                    242: void
1.1.1.2   root      243: final_start_function (first, file, write_symbols, optimize)
1.1       root      244:      rtx first;
                    245:      FILE *file;
1.1.1.4   root      246:      enum debugger write_symbols;
1.1       root      247:      int optimize;
                    248: {
1.1.1.2   root      249:   block_depth = 0;
1.1       root      250: 
1.1.1.9   root      251:   this_is_asm_operands = 0;
                    252: 
1.1       root      253:   /* Record beginning of the symbol-block that's the entire function.  */
                    254: 
1.1.1.4   root      255:   if (write_symbols == GDB_DEBUG)
1.1       root      256:     {
1.1.1.2   root      257:       pending_blocks[block_depth++] = next_block_index;
1.1       root      258:       fprintf (file, "\t.gdbbeg %d\n", next_block_index++);
                    259:     }
                    260: 
                    261:   /* Initial line number is supposed to be output
                    262:      before the function's prologue and label
                    263:      so that the function's address will not appear to be
                    264:      in the last statement of the preceding function.  */
                    265:   if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1.1.1.2   root      266:     output_source_line (file, first, write_symbols);
1.1       root      267: 
                    268: #ifdef FUNCTION_PROLOGUE
                    269:   /* First output the function prologue: code to set up the stack frame.  */
                    270:   FUNCTION_PROLOGUE (file, get_frame_size ());
                    271: #endif
                    272: 
1.1.1.4   root      273: #ifdef SDB_DEBUGGING_INFO
                    274:   next_block_index = 1;
                    275:   if (write_symbols == SDB_DEBUG)
                    276:     sdbout_begin_function (last_linenum);
                    277: #endif
                    278: 
1.1.1.2   root      279:   if (profile_flag)
1.1.1.4   root      280:     {
1.1.1.2   root      281:       int align = min (BIGGEST_ALIGNMENT, BITS_PER_WORD);
1.1.1.8   root      282:       extern int current_function_returns_struct;
                    283:       extern int current_function_needs_context;
                    284:       int sval = current_function_returns_struct;
                    285:       int cxt = current_function_needs_context;
1.1.1.6   root      286:       data_section ();
1.1.1.2   root      287:       ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
                    288:       ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
                    289:       assemble_integer_zero ();
1.1.1.6   root      290:       text_section ();
1.1.1.8   root      291: 
                    292: #ifdef STRUCT_VALUE_INCOMING_REGNUM
                    293:       if (sval)
                    294:        ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
                    295: #else
                    296: #ifdef STRUCT_VALUE_REGNUM
                    297:       if (sval)
                    298:        ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
                    299: #endif
                    300: #endif
                    301: 
                    302: #if 0
                    303: #ifdef STATIC_CHAIN_INCOMING_REGNUM
                    304:       if (cxt)
                    305:        ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
                    306: #else
                    307: #ifdef STATIC_CHAIN_REGNUM
                    308:       if (cxt)
                    309:        ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
                    310: #endif
                    311: #endif
                    312: #endif /* 0 */
                    313: 
1.1.1.2   root      314:       FUNCTION_PROFILER (file, profile_label_no);
                    315:       profile_label_no++;
                    316: 
1.1.1.8   root      317: #if 0
                    318: #ifdef STATIC_CHAIN_INCOMING_REGNUM
                    319:       if (cxt)
                    320:        ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
                    321: #else
                    322: #ifdef STATIC_CHAIN_REGNUM
                    323:       if (cxt)
                    324:        ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
                    325: #endif
                    326: #endif
                    327: #endif /* 0 */
                    328: 
                    329: #ifdef STRUCT_VALUE_INCOMING_REGNUM
                    330:       if (sval)
                    331:        ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
                    332: #else
                    333: #ifdef STRUCT_VALUE_REGNUM
                    334:       if (sval)
                    335:        ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
                    336: #endif
                    337: #endif
                    338:     }
1.1.1.2   root      339: }
                    340: 
                    341: /* Output assembler code for the end of a function.
                    342:    For clarity, args are same as those of `final_start_function'
                    343:    even though not all of them are needed.  */
                    344: 
                    345: void
                    346: final_end_function (first, file, write_symbols, optimize)
                    347:      rtx first;
                    348:      FILE *file;
1.1.1.4   root      349:      enum debugger write_symbols;
1.1.1.2   root      350:      int optimize;
                    351: {
                    352:   if (app_on)
                    353:     {
                    354:       fprintf (file, ASM_APP_OFF);
                    355:       app_on = 0;
                    356:     }
                    357: 
1.1.1.4   root      358:   if (write_symbols == GDB_DEBUG)
1.1.1.2   root      359:     fprintf (file, "\t.gdbend %d\n", pending_blocks[0]);
                    360: 
1.1.1.4   root      361: #ifdef SDB_DEBUGGING_INFO
                    362:   if (write_symbols == SDB_DEBUG)
                    363:     sdbout_end_function (last_linenum);
                    364: #endif
                    365: 
1.1.1.2   root      366: #ifdef FUNCTION_EPILOGUE
                    367:   /* Finally, output the function epilogue:
                    368:      code to restore the stack frame and return to the caller.  */
                    369:   FUNCTION_EPILOGUE (file, get_frame_size ());
                    370: #endif
                    371: 
1.1.1.6   root      372: #ifdef SDB_DEBUGGING_INFO
                    373:   if (write_symbols == SDB_DEBUG)
                    374:     sdbout_end_epilogue ();
                    375: #endif
                    376: 
1.1.1.2   root      377:   /* If FUNCTION_EPILOGUE is not defined, then the function body
                    378:      itself contains return instructions wherever needed.  */
                    379: }
                    380: 
                    381: /* Output assembler code for some insns: all or part of a function.
1.1.1.8   root      382:    For description of args, see `final_start_function', above.
                    383: 
                    384:    PRESCAN is 1 if we are not really outputting,
                    385:      just scanning as if we were outputting.
                    386:    Prescanning deletes and rearranges insns just like ordinary output.
                    387:    PRESCAN is -2 if we are outputting after having prescanned.
                    388:    In this case, don't try to delete or rearrange insns
                    389:    because that has already been done.
                    390:    Prescanning is done only on certain machines.  */
1.1.1.2   root      391: 
                    392: void
1.1.1.8   root      393: final (first, file, write_symbols, optimize, prescan)
1.1.1.2   root      394:      rtx first;
                    395:      FILE *file;
1.1.1.4   root      396:      enum debugger write_symbols;
1.1.1.2   root      397:      int optimize;
1.1.1.8   root      398:      int prescan;
1.1.1.2   root      399: {
                    400:   register rtx insn;
                    401:   register int i;
1.1       root      402: 
1.1.1.8   root      403:   init_recog ();
                    404: 
                    405:   CC_STATUS_INIT;
                    406: 
1.1       root      407:   for (insn = NEXT_INSN (first); insn; insn = NEXT_INSN (insn))
                    408:     {
                    409:       switch (GET_CODE (insn))
                    410:        {
                    411:        case NOTE:
1.1.1.8   root      412:          if (prescan > 0)
                    413:            break;
1.1.1.4   root      414:          if (write_symbols == NO_DEBUG)
1.1       root      415:            break;
                    416:          if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
                    417:            abort ();           /* Obsolete; shouldn't appear */
                    418:          if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
                    419:              || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
                    420:            break;
                    421:          if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
                    422:            break;              /* An insn that was "deleted" */
1.1.1.2   root      423:          if (app_on)
                    424:            {
                    425:              fprintf (file, ASM_APP_OFF);
                    426:              app_on = 0;
                    427:            }
1.1       root      428:          if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
                    429:            {
                    430:              /* Beginning of a symbol-block.  Assign it a sequence number
                    431:                 and push the number onto the stack PENDING_BLOCKS.  */
                    432: 
1.1.1.2   root      433:              if (block_depth == max_block_depth)
1.1       root      434:                {
                    435:                  /* PENDING_BLOCKS is full; make it longer.  */
1.1.1.2   root      436:                  max_block_depth *= 2;
                    437:                  pending_blocks
                    438:                    = (int *) xrealloc (pending_blocks,
                    439:                                        max_block_depth * sizeof (int));
1.1       root      440:                }
1.1.1.2   root      441:              pending_blocks[block_depth++] = next_block_index;
1.1       root      442: 
                    443:              /* Output debugging info about the symbol-block beginning.  */
                    444: 
1.1.1.4   root      445: #ifdef SDB_DEBUGGING_INFO
                    446:              if (write_symbols == SDB_DEBUG)
                    447:                sdbout_begin_block (file, last_linenum, next_block_index);
                    448: #endif
                    449: #ifdef DBX_DEBUGGING_INFO
                    450:              if (write_symbols == DBX_DEBUG)
1.1.1.2   root      451:                ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
1.1.1.4   root      452: #endif
                    453:              if (write_symbols == GDB_DEBUG)
1.1.1.2   root      454:                fprintf (file, "\t.gdbbeg %d\n", next_block_index);
1.1.1.4   root      455: 
1.1.1.2   root      456:              next_block_index++;
1.1       root      457:            }
                    458:          else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
                    459:            {
                    460:              /* End of a symbol-block.  Pop its sequence number off
                    461:                 PENDING_BLOCKS and output debugging info based on that.  */
                    462: 
1.1.1.4   root      463:              --block_depth;
                    464: 
                    465: #ifdef DBX_DEBUGGING_INFO
                    466:              if (write_symbols == DBX_DEBUG && block_depth >= 0)
                    467:                ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
                    468:                                           pending_blocks[block_depth]);
                    469: #endif
                    470: 
                    471: #ifdef SDB_DEBUGGING_INFO
                    472:              if (write_symbols == SDB_DEBUG && block_depth >= 0)
                    473:                sdbout_end_block (file, last_linenum);
                    474: #endif
                    475: 
                    476:              if (write_symbols == GDB_DEBUG)
                    477:                fprintf (file, "\t.gdbend %d\n", pending_blocks[block_depth]);
1.1       root      478:            }
1.1.1.2   root      479:          else if (NOTE_LINE_NUMBER (insn) > 0)
1.1       root      480:            /* This note is a line-number.  */
1.1.1.2   root      481:            output_source_line (file, insn, write_symbols);
1.1       root      482:          break;
                    483: 
                    484:        case BARRIER:
1.1.1.11! root      485: #ifdef ASM_OUTPUT_ALIGN_CODE
        !           486:          ASM_OUTPUT_ALIGN_CODE (file);
        !           487: #endif
1.1       root      488:          break;
                    489: 
                    490:        case CODE_LABEL:
1.1.1.8   root      491:          CC_STATUS_INIT;
                    492:          if (prescan > 0)
                    493:            break;
1.1.1.2   root      494:          if (app_on)
                    495:            {
                    496:              fprintf (file, ASM_APP_OFF);
                    497:              app_on = 0;
                    498:            }
                    499: #ifdef ASM_OUTPUT_CASE_LABEL
                    500:          if (NEXT_INSN (insn) != 0
                    501:              && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
                    502:            {
                    503:              rtx nextbody = PATTERN (NEXT_INSN (insn));
                    504: 
                    505:              /* If this label is followed by a jump-table,
                    506:                 output the two of them together in a special way.  */
                    507: 
                    508:              if (GET_CODE (nextbody) == ADDR_VEC
                    509:                  || GET_CODE (nextbody) == ADDR_DIFF_VEC)
                    510:                {
                    511:                  ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
                    512:                                         NEXT_INSN (insn));
                    513:                  break;
                    514:                }
                    515:            }
                    516: #endif
                    517: 
                    518:          ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1.1       root      519:          break;
                    520: 
                    521:        default:
                    522:          {
                    523:            register rtx body = PATTERN (insn);
                    524:            int insn_code_number;
                    525:            char *template;
                    526: 
                    527:            /* An INSN, JUMP_INSN or CALL_INSN.
1.1.1.2   root      528:               First check for special kinds that recog doesn't recognize.  */
1.1.1.4   root      529: 
1.1       root      530:            if (GET_CODE (body) == USE /* These are just declarations */
                    531:                || GET_CODE (body) == CLOBBER)
                    532:              break;
                    533:            if (GET_CODE (body) == ASM_INPUT)
                    534:              {
1.1.1.8   root      535:                /* There's no telling what that did to the condition codes.  */
                    536:                CC_STATUS_INIT;
                    537:                if (prescan > 0)
                    538:                  break;
1.1.1.2   root      539:                if (! app_on)
                    540:                  {
                    541:                    fprintf (file, ASM_APP_ON);
                    542:                    app_on = 1;
                    543:                  }
                    544:                fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
1.1       root      545:                break;
                    546:              }
                    547: 
1.1.1.2   root      548:            /* Detect `asm' construct with operands.  */
1.1.1.11! root      549:            if (asm_noperands (body) >= 0)
1.1.1.2   root      550:              {
                    551:                int noperands = asm_noperands (body);
1.1.1.8   root      552:                rtx *ops;
1.1.1.2   root      553:                char *string;
                    554: 
1.1.1.8   root      555:                /* There's no telling what that did to the condition codes.  */
                    556:                CC_STATUS_INIT;
                    557:                if (prescan > 0)
                    558:                  break;
                    559: 
                    560:                /* alloca won't do here, since only return from `final'
                    561:                   would free it.  */
1.1.1.11! root      562:                if (noperands > 0)
        !           563:                  ops = (rtx *) xmalloc (noperands * sizeof (rtx));
1.1.1.8   root      564: 
1.1.1.2   root      565:                if (! app_on)
                    566:                  {
                    567:                    fprintf (file, ASM_APP_ON);
                    568:                    app_on = 1;
                    569:                  }
                    570: 
                    571:                /* Get out the operand values.  */
                    572:                string = decode_asm_operands (body, ops, 0, 0, 0);
1.1.1.9   root      573:                /* Inhibit aborts on what would otherwise be compiler bugs.  */
                    574:                insn_noperands = noperands;
1.1.1.10  root      575:                this_is_asm_operands = insn;
1.1.1.2   root      576:                /* Output the insn using them.  */
                    577:                output_asm_insn (string, ops);
1.1.1.9   root      578:                this_is_asm_operands = 0;
1.1.1.11! root      579:                if (noperands > 0)
        !           580:                  free (ops);
1.1.1.2   root      581:                break;
                    582:              }
                    583: 
1.1.1.8   root      584:            if (prescan <= 0 && app_on)
1.1.1.2   root      585:              {
                    586:                fprintf (file, ASM_APP_OFF);
                    587:                app_on = 0;
                    588:              }
                    589: 
1.1       root      590:            /* Detect insns that are really jump-tables
                    591:               and output them as such.  */
                    592: 
                    593:            if (GET_CODE (body) == ADDR_VEC)
                    594:              {
                    595:                register int vlen, idx;
1.1.1.8   root      596: 
                    597:                if (prescan > 0)
                    598:                  break;
                    599: 
1.1       root      600:                vlen = XVECLEN (body, 0);
                    601:                for (idx = 0; idx < vlen; idx++)
1.1.1.4   root      602:                  ASM_OUTPUT_ADDR_VEC_ELT (file,
1.1       root      603:                           CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
1.1.1.4   root      604: #ifdef ASM_OUTPUT_CASE_END
                    605:                ASM_OUTPUT_CASE_END (file,
                    606:                                     CODE_LABEL_NUMBER (PREV_INSN (insn)),
                    607:                                     insn);
                    608: #endif
1.1       root      609:                break;
                    610:              }
                    611:            if (GET_CODE (body) == ADDR_DIFF_VEC)
                    612:              {
                    613:                register int vlen, idx;
1.1.1.8   root      614: 
                    615:                if (prescan > 0)
                    616:                  break;
                    617: 
1.1       root      618:                vlen = XVECLEN (body, 1);
                    619:                for (idx = 0; idx < vlen; idx++)
1.1.1.4   root      620:                  ASM_OUTPUT_ADDR_DIFF_ELT (file,
1.1       root      621:                           CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
                    622:                           CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
1.1.1.4   root      623: #ifdef ASM_OUTPUT_CASE_END
1.1.1.7   root      624:                ASM_OUTPUT_CASE_END (file,
                    625:                                     CODE_LABEL_NUMBER (PREV_INSN (insn)),
                    626:                                     insn);
1.1.1.4   root      627: #endif
1.1       root      628:                break;
                    629:              }
                    630: 
                    631:            /* We have a real machine instruction as rtl.  */
                    632: 
                    633:            body = PATTERN (insn);
                    634: 
1.1.1.4   root      635:            /* Check for redundant test and compare instructions
1.1       root      636:               (when the condition codes are already set up as desired).
                    637:               This is done only when optimizing; if not optimizing,
                    638:               it should be possible for the user to alter a variable
                    639:               with the debugger in between statements
                    640:               and the next statement should reexamine the variable
                    641:               to compute the condition codes.  */
                    642: 
                    643:            if (optimize
                    644:                && GET_CODE (body) == SET
                    645:                && GET_CODE (SET_DEST (body)) == CC0)
                    646:              {
                    647:                if (GET_CODE (SET_SRC (body)) == SUBREG)
1.1.1.6   root      648:                  SET_SRC (body) = alter_subreg (SET_SRC (body));
1.1       root      649:                if ((cc_status.value1 != 0
                    650:                     && rtx_equal_p (SET_SRC (body), cc_status.value1))
                    651:                    || (cc_status.value2 != 0
                    652:                        && rtx_equal_p (SET_SRC (body), cc_status.value2)))
1.1.1.2   root      653:                  {
                    654:                    /* Don't delete insn if has an addressing side-effect */
1.1.1.6   root      655:                    if (! find_reg_note (insn, REG_INC, 0)
                    656:                        /* or if anything in it is volatile.  */
                    657:                        && ! volatile_refs_p (PATTERN (insn)))
1.1.1.8   root      658:                      /* We don't really delete the insn; just ignore it.  */
1.1.1.2   root      659:                      break;
                    660:                  }
1.1       root      661:              }
                    662: 
                    663:            /* If this is a conditional branch, maybe modify it
                    664:               if the cc's are in a nonstandard state
                    665:               so that it accomplishes the same thing that it would
                    666:               do straightforwardly if the cc's were set up normally.  */
                    667: 
                    668:            if (cc_status.flags != 0
                    669:                && GET_CODE (insn) == JUMP_INSN
                    670:                && GET_CODE (body) == SET
                    671:                && SET_DEST (body) == pc_rtx
1.1.1.8   root      672:                && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
                    673:                /* This is done during prescan; it is not done again
                    674:                   in final scan when prescan has been done.  */
                    675:                && prescan >= 0)
1.1       root      676:              {
                    677:                /* This function may alter the contents of its argument
                    678:                   and clear some of the cc_status.flags bits.
                    679:                   It may also return 1 meaning condition now always true
                    680:                   or -1 meaning condition now always false
                    681:                   or 2 meaning condition nontrivial but altered.  */
                    682:                register int result = alter_cond (XEXP (SET_SRC (body), 0));
                    683:                /* If condition now has fixed value, replace the IF_THEN_ELSE
                    684:                   with its then-operand or its else-operand.  */
                    685:                if (result == 1)
                    686:                  SET_SRC (body) = XEXP (SET_SRC (body), 1);
                    687:                if (result == -1)
                    688:                  SET_SRC (body) = XEXP (SET_SRC (body), 2);
                    689:                /* The jump is now either unconditional or a no-op.
                    690:                   If it has become a no-op, don't try to output it.
                    691:                   (It would not be recognized.)  */
                    692:                if (SET_SRC (body) == pc_rtx)
1.1.1.8   root      693:                  {
                    694:                    PUT_CODE (insn, NOTE);
                    695:                    NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
                    696:                    NOTE_SOURCE_FILE (insn) = 0;
                    697:                    break;
                    698:                  }
1.1       root      699:                /* Rerecognize the instruction if it has changed.  */
                    700:                if (result != 0)
                    701:                  INSN_CODE (insn) = -1;
                    702:              }
                    703: 
1.1.1.8   root      704: #ifdef STORE_FLAG_VALUE
1.1       root      705:            /* Make same adjustments to instructions that examine the
1.1.1.8   root      706:               condition codes without jumping (if this machine has them).  */
1.1       root      707: 
                    708:            if (cc_status.flags != 0
                    709:                && GET_CODE (body) == SET)
                    710:              switch (GET_CODE (SET_SRC (body)))
                    711:                {
                    712:                case GTU:
                    713:                case GT:
                    714:                case LTU:
                    715:                case LT:
                    716:                case GEU:
                    717:                case GE:
                    718:                case LEU:
                    719:                case LE:
                    720:                case EQ:
                    721:                case NE:
                    722:                  {
1.1.1.8   root      723:                    register int result;
                    724:                    if (GET_CODE (XEXP (SET_SRC (body), 0)) != CC0)
                    725:                      break;
                    726:                    result = alter_cond (SET_SRC (body));
1.1       root      727:                    if (result == 1)
1.1.1.8   root      728:                      SET_SRC (body) = gen_rtx (CONST_INT, VOIDmode,
                    729:                                                STORE_FLAG_VALUE);
1.1       root      730:                    if (result == -1)
                    731:                      SET_SRC (body) = const0_rtx;
                    732:                    if (result != 0)
                    733:                      INSN_CODE (insn) = -1;
                    734:                  }
                    735:                }
1.1.1.8   root      736: #endif /* STORE_FLAG_VALUE */
1.1       root      737: 
                    738:            /* Try to recognize the instruction.
                    739:               If successful, verify that the operands satisfy the
                    740:               constraints for the instruction.  Crash if they don't,
                    741:               since `reload' should have changed them so that they do.  */
                    742: 
                    743:            insn_code_number = recog_memoized (insn);
                    744:            insn_extract (insn);
                    745:            for (i = 0; i < insn_n_operands[insn_code_number]; i++)
1.1.1.11! root      746:              {
        !           747:                if (GET_CODE (recog_operand[i]) == SUBREG)
        !           748:                  recog_operand[i] = alter_subreg (recog_operand[i]);
        !           749:              }
1.1       root      750: 
                    751: #ifdef REGISTER_CONSTRAINTS
                    752:            if (! constrain_operands (insn_code_number))
                    753:              abort ();
                    754: #endif
                    755: 
1.1.1.4   root      756:            /* Some target machines need to prescan each insn before
                    757:               it is output.  */
                    758: 
                    759: #ifdef FINAL_PRESCAN_INSN
                    760:            FINAL_PRESCAN_INSN (insn, recog_operand,
                    761:                                insn_n_operands[insn_code_number]);
                    762: #endif
                    763: 
1.1.1.2   root      764:            cc_prev_status = cc_status;
                    765: 
1.1       root      766:            /* Update `cc_status' for this instruction.
                    767:               The instruction's output routine may change it further.
1.1.1.11! root      768:               If the output routine for a jump insn needs to depend
        !           769:               on the cc status, it should look at cc_prev_status.  */
1.1       root      770: 
1.1.1.8   root      771:            NOTICE_UPDATE_CC (body, insn);
1.1       root      772: 
                    773:            /* If the proper template needs to be chosen by some C code,
1.1.1.2   root      774:               run that code and get the real template.  */
1.1       root      775: 
                    776:            template = insn_template[insn_code_number];
                    777:            if (template == 0)
1.1.1.5   root      778:              template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
1.1       root      779: 
1.1.1.8   root      780:            if (prescan > 0)
                    781:              break;
                    782: 
1.1       root      783:            /* Output assembler code from the template.  */
                    784: 
                    785:            output_asm_insn (template, recog_operand);
                    786:          }
                    787:        }
                    788:     }
1.1.1.2   root      789: }
                    790: 
                    791: /* Set up FILENAME as the current file for GDB line-number output.  */
1.1       root      792: 
1.1.1.2   root      793: void
                    794: set_current_gdbfile (filename)
                    795:      char *filename;
                    796: {
                    797:   register struct gdbfile *f;
                    798:   for (f = gdbfiles; f; f = f->next)
                    799:     if (!strcmp (f->name, filename))
                    800:       break;
1.1       root      801: 
1.1.1.2   root      802:   if (!f)
                    803:     {
                    804:       f = (struct gdbfile *) permalloc (sizeof (struct gdbfile));
                    805:       f->next = gdbfiles;
                    806:       gdbfiles = f;
                    807:       f->name = filename;
                    808:       f->filenum = next_gdb_filenum++;
                    809:       f->nlines = 0;
                    810:     }
                    811:   current_gdbfile = f;
                    812:   lastfile = filename;
1.1       root      813: }
                    814: 
1.1.1.2   root      815: /* Output debugging info to the assembler file FILE
                    816:    based on the NOTE-insn INSN, assumed to be a line number.  */
1.1       root      817: 
1.1.1.2   root      818: static void
                    819: output_source_line (file, insn, write_symbols)
1.1       root      820:      FILE *file;
                    821:      rtx insn;
1.1.1.4   root      822:      enum debugger write_symbols;
1.1       root      823: {
                    824:   register char *filename = NOTE_SOURCE_FILE (insn);
1.1.1.4   root      825: 
                    826:   last_linenum = NOTE_LINE_NUMBER (insn);
                    827: 
                    828:   if (write_symbols == GDB_DEBUG)
1.1.1.2   root      829:     {
                    830:       /* Output GDB-format line number info.  */
1.1       root      831: 
1.1.1.2   root      832:       /* If this is not the same source file as last time,
                    833:         find or assign a GDB-file-number to this file.  */
                    834:       if (filename && (lastfile == 0 || strcmp (filename, lastfile)
                    835:                       || current_gdbfile == 0))
                    836:        set_current_gdbfile (filename);
                    837: 
                    838:       ++current_gdbfile->nlines;
                    839:       fprintf (file, "\t.gdbline %d,%d\n",
                    840:               current_gdbfile->filenum, NOTE_LINE_NUMBER (insn));
                    841:     }
1.1.1.4   root      842: 
1.1.1.6   root      843:   if (write_symbols == SDB_DEBUG || write_symbols == DBX_DEBUG)
1.1.1.4   root      844:     {
1.1.1.6   root      845: #ifdef SDB_DEBUGGING_INFO
                    846:       if (write_symbols == SDB_DEBUG
                    847:          /* COFF can't handle multiple source files--lose, lose.  */
1.1.1.10  root      848:          && !strcmp (filename, main_input_filename)
                    849:          /* COFF can't handle line #s before start-line of this function.  */
                    850:          && last_linenum >= sdb_begin_function_line)
1.1.1.6   root      851:        {
1.1.1.4   root      852: #ifdef ASM_OUTPUT_SOURCE_LINE
1.1.1.6   root      853:          ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
1.1.1.4   root      854: #else
1.1.1.6   root      855:          fprintf (file, "\t.ln\t%d\n",
                    856:                   (sdb_begin_function_line
                    857:                    ? last_linenum - sdb_begin_function_line : 1));
1.1.1.4   root      858: #endif
1.1.1.6   root      859:        }
1.1.1.4   root      860: #endif
                    861: 
                    862: #ifdef DBX_DEBUGGING_INFO
1.1.1.6   root      863:       if (write_symbols == DBX_DEBUG)
1.1.1.4   root      864:        {
1.1.1.6   root      865:          /* Write DBX line number data.  */
                    866: 
                    867:          if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
                    868:            {
1.1.1.2   root      869: #ifdef ASM_OUTPUT_SOURCE_FILENAME
1.1.1.6   root      870:              ASM_OUTPUT_SOURCE_FILENAME (file, filename);
1.1.1.2   root      871: #else
1.1.1.6   root      872:              fprintf (file, "\t.stabs \"%s\",%d,0,0,Ltext\n",
                    873:                       filename, N_SOL);
1.1.1.2   root      874: #endif
1.1.1.6   root      875:              lastfile = filename;
                    876:            }
1.1.1.4   root      877:        }
1.1.1.2   root      878: 
                    879: #ifdef ASM_OUTPUT_SOURCE_LINE
                    880:       ASM_OUTPUT_SOURCE_LINE (file, NOTE_LINE_NUMBER (insn));
                    881: #else
                    882:       fprintf (file, "\t.stabd %d,0,%d\n",
                    883:               N_SLINE, NOTE_LINE_NUMBER (insn));
                    884: #endif
1.1.1.4   root      885: #endif /* DBX_DEBUGGING_INFO */
1.1.1.2   root      886:     }
1.1       root      887: }
                    888: 
1.1.1.2   root      889: /* If X is a SUBREG, replace it with a REG or a MEM,
                    890:    based on the thing it is a subreg of.  */
1.1       root      891: 
1.1.1.10  root      892: rtx
1.1       root      893: alter_subreg (x)
                    894:      register rtx x;
                    895: {
                    896:   register rtx y = SUBREG_REG (x);
                    897:   if (GET_CODE (y) == SUBREG)
1.1.1.6   root      898:     y = alter_subreg (y);
1.1       root      899: 
                    900:   if (GET_CODE (y) == REG)
                    901:     {
                    902:       /* If the containing reg really gets a hard reg, so do we.  */
                    903:       PUT_CODE (x, REG);
                    904:       REGNO (x) = REGNO (y) + SUBREG_WORD (x);
                    905:     }
                    906:   else if (GET_CODE (y) == MEM)
                    907:     {
1.1.1.2   root      908:       register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
1.1       root      909: #ifdef BYTES_BIG_ENDIAN
1.1.1.2   root      910:       offset -= (min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
                    911:                 - min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
1.1       root      912: #endif
                    913:       PUT_CODE (x, MEM);
                    914:       XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
                    915:     }
1.1.1.6   root      916:   else if (GET_CODE (y) == CONST_DOUBLE)
                    917:     return y;
                    918: 
                    919:   return x;
1.1       root      920: }
                    921: 
1.1.1.2   root      922: /* Do alter_subreg on all the SUBREGs contained in X.  */
1.1       root      923: 
1.1.1.2   root      924: static rtx
                    925: walk_alter_subreg (x)
                    926:      rtx x;
                    927: {
                    928:   switch (GET_CODE (x))
1.1       root      929:     {
1.1.1.2   root      930:     case PLUS:
                    931:     case MULT:
                    932:       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
                    933:       XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
                    934:       break;
                    935: 
                    936:     case MEM:
                    937:       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
                    938:       break;
                    939: 
                    940:     case SUBREG:
1.1.1.6   root      941:       return alter_subreg (x);
1.1       root      942:     }
                    943: 
1.1.1.2   root      944:   return x;
1.1       root      945: }
                    946: 
                    947: /* Given BODY, the body of a jump instruction, alter the jump condition
                    948:    as required by the bits that are set in cc_status.flags.
                    949:    Not all of the bits there can be handled at this level in all cases.
                    950: 
                    951:    The value is normally 0.
                    952:    1 means that the condition has become always true.
1.1.1.8   root      953:    -1 means that the condition has become always false.
                    954:    2 means that COND has been altered.  */
1.1       root      955: 
                    956: static int
                    957: alter_cond (cond)
                    958:      register rtx cond;
                    959: {
                    960:   int value = 0;
                    961: 
                    962:   if (cc_status.flags & CC_REVERSED)
                    963:     {
                    964:       value = 2;
                    965:       switch (GET_CODE (cond))
                    966:        {
                    967:        case LE:
                    968:          PUT_CODE (cond, GE);
                    969:          break;
                    970:        case GE:
                    971:          PUT_CODE (cond, LE);
                    972:          break;
                    973:        case LT:
                    974:          PUT_CODE (cond, GT);
                    975:          break;
                    976:        case GT:
                    977:          PUT_CODE (cond, LT);
                    978:          break;
                    979:        case LEU:
                    980:          PUT_CODE (cond, GEU);
                    981:          break;
                    982:        case GEU:
                    983:          PUT_CODE (cond, LEU);
                    984:          break;
                    985:        case LTU:
                    986:          PUT_CODE (cond, GTU);
                    987:          break;
                    988:        case GTU:
                    989:          PUT_CODE (cond, LTU);
                    990:          break;
                    991:        }
                    992:     }
                    993: 
1.1.1.8   root      994:   if (cc_status.flags & CC_NOT_POSITIVE)
1.1       root      995:     switch (GET_CODE (cond))
                    996:       {
                    997:       case LE:
                    998:       case LEU:
                    999:       case GEU:
                   1000:        /* Jump becomes unconditional.  */
                   1001:        return 1;
                   1002: 
                   1003:       case GT:
                   1004:       case GTU:
                   1005:       case LTU:
                   1006:        /* Jump becomes no-op.  */
                   1007:        return -1;
                   1008: 
                   1009:       case GE:
                   1010:        PUT_CODE (cond, EQ);
                   1011:        value = 2;
                   1012:        break;
                   1013: 
                   1014:       case LT:
                   1015:        PUT_CODE (cond, NE);
                   1016:        value = 2;
                   1017:        break;
                   1018:       }
                   1019: 
1.1.1.8   root     1020:   if (cc_status.flags & CC_NOT_NEGATIVE)
1.1       root     1021:     switch (GET_CODE (cond))
                   1022:       {
                   1023:       case GE:
                   1024:       case GEU:
                   1025:        /* Jump becomes unconditional.  */
                   1026:        return 1;
                   1027: 
                   1028:       case LT:
                   1029:       case LTU:
                   1030:        /* Jump becomes no-op.  */
                   1031:        return -1;
                   1032: 
                   1033:       case LE:
                   1034:       case LEU:
                   1035:        PUT_CODE (cond, EQ);
                   1036:        value = 2;
                   1037:        break;
                   1038: 
                   1039:       case GT:
                   1040:       case GTU:
                   1041:        PUT_CODE (cond, NE);
                   1042:        value = 2;
                   1043:        break;
                   1044:       }
                   1045: 
1.1.1.8   root     1046:   if (cc_status.flags & CC_NO_OVERFLOW)
1.1       root     1047:     switch (GET_CODE (cond))
                   1048:       {
                   1049:       case GEU:
                   1050:        /* Jump becomes unconditional.  */
                   1051:        return 1;
                   1052: 
                   1053:       case LEU:
                   1054:        PUT_CODE (cond, EQ);
                   1055:        value = 2;
                   1056:        break;
                   1057: 
                   1058:       case GTU:
                   1059:        PUT_CODE (cond, NE);
                   1060:        value = 2;
                   1061:        break;
                   1062: 
                   1063:       case LTU:
                   1064:        /* Jump becomes no-op.  */
                   1065:        return -1;
                   1066:       }
                   1067: 
1.1.1.8   root     1068:   if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
                   1069:     switch (GET_CODE (cond))
                   1070:       {
                   1071:       case LE:
                   1072:       case LEU:
                   1073:       case GE:
                   1074:       case GEU:
                   1075:       case LT:
                   1076:       case LTU:
                   1077:       case GT:
                   1078:       case GTU:
                   1079:        abort ();
                   1080: 
                   1081:       case NE:
                   1082:        PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
                   1083:        value = 2;
                   1084:        break;
                   1085: 
                   1086:       case EQ:
                   1087:        PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
                   1088:        value = 2;
                   1089:        break;
                   1090:       }
                   1091:   
1.1       root     1092:   return value;
                   1093: }
                   1094: 
1.1.1.9   root     1095: /* Report inconsistency between the assembler template and the operands.
                   1096:    In an `asm', it's the user's fault; otherwise, the compiler's fault.  */
                   1097: 
                   1098: static void
                   1099: output_operand_lossage (str)
                   1100:      char *str;
                   1101: {
                   1102:   if (this_is_asm_operands)
1.1.1.11! root     1103:     error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
1.1.1.9   root     1104:   else
                   1105:     abort ();
                   1106: }
                   1107: 
1.1       root     1108: /* Output of assembler code from a template, and its subroutines.  */
                   1109: 
                   1110: /* Output text from TEMPLATE to the assembler output file,
                   1111:    obeying %-directions to substitute operands taken from
                   1112:    the vector OPERANDS.
                   1113: 
                   1114:    %N (for N a digit) means print operand N in usual manner.
                   1115:    %lN means require operand N to be a CODE_LABEL or LABEL_REF
                   1116:       and print the label name with no punctuation.
                   1117:    %cN means require operand N to be a constant
                   1118:       and print the constant expression with no punctuation.
                   1119:    %aN means expect operand N to be a memory address
                   1120:       (not a memory reference!) and print a reference
                   1121:       to that address.
                   1122:    %nN means expect operand N to be a constant
                   1123:       and print a constant expression for minus the value
                   1124:       of the operand, with no other punctuation.  */
                   1125: 
                   1126: void
                   1127: output_asm_insn (template, operands)
                   1128:      char *template;
                   1129:      rtx *operands;
                   1130: {
                   1131:   register char *p;
                   1132:   register int c;
                   1133: 
1.1.1.2   root     1134:   /* An insn may return a null string template
                   1135:      in a case where no assembler code is needed.  */
                   1136:   if (*template == 0)
                   1137:     return;
                   1138: 
1.1       root     1139:   p = template;
1.1.1.2   root     1140:   putc ('\t', asm_out_file);
                   1141: 
                   1142: #ifdef ASM_OUTPUT_OPCODE
                   1143:   ASM_OUTPUT_OPCODE (asm_out_file, p);
                   1144: #endif
                   1145: 
1.1       root     1146:   while (c = *p++)
                   1147:     {
1.1.1.2   root     1148: #ifdef ASM_OUTPUT_OPCODE
                   1149:       if (c == '\n')
1.1       root     1150:        {
1.1.1.2   root     1151:          putc (c, asm_out_file);
                   1152:          while ((c = *p) == '\t')
1.1       root     1153:            {
1.1.1.2   root     1154:              putc (c, asm_out_file);
                   1155:              p++;
1.1       root     1156:            }
1.1.1.2   root     1157:          ASM_OUTPUT_OPCODE (asm_out_file, p);
                   1158:        }
                   1159:       else
                   1160: #endif
                   1161:       if (c != '%')
                   1162:        putc (c, asm_out_file);
                   1163:       else
                   1164:        {
                   1165:          /* %% outputs a single %.  */
                   1166:          if (*p == '%')
1.1       root     1167:            {
1.1.1.2   root     1168:              p++;
                   1169:              putc (c, asm_out_file);
1.1       root     1170:            }
1.1.1.2   root     1171:          /* % followed by a letter and some digits
                   1172:             outputs an operand in a special way depending on the letter.
                   1173:             Letters `acln' are implemented here.
                   1174:             Other letters are passed to `output_operand' so that
                   1175:             the PRINT_OPERAND macro can define them.  */
                   1176:          else if ((*p >= 'a' && *p <= 'z')
                   1177:                   || (*p >= 'A' && *p <= 'Z'))
1.1       root     1178:            {
1.1.1.2   root     1179:              int letter = *p++;
                   1180:              c = atoi (p);
                   1181: 
1.1.1.9   root     1182:              if (this_is_asm_operands
                   1183:                  && c >= (unsigned) insn_noperands && *p >= '0' && *p <= '9')
                   1184:                output_operand_lossage ("operand number out of range");
                   1185:              else if (letter == 'l')
1.1.1.2   root     1186:                output_asm_label (operands[c]);
                   1187:              else if (letter == 'a')
                   1188:                output_address (operands[c]);
                   1189:              else if (letter == 'c')
                   1190:                {
                   1191:                  if (CONSTANT_ADDRESS_P (operands[c]))
                   1192:                    output_addr_const (asm_out_file, operands[c]);
                   1193:                  else
                   1194:                    output_operand (operands[c], 'c');
                   1195:                }
                   1196:              else if (letter == 'n')
1.1       root     1197:                {
1.1.1.2   root     1198:                  if (GET_CODE (operands[c]) == CONST_INT)
                   1199:                    fprintf (asm_out_file, "%d", - INTVAL (operands[c]));
                   1200:                  else
                   1201:                    {
                   1202:                      putc ('-', asm_out_file);
                   1203:                      output_addr_const (asm_out_file, operands[c]);
                   1204:                    }
1.1       root     1205:                }
1.1.1.2   root     1206:              else if (*p >= '0' && *p <= '9')
                   1207:                output_operand (operands[c], letter);
                   1208:              else
                   1209:                /* No operand-number follows the letter.  */
                   1210:                output_operand (0, letter);
                   1211: 
                   1212:              while ((c = *p) >= '0' && c <= '9') p++;
1.1       root     1213:            }
1.1.1.2   root     1214:          /* % followed by a digit outputs an operand the default way.  */
                   1215:          else if (*p >= '0' && *p <= '9')
1.1       root     1216:            {
                   1217:              c = atoi (p);
1.1.1.9   root     1218:              if (this_is_asm_operands && c >= (unsigned) insn_noperands)
                   1219:                output_operand_lossage ("operand number out of range");
                   1220:              else
                   1221:                output_operand (operands[c], 0);
1.1.1.2   root     1222:              while ((c = *p) >= '0' && c <= '9') p++;
1.1       root     1223:            }
1.1.1.2   root     1224:          /* % followed by punctuation: output something for that
                   1225:             punctuation character alone, with no operand.
                   1226:             The PRINT_OPERAND macro decides what is actually done.  */
                   1227:          else
                   1228:            output_operand (0, *p++);
1.1       root     1229:        }
                   1230:     }
                   1231: 
1.1.1.2   root     1232:   putc ('\n', asm_out_file);
1.1       root     1233: }
1.1.1.9   root     1234: 
1.1.1.3   root     1235: /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol.  */
                   1236: 
                   1237: void
1.1       root     1238: output_asm_label (x)
                   1239:      rtx x;
                   1240: {
1.1.1.2   root     1241:   char buf[20];
                   1242: 
1.1       root     1243:   if (GET_CODE (x) == LABEL_REF)
1.1.1.2   root     1244:     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
1.1       root     1245:   else if (GET_CODE (x) == CODE_LABEL)
1.1.1.2   root     1246:     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
1.1       root     1247:   else
1.1.1.9   root     1248:     output_operand_lossage ("`%l' operand isn't a label");
1.1.1.2   root     1249: 
                   1250:   assemble_name (asm_out_file, buf);
1.1       root     1251: }
                   1252: 
                   1253: /* Print operand X using machine-dependent assembler syntax.
1.1.1.2   root     1254:    The macro PRINT_OPERAND is defined just to control this function.
                   1255:    CODE is a non-digit that preceded the operand-number in the % spec,
                   1256:    such as 'z' if the spec was `%z3'.  CODE is 0 if there was no char
                   1257:    between the % and the digits.
                   1258:    When CODE is a non-letter, X is 0.
                   1259: 
                   1260:    The meanings of the letters are machine-dependent and controlled
                   1261:    by PRINT_OPERAND.  */
1.1       root     1262: 
                   1263: static void
1.1.1.2   root     1264: output_operand (x, code)
1.1       root     1265:      rtx x;
1.1.1.2   root     1266:      int code;
1.1       root     1267: {
1.1.1.2   root     1268:   if (x && GET_CODE (x) == SUBREG)
1.1.1.6   root     1269:     x = alter_subreg (x);
1.1.1.2   root     1270:   PRINT_OPERAND (asm_out_file, x, code);
1.1       root     1271: }
                   1272: 
                   1273: /* Print a memory reference operand for address X
                   1274:    using machine-dependent assembler syntax.
                   1275:    The macro PRINT_OPERAND_ADDRESS exists just to control this function.  */
                   1276: 
1.1.1.2   root     1277: void
1.1       root     1278: output_address (x)
                   1279:      rtx x;
                   1280: {
1.1.1.2   root     1281:   walk_alter_subreg (x);
                   1282:   PRINT_OPERAND_ADDRESS (asm_out_file, x);
1.1       root     1283: }
                   1284: 
                   1285: /* Print an integer constant expression in assembler syntax.
                   1286:    Addition and subtraction are the only arithmetic
                   1287:    that may appear in these expressions.  */
                   1288: 
                   1289: void
                   1290: output_addr_const (file, x)
                   1291:      FILE *file;
                   1292:      rtx x;
                   1293: {
1.1.1.2   root     1294:   char buf[20];
                   1295: 
1.1       root     1296:  restart:
                   1297:   switch (GET_CODE (x))
                   1298:     {
                   1299:     case SYMBOL_REF:
1.1.1.2   root     1300:       assemble_name (file, XSTR (x, 0));
1.1       root     1301:       break;
                   1302: 
                   1303:     case LABEL_REF:
1.1.1.2   root     1304:       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
                   1305:       assemble_name (asm_out_file, buf);
1.1       root     1306:       break;
                   1307: 
                   1308:     case CODE_LABEL:
1.1.1.2   root     1309:       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
                   1310:       assemble_name (asm_out_file, buf);
1.1       root     1311:       break;
                   1312: 
                   1313:     case CONST_INT:
                   1314:       fprintf (file, "%d", INTVAL (x));
                   1315:       break;
                   1316: 
                   1317:     case CONST:
                   1318:       x = XEXP (x, 0);
                   1319:       goto restart;
                   1320: 
1.1.1.8   root     1321:     case CONST_DOUBLE:
                   1322:       if (GET_MODE (x) == DImode)
                   1323:        {
                   1324:          /* We can use %d if the number is <32 bits and positive.  */
                   1325:          if (XINT (x, 1) || XINT (x, 0) < 0)
                   1326:            fprintf (file, "0x%x%08x", XINT (x, 1), XINT (x, 0));
                   1327:          else
                   1328:            fprintf (file, "%d", XINT (x, 0));
                   1329:        }
                   1330:       else
                   1331:        /* We can't handle floating point constants;
                   1332:           PRINT_OPERAND must handle them.  */
1.1.1.9   root     1333:        output_operand_lossage ("floating constant misused");
1.1.1.8   root     1334:       break;
                   1335: 
1.1       root     1336:     case PLUS:
1.1.1.4   root     1337:       /* Some assemblers need integer constants to appear last (eg masm).  */
                   1338:       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
                   1339:        {
                   1340:          output_addr_const (file, XEXP (x, 1));
1.1.1.11! root     1341:          if (INTVAL (XEXP (x, 0)) >= 0)
        !          1342:            fprintf (file, "+");
1.1.1.4   root     1343:          output_addr_const (file, XEXP (x, 0));
                   1344:        }
                   1345:       else
                   1346:        {
                   1347:          output_addr_const (file, XEXP (x, 0));
1.1.1.11! root     1348:          if (INTVAL (XEXP (x, 1)) >= 0)
        !          1349:            fprintf (file, "+");
1.1.1.4   root     1350:          output_addr_const (file, XEXP (x, 1));
                   1351:        }
1.1       root     1352:       break;
                   1353: 
                   1354:     case MINUS:
                   1355:       output_addr_const (file, XEXP (x, 0));
                   1356:       fprintf (file, "-");
                   1357:       output_addr_const (file, XEXP (x, 1));
                   1358:       break;
                   1359: 
                   1360:     default:
1.1.1.9   root     1361:       output_operand_lossage ("invalid expression as operand");
1.1       root     1362:     }
                   1363: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.