* config/i386/i386.md (clrstrsi): Call ix86_set_move_mem_attrs.
[official-gcc.git] / gcc / dwarf2asm.c
blobca1efb547b7ed241192cd8d2e969020c7cde6861
1 /* Dwarf2 assembler output helper routines.
2 Copyright (C) 2001 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "flags.h"
25 #include "rtl.h"
26 #include "output.h"
27 #include "dwarf2asm.h"
28 #include "tm_p.h"
31 /* How to start an assembler comment. */
32 #ifndef ASM_COMMENT_START
33 #define ASM_COMMENT_START ";#"
34 #endif
36 /* Definitions of defaults for assembler-dependent names of various
37 pseudo-ops and section names. These may be overridden in the tm.h
38 file (if necessary) for a particular assembler. */
40 #ifdef OBJECT_FORMAT_ELF
41 #ifndef UNALIGNED_SHORT_ASM_OP
42 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
43 #endif
44 #ifndef UNALIGNED_INT_ASM_OP
45 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
46 #endif
47 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
48 #define UNALIGNED_DOUBLE_INT_ASM_OP "\t.8byte\t"
49 #endif
50 #endif /* OBJECT_FORMAT_ELF */
52 #ifndef ASM_BYTE_OP
53 #define ASM_BYTE_OP "\t.byte\t"
54 #endif
56 /* We don't have unaligned support, let's hope the normal output works for
57 .debug_frame. But we know it won't work for .debug_info. */
58 #if !defined(UNALIGNED_INT_ASM_OP) && defined(DWARF2_DEBUGGING_INFO)
59 #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP.
60 #endif
63 #ifdef UNALIGNED_INT_ASM_OP
64 static const char * unaligned_integer_asm_op PARAMS ((int));
66 static inline const char *
67 unaligned_integer_asm_op (size)
68 int size;
70 const char *op;
71 switch (size)
73 case 1:
74 op = ASM_BYTE_OP;
75 break;
76 case 2:
77 op = UNALIGNED_SHORT_ASM_OP;
78 break;
79 case 4:
80 op = UNALIGNED_INT_ASM_OP;
81 break;
82 case 8:
83 #ifdef UNALIGNED_DOUBLE_INT_ASM_OP
84 op = UNALIGNED_DOUBLE_INT_ASM_OP;
85 break;
86 #endif
87 default:
88 abort ();
90 return op;
92 #endif /* UNALIGNED_INT_ASM_OP */
94 void
95 dw2_asm_output_data VPARAMS ((int size, unsigned HOST_WIDE_INT value,
96 const char *comment, ...))
98 #ifndef ANSI_PROTOTYPES
99 int size;
100 unsigned HOST_WIDE_INT value;
101 const char *comment;
102 #endif
103 va_list ap;
105 VA_START (ap, comment);
107 #ifndef ANSI_PROTOTYPES
108 size = va_arg (ap, int);
109 value = va_arg (ap, unsigned HOST_WIDE_INT);
110 comment = va_arg (ap, const char *);
111 #endif
113 #ifdef UNALIGNED_INT_ASM_OP
114 fputs (unaligned_integer_asm_op (size), asm_out_file);
115 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_HEX, value);
116 #else
117 assemble_integer (GEN_INT (value), size, 1);
118 #endif
120 if (flag_debug_asm && comment)
122 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
123 vfprintf (asm_out_file, comment, ap);
125 fputc ('\n', asm_out_file);
127 va_end (ap);
130 void
131 dw2_asm_output_delta VPARAMS ((int size, const char *lab1, const char *lab2,
132 const char *comment, ...))
134 #ifndef ANSI_PROTOTYPES
135 int size;
136 const char *lab1, *lab2;
137 const char *comment;
138 #endif
139 va_list ap;
141 VA_START (ap, comment);
143 #ifndef ANSI_PROTOTYPES
144 size = va_arg (ap, int);
145 lab1 = va_arg (ap, const char *);
146 lab2 = va_arg (ap, const char *);
147 comment = va_arg (ap, const char *);
148 #endif
150 #ifdef UNALIGNED_INT_ASM_OP
151 fputs (unaligned_integer_asm_op (size), asm_out_file);
152 assemble_name (asm_out_file, lab1);
153 fputc ('-', asm_out_file);
154 assemble_name (asm_out_file, lab2);
155 #else
156 assemble_integer (gen_rtx_MINUS (smallest_mode_for_size (size, MODE_INT),
157 gen_rtx_SYMBOL_REF (Pmode, lab1),
158 gen_rtx_SYMBOL_REF (Pmode, lab2)),
159 size, 1);
160 #endif
162 if (flag_debug_asm && comment)
164 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
165 vfprintf (asm_out_file, comment, ap);
167 fputc ('\n', asm_out_file);
169 va_end (ap);
172 void
173 dw2_asm_output_offset VPARAMS ((int size, const char *label,
174 const char *comment, ...))
176 #ifndef ANSI_PROTOTYPES
177 int size;
178 const char *label;
179 const char *comment;
180 #endif
181 va_list ap;
183 VA_START (ap, comment);
185 #ifndef ANSI_PROTOTYPES
186 size = va_arg (ap, int);
187 label = va_arg (ap, const char *);
188 comment = va_arg (ap, const char *);
189 #endif
191 #ifdef UNALIGNED_INT_ASM_OP
192 fputs (unaligned_integer_asm_op (size), asm_out_file);
193 assemble_name (asm_out_file, label);
194 #else
195 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, label), size, 1);
196 #endif
198 if (flag_debug_asm && comment)
200 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
201 vfprintf (asm_out_file, comment, ap);
203 fputc ('\n', asm_out_file);
205 va_end (ap);
208 void
209 dw2_asm_output_pcrel VPARAMS ((int size, const char *label,
210 const char *comment, ...))
212 #ifndef ANSI_PROTOTYPES
213 int size;
214 const char *label;
215 const char *comment;
216 #endif
217 va_list ap;
219 VA_START (ap, comment);
221 #ifndef ANSI_PROTOTYPES
222 size = va_arg (ap, int);
223 label = va_arg (ap, const char *);
224 comment = va_arg (ap, const char *);
225 #endif
227 #ifdef UNALIGNED_INT_ASM_OP
228 fputs (unaligned_integer_asm_op (size), asm_out_file);
230 /* ??? This needs target conditionalization. E.g. the solaris
231 assembler uses %r_disp32(label). Others don't like "." and
232 we need to generate a temporary label here. */
233 assemble_name (asm_out_file, label);
234 fputc ('-', asm_out_file);
235 fputc ('.', asm_out_file);
236 #else
237 abort ();
238 #endif
240 if (flag_debug_asm && comment)
242 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
243 vfprintf (asm_out_file, comment, ap);
245 fputc ('\n', asm_out_file);
247 va_end (ap);
250 void
251 dw2_asm_output_addr_rtx VPARAMS ((int size, rtx addr,
252 const char *comment, ...))
254 #ifndef ANSI_PROTOTYPES
255 int size;
256 rtx addr;
257 const char *comment;
258 #endif
259 va_list ap;
261 VA_START (ap, comment);
263 #ifndef ANSI_PROTOTYPES
264 size = va_arg (ap, int);
265 addr = va_arg (ap, rtx);
266 comment = va_arg (ap, const char *);
267 #endif
269 #ifdef UNALIGNED_INT_ASM_OP
270 fputs (unaligned_integer_asm_op (size), asm_out_file);
271 output_addr_const (asm_out_file, addr);
272 #else
273 assemble_integer (addr, size, 1);
274 #endif
276 if (flag_debug_asm && comment)
278 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
279 vfprintf (asm_out_file, comment, ap);
281 fputc ('\n', asm_out_file);
283 va_end (ap);
286 void
287 dw2_asm_output_nstring VPARAMS ((const char *str, size_t orig_len,
288 const char *comment, ...))
290 #ifndef ANSI_PROTOTYPES
291 const char *str;
292 size_t orig_len;
293 const char *comment;
294 #endif
295 va_list ap;
296 size_t i, len = orig_len;
298 VA_START (ap, comment);
300 #ifndef ANSI_PROTOTYPES
301 str = va_arg (ap, const char *);
302 len = va_arg (ap, size_t);
303 comment = va_arg (ap, const char *);
304 #endif
306 if (len == (size_t) -1)
307 len = strlen (str);
309 if (flag_debug_asm && comment)
311 fputs ("\t.ascii \"", asm_out_file);
312 for (i = 0; i < len; i++)
314 int c = str[i];
315 if (c == '\"' || c == '\\')
316 fputc ('\\', asm_out_file);
317 if (ISPRINT(c))
318 fputc (c, asm_out_file);
319 else
320 fprintf (asm_out_file, "\\%o", c);
322 fprintf (asm_out_file, "\\0\"\t%s ", ASM_COMMENT_START);
323 vfprintf (asm_out_file, comment, ap);
324 fputc ('\n', asm_out_file);
326 else
328 /* If an explicit length was given, we can't assume there
329 is a null termination in the string buffer. */
330 if (orig_len == (size_t) -1)
331 len += 1;
332 ASM_OUTPUT_ASCII (asm_out_file, str, len);
333 if (orig_len != (size_t) -1)
334 fprintf (asm_out_file, "%s0\n", ASM_BYTE_OP);
337 va_end (ap);
341 /* Return the size of an unsigned LEB128 quantity. */
344 size_of_uleb128 (value)
345 unsigned HOST_WIDE_INT value;
347 int size = 0, byte;
351 byte = (value & 0x7f);
352 value >>= 7;
353 size += 1;
355 while (value != 0);
357 return size;
360 /* Return the size of a signed LEB128 quantity. */
363 size_of_sleb128 (value)
364 HOST_WIDE_INT value;
366 int size = 0, byte;
370 byte = (value & 0x7f);
371 value >>= 7;
372 size += 1;
374 while (!((value == 0 && (byte & 0x40) == 0)
375 || (value == -1 && (byte & 0x40) != 0)));
377 return size;
380 /* Output an unsigned LEB128 quantity. */
382 void
383 dw2_asm_output_data_uleb128 VPARAMS ((unsigned HOST_WIDE_INT value,
384 const char *comment, ...))
386 #ifndef ANSI_PROTOTYPES
387 unsigned HOST_WIDE_INT value;
388 const char *comment;
389 #endif
390 va_list ap;
392 VA_START (ap, comment);
394 #ifndef ANSI_PROTOTYPES
395 value = va_arg (ap, unsigned HOST_WIDE_INT);
396 comment = va_arg (ap, const char *);
397 #endif
399 #ifdef HAVE_AS_LEB128
400 fputs ("\t.uleb128\t", asm_out_file);
401 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_HEX, value);
403 if (flag_debug_asm && comment)
405 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
406 vfprintf (asm_out_file, comment, ap);
408 #else
410 unsigned HOST_WIDE_INT work = value;
412 fputs (ASM_BYTE_OP, asm_out_file);
415 int byte = (work & 0x7f);
416 work >>= 7;
417 if (work != 0)
418 /* More bytes to follow. */
419 byte |= 0x80;
421 fprintf (asm_out_file, "0x%x", byte);
422 if (work != 0)
423 fputc (',', asm_out_file);
425 while (work != 0);
427 if (flag_debug_asm)
429 fprintf (asm_out_file, "\t%s uleb128 ", ASM_COMMENT_START);
430 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_HEX, value);
431 if (comment)
433 fputs ("; ", asm_out_file);
434 vfprintf (asm_out_file, comment, ap);
438 #endif
439 fputc ('\n', asm_out_file);
441 va_end (ap);
444 /* Output an signed LEB128 quantity. */
446 void
447 dw2_asm_output_data_sleb128 VPARAMS ((HOST_WIDE_INT value,
448 const char *comment, ...))
450 #ifndef ANSI_PROTOTYPES
451 HOST_WIDE_INT value;
452 const char *comment;
453 #endif
454 va_list ap;
456 VA_START (ap, comment);
458 #ifndef ANSI_PROTOTYPES
459 value = va_arg (ap, HOST_WIDE_INT);
460 comment = va_arg (ap, const char *);
461 #endif
463 #ifdef HAVE_AS_LEB128
464 fputs ("\t.sleb128\t", asm_out_file);
465 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_HEX, value);
467 if (flag_debug_asm && comment)
469 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
470 vfprintf (asm_out_file, comment, ap);
472 #else
474 HOST_WIDE_INT work = value;
475 int more, byte;
477 fputs (ASM_BYTE_OP, asm_out_file);
480 byte = (work & 0x7f);
481 /* arithmetic shift */
482 work >>= 7;
483 more = !((work == 0 && (byte & 0x40) == 0)
484 || (work == -1 && (byte & 0x40) != 0));
485 if (more)
486 byte |= 0x80;
488 fprintf (asm_out_file, "0x%x", byte);
489 if (more)
490 fputc (',', asm_out_file);
492 while (more);
494 if (flag_debug_asm)
496 fprintf (asm_out_file, "\t%s sleb128 ", ASM_COMMENT_START);
497 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, value);
498 if (comment)
500 fputs ("; ", asm_out_file);
501 vfprintf (asm_out_file, comment, ap);
505 #endif
506 fputc ('\n', asm_out_file);
508 va_end (ap);
511 void
512 dw2_asm_output_delta_uleb128 VPARAMS ((const char *lab1 ATTRIBUTE_UNUSED,
513 const char *lab2 ATTRIBUTE_UNUSED,
514 const char *comment, ...))
516 #ifndef ANSI_PROTOTYPES
517 const char *lab1, *lab2;
518 const char *comment;
519 #endif
520 va_list ap;
522 VA_START (ap, comment);
524 #ifndef ANSI_PROTOTYPES
525 lab1 = va_arg (ap, const char *);
526 lab2 = va_arg (ap, const char *);
527 comment = va_arg (ap, const char *);
528 #endif
530 #ifdef HAVE_AS_LEB128
531 fputs ("\t.uleb128\t", asm_out_file);
532 assemble_name (asm_out_file, lab1);
533 fputc ('-', asm_out_file);
534 assemble_name (asm_out_file, lab2);
535 #else
536 abort ();
537 #endif
539 if (flag_debug_asm && comment)
541 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
542 vfprintf (asm_out_file, comment, ap);
544 fputc ('\n', asm_out_file);
546 va_end (ap);
549 void
550 dw2_asm_output_delta_sleb128 VPARAMS ((const char *lab1 ATTRIBUTE_UNUSED,
551 const char *lab2 ATTRIBUTE_UNUSED,
552 const char *comment, ...))
554 #ifndef ANSI_PROTOTYPES
555 const char *lab1, *lab2;
556 const char *comment;
557 #endif
558 va_list ap;
560 VA_START (ap, comment);
562 #ifndef ANSI_PROTOTYPES
563 lab1 = va_arg (ap, const char *);
564 lab2 = va_arg (ap, const char *);
565 comment = va_arg (ap, const char *);
566 #endif
568 #ifdef HAVE_AS_LEB128
569 fputs ("\t.sleb128\t", asm_out_file);
570 assemble_name (asm_out_file, lab1);
571 fputc ('-', asm_out_file);
572 assemble_name (asm_out_file, lab2);
573 #else
574 abort ();
575 #endif
577 if (flag_debug_asm && comment)
579 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
580 vfprintf (asm_out_file, comment, ap);
582 fputc ('\n', asm_out_file);
584 va_end (ap);