OSDN Git Service

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