Pass pointer to RTX when calling alter_subreg().
[official-gcc.git] / gcc / dwarf2asm.c
blob94f0e967be0adde3b2a663ec122716b4c4d8e29d
1 /* Dwarf2 assembler output helper routines.
2 Copyright (C) 2001 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "flags.h"
25 #include "tree.h"
26 #include "rtl.h"
27 #include "output.h"
28 #include "dwarf2asm.h"
29 #include "dwarf2.h"
30 #include "splay-tree.h"
31 #include "ggc.h"
32 #include "tm_p.h"
35 /* How to start an assembler comment. */
36 #ifndef ASM_COMMENT_START
37 #define ASM_COMMENT_START ";#"
38 #endif
40 /* We don't have unaligned support, let's hope the normal output works for
41 .debug_frame. But we know it won't work for .debug_info. */
42 #if !defined(UNALIGNED_INT_ASM_OP) && defined(DWARF2_DEBUGGING_INFO)
43 #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP.
44 #endif
47 /* Despite the fact that assemble_integer handles unaligned data,
48 continue emitting things by hand when possible, since that makes
49 the assembler commentary come out prettier. */
50 #ifdef UNALIGNED_INT_ASM_OP
51 static const char * unaligned_integer_asm_op PARAMS ((int));
53 static inline const char *
54 unaligned_integer_asm_op (size)
55 int size;
57 const char *op = NULL;
58 switch (size)
60 case 1:
61 op = ASM_BYTE_OP;
62 break;
63 case 2:
64 op = UNALIGNED_SHORT_ASM_OP;
65 break;
66 case 4:
67 op = UNALIGNED_INT_ASM_OP;
68 break;
69 case 8:
70 #ifdef UNALIGNED_DOUBLE_INT_ASM_OP
71 op = UNALIGNED_DOUBLE_INT_ASM_OP;
72 break;
73 #endif
74 default:
75 abort ();
78 if (! op)
79 abort ();
81 return op;
83 #endif /* UNALIGNED_INT_ASM_OP */
85 /* Output an immediate constant in a given size. */
87 void
88 dw2_asm_output_data VPARAMS ((int size, unsigned HOST_WIDE_INT value,
89 const char *comment, ...))
91 VA_OPEN (ap, comment);
92 VA_FIXEDARG (ap, int, size);
93 VA_FIXEDARG (ap, unsigned HOST_WIDE_INT, value);
94 VA_FIXEDARG (ap, const char *, comment);
96 if (size * 8 < HOST_BITS_PER_WIDE_INT)
97 value &= ~(~(unsigned HOST_WIDE_INT)0 << (size * 8));
99 #ifdef UNALIGNED_INT_ASM_OP
100 fputs (unaligned_integer_asm_op (size), asm_out_file);
101 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_HEX, value);
102 #else
103 assemble_integer (GEN_INT (value), size, BITS_PER_UNIT, 1);
104 #endif
106 if (flag_debug_asm && comment)
108 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
109 vfprintf (asm_out_file, comment, ap);
111 fputc ('\n', asm_out_file);
113 VA_CLOSE (ap);
116 /* Output the difference between two symbols in a given size. */
117 /* ??? There appear to be assemblers that do not like such
118 subtraction, but do support ASM_SET_OP. It's unfortunately
119 impossible to do here, since the ASM_SET_OP for the difference
120 symbol must appear after both symbols are defined. */
122 void
123 dw2_asm_output_delta VPARAMS ((int size, const char *lab1, const char *lab2,
124 const char *comment, ...))
126 VA_OPEN (ap, comment);
127 VA_FIXEDARG (ap, int, size);
128 VA_FIXEDARG (ap, const char *, lab1);
129 VA_FIXEDARG (ap, const char *, lab2);
130 VA_FIXEDARG (ap, const char *, comment);
132 #ifdef UNALIGNED_INT_ASM_OP
133 fputs (unaligned_integer_asm_op (size), asm_out_file);
134 assemble_name (asm_out_file, lab1);
135 fputc ('-', asm_out_file);
136 assemble_name (asm_out_file, lab2);
137 #else
138 assemble_integer (gen_rtx_MINUS (Pmode, gen_rtx_SYMBOL_REF (Pmode, lab1),
139 gen_rtx_SYMBOL_REF (Pmode, lab2)),
140 size, BITS_PER_UNIT, 1);
141 #endif
143 if (flag_debug_asm && comment)
145 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
146 vfprintf (asm_out_file, comment, ap);
148 fputc ('\n', asm_out_file);
150 VA_CLOSE (ap);
153 /* Output a section-relative reference to a label. In general this
154 can only be done for debugging symbols. E.g. on most targets with
155 the GNU linker, this is accomplished with a direct reference and
156 the knowledge that the debugging section will be placed at VMA 0.
157 Some targets have special relocations for this that we must use. */
159 void
160 dw2_asm_output_offset VPARAMS ((int size, const char *label,
161 const char *comment, ...))
163 VA_OPEN (ap, comment);
164 VA_FIXEDARG (ap, int, size);
165 VA_FIXEDARG (ap, const char *, label);
166 VA_FIXEDARG (ap, const char *, comment);
168 #ifdef ASM_OUTPUT_DWARF_OFFSET
169 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, size, label);
170 #else
171 #ifdef UNALIGNED_INT_ASM_OP
172 fputs (unaligned_integer_asm_op (size), asm_out_file);
173 assemble_name (asm_out_file, label);
174 #else
175 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, label), size, BITS_PER_UNIT, 1);
176 #endif
177 #endif
179 if (flag_debug_asm && comment)
181 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
182 vfprintf (asm_out_file, comment, ap);
184 fputc ('\n', asm_out_file);
186 VA_CLOSE (ap);
189 /* Output a self-relative reference to a label, possibly in a
190 different section or object file. */
192 void
193 dw2_asm_output_pcrel VPARAMS ((int size ATTRIBUTE_UNUSED,
194 const char *label ATTRIBUTE_UNUSED,
195 const char *comment, ...))
197 VA_OPEN (ap, comment);
198 VA_FIXEDARG (ap, int, size);
199 VA_FIXEDARG (ap, const char *, label);
200 VA_FIXEDARG (ap, const char *, comment);
202 #ifdef ASM_OUTPUT_DWARF_PCREL
203 ASM_OUTPUT_DWARF_PCREL (asm_out_file, size, label);
204 #else
205 #ifdef UNALIGNED_INT_ASM_OP
206 fputs (unaligned_integer_asm_op (size), asm_out_file);
207 assemble_name (asm_out_file, label);
208 fputc ('-', asm_out_file);
209 fputc ('.', asm_out_file);
210 #else
211 abort ();
212 #endif
213 #endif
215 if (flag_debug_asm && comment)
217 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
218 vfprintf (asm_out_file, comment, ap);
220 fputc ('\n', asm_out_file);
222 VA_CLOSE (ap);
225 /* Output an absolute reference to a label. */
227 void
228 dw2_asm_output_addr VPARAMS ((int size, const char *label,
229 const char *comment, ...))
231 VA_OPEN (ap, comment);
232 VA_FIXEDARG (ap, int, size);
233 VA_FIXEDARG (ap, const char *, label);
234 VA_FIXEDARG (ap, const char *, comment);
236 #ifdef UNALIGNED_INT_ASM_OP
237 fputs (unaligned_integer_asm_op (size), asm_out_file);
238 assemble_name (asm_out_file, label);
239 #else
240 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, label), size, BITS_PER_UNIT, 1);
241 #endif
243 if (flag_debug_asm && comment)
245 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
246 vfprintf (asm_out_file, comment, ap);
248 fputc ('\n', asm_out_file);
250 VA_CLOSE (ap);
253 /* Similar, but use an RTX expression instead of a text label. */
255 void
256 dw2_asm_output_addr_rtx VPARAMS ((int size, rtx addr,
257 const char *comment, ...))
259 VA_OPEN (ap, comment);
260 VA_FIXEDARG (ap, int, size);
261 VA_FIXEDARG (ap, rtx, addr);
262 VA_FIXEDARG (ap, const char *, comment);
264 #ifdef UNALIGNED_INT_ASM_OP
265 fputs (unaligned_integer_asm_op (size), asm_out_file);
266 output_addr_const (asm_out_file, addr);
267 #else
268 assemble_integer (addr, size, BITS_PER_UNIT, 1);
269 #endif
271 if (flag_debug_asm && comment)
273 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
274 vfprintf (asm_out_file, comment, ap);
276 fputc ('\n', asm_out_file);
278 VA_CLOSE (ap);
281 void
282 dw2_asm_output_nstring VPARAMS ((const char *str, size_t orig_len,
283 const char *comment, ...))
285 size_t i, len;
287 VA_OPEN (ap, comment);
288 VA_FIXEDARG (ap, const char *, str);
289 VA_FIXEDARG (ap, size_t, orig_len);
290 VA_FIXEDARG (ap, const char *, comment);
292 len = orig_len;
294 if (len == (size_t) -1)
295 len = strlen (str);
297 if (flag_debug_asm && comment)
299 fputs ("\t.ascii \"", asm_out_file);
300 for (i = 0; i < len; i++)
302 int c = str[i];
303 if (c == '\"' || c == '\\')
304 fputc ('\\', asm_out_file);
305 if (ISPRINT(c))
306 fputc (c, asm_out_file);
307 else
308 fprintf (asm_out_file, "\\%o", c);
310 fprintf (asm_out_file, "\\0\"\t%s ", ASM_COMMENT_START);
311 vfprintf (asm_out_file, comment, ap);
312 fputc ('\n', asm_out_file);
314 else
316 /* If an explicit length was given, we can't assume there
317 is a null termination in the string buffer. */
318 if (orig_len == (size_t) -1)
319 len += 1;
320 ASM_OUTPUT_ASCII (asm_out_file, str, len);
321 if (orig_len != (size_t) -1)
322 fprintf (asm_out_file, "%s0\n", ASM_BYTE_OP);
325 VA_CLOSE (ap);
329 /* Return the size of an unsigned LEB128 quantity. */
332 size_of_uleb128 (value)
333 unsigned HOST_WIDE_INT value;
335 int size = 0, byte;
339 byte = (value & 0x7f);
340 value >>= 7;
341 size += 1;
343 while (value != 0);
345 return size;
348 /* Return the size of a signed LEB128 quantity. */
351 size_of_sleb128 (value)
352 HOST_WIDE_INT value;
354 int size = 0, byte;
358 byte = (value & 0x7f);
359 value >>= 7;
360 size += 1;
362 while (!((value == 0 && (byte & 0x40) == 0)
363 || (value == -1 && (byte & 0x40) != 0)));
365 return size;
368 /* Given an encoding, return the number of bytes the format occupies.
369 This is only defined for fixed-size encodings, and so does not
370 include leb128. */
373 size_of_encoded_value (encoding)
374 int encoding;
376 if (encoding == DW_EH_PE_omit)
377 return 0;
379 switch (encoding & 0x07)
381 case DW_EH_PE_absptr:
382 return POINTER_SIZE / BITS_PER_UNIT;
383 case DW_EH_PE_udata2:
384 return 2;
385 case DW_EH_PE_udata4:
386 return 4;
387 case DW_EH_PE_udata8:
388 return 8;
390 abort ();
393 /* Yield a name for a given pointer encoding. */
395 const char *
396 eh_data_format_name (format)
397 int format;
399 #if HAVE_DESIGNATED_INITIALIZERS
400 #define S(p, v) [p] = v,
401 #else
402 #define S(p, v) case p: return v;
403 #endif
405 #if HAVE_DESIGNATED_INITIALIZERS
406 __extension__ static const char * const format_names[256] = {
407 #else
408 switch (format) {
409 #endif
411 S(DW_EH_PE_absptr, "absolute")
412 S(DW_EH_PE_omit, "omit")
413 S(DW_EH_PE_aligned, "aligned absolute")
415 S(DW_EH_PE_uleb128, "uleb128")
416 S(DW_EH_PE_udata2, "udata2")
417 S(DW_EH_PE_udata4, "udata4")
418 S(DW_EH_PE_udata8, "udata8")
419 S(DW_EH_PE_sleb128, "sleb128")
420 S(DW_EH_PE_sdata2, "sdata2")
421 S(DW_EH_PE_sdata4, "sdata4")
422 S(DW_EH_PE_sdata8, "sdata8")
424 S(DW_EH_PE_absptr | DW_EH_PE_pcrel, "pcrel")
425 S(DW_EH_PE_uleb128 | DW_EH_PE_pcrel, "pcrel uleb128")
426 S(DW_EH_PE_udata2 | DW_EH_PE_pcrel, "pcrel udata2")
427 S(DW_EH_PE_udata4 | DW_EH_PE_pcrel, "pcrel udata4")
428 S(DW_EH_PE_udata8 | DW_EH_PE_pcrel, "pcrel udata8")
429 S(DW_EH_PE_sleb128 | DW_EH_PE_pcrel, "pcrel sleb128")
430 S(DW_EH_PE_sdata2 | DW_EH_PE_pcrel, "pcrel sdata2")
431 S(DW_EH_PE_sdata4 | DW_EH_PE_pcrel, "pcrel sdata4")
432 S(DW_EH_PE_sdata8 | DW_EH_PE_pcrel, "pcrel sdata8")
434 S(DW_EH_PE_absptr | DW_EH_PE_textrel, "textrel")
435 S(DW_EH_PE_uleb128 | DW_EH_PE_textrel, "textrel uleb128")
436 S(DW_EH_PE_udata2 | DW_EH_PE_textrel, "textrel udata2")
437 S(DW_EH_PE_udata4 | DW_EH_PE_textrel, "textrel udata4")
438 S(DW_EH_PE_udata8 | DW_EH_PE_textrel, "textrel udata8")
439 S(DW_EH_PE_sleb128 | DW_EH_PE_textrel, "textrel sleb128")
440 S(DW_EH_PE_sdata2 | DW_EH_PE_textrel, "textrel sdata2")
441 S(DW_EH_PE_sdata4 | DW_EH_PE_textrel, "textrel sdata4")
442 S(DW_EH_PE_sdata8 | DW_EH_PE_textrel, "textrel sdata8")
444 S(DW_EH_PE_absptr | DW_EH_PE_datarel, "datarel")
445 S(DW_EH_PE_uleb128 | DW_EH_PE_datarel, "datarel uleb128")
446 S(DW_EH_PE_udata2 | DW_EH_PE_datarel, "datarel udata2")
447 S(DW_EH_PE_udata4 | DW_EH_PE_datarel, "datarel udata4")
448 S(DW_EH_PE_udata8 | DW_EH_PE_datarel, "datarel udata8")
449 S(DW_EH_PE_sleb128 | DW_EH_PE_datarel, "datarel sleb128")
450 S(DW_EH_PE_sdata2 | DW_EH_PE_datarel, "datarel sdata2")
451 S(DW_EH_PE_sdata4 | DW_EH_PE_datarel, "datarel sdata4")
452 S(DW_EH_PE_sdata8 | DW_EH_PE_datarel, "datarel sdata8")
454 S(DW_EH_PE_absptr | DW_EH_PE_funcrel, "funcrel")
455 S(DW_EH_PE_uleb128 | DW_EH_PE_funcrel, "funcrel uleb128")
456 S(DW_EH_PE_udata2 | DW_EH_PE_funcrel, "funcrel udata2")
457 S(DW_EH_PE_udata4 | DW_EH_PE_funcrel, "funcrel udata4")
458 S(DW_EH_PE_udata8 | DW_EH_PE_funcrel, "funcrel udata8")
459 S(DW_EH_PE_sleb128 | DW_EH_PE_funcrel, "funcrel sleb128")
460 S(DW_EH_PE_sdata2 | DW_EH_PE_funcrel, "funcrel sdata2")
461 S(DW_EH_PE_sdata4 | DW_EH_PE_funcrel, "funcrel sdata4")
462 S(DW_EH_PE_sdata8 | DW_EH_PE_funcrel, "funcrel sdata8")
464 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_pcrel,
465 "indirect pcrel")
466 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_pcrel,
467 "indirect pcrel uleb128")
468 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_pcrel,
469 "indirect pcrel udata2")
470 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_pcrel,
471 "indirect pcrel udata4")
472 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_pcrel,
473 "indirect pcrel udata8")
474 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_pcrel,
475 "indirect pcrel sleb128")
476 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_pcrel,
477 "indirect pcrel sdata2")
478 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_pcrel,
479 "indirect pcrel sdata4")
480 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_pcrel,
481 "indirect pcrel sdata8")
483 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_textrel,
484 "indirect textrel")
485 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_textrel,
486 "indirect textrel uleb128")
487 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_textrel,
488 "indirect textrel udata2")
489 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_textrel,
490 "indirect textrel udata4")
491 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_textrel,
492 "indirect textrel udata8")
493 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_textrel,
494 "indirect textrel sleb128")
495 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_textrel,
496 "indirect textrel sdata2")
497 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_textrel,
498 "indirect textrel sdata4")
499 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_textrel,
500 "indirect textrel sdata8")
502 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_datarel,
503 "indirect datarel")
504 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_datarel,
505 "indirect datarel uleb128")
506 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_datarel,
507 "indirect datarel udata2")
508 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_datarel,
509 "indirect datarel udata4")
510 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_datarel,
511 "indirect datarel udata8")
512 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_datarel,
513 "indirect datarel sleb128")
514 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_datarel,
515 "indirect datarel sdata2")
516 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_datarel,
517 "indirect datarel sdata4")
518 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_datarel,
519 "indirect datarel sdata8")
521 S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_funcrel,
522 "indirect funcrel")
523 S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_funcrel,
524 "indirect funcrel uleb128")
525 S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_funcrel,
526 "indirect funcrel udata2")
527 S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_funcrel,
528 "indirect funcrel udata4")
529 S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_funcrel,
530 "indirect funcrel udata8")
531 S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_funcrel,
532 "indirect funcrel sleb128")
533 S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_funcrel,
534 "indirect funcrel sdata2")
535 S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_funcrel,
536 "indirect funcrel sdata4")
537 S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_funcrel,
538 "indirect funcrel sdata8")
540 #if HAVE_DESIGNATED_INITIALIZERS
543 if (format < 0 || format > 0xff || format_names[format] == NULL)
544 abort ();
545 return format_names[format];
546 #else
548 abort ();
549 #endif
552 /* Output an unsigned LEB128 quantity. */
554 void
555 dw2_asm_output_data_uleb128 VPARAMS ((unsigned HOST_WIDE_INT value,
556 const char *comment, ...))
558 VA_OPEN (ap, comment);
559 VA_FIXEDARG (ap, unsigned HOST_WIDE_INT, value);
560 VA_FIXEDARG (ap, const char *, comment);
562 #ifdef HAVE_AS_LEB128
563 fputs ("\t.uleb128 ", asm_out_file);
564 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_HEX, value);
566 if (flag_debug_asm && comment)
568 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
569 vfprintf (asm_out_file, comment, ap);
571 #else
573 unsigned HOST_WIDE_INT work = value;
575 fputs (ASM_BYTE_OP, asm_out_file);
578 int byte = (work & 0x7f);
579 work >>= 7;
580 if (work != 0)
581 /* More bytes to follow. */
582 byte |= 0x80;
584 fprintf (asm_out_file, "0x%x", byte);
585 if (work != 0)
586 fputc (',', asm_out_file);
588 while (work != 0);
590 if (flag_debug_asm)
592 fprintf (asm_out_file, "\t%s uleb128 ", ASM_COMMENT_START);
593 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_HEX, value);
594 if (comment)
596 fputs ("; ", asm_out_file);
597 vfprintf (asm_out_file, comment, ap);
601 #endif
602 fputc ('\n', asm_out_file);
604 VA_CLOSE (ap);
607 /* Output an signed LEB128 quantity. */
609 void
610 dw2_asm_output_data_sleb128 VPARAMS ((HOST_WIDE_INT value,
611 const char *comment, ...))
613 VA_OPEN (ap, comment);
614 VA_FIXEDARG (ap, HOST_WIDE_INT, value);
615 VA_FIXEDARG (ap, const char *, comment);
617 #ifdef HAVE_AS_LEB128
618 fputs ("\t.sleb128 ", asm_out_file);
619 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, value);
621 if (flag_debug_asm && comment)
623 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
624 vfprintf (asm_out_file, comment, ap);
626 #else
628 HOST_WIDE_INT work = value;
629 int more, byte;
631 fputs (ASM_BYTE_OP, asm_out_file);
634 byte = (work & 0x7f);
635 /* arithmetic shift */
636 work >>= 7;
637 more = !((work == 0 && (byte & 0x40) == 0)
638 || (work == -1 && (byte & 0x40) != 0));
639 if (more)
640 byte |= 0x80;
642 fprintf (asm_out_file, "0x%x", byte);
643 if (more)
644 fputc (',', asm_out_file);
646 while (more);
648 if (flag_debug_asm)
650 fprintf (asm_out_file, "\t%s sleb128 ", ASM_COMMENT_START);
651 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, value);
652 if (comment)
654 fputs ("; ", asm_out_file);
655 vfprintf (asm_out_file, comment, ap);
659 #endif
660 fputc ('\n', asm_out_file);
662 VA_CLOSE (ap);
665 void
666 dw2_asm_output_delta_uleb128 VPARAMS ((const char *lab1 ATTRIBUTE_UNUSED,
667 const char *lab2 ATTRIBUTE_UNUSED,
668 const char *comment, ...))
670 VA_OPEN (ap, comment);
671 VA_FIXEDARG (ap, const char *, lab1);
672 VA_FIXEDARG (ap, const char *, lab2);
673 VA_FIXEDARG (ap, const char *, comment);
675 #ifdef HAVE_AS_LEB128
676 fputs ("\t.uleb128 ", asm_out_file);
677 assemble_name (asm_out_file, lab1);
678 fputc ('-', asm_out_file);
679 assemble_name (asm_out_file, lab2);
680 #else
681 abort ();
682 #endif
684 if (flag_debug_asm && comment)
686 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
687 vfprintf (asm_out_file, comment, ap);
689 fputc ('\n', asm_out_file);
691 VA_CLOSE (ap);
694 void
695 dw2_asm_output_delta_sleb128 VPARAMS ((const char *lab1 ATTRIBUTE_UNUSED,
696 const char *lab2 ATTRIBUTE_UNUSED,
697 const char *comment, ...))
699 VA_OPEN (ap, comment);
700 VA_FIXEDARG (ap, const char *, lab1);
701 VA_FIXEDARG (ap, const char *, lab2);
702 VA_FIXEDARG (ap, const char *, comment);
704 #ifdef HAVE_AS_LEB128
705 fputs ("\t.sleb128 ", asm_out_file);
706 assemble_name (asm_out_file, lab1);
707 fputc ('-', asm_out_file);
708 assemble_name (asm_out_file, lab2);
709 #else
710 abort ();
711 #endif
713 if (flag_debug_asm && comment)
715 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
716 vfprintf (asm_out_file, comment, ap);
718 fputc ('\n', asm_out_file);
720 VA_CLOSE (ap);
723 static int mark_indirect_pool_entry PARAMS ((splay_tree_node, void *));
724 static void mark_indirect_pool PARAMS ((PTR arg));
725 static rtx dw2_force_const_mem PARAMS ((rtx));
726 static int dw2_output_indirect_constant_1 PARAMS ((splay_tree_node, void *));
728 static splay_tree indirect_pool;
730 #if defined(HAVE_GAS_HIDDEN) && defined(SUPPORTS_ONE_ONLY)
731 # define USE_LINKONCE_INDIRECT 1
732 #else
733 # define USE_LINKONCE_INDIRECT 0
734 #endif
736 /* Mark all indirect constants for GC. */
738 static int
739 mark_indirect_pool_entry (node, data)
740 splay_tree_node node;
741 void* data ATTRIBUTE_UNUSED;
743 ggc_mark_nonnull_tree ((tree) node->value);
744 return 0;
747 /* Mark all indirect constants for GC. */
749 static void
750 mark_indirect_pool (arg)
751 PTR arg ATTRIBUTE_UNUSED;
753 splay_tree_foreach (indirect_pool, mark_indirect_pool_entry, NULL);
756 /* Put X, a SYMBOL_REF, in memory. Return a SYMBOL_REF to the allocated
757 memory. Differs from force_const_mem in that a single pool is used for
758 the entire unit of translation, and the memory is not guaranteed to be
759 "near" the function in any interesting sense. */
761 static rtx
762 dw2_force_const_mem (x)
763 rtx x;
765 splay_tree_node node;
766 const char *str;
767 tree decl;
769 if (! indirect_pool)
771 indirect_pool = splay_tree_new (splay_tree_compare_pointers, NULL, NULL);
772 ggc_add_root (&indirect_pool, 1, sizeof indirect_pool, mark_indirect_pool);
775 if (GET_CODE (x) != SYMBOL_REF)
776 abort ();
778 STRIP_NAME_ENCODING (str, XSTR (x, 0));
779 node = splay_tree_lookup (indirect_pool, (splay_tree_key) str);
780 if (node)
781 decl = (tree) node->value;
782 else
784 tree id;
786 if (USE_LINKONCE_INDIRECT)
788 char *ref_name = alloca (strlen (str) + sizeof "DW.ref.");
790 sprintf (ref_name, "DW.ref.%s", str);
791 id = get_identifier (ref_name);
792 decl = build_decl (VAR_DECL, id, ptr_type_node);
793 DECL_ARTIFICIAL (decl) = 1;
794 TREE_PUBLIC (decl) = 1;
795 DECL_INITIAL (decl) = decl;
796 make_decl_one_only (decl);
798 else
800 extern int const_labelno;
801 char label[32];
803 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
804 ++const_labelno;
805 id = get_identifier (label);
806 decl = build_decl (VAR_DECL, id, ptr_type_node);
807 DECL_ARTIFICIAL (decl) = 1;
808 TREE_STATIC (decl) = 1;
809 DECL_INITIAL (decl) = decl;
812 id = maybe_get_identifier (str);
813 if (id)
814 TREE_SYMBOL_REFERENCED (id) = 1;
816 splay_tree_insert (indirect_pool, (splay_tree_key) str,
817 (splay_tree_value) decl);
820 return XEXP (DECL_RTL (decl), 0);
823 /* A helper function for dw2_output_indirect_constants called through
824 splay_tree_foreach. Emit one queued constant to memory. */
826 static int
827 dw2_output_indirect_constant_1 (node, data)
828 splay_tree_node node;
829 void* data ATTRIBUTE_UNUSED;
831 const char *sym;
832 rtx sym_ref;
834 sym = (const char *) node->key;
835 sym_ref = gen_rtx_SYMBOL_REF (Pmode, sym);
836 if (USE_LINKONCE_INDIRECT)
837 fprintf (asm_out_file, "\t.hidden DW.ref.%s\n", sym);
838 assemble_variable ((tree) node->value, 1, 1, 1);
839 assemble_integer (sym_ref, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
841 return 0;
844 /* Emit the constants queued through dw2_force_const_mem. */
846 void
847 dw2_output_indirect_constants ()
849 if (indirect_pool)
850 splay_tree_foreach (indirect_pool, dw2_output_indirect_constant_1, NULL);
853 /* Like dw2_asm_output_addr_rtx, but encode the pointer as directed. */
855 void
856 dw2_asm_output_encoded_addr_rtx VPARAMS ((int encoding,
857 rtx addr,
858 const char *comment, ...))
860 int size;
862 VA_OPEN (ap, comment);
863 VA_FIXEDARG (ap, int, encoding);
864 VA_FIXEDARG (ap, rtx, addr);
865 VA_FIXEDARG (ap, const char *, comment);
867 size = size_of_encoded_value (encoding);
869 if (encoding == DW_EH_PE_aligned)
871 assemble_align (POINTER_SIZE);
872 assemble_integer (addr, size, POINTER_SIZE, 1);
873 return;
876 /* NULL is _always_ represented as a plain zero, as is 1 for Ada's
877 "all others". */
878 if (addr == const0_rtx || addr == const1_rtx)
879 assemble_integer (addr, size, BITS_PER_UNIT, 1);
880 else
882 restart:
883 /* Allow the target first crack at emitting this. Some of the
884 special relocations require special directives instead of
885 just ".4byte" or whatever. */
886 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
887 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX (asm_out_file, encoding, size,
888 addr, done);
889 #endif
891 /* Indirection is used to get dynamic relocations out of a
892 read-only section. */
893 if (encoding & DW_EH_PE_indirect)
895 /* It is very tempting to use force_const_mem so that we share data
896 with the normal constant pool. However, we've already emitted
897 the constant pool for this function. Moreover, we'd like to
898 share these constants across the entire unit of translation,
899 or better, across the entire application (or DSO). */
900 addr = dw2_force_const_mem (addr);
901 encoding &= ~DW_EH_PE_indirect;
902 goto restart;
905 switch (encoding & 0xF0)
907 case DW_EH_PE_absptr:
908 #ifdef UNALIGNED_INT_ASM_OP
909 fputs (unaligned_integer_asm_op (size), asm_out_file);
910 output_addr_const (asm_out_file, addr);
911 #else
912 assemble_integer (addr, size, BITS_PER_UNIT, 1);
913 #endif
914 break;
916 case DW_EH_PE_pcrel:
917 if (GET_CODE (addr) != SYMBOL_REF)
918 abort ();
919 #ifdef ASM_OUTPUT_DWARF_PCREL
920 ASM_OUTPUT_DWARF_PCREL (asm_out_file, size, XSTR (addr, 0));
921 #else
922 #ifdef UNALIGNED_INT_ASM_OP
923 fputs (unaligned_integer_asm_op (size), asm_out_file);
924 assemble_name (asm_out_file, XSTR (addr, 0));
925 fputc ('-', asm_out_file);
926 fputc ('.', asm_out_file);
927 #else
928 abort ();
929 #endif
930 #endif
931 break;
933 default:
934 /* Other encodings should have been handled by
935 ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX. */
936 abort ();
939 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
940 done:;
941 #endif
944 if (flag_debug_asm && comment)
946 fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
947 vfprintf (asm_out_file, comment, ap);
949 fputc ('\n', asm_out_file);
951 VA_CLOSE (ap);