OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / dwarf2asm.c
1 /* Dwarf2 assembler output helper routines.
2    Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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 3, or (at your option) any later
9 version.
10
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.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3.  If not see
18 <http://www.gnu.org/licenses/>.  */
19
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "flags.h"
26 #include "tree.h"
27 #include "rtl.h"
28 #include "output.h"
29 #include "target.h"
30 #include "dwarf2asm.h"
31 #include "dwarf2.h"
32 #include "splay-tree.h"
33 #include "ggc.h"
34 #include "tm_p.h"
35
36
37 /* How to start an assembler comment.  */
38 #ifndef ASM_COMMENT_START
39 #define ASM_COMMENT_START ";#"
40 #endif
41
42 \f
43 /* Output an unaligned integer with the given value and size.  Prefer not
44    to print a newline, since the caller may want to add a comment.  */
45
46 void
47 dw2_assemble_integer (int size, rtx x)
48 {
49   const char *op = integer_asm_op (size, FALSE);
50
51   if (op)
52     {
53       fputs (op, asm_out_file);
54       if (GET_CODE (x) == CONST_INT)
55         fprintf (asm_out_file, HOST_WIDE_INT_PRINT_HEX,
56                  (unsigned HOST_WIDE_INT) INTVAL (x));
57       else
58         output_addr_const (asm_out_file, x);
59     }
60   else
61     assemble_integer (x, size, BITS_PER_UNIT, 1);
62 }
63
64
65 /* Output a value of a given size in target byte order.  */
66
67 void
68 dw2_asm_output_data_raw (int size, unsigned HOST_WIDE_INT value)
69 {
70   unsigned char bytes[8];
71   int i;
72
73   for (i = 0; i < 8; ++i)
74     {
75       bytes[i] = value & 0xff;
76       value >>= 8;
77     }
78
79   if (BYTES_BIG_ENDIAN)
80     {
81       for (i = size - 1; i > 0; --i)
82         fprintf (asm_out_file, "0x%x,", bytes[i]);
83       fprintf (asm_out_file, "0x%x", bytes[0]);
84     }
85   else
86     {
87       for (i = 0; i < size - 1; ++i)
88         fprintf (asm_out_file, "0x%x,", bytes[i]);
89       fprintf (asm_out_file, "0x%x", bytes[i]);
90     }
91 }
92
93 /* Output an immediate constant in a given SIZE in bytes.  */
94
95 void
96 dw2_asm_output_data (int size, unsigned HOST_WIDE_INT value,
97                      const char *comment, ...)
98 {
99   va_list ap;
100   const char *op = integer_asm_op (size, FALSE);
101
102   va_start (ap, comment);
103
104   if (size * 8 < HOST_BITS_PER_WIDE_INT)
105     value &= ~(~(unsigned HOST_WIDE_INT) 0 << (size * 8));
106
107   if (op)
108     fprintf (asm_out_file, "%s" HOST_WIDE_INT_PRINT_HEX, op, value);
109   else
110     assemble_integer (GEN_INT (value), size, BITS_PER_UNIT, 1);
111
112   if (flag_debug_asm && comment)
113     {
114       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
115       vfprintf (asm_out_file, comment, ap);
116     }
117   fputc ('\n', asm_out_file);
118
119   va_end (ap);
120 }
121
122 /* Output the difference between two symbols in a given size.  */
123 /* ??? There appear to be assemblers that do not like such
124    subtraction, but do support ASM_SET_OP.  It's unfortunately
125    impossible to do here, since the ASM_SET_OP for the difference
126    symbol must appear after both symbols are defined.  */
127
128 void
129 dw2_asm_output_delta (int size, const char *lab1, const char *lab2,
130                       const char *comment, ...)
131 {
132   va_list ap;
133
134   va_start (ap, comment);
135
136 #ifdef ASM_OUTPUT_DWARF_DELTA
137   ASM_OUTPUT_DWARF_DELTA (asm_out_file, size, lab1, lab2);
138 #else
139   dw2_assemble_integer (size,
140                         gen_rtx_MINUS (Pmode,
141                                        gen_rtx_SYMBOL_REF (Pmode, lab1),
142                                        gen_rtx_SYMBOL_REF (Pmode, lab2)));
143 #endif
144   if (flag_debug_asm && comment)
145     {
146       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
147       vfprintf (asm_out_file, comment, ap);
148     }
149   fputc ('\n', asm_out_file);
150
151   va_end (ap);
152 }
153
154 /* Output a section-relative reference to a LABEL, which was placed in
155    BASE.  In general this can only be done for debugging symbols.
156    E.g. on most targets with the GNU linker, this is accomplished with
157    a direct reference and the knowledge that the debugging section
158    will be placed at VMA 0.  Some targets have special relocations for
159    this that we must use.  */
160
161 void
162 dw2_asm_output_offset (int size, const char *label,
163                        section *base ATTRIBUTE_UNUSED,
164                        const char *comment, ...)
165 {
166   va_list ap;
167
168   va_start (ap, comment);
169
170 #ifdef ASM_OUTPUT_DWARF_OFFSET
171   ASM_OUTPUT_DWARF_OFFSET (asm_out_file, size, label, base);
172 #else
173   dw2_assemble_integer (size, gen_rtx_SYMBOL_REF (Pmode, label));
174 #endif
175
176   if (flag_debug_asm && comment)
177     {
178       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
179       vfprintf (asm_out_file, comment, ap);
180     }
181   fputc ('\n', asm_out_file);
182
183   va_end (ap);
184 }
185
186 #if 0
187
188 /* Output a self-relative reference to a label, possibly in a
189    different section or object file.  */
190
191 void
192 dw2_asm_output_pcrel (int size ATTRIBUTE_UNUSED,
193                       const char *label ATTRIBUTE_UNUSED,
194                       const char *comment, ...)
195 {
196   va_list ap;
197
198   va_start (ap, comment);
199
200 #ifdef ASM_OUTPUT_DWARF_PCREL
201   ASM_OUTPUT_DWARF_PCREL (asm_out_file, size, label);
202 #else
203   dw2_assemble_integer (size,
204                         gen_rtx_MINUS (Pmode,
205                                        gen_rtx_SYMBOL_REF (Pmode, label),
206                                        pc_rtx));
207 #endif
208
209   if (flag_debug_asm && comment)
210     {
211       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
212       vfprintf (asm_out_file, comment, ap);
213     }
214   fputc ('\n', asm_out_file);
215
216   va_end (ap);
217 }
218 #endif /* 0 */
219
220 /* Output an absolute reference to a label.  */
221
222 void
223 dw2_asm_output_addr (int size, const char *label,
224                      const char *comment, ...)
225 {
226   va_list ap;
227
228   va_start (ap, comment);
229
230   dw2_assemble_integer (size, gen_rtx_SYMBOL_REF (Pmode, label));
231
232   if (flag_debug_asm && comment)
233     {
234       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
235       vfprintf (asm_out_file, comment, ap);
236     }
237   fputc ('\n', asm_out_file);
238
239   va_end (ap);
240 }
241
242 /* Similar, but use an RTX expression instead of a text label.  */
243
244 void
245 dw2_asm_output_addr_rtx (int size, rtx addr,
246                          const char *comment, ...)
247 {
248   va_list ap;
249
250   va_start (ap, comment);
251
252   dw2_assemble_integer (size, addr);
253
254   if (flag_debug_asm && comment)
255     {
256       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
257       vfprintf (asm_out_file, comment, ap);
258     }
259   fputc ('\n', asm_out_file);
260
261   va_end (ap);
262 }
263
264 /* Output the first ORIG_LEN characters of STR as a string.
265    If ORIG_LEN is equal to -1, ignore this parameter and output
266    the entire STR instead.
267    If COMMENT is not NULL and comments in the debug information
268    have been requested by the user, append the given COMMENT
269    to the generated output.  */
270    
271 void
272 dw2_asm_output_nstring (const char *str, size_t orig_len,
273                         const char *comment, ...)
274 {
275   size_t i, len;
276   va_list ap;
277
278   va_start (ap, comment);
279
280   len = orig_len;
281
282   if (len == (size_t) -1)
283     len = strlen (str);
284
285   if (flag_debug_asm && comment)
286     {
287       fputs ("\t.ascii \"", asm_out_file);
288       for (i = 0; i < len; i++)
289         {
290           int c = str[i];
291           if (c == '\"' || c == '\\')
292             fputc ('\\', asm_out_file);
293           if (ISPRINT(c))
294             fputc (c, asm_out_file);
295           else
296             fprintf (asm_out_file, "\\%o", c);
297         }
298       fprintf (asm_out_file, "\\0\"\t%s ", ASM_COMMENT_START);
299       vfprintf (asm_out_file, comment, ap);
300       fputc ('\n', asm_out_file);
301     }
302   else
303     {
304       /* If an explicit length was given, we can't assume there
305          is a null termination in the string buffer.  */
306       if (orig_len == (size_t) -1)
307         len += 1;
308       ASM_OUTPUT_ASCII (asm_out_file, str, len);
309       if (orig_len != (size_t) -1)
310         assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
311     }
312
313   va_end (ap);
314 }
315 \f
316
317 /* Return the size of an unsigned LEB128 quantity.  */
318
319 int
320 size_of_uleb128 (unsigned HOST_WIDE_INT value)
321 {
322   int size = 0;
323
324   do
325     {
326       value >>= 7;
327       size += 1;
328     }
329   while (value != 0);
330
331   return size;
332 }
333
334 /* Return the size of a signed LEB128 quantity.  */
335
336 int
337 size_of_sleb128 (HOST_WIDE_INT value)
338 {
339   int size = 0, byte;
340
341   do
342     {
343       byte = (value & 0x7f);
344       value >>= 7;
345       size += 1;
346     }
347   while (!((value == 0 && (byte & 0x40) == 0)
348            || (value == -1 && (byte & 0x40) != 0)));
349
350   return size;
351 }
352
353 /* Given an encoding, return the number of bytes the format occupies.
354    This is only defined for fixed-size encodings, and so does not
355    include leb128.  */
356
357 int
358 size_of_encoded_value (int encoding)
359 {
360   if (encoding == DW_EH_PE_omit)
361     return 0;
362
363   switch (encoding & 0x07)
364     {
365     case DW_EH_PE_absptr:
366       return POINTER_SIZE / BITS_PER_UNIT;
367     case DW_EH_PE_udata2:
368       return 2;
369     case DW_EH_PE_udata4:
370       return 4;
371     case DW_EH_PE_udata8:
372       return 8;
373     default:
374       gcc_unreachable ();
375     }
376 }
377
378 /* Yield a name for a given pointer encoding.  */
379
380 const char *
381 eh_data_format_name (int format)
382 {
383 #if HAVE_DESIGNATED_INITIALIZERS
384 #define S(p, v)         [p] = v,
385 #else
386 #define S(p, v)         case p: return v;
387 #endif
388
389 #if HAVE_DESIGNATED_INITIALIZERS
390   __extension__ static const char * const format_names[256] = {
391 #else
392   switch (format) {
393 #endif
394
395   S(DW_EH_PE_absptr, "absolute")
396   S(DW_EH_PE_omit, "omit")
397   S(DW_EH_PE_aligned, "aligned absolute")
398
399   S(DW_EH_PE_uleb128, "uleb128")
400   S(DW_EH_PE_udata2, "udata2")
401   S(DW_EH_PE_udata4, "udata4")
402   S(DW_EH_PE_udata8, "udata8")
403   S(DW_EH_PE_sleb128, "sleb128")
404   S(DW_EH_PE_sdata2, "sdata2")
405   S(DW_EH_PE_sdata4, "sdata4")
406   S(DW_EH_PE_sdata8, "sdata8")
407
408   S(DW_EH_PE_absptr | DW_EH_PE_pcrel, "pcrel")
409   S(DW_EH_PE_uleb128 | DW_EH_PE_pcrel, "pcrel uleb128")
410   S(DW_EH_PE_udata2 | DW_EH_PE_pcrel, "pcrel udata2")
411   S(DW_EH_PE_udata4 | DW_EH_PE_pcrel, "pcrel udata4")
412   S(DW_EH_PE_udata8 | DW_EH_PE_pcrel, "pcrel udata8")
413   S(DW_EH_PE_sleb128 | DW_EH_PE_pcrel, "pcrel sleb128")
414   S(DW_EH_PE_sdata2 | DW_EH_PE_pcrel, "pcrel sdata2")
415   S(DW_EH_PE_sdata4 | DW_EH_PE_pcrel, "pcrel sdata4")
416   S(DW_EH_PE_sdata8 | DW_EH_PE_pcrel, "pcrel sdata8")
417
418   S(DW_EH_PE_absptr | DW_EH_PE_textrel, "textrel")
419   S(DW_EH_PE_uleb128 | DW_EH_PE_textrel, "textrel uleb128")
420   S(DW_EH_PE_udata2 | DW_EH_PE_textrel, "textrel udata2")
421   S(DW_EH_PE_udata4 | DW_EH_PE_textrel, "textrel udata4")
422   S(DW_EH_PE_udata8 | DW_EH_PE_textrel, "textrel udata8")
423   S(DW_EH_PE_sleb128 | DW_EH_PE_textrel, "textrel sleb128")
424   S(DW_EH_PE_sdata2 | DW_EH_PE_textrel, "textrel sdata2")
425   S(DW_EH_PE_sdata4 | DW_EH_PE_textrel, "textrel sdata4")
426   S(DW_EH_PE_sdata8 | DW_EH_PE_textrel, "textrel sdata8")
427
428   S(DW_EH_PE_absptr | DW_EH_PE_datarel, "datarel")
429   S(DW_EH_PE_uleb128 | DW_EH_PE_datarel, "datarel uleb128")
430   S(DW_EH_PE_udata2 | DW_EH_PE_datarel, "datarel udata2")
431   S(DW_EH_PE_udata4 | DW_EH_PE_datarel, "datarel udata4")
432   S(DW_EH_PE_udata8 | DW_EH_PE_datarel, "datarel udata8")
433   S(DW_EH_PE_sleb128 | DW_EH_PE_datarel, "datarel sleb128")
434   S(DW_EH_PE_sdata2 | DW_EH_PE_datarel, "datarel sdata2")
435   S(DW_EH_PE_sdata4 | DW_EH_PE_datarel, "datarel sdata4")
436   S(DW_EH_PE_sdata8 | DW_EH_PE_datarel, "datarel sdata8")
437
438   S(DW_EH_PE_absptr | DW_EH_PE_funcrel, "funcrel")
439   S(DW_EH_PE_uleb128 | DW_EH_PE_funcrel, "funcrel uleb128")
440   S(DW_EH_PE_udata2 | DW_EH_PE_funcrel, "funcrel udata2")
441   S(DW_EH_PE_udata4 | DW_EH_PE_funcrel, "funcrel udata4")
442   S(DW_EH_PE_udata8 | DW_EH_PE_funcrel, "funcrel udata8")
443   S(DW_EH_PE_sleb128 | DW_EH_PE_funcrel, "funcrel sleb128")
444   S(DW_EH_PE_sdata2 | DW_EH_PE_funcrel, "funcrel sdata2")
445   S(DW_EH_PE_sdata4 | DW_EH_PE_funcrel, "funcrel sdata4")
446   S(DW_EH_PE_sdata8 | DW_EH_PE_funcrel, "funcrel sdata8")
447
448   S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_pcrel,
449     "indirect pcrel")
450   S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_pcrel,
451     "indirect pcrel uleb128")
452   S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_pcrel,
453     "indirect pcrel udata2")
454   S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_pcrel,
455     "indirect pcrel udata4")
456   S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_pcrel,
457     "indirect pcrel udata8")
458   S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_pcrel,
459     "indirect pcrel sleb128")
460   S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_pcrel,
461     "indirect pcrel sdata2")
462   S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_pcrel,
463     "indirect pcrel sdata4")
464   S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_pcrel,
465     "indirect pcrel sdata8")
466
467   S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_textrel,
468     "indirect textrel")
469   S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_textrel,
470     "indirect textrel uleb128")
471   S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_textrel,
472     "indirect textrel udata2")
473   S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_textrel,
474     "indirect textrel udata4")
475   S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_textrel,
476     "indirect textrel udata8")
477   S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_textrel,
478     "indirect textrel sleb128")
479   S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_textrel,
480     "indirect textrel sdata2")
481   S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_textrel,
482     "indirect textrel sdata4")
483   S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_textrel,
484     "indirect textrel sdata8")
485
486   S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_datarel,
487     "indirect datarel")
488   S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_datarel,
489     "indirect datarel uleb128")
490   S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_datarel,
491     "indirect datarel udata2")
492   S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_datarel,
493     "indirect datarel udata4")
494   S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_datarel,
495     "indirect datarel udata8")
496   S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_datarel,
497     "indirect datarel sleb128")
498   S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_datarel,
499     "indirect datarel sdata2")
500   S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_datarel,
501     "indirect datarel sdata4")
502   S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_datarel,
503     "indirect datarel sdata8")
504
505   S(DW_EH_PE_indirect | DW_EH_PE_absptr | DW_EH_PE_funcrel,
506     "indirect funcrel")
507   S(DW_EH_PE_indirect | DW_EH_PE_uleb128 | DW_EH_PE_funcrel,
508     "indirect funcrel uleb128")
509   S(DW_EH_PE_indirect | DW_EH_PE_udata2 | DW_EH_PE_funcrel,
510     "indirect funcrel udata2")
511   S(DW_EH_PE_indirect | DW_EH_PE_udata4 | DW_EH_PE_funcrel,
512     "indirect funcrel udata4")
513   S(DW_EH_PE_indirect | DW_EH_PE_udata8 | DW_EH_PE_funcrel,
514     "indirect funcrel udata8")
515   S(DW_EH_PE_indirect | DW_EH_PE_sleb128 | DW_EH_PE_funcrel,
516     "indirect funcrel sleb128")
517   S(DW_EH_PE_indirect | DW_EH_PE_sdata2 | DW_EH_PE_funcrel,
518     "indirect funcrel sdata2")
519   S(DW_EH_PE_indirect | DW_EH_PE_sdata4 | DW_EH_PE_funcrel,
520     "indirect funcrel sdata4")
521   S(DW_EH_PE_indirect | DW_EH_PE_sdata8 | DW_EH_PE_funcrel,
522     "indirect funcrel sdata8")
523
524 #if HAVE_DESIGNATED_INITIALIZERS
525   };
526
527   gcc_assert (format >= 0 && format < 0x100 && format_names[format]);
528   
529   return format_names[format];
530 #else
531   }
532   gcc_unreachable ();
533 #endif
534 }
535
536 /* Output an unsigned LEB128 quantity, but only the byte values.  */
537
538 void
539 dw2_asm_output_data_uleb128_raw (unsigned HOST_WIDE_INT value)
540 {
541   while (1)
542     {
543       int byte = (value & 0x7f);
544       value >>= 7;
545       if (value != 0)
546         /* More bytes to follow.  */
547         byte |= 0x80;
548
549       fprintf (asm_out_file, "0x%x", byte);
550       if (value == 0)
551         break;
552       fputc (',', asm_out_file);
553     }
554 }
555
556 /* Output an unsigned LEB128 quantity.  */
557
558 void
559 dw2_asm_output_data_uleb128 (unsigned HOST_WIDE_INT value,
560                              const char *comment, ...)
561 {
562   va_list ap;
563
564   va_start (ap, comment);
565
566 #ifdef HAVE_AS_LEB128
567   fprintf (asm_out_file, "\t.uleb128 " HOST_WIDE_INT_PRINT_HEX , value);
568
569   if (flag_debug_asm && comment)
570     {
571       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
572       vfprintf (asm_out_file, comment, ap);
573     }
574 #else
575   {
576     unsigned HOST_WIDE_INT work = value;
577     const char *byte_op = targetm.asm_out.byte_op;
578
579     if (byte_op)
580       fputs (byte_op, asm_out_file);
581     do
582       {
583         int byte = (work & 0x7f);
584         work >>= 7;
585         if (work != 0)
586           /* More bytes to follow.  */
587           byte |= 0x80;
588
589         if (byte_op)
590           {
591             fprintf (asm_out_file, "0x%x", byte);
592             if (work != 0)
593               fputc (',', asm_out_file);
594           }
595         else
596           assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
597       }
598     while (work != 0);
599
600   if (flag_debug_asm)
601     {
602       fprintf (asm_out_file, "\t%s uleb128 " HOST_WIDE_INT_PRINT_HEX,
603                ASM_COMMENT_START, value);
604       if (comment)
605         {
606           fputs ("; ", asm_out_file);
607           vfprintf (asm_out_file, comment, ap);
608         }
609     }
610   }
611 #endif
612   fputc ('\n', asm_out_file);
613
614   va_end (ap);
615 }
616
617 /* Output an signed LEB128 quantity, but only the byte values.  */
618
619 void
620 dw2_asm_output_data_sleb128_raw (HOST_WIDE_INT value)
621 {
622   int byte, more;
623
624   while (1)
625     {
626       byte = (value & 0x7f);
627       value >>= 7;
628       more = !((value == 0 && (byte & 0x40) == 0)
629                 || (value == -1 && (byte & 0x40) != 0));
630       if (more)
631         byte |= 0x80;
632
633       fprintf (asm_out_file, "0x%x", byte);
634       if (!more)
635         break;
636       fputc (',', asm_out_file);
637     }
638 }
639
640 /* Output a signed LEB128 quantity.  */
641
642 void
643 dw2_asm_output_data_sleb128 (HOST_WIDE_INT value,
644                              const char *comment, ...)
645 {
646   va_list ap;
647
648   va_start (ap, comment);
649
650 #ifdef HAVE_AS_LEB128
651   fprintf (asm_out_file, "\t.sleb128 " HOST_WIDE_INT_PRINT_DEC, value);
652
653   if (flag_debug_asm && comment)
654     {
655       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
656       vfprintf (asm_out_file, comment, ap);
657     }
658 #else
659   {
660     HOST_WIDE_INT work = value;
661     int more, byte;
662     const char *byte_op = targetm.asm_out.byte_op;
663
664     if (byte_op)
665       fputs (byte_op, asm_out_file);
666     do
667       {
668         byte = (work & 0x7f);
669         /* arithmetic shift */
670         work >>= 7;
671         more = !((work == 0 && (byte & 0x40) == 0)
672                  || (work == -1 && (byte & 0x40) != 0));
673         if (more)
674           byte |= 0x80;
675
676         if (byte_op)
677           {
678             fprintf (asm_out_file, "0x%x", byte);
679             if (more)
680               fputc (',', asm_out_file);
681           }
682         else
683           assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
684       }
685     while (more);
686
687   if (flag_debug_asm)
688     {
689       fprintf (asm_out_file, "\t%s sleb128 " HOST_WIDE_INT_PRINT_DEC,
690                ASM_COMMENT_START, value);
691       if (comment)
692         {
693           fputs ("; ", asm_out_file);
694           vfprintf (asm_out_file, comment, ap);
695         }
696     }
697   }
698 #endif
699   fputc ('\n', asm_out_file);
700
701   va_end (ap);
702 }
703
704 void
705 dw2_asm_output_delta_uleb128 (const char *lab1 ATTRIBUTE_UNUSED,
706                               const char *lab2 ATTRIBUTE_UNUSED,
707                               const char *comment, ...)
708 {
709   va_list ap;
710
711   va_start (ap, comment);
712
713 #ifdef HAVE_AS_LEB128
714   fputs ("\t.uleb128 ", asm_out_file);
715   assemble_name (asm_out_file, lab1);
716   fputc ('-', asm_out_file);
717   assemble_name (asm_out_file, lab2);
718 #else
719   gcc_unreachable ();
720 #endif
721
722   if (flag_debug_asm && comment)
723     {
724       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
725       vfprintf (asm_out_file, comment, ap);
726     }
727   fputc ('\n', asm_out_file);
728
729   va_end (ap);
730 }
731
732 #if 0
733
734 void
735 dw2_asm_output_delta_sleb128 (const char *lab1 ATTRIBUTE_UNUSED,
736                               const char *lab2 ATTRIBUTE_UNUSED,
737                               const char *comment, ...)
738 {
739   va_list ap;
740
741   va_start (ap, comment);
742
743 #ifdef HAVE_AS_LEB128
744   fputs ("\t.sleb128 ", asm_out_file);
745   assemble_name (asm_out_file, lab1);
746   fputc ('-', asm_out_file);
747   assemble_name (asm_out_file, lab2);
748 #else
749   gcc_unreachable ();
750 #endif
751
752   if (flag_debug_asm && comment)
753     {
754       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
755       vfprintf (asm_out_file, comment, ap);
756     }
757   fputc ('\n', asm_out_file);
758
759   va_end (ap);
760 }
761 #endif /* 0 */
762 \f
763 static int dw2_output_indirect_constant_1 (splay_tree_node, void *);
764
765 static GTY((param1_is (char *), param2_is (tree))) splay_tree indirect_pool;
766
767 static GTY(()) int dw2_const_labelno;
768
769 #if defined(HAVE_GAS_HIDDEN) && defined(SUPPORTS_ONE_ONLY)
770 # define USE_LINKONCE_INDIRECT 1
771 #else
772 # define USE_LINKONCE_INDIRECT 0
773 #endif
774
775 /* Comparison function for a splay tree in which the keys are strings.
776    K1 and K2 have the dynamic type "const char *".  Returns <0, 0, or
777    >0 to indicate whether K1 is less than, equal to, or greater than
778    K2, respectively.  */
779
780 static int
781 splay_tree_compare_strings (splay_tree_key k1, splay_tree_key k2)
782 {
783   const char *s1 = (const char *)k1;
784   const char *s2 = (const char *)k2;
785   int ret;
786
787   if (s1 == s2)
788     return 0;
789
790   ret = strcmp (s1, s2);
791
792   /* The strings are always those from IDENTIFIER_NODEs, and,
793      therefore, we should never have two copies of the same
794      string.  */
795   gcc_assert (ret);
796
797   return ret;
798 }
799
800 /* Put X, a SYMBOL_REF, in memory.  Return a SYMBOL_REF to the allocated
801    memory.  Differs from force_const_mem in that a single pool is used for
802    the entire unit of translation, and the memory is not guaranteed to be
803    "near" the function in any interesting sense.  IS_PUBLIC controls whether
804    the symbol can be shared across the entire application (or DSO).  */
805
806 rtx
807 dw2_force_const_mem (rtx x, bool is_public)
808 {
809   splay_tree_node node;
810   const char *key;
811   tree decl;
812
813   if (! indirect_pool)
814     /* We use strcmp, rather than just comparing pointers, so that the
815        sort order will not depend on the host system.  */
816     indirect_pool = splay_tree_new_ggc (splay_tree_compare_strings);
817
818   gcc_assert (GET_CODE (x) == SYMBOL_REF);
819
820   key = XSTR (x, 0);
821   node = splay_tree_lookup (indirect_pool, (splay_tree_key) key);
822   if (node)
823     decl = (tree) node->value;
824   else
825     {
826       tree id;
827       const char *str = targetm.strip_name_encoding (key);
828
829       if (is_public && USE_LINKONCE_INDIRECT)
830         {
831           char *ref_name = XALLOCAVEC (char, strlen (str) + sizeof "DW.ref.");
832
833           sprintf (ref_name, "DW.ref.%s", str);
834           id = get_identifier (ref_name);
835           decl = build_decl (VAR_DECL, id, ptr_type_node);
836           DECL_ARTIFICIAL (decl) = 1;
837           DECL_IGNORED_P (decl) = 1;
838           TREE_PUBLIC (decl) = 1;
839           DECL_INITIAL (decl) = decl;
840           make_decl_one_only (decl);
841         }
842       else
843         {
844           char label[32];
845
846           ASM_GENERATE_INTERNAL_LABEL (label, "LDFCM", dw2_const_labelno);
847           ++dw2_const_labelno;
848           id = get_identifier (label);
849           decl = build_decl (VAR_DECL, id, ptr_type_node);
850           DECL_ARTIFICIAL (decl) = 1;
851           DECL_IGNORED_P (decl) = 1;
852           TREE_STATIC (decl) = 1;
853           DECL_INITIAL (decl) = decl;
854         }
855
856       id = maybe_get_identifier (str);
857       if (id)
858         TREE_SYMBOL_REFERENCED (id) = 1;
859
860       splay_tree_insert (indirect_pool, (splay_tree_key) key,
861                          (splay_tree_value) decl);
862     }
863
864   return XEXP (DECL_RTL (decl), 0);
865 }
866
867 /* A helper function for dw2_output_indirect_constants called through
868    splay_tree_foreach.  Emit one queued constant to memory.  */
869
870 static int
871 dw2_output_indirect_constant_1 (splay_tree_node node,
872                                 void *data ATTRIBUTE_UNUSED)
873 {
874   const char *sym;
875   rtx sym_ref;
876   tree decl;
877
878   sym = (const char *) node->key;
879   decl = (tree) node->value;
880   sym_ref = gen_rtx_SYMBOL_REF (Pmode, sym);
881   sym = targetm.strip_name_encoding (sym);
882   if (TREE_PUBLIC (decl) && USE_LINKONCE_INDIRECT)
883     fprintf (asm_out_file, "\t.hidden %sDW.ref.%s\n", user_label_prefix, sym);
884   assemble_variable (decl, 1, 1, 1);
885   assemble_integer (sym_ref, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
886
887   return 0;
888 }
889
890 /* Emit the constants queued through dw2_force_const_mem.  */
891
892 void
893 dw2_output_indirect_constants (void)
894 {
895   if (indirect_pool)
896     splay_tree_foreach (indirect_pool, dw2_output_indirect_constant_1, NULL);
897 }
898
899 /* Like dw2_asm_output_addr_rtx, but encode the pointer as directed.
900    If PUBLIC is set and the encoding is DW_EH_PE_indirect, the indirect
901    reference is shared across the entire application (or DSO).  */
902
903 void
904 dw2_asm_output_encoded_addr_rtx (int encoding, rtx addr, bool is_public,
905                                  const char *comment, ...)
906 {
907   int size;
908   va_list ap;
909
910   va_start (ap, comment);
911
912   size = size_of_encoded_value (encoding);
913
914   if (encoding == DW_EH_PE_aligned)
915     {
916       assemble_align (POINTER_SIZE);
917       assemble_integer (addr, size, POINTER_SIZE, 1);
918       return;
919     }
920
921   /* NULL is _always_ represented as a plain zero, as is 1 for Ada's
922      "all others".  */
923   if (addr == const0_rtx || addr == const1_rtx)
924     assemble_integer (addr, size, BITS_PER_UNIT, 1);
925   else
926     {
927     restart:
928       /* Allow the target first crack at emitting this.  Some of the
929          special relocations require special directives instead of
930          just ".4byte" or whatever.  */
931 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
932       ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX (asm_out_file, encoding, size,
933                                          addr, done);
934 #endif
935
936       /* Indirection is used to get dynamic relocations out of a
937          read-only section.  */
938       if (encoding & DW_EH_PE_indirect)
939         {
940           /* It is very tempting to use force_const_mem so that we share data
941              with the normal constant pool.  However, we've already emitted
942              the constant pool for this function.  Moreover, we'd like to
943              share these constants across the entire unit of translation and
944              even, if possible, across the entire application (or DSO).  */
945           addr = dw2_force_const_mem (addr, is_public);
946           encoding &= ~DW_EH_PE_indirect;
947           goto restart;
948         }
949
950       switch (encoding & 0xF0)
951         {
952         case DW_EH_PE_absptr:
953           dw2_assemble_integer (size, addr);
954           break;
955
956         case DW_EH_PE_pcrel:
957           gcc_assert (GET_CODE (addr) == SYMBOL_REF);
958 #ifdef ASM_OUTPUT_DWARF_PCREL
959           ASM_OUTPUT_DWARF_PCREL (asm_out_file, size, XSTR (addr, 0));
960 #else
961           dw2_assemble_integer (size, gen_rtx_MINUS (Pmode, addr, pc_rtx));
962 #endif
963           break;
964
965         default:
966           /* Other encodings should have been handled by
967              ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX.  */
968           gcc_unreachable ();
969         }
970
971 #ifdef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
972     done:;
973 #endif
974     }
975
976   if (flag_debug_asm && comment)
977     {
978       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
979       vfprintf (asm_out_file, comment, ap);
980     }
981   fputc ('\n', asm_out_file);
982
983   va_end (ap);
984 }
985
986 #include "gt-dwarf2asm.h"