|
|
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:
485: break;
486:
487: case CODE_LABEL:
1.1.1.8 root 488: CC_STATUS_INIT;
489: if (prescan > 0)
490: break;
1.1.1.2 root 491: if (app_on)
492: {
493: fprintf (file, ASM_APP_OFF);
494: app_on = 0;
495: }
496: #ifdef ASM_OUTPUT_CASE_LABEL
497: if (NEXT_INSN (insn) != 0
498: && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
499: {
500: rtx nextbody = PATTERN (NEXT_INSN (insn));
501:
502: /* If this label is followed by a jump-table,
503: output the two of them together in a special way. */
504:
505: if (GET_CODE (nextbody) == ADDR_VEC
506: || GET_CODE (nextbody) == ADDR_DIFF_VEC)
507: {
508: ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
509: NEXT_INSN (insn));
510: break;
511: }
512: }
513: #endif
514:
515: ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1.1 root 516: break;
517:
518: default:
519: {
520: register rtx body = PATTERN (insn);
521: int insn_code_number;
522: char *template;
523:
524: /* An INSN, JUMP_INSN or CALL_INSN.
1.1.1.2 root 525: First check for special kinds that recog doesn't recognize. */
1.1.1.4 root 526:
1.1 root 527: if (GET_CODE (body) == USE /* These are just declarations */
528: || GET_CODE (body) == CLOBBER)
529: break;
530: if (GET_CODE (body) == ASM_INPUT)
531: {
1.1.1.8 root 532: /* There's no telling what that did to the condition codes. */
533: CC_STATUS_INIT;
534: if (prescan > 0)
535: break;
1.1.1.2 root 536: if (! app_on)
537: {
538: fprintf (file, ASM_APP_ON);
539: app_on = 1;
540: }
541: fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
1.1 root 542: break;
543: }
544:
1.1.1.2 root 545: /* Detect `asm' construct with operands. */
546: if (asm_noperands (body) > 0)
547: {
548: int noperands = asm_noperands (body);
1.1.1.8 root 549: rtx *ops;
1.1.1.2 root 550: char *string;
551:
1.1.1.8 root 552: /* There's no telling what that did to the condition codes. */
553: CC_STATUS_INIT;
554: if (prescan > 0)
555: break;
556:
557: /* alloca won't do here, since only return from `final'
558: would free it. */
559: ops = (rtx *) malloc (noperands * sizeof (rtx));
560:
1.1.1.2 root 561: if (! app_on)
562: {
563: fprintf (file, ASM_APP_ON);
564: app_on = 1;
565: }
566:
567: /* Get out the operand values. */
568: string = decode_asm_operands (body, ops, 0, 0, 0);
1.1.1.9 root 569: /* Inhibit aborts on what would otherwise be compiler bugs. */
570: insn_noperands = noperands;
1.1.1.10! root 571: this_is_asm_operands = insn;
1.1.1.2 root 572: /* Output the insn using them. */
573: output_asm_insn (string, ops);
1.1.1.9 root 574: this_is_asm_operands = 0;
1.1.1.8 root 575: free (ops);
1.1.1.2 root 576: break;
577: }
578:
1.1.1.8 root 579: if (prescan <= 0 && app_on)
1.1.1.2 root 580: {
581: fprintf (file, ASM_APP_OFF);
582: app_on = 0;
583: }
584:
1.1 root 585: /* Detect insns that are really jump-tables
586: and output them as such. */
587:
588: if (GET_CODE (body) == ADDR_VEC)
589: {
590: register int vlen, idx;
1.1.1.8 root 591:
592: if (prescan > 0)
593: break;
594:
1.1 root 595: vlen = XVECLEN (body, 0);
596: for (idx = 0; idx < vlen; idx++)
1.1.1.4 root 597: ASM_OUTPUT_ADDR_VEC_ELT (file,
1.1 root 598: CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
1.1.1.4 root 599: #ifdef ASM_OUTPUT_CASE_END
600: ASM_OUTPUT_CASE_END (file,
601: CODE_LABEL_NUMBER (PREV_INSN (insn)),
602: insn);
603: #endif
1.1 root 604: break;
605: }
606: if (GET_CODE (body) == ADDR_DIFF_VEC)
607: {
608: register int vlen, idx;
1.1.1.8 root 609:
610: if (prescan > 0)
611: break;
612:
1.1 root 613: vlen = XVECLEN (body, 1);
614: for (idx = 0; idx < vlen; idx++)
1.1.1.4 root 615: ASM_OUTPUT_ADDR_DIFF_ELT (file,
1.1 root 616: CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
617: CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
1.1.1.4 root 618: #ifdef ASM_OUTPUT_CASE_END
1.1.1.7 root 619: ASM_OUTPUT_CASE_END (file,
620: CODE_LABEL_NUMBER (PREV_INSN (insn)),
621: insn);
1.1.1.4 root 622: #endif
1.1 root 623: break;
624: }
625:
626: /* We have a real machine instruction as rtl. */
627:
628: body = PATTERN (insn);
629:
1.1.1.4 root 630: /* Check for redundant test and compare instructions
1.1 root 631: (when the condition codes are already set up as desired).
632: This is done only when optimizing; if not optimizing,
633: it should be possible for the user to alter a variable
634: with the debugger in between statements
635: and the next statement should reexamine the variable
636: to compute the condition codes. */
637:
638: if (optimize
639: && GET_CODE (body) == SET
640: && GET_CODE (SET_DEST (body)) == CC0)
641: {
642: if (GET_CODE (SET_SRC (body)) == SUBREG)
1.1.1.6 root 643: SET_SRC (body) = alter_subreg (SET_SRC (body));
1.1 root 644: if ((cc_status.value1 != 0
645: && rtx_equal_p (SET_SRC (body), cc_status.value1))
646: || (cc_status.value2 != 0
647: && rtx_equal_p (SET_SRC (body), cc_status.value2)))
1.1.1.2 root 648: {
649: /* Don't delete insn if has an addressing side-effect */
1.1.1.6 root 650: if (! find_reg_note (insn, REG_INC, 0)
651: /* or if anything in it is volatile. */
652: && ! volatile_refs_p (PATTERN (insn)))
1.1.1.8 root 653: /* We don't really delete the insn; just ignore it. */
1.1.1.2 root 654: break;
655: }
1.1 root 656: }
657:
658: /* If this is a conditional branch, maybe modify it
659: if the cc's are in a nonstandard state
660: so that it accomplishes the same thing that it would
661: do straightforwardly if the cc's were set up normally. */
662:
663: if (cc_status.flags != 0
664: && GET_CODE (insn) == JUMP_INSN
665: && GET_CODE (body) == SET
666: && SET_DEST (body) == pc_rtx
1.1.1.8 root 667: && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
668: /* This is done during prescan; it is not done again
669: in final scan when prescan has been done. */
670: && prescan >= 0)
1.1 root 671: {
672: /* This function may alter the contents of its argument
673: and clear some of the cc_status.flags bits.
674: It may also return 1 meaning condition now always true
675: or -1 meaning condition now always false
676: or 2 meaning condition nontrivial but altered. */
677: register int result = alter_cond (XEXP (SET_SRC (body), 0));
678: /* If condition now has fixed value, replace the IF_THEN_ELSE
679: with its then-operand or its else-operand. */
680: if (result == 1)
681: SET_SRC (body) = XEXP (SET_SRC (body), 1);
682: if (result == -1)
683: SET_SRC (body) = XEXP (SET_SRC (body), 2);
684: /* The jump is now either unconditional or a no-op.
685: If it has become a no-op, don't try to output it.
686: (It would not be recognized.) */
687: if (SET_SRC (body) == pc_rtx)
1.1.1.8 root 688: {
689: PUT_CODE (insn, NOTE);
690: NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
691: NOTE_SOURCE_FILE (insn) = 0;
692: break;
693: }
1.1 root 694: /* Rerecognize the instruction if it has changed. */
695: if (result != 0)
696: INSN_CODE (insn) = -1;
697: }
698:
1.1.1.8 root 699: #ifdef STORE_FLAG_VALUE
1.1 root 700: /* Make same adjustments to instructions that examine the
1.1.1.8 root 701: condition codes without jumping (if this machine has them). */
1.1 root 702:
703: if (cc_status.flags != 0
704: && GET_CODE (body) == SET)
705: switch (GET_CODE (SET_SRC (body)))
706: {
707: case GTU:
708: case GT:
709: case LTU:
710: case LT:
711: case GEU:
712: case GE:
713: case LEU:
714: case LE:
715: case EQ:
716: case NE:
717: {
1.1.1.8 root 718: register int result;
719: if (GET_CODE (XEXP (SET_SRC (body), 0)) != CC0)
720: break;
721: result = alter_cond (SET_SRC (body));
1.1 root 722: if (result == 1)
1.1.1.8 root 723: SET_SRC (body) = gen_rtx (CONST_INT, VOIDmode,
724: STORE_FLAG_VALUE);
1.1 root 725: if (result == -1)
726: SET_SRC (body) = const0_rtx;
727: if (result != 0)
728: INSN_CODE (insn) = -1;
729: }
730: }
1.1.1.8 root 731: #endif /* STORE_FLAG_VALUE */
1.1 root 732:
733: /* Try to recognize the instruction.
734: If successful, verify that the operands satisfy the
735: constraints for the instruction. Crash if they don't,
736: since `reload' should have changed them so that they do. */
737:
738: insn_code_number = recog_memoized (insn);
739: insn_extract (insn);
740: for (i = 0; i < insn_n_operands[insn_code_number]; i++)
741: if (GET_CODE (recog_operand[i]) == SUBREG)
1.1.1.6 root 742: recog_operand[i] = alter_subreg (recog_operand[i]);
1.1 root 743:
744: #ifdef REGISTER_CONSTRAINTS
745: if (! constrain_operands (insn_code_number))
746: abort ();
747: #endif
748:
1.1.1.4 root 749: /* Some target machines need to prescan each insn before
750: it is output. */
751:
752: #ifdef FINAL_PRESCAN_INSN
753: FINAL_PRESCAN_INSN (insn, recog_operand,
754: insn_n_operands[insn_code_number]);
755: #endif
756:
1.1.1.2 root 757: cc_prev_status = cc_status;
758:
1.1 root 759: /* Update `cc_status' for this instruction.
760: The instruction's output routine may change it further.
761: This should be a no-op for jump instructions
762: because their output routines may need to examine `cc_status',
763: below. That's ok since jump insns don't normally alter
764: the condition codes. */
765:
1.1.1.8 root 766: NOTICE_UPDATE_CC (body, insn);
1.1 root 767:
768: /* If the proper template needs to be chosen by some C code,
1.1.1.2 root 769: run that code and get the real template. */
1.1 root 770:
771: template = insn_template[insn_code_number];
772: if (template == 0)
1.1.1.5 root 773: template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
1.1 root 774:
1.1.1.8 root 775: if (prescan > 0)
776: break;
777:
1.1 root 778: /* Output assembler code from the template. */
779:
780: output_asm_insn (template, recog_operand);
781: }
782: }
783: }
1.1.1.2 root 784: }
785:
786: /* Set up FILENAME as the current file for GDB line-number output. */
1.1 root 787:
1.1.1.2 root 788: void
789: set_current_gdbfile (filename)
790: char *filename;
791: {
792: register struct gdbfile *f;
793: for (f = gdbfiles; f; f = f->next)
794: if (!strcmp (f->name, filename))
795: break;
1.1 root 796:
1.1.1.2 root 797: if (!f)
798: {
799: f = (struct gdbfile *) permalloc (sizeof (struct gdbfile));
800: f->next = gdbfiles;
801: gdbfiles = f;
802: f->name = filename;
803: f->filenum = next_gdb_filenum++;
804: f->nlines = 0;
805: }
806: current_gdbfile = f;
807: lastfile = filename;
1.1 root 808: }
809:
1.1.1.2 root 810: /* Output debugging info to the assembler file FILE
811: based on the NOTE-insn INSN, assumed to be a line number. */
1.1 root 812:
1.1.1.2 root 813: static void
814: output_source_line (file, insn, write_symbols)
1.1 root 815: FILE *file;
816: rtx insn;
1.1.1.4 root 817: enum debugger write_symbols;
1.1 root 818: {
819: register char *filename = NOTE_SOURCE_FILE (insn);
1.1.1.4 root 820:
821: last_linenum = NOTE_LINE_NUMBER (insn);
822:
823: if (write_symbols == GDB_DEBUG)
1.1.1.2 root 824: {
825: /* Output GDB-format line number info. */
1.1 root 826:
1.1.1.2 root 827: /* If this is not the same source file as last time,
828: find or assign a GDB-file-number to this file. */
829: if (filename && (lastfile == 0 || strcmp (filename, lastfile)
830: || current_gdbfile == 0))
831: set_current_gdbfile (filename);
832:
833: ++current_gdbfile->nlines;
834: fprintf (file, "\t.gdbline %d,%d\n",
835: current_gdbfile->filenum, NOTE_LINE_NUMBER (insn));
836: }
1.1.1.4 root 837:
1.1.1.6 root 838: if (write_symbols == SDB_DEBUG || write_symbols == DBX_DEBUG)
1.1.1.4 root 839: {
1.1.1.6 root 840: #ifdef SDB_DEBUGGING_INFO
841: if (write_symbols == SDB_DEBUG
842: /* COFF can't handle multiple source files--lose, lose. */
1.1.1.10! root 843: && !strcmp (filename, main_input_filename)
! 844: /* COFF can't handle line #s before start-line of this function. */
! 845: && last_linenum >= sdb_begin_function_line)
1.1.1.6 root 846: {
1.1.1.4 root 847: #ifdef ASM_OUTPUT_SOURCE_LINE
1.1.1.6 root 848: ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
1.1.1.4 root 849: #else
1.1.1.6 root 850: fprintf (file, "\t.ln\t%d\n",
851: (sdb_begin_function_line
852: ? last_linenum - sdb_begin_function_line : 1));
1.1.1.4 root 853: #endif
1.1.1.6 root 854: }
1.1.1.4 root 855: #endif
856:
857: #ifdef DBX_DEBUGGING_INFO
1.1.1.6 root 858: if (write_symbols == DBX_DEBUG)
1.1.1.4 root 859: {
1.1.1.6 root 860: /* Write DBX line number data. */
861:
862: if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
863: {
1.1.1.2 root 864: #ifdef ASM_OUTPUT_SOURCE_FILENAME
1.1.1.6 root 865: ASM_OUTPUT_SOURCE_FILENAME (file, filename);
1.1.1.2 root 866: #else
1.1.1.6 root 867: fprintf (file, "\t.stabs \"%s\",%d,0,0,Ltext\n",
868: filename, N_SOL);
1.1.1.2 root 869: #endif
1.1.1.6 root 870: lastfile = filename;
871: }
1.1.1.4 root 872: }
1.1.1.2 root 873:
874: #ifdef ASM_OUTPUT_SOURCE_LINE
875: ASM_OUTPUT_SOURCE_LINE (file, NOTE_LINE_NUMBER (insn));
876: #else
877: fprintf (file, "\t.stabd %d,0,%d\n",
878: N_SLINE, NOTE_LINE_NUMBER (insn));
879: #endif
1.1.1.4 root 880: #endif /* DBX_DEBUGGING_INFO */
1.1.1.2 root 881: }
1.1 root 882: }
883:
1.1.1.2 root 884: /* If X is a SUBREG, replace it with a REG or a MEM,
885: based on the thing it is a subreg of. */
1.1 root 886:
1.1.1.10! root 887: rtx
1.1 root 888: alter_subreg (x)
889: register rtx x;
890: {
891: register rtx y = SUBREG_REG (x);
892: if (GET_CODE (y) == SUBREG)
1.1.1.6 root 893: y = alter_subreg (y);
1.1 root 894:
895: if (GET_CODE (y) == REG)
896: {
897: /* If the containing reg really gets a hard reg, so do we. */
898: PUT_CODE (x, REG);
899: REGNO (x) = REGNO (y) + SUBREG_WORD (x);
900: }
901: else if (GET_CODE (y) == MEM)
902: {
1.1.1.2 root 903: register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
1.1 root 904: #ifdef BYTES_BIG_ENDIAN
1.1.1.2 root 905: offset -= (min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
906: - min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
1.1 root 907: #endif
908: PUT_CODE (x, MEM);
909: XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
910: }
1.1.1.6 root 911: else if (GET_CODE (y) == CONST_DOUBLE)
912: return y;
913:
914: return x;
1.1 root 915: }
916:
1.1.1.2 root 917: /* Do alter_subreg on all the SUBREGs contained in X. */
1.1 root 918:
1.1.1.2 root 919: static rtx
920: walk_alter_subreg (x)
921: rtx x;
922: {
923: switch (GET_CODE (x))
1.1 root 924: {
1.1.1.2 root 925: case PLUS:
926: case MULT:
927: XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
928: XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
929: break;
930:
931: case MEM:
932: XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
933: break;
934:
935: case SUBREG:
1.1.1.6 root 936: return alter_subreg (x);
1.1 root 937: }
938:
1.1.1.2 root 939: return x;
1.1 root 940: }
941:
942: /* Given BODY, the body of a jump instruction, alter the jump condition
943: as required by the bits that are set in cc_status.flags.
944: Not all of the bits there can be handled at this level in all cases.
945:
946: The value is normally 0.
947: 1 means that the condition has become always true.
1.1.1.8 root 948: -1 means that the condition has become always false.
949: 2 means that COND has been altered. */
1.1 root 950:
951: static int
952: alter_cond (cond)
953: register rtx cond;
954: {
955: int value = 0;
956:
957: if (cc_status.flags & CC_REVERSED)
958: {
959: value = 2;
960: switch (GET_CODE (cond))
961: {
962: case LE:
963: PUT_CODE (cond, GE);
964: break;
965: case GE:
966: PUT_CODE (cond, LE);
967: break;
968: case LT:
969: PUT_CODE (cond, GT);
970: break;
971: case GT:
972: PUT_CODE (cond, LT);
973: break;
974: case LEU:
975: PUT_CODE (cond, GEU);
976: break;
977: case GEU:
978: PUT_CODE (cond, LEU);
979: break;
980: case LTU:
981: PUT_CODE (cond, GTU);
982: break;
983: case GTU:
984: PUT_CODE (cond, LTU);
985: break;
986: }
987: }
988:
1.1.1.8 root 989: if (cc_status.flags & CC_NOT_POSITIVE)
1.1 root 990: switch (GET_CODE (cond))
991: {
992: case LE:
993: case LEU:
994: case GEU:
995: /* Jump becomes unconditional. */
996: return 1;
997:
998: case GT:
999: case GTU:
1000: case LTU:
1001: /* Jump becomes no-op. */
1002: return -1;
1003:
1004: case GE:
1005: PUT_CODE (cond, EQ);
1006: value = 2;
1007: break;
1008:
1009: case LT:
1010: PUT_CODE (cond, NE);
1011: value = 2;
1012: break;
1013: }
1014:
1.1.1.8 root 1015: if (cc_status.flags & CC_NOT_NEGATIVE)
1.1 root 1016: switch (GET_CODE (cond))
1017: {
1018: case GE:
1019: case GEU:
1020: /* Jump becomes unconditional. */
1021: return 1;
1022:
1023: case LT:
1024: case LTU:
1025: /* Jump becomes no-op. */
1026: return -1;
1027:
1028: case LE:
1029: case LEU:
1030: PUT_CODE (cond, EQ);
1031: value = 2;
1032: break;
1033:
1034: case GT:
1035: case GTU:
1036: PUT_CODE (cond, NE);
1037: value = 2;
1038: break;
1039: }
1040:
1.1.1.8 root 1041: if (cc_status.flags & CC_NO_OVERFLOW)
1.1 root 1042: switch (GET_CODE (cond))
1043: {
1044: case GEU:
1045: /* Jump becomes unconditional. */
1046: return 1;
1047:
1048: case LEU:
1049: PUT_CODE (cond, EQ);
1050: value = 2;
1051: break;
1052:
1053: case GTU:
1054: PUT_CODE (cond, NE);
1055: value = 2;
1056: break;
1057:
1058: case LTU:
1059: /* Jump becomes no-op. */
1060: return -1;
1061: }
1062:
1.1.1.8 root 1063: if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
1064: switch (GET_CODE (cond))
1065: {
1066: case LE:
1067: case LEU:
1068: case GE:
1069: case GEU:
1070: case LT:
1071: case LTU:
1072: case GT:
1073: case GTU:
1074: abort ();
1075:
1076: case NE:
1077: PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
1078: value = 2;
1079: break;
1080:
1081: case EQ:
1082: PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
1083: value = 2;
1084: break;
1085: }
1086:
1.1 root 1087: return value;
1088: }
1089:
1.1.1.9 root 1090: /* Report inconsistency between the assembler template and the operands.
1091: In an `asm', it's the user's fault; otherwise, the compiler's fault. */
1092:
1093: static void
1094: output_operand_lossage (str)
1095: char *str;
1096: {
1097: if (this_is_asm_operands)
1098: {
1.1.1.10! root 1099: error_for_asm (this_is_asm_operands, "invalid `asm' above: %s", str);
1.1.1.9 root 1100: fprintf (asm_out_file, "!!error here!!");
1101: }
1102: else
1103: abort ();
1104: }
1105:
1.1 root 1106: /* Output of assembler code from a template, and its subroutines. */
1107:
1108: /* Output text from TEMPLATE to the assembler output file,
1109: obeying %-directions to substitute operands taken from
1110: the vector OPERANDS.
1111:
1112: %N (for N a digit) means print operand N in usual manner.
1113: %lN means require operand N to be a CODE_LABEL or LABEL_REF
1114: and print the label name with no punctuation.
1115: %cN means require operand N to be a constant
1116: and print the constant expression with no punctuation.
1117: %aN means expect operand N to be a memory address
1118: (not a memory reference!) and print a reference
1119: to that address.
1120: %nN means expect operand N to be a constant
1121: and print a constant expression for minus the value
1122: of the operand, with no other punctuation. */
1123:
1124: void
1125: output_asm_insn (template, operands)
1126: char *template;
1127: rtx *operands;
1128: {
1129: register char *p;
1130: register int c;
1131:
1.1.1.2 root 1132: /* An insn may return a null string template
1133: in a case where no assembler code is needed. */
1134: if (*template == 0)
1135: return;
1136:
1.1 root 1137: p = template;
1.1.1.2 root 1138: putc ('\t', asm_out_file);
1139:
1140: #ifdef ASM_OUTPUT_OPCODE
1141: ASM_OUTPUT_OPCODE (asm_out_file, p);
1142: #endif
1143:
1.1 root 1144: while (c = *p++)
1145: {
1.1.1.2 root 1146: #ifdef ASM_OUTPUT_OPCODE
1147: if (c == '\n')
1.1 root 1148: {
1.1.1.2 root 1149: putc (c, asm_out_file);
1150: while ((c = *p) == '\t')
1.1 root 1151: {
1.1.1.2 root 1152: putc (c, asm_out_file);
1153: p++;
1.1 root 1154: }
1.1.1.2 root 1155: ASM_OUTPUT_OPCODE (asm_out_file, p);
1156: }
1157: else
1158: #endif
1159: if (c != '%')
1160: putc (c, asm_out_file);
1161: else
1162: {
1163: /* %% outputs a single %. */
1164: if (*p == '%')
1.1 root 1165: {
1.1.1.2 root 1166: p++;
1167: putc (c, asm_out_file);
1.1 root 1168: }
1.1.1.2 root 1169: /* % followed by a letter and some digits
1170: outputs an operand in a special way depending on the letter.
1171: Letters `acln' are implemented here.
1172: Other letters are passed to `output_operand' so that
1173: the PRINT_OPERAND macro can define them. */
1174: else if ((*p >= 'a' && *p <= 'z')
1175: || (*p >= 'A' && *p <= 'Z'))
1.1 root 1176: {
1.1.1.2 root 1177: int letter = *p++;
1178: c = atoi (p);
1179:
1.1.1.9 root 1180: if (this_is_asm_operands
1181: && c >= (unsigned) insn_noperands && *p >= '0' && *p <= '9')
1182: output_operand_lossage ("operand number out of range");
1183: else if (letter == 'l')
1.1.1.2 root 1184: output_asm_label (operands[c]);
1185: else if (letter == 'a')
1186: output_address (operands[c]);
1187: else if (letter == 'c')
1188: {
1189: if (CONSTANT_ADDRESS_P (operands[c]))
1190: output_addr_const (asm_out_file, operands[c]);
1191: else
1192: output_operand (operands[c], 'c');
1193: }
1194: else if (letter == 'n')
1.1 root 1195: {
1.1.1.2 root 1196: if (GET_CODE (operands[c]) == CONST_INT)
1197: fprintf (asm_out_file, "%d", - INTVAL (operands[c]));
1198: else
1199: {
1200: putc ('-', asm_out_file);
1201: output_addr_const (asm_out_file, operands[c]);
1202: }
1.1 root 1203: }
1.1.1.2 root 1204: else if (*p >= '0' && *p <= '9')
1205: output_operand (operands[c], letter);
1206: else
1207: /* No operand-number follows the letter. */
1208: output_operand (0, letter);
1209:
1210: while ((c = *p) >= '0' && c <= '9') p++;
1.1 root 1211: }
1.1.1.2 root 1212: /* % followed by a digit outputs an operand the default way. */
1213: else if (*p >= '0' && *p <= '9')
1.1 root 1214: {
1215: c = atoi (p);
1.1.1.9 root 1216: if (this_is_asm_operands && c >= (unsigned) insn_noperands)
1217: output_operand_lossage ("operand number out of range");
1218: else
1219: output_operand (operands[c], 0);
1.1.1.2 root 1220: while ((c = *p) >= '0' && c <= '9') p++;
1.1 root 1221: }
1.1.1.2 root 1222: /* % followed by punctuation: output something for that
1223: punctuation character alone, with no operand.
1224: The PRINT_OPERAND macro decides what is actually done. */
1225: else
1226: output_operand (0, *p++);
1.1 root 1227: }
1228: }
1229:
1.1.1.2 root 1230: putc ('\n', asm_out_file);
1.1 root 1231: }
1.1.1.9 root 1232:
1.1.1.3 root 1233: /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
1234:
1235: void
1.1 root 1236: output_asm_label (x)
1237: rtx x;
1238: {
1.1.1.2 root 1239: char buf[20];
1240:
1.1 root 1241: if (GET_CODE (x) == LABEL_REF)
1.1.1.2 root 1242: ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
1.1 root 1243: else if (GET_CODE (x) == CODE_LABEL)
1.1.1.2 root 1244: ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
1.1 root 1245: else
1.1.1.9 root 1246: output_operand_lossage ("`%l' operand isn't a label");
1.1.1.2 root 1247:
1248: assemble_name (asm_out_file, buf);
1.1 root 1249: }
1250:
1251: /* Print operand X using machine-dependent assembler syntax.
1.1.1.2 root 1252: The macro PRINT_OPERAND is defined just to control this function.
1253: CODE is a non-digit that preceded the operand-number in the % spec,
1254: such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
1255: between the % and the digits.
1256: When CODE is a non-letter, X is 0.
1257:
1258: The meanings of the letters are machine-dependent and controlled
1259: by PRINT_OPERAND. */
1.1 root 1260:
1261: static void
1.1.1.2 root 1262: output_operand (x, code)
1.1 root 1263: rtx x;
1.1.1.2 root 1264: int code;
1.1 root 1265: {
1.1.1.2 root 1266: if (x && GET_CODE (x) == SUBREG)
1.1.1.6 root 1267: x = alter_subreg (x);
1.1.1.2 root 1268: PRINT_OPERAND (asm_out_file, x, code);
1.1 root 1269: }
1270:
1271: /* Print a memory reference operand for address X
1272: using machine-dependent assembler syntax.
1273: The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
1274:
1.1.1.2 root 1275: void
1.1 root 1276: output_address (x)
1277: rtx x;
1278: {
1.1.1.2 root 1279: walk_alter_subreg (x);
1280: PRINT_OPERAND_ADDRESS (asm_out_file, x);
1.1 root 1281: }
1282:
1283: /* Print an integer constant expression in assembler syntax.
1284: Addition and subtraction are the only arithmetic
1285: that may appear in these expressions. */
1286:
1287: void
1288: output_addr_const (file, x)
1289: FILE *file;
1290: rtx x;
1291: {
1.1.1.2 root 1292: char buf[20];
1293:
1.1 root 1294: restart:
1295: switch (GET_CODE (x))
1296: {
1297: case SYMBOL_REF:
1.1.1.2 root 1298: assemble_name (file, XSTR (x, 0));
1.1 root 1299: break;
1300:
1301: case LABEL_REF:
1.1.1.2 root 1302: ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
1303: assemble_name (asm_out_file, buf);
1.1 root 1304: break;
1305:
1306: case CODE_LABEL:
1.1.1.2 root 1307: ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
1308: assemble_name (asm_out_file, buf);
1.1 root 1309: break;
1310:
1311: case CONST_INT:
1312: fprintf (file, "%d", INTVAL (x));
1313: break;
1314:
1315: case CONST:
1316: x = XEXP (x, 0);
1317: goto restart;
1318:
1.1.1.8 root 1319: case CONST_DOUBLE:
1320: if (GET_MODE (x) == DImode)
1321: {
1322: /* We can use %d if the number is <32 bits and positive. */
1323: if (XINT (x, 1) || XINT (x, 0) < 0)
1324: fprintf (file, "0x%x%08x", XINT (x, 1), XINT (x, 0));
1325: else
1326: fprintf (file, "%d", XINT (x, 0));
1327: }
1328: else
1329: /* We can't handle floating point constants;
1330: PRINT_OPERAND must handle them. */
1.1.1.9 root 1331: output_operand_lossage ("floating constant misused");
1.1.1.8 root 1332: break;
1333:
1.1 root 1334: case PLUS:
1.1.1.4 root 1335: /* Some assemblers need integer constants to appear last (eg masm). */
1336: if (GET_CODE (XEXP (x, 0)) == CONST_INT)
1337: {
1338: output_addr_const (file, XEXP (x, 1));
1339: fprintf (file, "+");
1340: output_addr_const (file, XEXP (x, 0));
1341: }
1342: else
1343: {
1344: output_addr_const (file, XEXP (x, 0));
1345: fprintf (file, "+");
1346: output_addr_const (file, XEXP (x, 1));
1347: }
1.1 root 1348: break;
1349:
1350: case MINUS:
1351: output_addr_const (file, XEXP (x, 0));
1352: fprintf (file, "-");
1353: output_addr_const (file, XEXP (x, 1));
1354: break;
1355:
1356: default:
1.1.1.9 root 1357: output_operand_lossage ("invalid expression as operand");
1.1 root 1358: }
1359: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.