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