90236a9b542a481aca7fd2e93f173ea572a69e13
[libfirm] / ir / ir / irdumptxt.c
1 /*
2  * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Write text representation of firm to file.
23  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Hubert Schmidt,
24  *          Matthias Braun
25  */
26 #include "config.h"
27
28 #include <string.h>
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <stdbool.h>
32
33 #include "irdump_t.h"
34 #include "irgraph_t.h"
35 #include "irnode_t.h"
36
37 #include "irprog_t.h"
38 #include "entity_t.h"
39 #include "trouts.h"
40 #include "irgwalk.h"
41 #include "tv_t.h"
42 #include "irprintf.h"
43 #include "error.h"
44
45 #include "irdom.h"
46
47 static ir_dump_verbosity_t  verbosity = dump_verbosity_max;
48
49 void ir_set_dump_verbosity(ir_dump_verbosity_t new_verbosity)
50 {
51         verbosity = new_verbosity;
52 }
53
54 ir_dump_verbosity_t ir_get_dump_verbosity(void)
55 {
56         return verbosity;
57 }
58
59 /* Write the irnode and all its attributes to the file passed. */
60 void dump_irnode_to_file(FILE *F, ir_node *n)
61 {
62         char     comma;
63         ir_graph *irg;
64
65         dump_node_opcode(F, n);
66         fprintf(F, " %ld\n", get_irn_node_nr(n));
67
68         fprintf(F, "  index: %u\n", get_irn_idx(n));
69         if (ir_get_dump_flags() & ir_dump_flag_analysed_types)
70                 fprintf (F, "  addr:    %p\n", (void *)n);
71         fprintf (F, "  mode:    %s\n", get_mode_name(get_irn_mode(n)));
72         fprintf (F, "  visited: %lu\n", get_irn_visited(n));
73         irg = get_irn_irg(n);
74         if (irg != get_const_code_irg())
75                 fprintf (F, "  irg:     %s\n", get_ent_dump_name(get_irg_entity(irg)));
76
77         if (get_irn_pinned(n) == op_pin_state_floats &&
78                 get_irg_pinned(get_irn_irg(n)) == op_pin_state_floats) {
79                 fprintf(F, "  node was pinned in ");
80                 dump_node_opcode(F, get_irn_n(n, -1));
81                 fprintf(F, " %ld\n", get_irn_node_nr(get_irn_n(n, -1)));
82         }
83
84         fprintf(F, "  arity:   %d\n", get_irn_arity(n));
85         /* show all predecessor nodes */
86         fprintf(F, "  pred nodes:\n");
87         if (!is_Block(n)) {
88                 fprintf(F, "    -1:    ");
89                 dump_node_opcode(F, get_irn_n(n, -1));
90                 fprintf(F, " %ld\n", get_irn_node_nr(get_irn_n(n, -1)));
91         }
92
93         {
94                 int i;
95                 for (i = 0; i < get_irn_arity(n); ++i) {
96                         fprintf(F, "     %d: %s ", i, is_backedge(n, i) ? "be" : "  ");
97                         dump_node_opcode(F, get_irn_n(n, i));
98                         fprintf(F, " %ld\n", get_irn_node_nr(get_irn_n(n, i)));
99                 }
100         }
101
102         fprintf(F, "  Private Attributes:\n");
103
104         if (is_Proj(n)) {
105                 ir_node *pred = get_Proj_pred(n);
106                 long     pn   = get_Proj_proj(n);
107                 fprintf(F, "  proj nr: %ld\n", pn);
108                 if (is_Switch(pred)) {
109                         const ir_switch_table *table = get_Switch_table(pred);
110                         size_t n_entries = ir_switch_table_get_n_entries(table);
111                         size_t i;
112                         for (i = 0; i < n_entries; ++i) {
113                                 const ir_switch_table_entry *entry
114                                         = ir_switch_table_get_entry_const(table, i);
115                                 if (entry->pn == pn && entry->min != NULL && entry->max != NULL) {
116                                         ir_tarval *min = entry->min;
117                                         ir_tarval *max = entry->max;
118                                         if (min != max) {
119                                                 ir_fprintf(F, "  switch case %+F .. %+F\n", min, max);
120                                         } else {
121                                                 ir_fprintf(F, "  switch case %+F\n", min);
122                                         }
123                                 }
124                         }
125                 }
126         }
127
128         if (is_fragile_op(n)) {
129                 fprintf(F, "  pinned state: %s\n", get_op_pin_state_name(get_irn_pinned(n)));
130                 /* not dumped: frag array */
131         }
132
133         /* This is not nice, output it as a marker in the predecessor list. */
134         if (is_Block(n) || get_irn_op(n) == op_Phi) {
135             int i;
136                 fprintf(F, "  backedges:");
137                 comma = ' ';
138                 for (i = 0; i < get_irn_arity(n); i++)
139                         if (is_backedge(n, i)) { fprintf(F, "%c %d", comma, i); comma = ','; }
140                         fprintf(F, "\n");
141         }
142
143         /* Loop node.   Someone else please tell me what's wrong ... */
144         if (is_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_LOOPINFO)) {
145                 ir_loop *loop = get_irn_loop(n);
146                 if (loop != NULL) {
147                         fprintf(F, "  in loop %ld with depth %u\n",
148                                 get_loop_loop_nr(loop), get_loop_depth(loop));
149                 }
150         }
151
152         /* Source types */
153         switch (get_irn_opcode(n)) {
154         case iro_Block: {
155                 if (get_Block_entity(n) != NULL)
156                         fprintf(F, "  Label: %lu\n", get_entity_label(get_Block_entity(n)));
157                 fprintf(F, "  block visited: %lu\n", get_Block_block_visited(n));
158                 fprintf(F, "  block marked: %u\n", get_Block_mark(n));
159                 if (is_irg_state(get_irn_irg(n), IR_GRAPH_STATE_CONSISTENT_DOMINANCE)) {
160                         fprintf(F, "  dom depth %d\n", get_Block_dom_depth(n));
161                         fprintf(F, "  domtree pre num %u\n", get_Block_dom_tree_pre_num(n));
162                         fprintf(F, "  max subtree pre num %u\n", get_Block_dom_max_subtree_pre_num(n));
163                 }
164                 if (is_irg_state(get_irn_irg(n), IR_GRAPH_STATE_CONSISTENT_POSTDOMINANCE)) {
165                         fprintf(F, "  pdom depth %d\n", get_Block_postdom_depth(n));
166                         fprintf(F, "  pdomtree pre num %u\n", get_Block_pdom_tree_pre_num(n));
167                         fprintf(F, "  max pdomsubtree pre num %u\n", get_Block_pdom_max_subtree_pre_num(n));
168                 }
169
170                 /* not dumped: graph_arr */
171                 /* not dumped: mature    */
172         }  break;
173         case iro_Start: {
174                 size_t   i;
175                 ir_type *tp = get_entity_type(get_irg_entity(get_irn_irg(n)));
176                 ir_fprintf(F, "  start of method of type %+F\n", tp);
177                 for (i = 0; i < get_method_n_params(tp); ++i)
178                         ir_fprintf(F, "    param %d type: %+F\n", i, get_method_param_type(tp, i));
179         } break;
180         case iro_Cond: {
181                 if (get_Cond_jmp_pred(n) != COND_JMP_PRED_NONE) {
182                         fprintf(F, "  jump prediction: %s\n",
183                                 get_cond_jmp_predicate_name(get_Cond_jmp_pred(n)));
184                 }
185         } break;
186         case iro_Alloc: {
187                 ir_fprintf(F, "  allocating entity of type: %+F\n", get_Alloc_type(n));
188                 fprintf(F, "  allocating on: the %s\n", (get_Alloc_where(n) == stack_alloc) ? "stack" : "heap");
189         } break;
190         case iro_Free: {
191                 ir_fprintf(F, "  freeing entity of type %+F\n", get_Free_type(n));
192                 fprintf(F, "  allocated on: the %s\n", (get_Free_where(n) == stack_alloc) ? "stack" : "heap");
193         } break;
194         case iro_Sel: {
195                 ir_entity *ent = get_Sel_entity(n);
196                 if (ent) {
197                         fprintf(F, "  Selecting entity %s (%ld)\n", get_entity_name(ent), get_entity_nr(ent));
198                         ir_fprintf(F, "    of type    %+F\n",  get_entity_type(ent));
199                         ir_fprintf(F, "    with owner %+F.\n", get_entity_owner(ent));
200                 } else {
201                         fprintf(F, "  <NULL entity>\n");
202                 }
203         } break;
204         case iro_Call: {
205                 ir_type *tp = get_Call_type(n);
206                 ir_fprintf(F, "  calling method of type %+F\n", tp);
207                 if (get_unknown_type() != tp) {
208                         size_t i;
209                         for (i = 0; i < get_method_n_params(tp); ++i)
210                                 ir_fprintf(F, "    param %d type: %+F\n", i, get_method_param_type(tp, i));
211                         for (i = 0; i < get_method_n_ress(tp); ++i)
212                                 ir_fprintf(F, "    result %d type: %+F\n", i, get_method_res_type(tp, i));
213                 }
214                 if (Call_has_callees(n)) {
215                         size_t i;
216                         fprintf(F, "  possible callees:\n");
217                         for (i = 0; i < get_Call_n_callees(n); i++) {
218                                 ir_fprintf(F, "    %zu: %s\n", i, get_ent_dump_name(get_Call_callee(n, i)));
219                         }
220                 }
221         } break;
222         case iro_Cast: {
223                 ir_fprintf(F, "  cast to type: %+F\n", get_Cast_type(n));
224         } break;
225         case iro_Cmp: {
226                 ir_relation relation = get_Cmp_relation(n);
227                 ir_fprintf(F, "  relation: %s\n", get_relation_string(relation));
228         } break;
229         case iro_Return: {
230                 size_t   i;
231                 ir_type *tp = get_entity_type(get_irg_entity(get_irn_irg(n)));
232                 ir_fprintf(F, "  return in method of type %+F\n", tp);
233                 for (i = 0; i < get_method_n_ress(tp); ++i) {
234                         ir_fprintf(F, "    result %d type: %+F\n", i,
235                                            get_method_res_type(tp, i));
236                 }
237         } break;
238         case iro_SymConst: {
239                 switch (get_SymConst_kind(n)) {
240                 case symconst_addr_ent:
241                         fprintf(F, "  kind:   addr_ent\n");
242                         fprintf(F, "  entity: ");
243                         dump_entity_to_file(F, get_SymConst_entity(n));
244                         break;
245                 case symconst_ofs_ent:
246                         fprintf(F, "  kind:   offset\n");
247                         fprintf(F, "  entity: ");
248                         dump_entity_to_file(F, get_SymConst_entity(n));
249                         break;
250                 case symconst_type_tag:
251                         fprintf(F, "  kind: type_tag\n");
252                         fprintf(F, "  type: ");
253                         dump_type_to_file(F, get_SymConst_type(n));
254                         break;
255                 case symconst_type_size:
256                         fprintf(F, "  kind: size\n");
257                         fprintf(F, "  type: ");
258                         dump_type_to_file(F, get_SymConst_type(n));
259                         break;
260                 case symconst_type_align:
261                         fprintf(F, "  kind: alignment\n");
262                         fprintf(F, "  type: ");
263                         dump_type_to_file(F, get_SymConst_type(n));
264                         break;
265                 case symconst_enum_const:
266                         fprintf(F, "  kind: enumeration\n");
267                         fprintf(F, "  name: %s\n", get_enumeration_const_name(get_SymConst_enum(n)));
268                         break;
269                 }
270         } break;
271         case iro_Load:
272                 fprintf(F, "  mode of loaded value: %s\n", get_mode_name_ex(get_Load_mode(n), NULL));
273                 fprintf(F, "  volatility: %s\n", get_volatility_name(get_Load_volatility(n)));
274                 fprintf(F, "  align: %s\n", get_align_name(get_Load_unaligned(n)));
275                 break;
276         case iro_Store:
277                 fprintf(F, "  volatility: %s\n", get_volatility_name(get_Store_volatility(n)));
278                 fprintf(F, "  align: %s\n", get_align_name(get_Store_unaligned(n)));
279                 break;
280         case iro_Confirm:
281                 fprintf(F, "  compare operation: %s\n", get_relation_string(get_Confirm_relation(n)));
282                 break;
283         case iro_ASM: {
284                 const ir_asm_constraint *cons;
285                 ident **clobber;
286                 int l;
287
288                 fprintf(F, "  assembler text: %s", get_id_str(get_ASM_text(n)));
289                 l = get_ASM_n_input_constraints(n);
290                 if (l > 0) {
291                         int i;
292                         fprintf(F, "\n  inputs:  ");
293                         cons = get_ASM_input_constraints(n);
294                         for (i = 0; i < l; ++i)
295                                 fprintf(F, "%%%u %s ", cons[i].pos, get_id_str(cons[i].constraint));
296                 }
297                 l = get_ASM_n_output_constraints(n);
298                 if (l > 0) {
299                         int i;
300                         fprintf(F, "\n  outputs: ");
301                         cons = get_ASM_output_constraints(n);
302                         for (i = 0; i < l; ++i)
303                                 fprintf(F, "%%%u %s ", cons[i].pos, get_id_str(cons[i].constraint));
304                 }
305                 l = get_ASM_n_clobbers(n);
306                 if (l > 0) {
307                         int i;
308                         fprintf(F, "\n  clobber: ");
309                         clobber = get_ASM_clobbers(n);
310                         for (i = 0; i < l; ++i)
311                                 fprintf(F, "%s ", get_id_str(clobber[i]));
312                 }
313                 if (get_irn_pinned(n) != op_pin_state_floats)
314                         fprintf(F, "\n  volatile");
315                 fprintf(F, "\n");
316         } break;
317
318         default:
319                 break;
320         }
321
322         if (get_irg_typeinfo_state(get_irn_irg(n)) == ir_typeinfo_consistent  ||
323                 get_irg_typeinfo_state(get_irn_irg(n)) == ir_typeinfo_inconsistent  )
324                 if (get_irn_typeinfo_type(n) != firm_none_type)
325                         ir_fprintf (F, "  Analysed type: %s\n", get_irn_typeinfo_type(n));
326 }
327
328 void dump_graph_as_text(FILE *out, ir_graph *irg)
329 {
330         fprintf(out, "graph %s\n", get_irg_dump_name(irg));
331 }
332
333 static int need_nl = 1;
334
335 static bool is_init_string(ir_initializer_t const* const init, ir_type *const type)
336 {
337         ir_type *const element_type = get_array_element_type(type);
338         ir_mode *      mode;
339         size_t         n;
340         size_t         i;
341
342         if (!is_Primitive_type(element_type))
343                 return false;
344
345         mode = get_type_mode(element_type);
346         if (!mode_is_int(mode) || get_mode_size_bits(mode) != 8)
347                 return false;
348
349         n = get_initializer_compound_n_entries(init);
350         for (i = 0; i != n; ++i) {
351                 ir_initializer_t const* const val = get_initializer_compound_value(init, i);
352                 ir_tarval*              const tv  = get_initializer_tarval_value(val);
353                 long                          v;
354
355                 if (!tarval_is_constant(tv))
356                         return false;
357
358                 v = get_tarval_long(tv);
359                 if (v != 0 && (v < 0x07 || 0x0D < v) && v != 0x1B && (v < 0x20 || 0x80 <= v) && (v < 0xA0 || 0x100 <= v))
360                         return false;
361         }
362
363         return true;
364 }
365
366 /**
367  * Dump initializers.
368  */
369 static void dump_ir_initializers_to_file(FILE *F, const char *prefix,
370                                          const ir_initializer_t *initializer,
371                                          ir_type *type)
372 {
373         ir_tarval *tv;
374         ir_node   *value;
375
376         if (need_nl) {
377                 fprintf(F, "\n%s    ", prefix);
378                 need_nl = 0;
379         }
380         switch (get_initializer_kind(initializer)) {
381         case IR_INITIALIZER_NULL:
382                 fprintf(F, "\t = <NOT_SET>");
383                 break;
384         case IR_INITIALIZER_TARVAL:
385                 tv = get_initializer_tarval_value(initializer);
386                 ir_fprintf(F, "\t = <TV>%F", tv);
387                 break;
388         case IR_INITIALIZER_CONST:
389                 value = get_initializer_const_value(initializer);
390                 ir_fprintf(F, "\t = %F", value);
391                 break;
392         case IR_INITIALIZER_COMPOUND:
393                 if (is_Array_type(type)) {
394                         size_t const n = get_initializer_compound_n_entries(initializer);
395                         size_t       i;
396
397                         if (is_init_string(initializer, type)) {
398                                 fprintf(F, "\t[0...%u] = '", (unsigned)n - 1);
399                                 for (i = 0; i != n; ++i) {
400                                         ir_initializer_t const* const val = get_initializer_compound_value(initializer, i);
401                                         ir_tarval*              const tv  = get_initializer_tarval_value(val);
402                                         long                    const v   = get_tarval_long(tv);
403
404                                         switch (v) {
405                                                 case 0x00: fprintf(F, "\\\\000");  break;
406                                                 case 0x07: fprintf(F, "\\\\a");    break;
407                                                 case 0x08: fprintf(F, "\\\\b");    break;
408                                                 case 0x09: fprintf(F, "\\\\t");    break;
409                                                 case 0x0A: fprintf(F, "\\\\n");    break;
410                                                 case 0x0B: fprintf(F, "\\\\v");    break;
411                                                 case 0x0C: fprintf(F, "\\\\f");    break;
412                                                 case 0x0D: fprintf(F, "\\\\r");    break;
413                                                 case 0x1B: fprintf(F, "\\\\033");  break;
414                                                 case 0x22: fprintf(F, "\\\\\\\""); break;
415                                                 case 0x5C: fprintf(F, "\\\\\\\\"); break;
416                                                 default:   fprintf(F, "%c", (unsigned char)v); break;
417                                         }
418                                 }
419                                 fprintf(F, "'");
420                         } else {
421                                 ir_type *const element_type = get_array_element_type(type);
422
423                                 for (i = 0; i < n; ++i) {
424                                         ir_initializer_t *sub_initializer
425                                                 = get_initializer_compound_value(initializer, i);
426
427                                         if (need_nl) {
428                                                 fprintf(F, "\n%s    ", prefix);
429                                                 need_nl = 0;
430                                         }
431                                         fprintf(F, "[%d]", (int) i);
432                                         dump_ir_initializers_to_file(F, prefix, sub_initializer, element_type);
433                                 }
434                         }
435                 } else {
436                         size_t i, n;
437                         assert(is_compound_type(type));
438                         n = get_compound_n_members(type);
439                         for (i = 0; i < n; ++i) {
440                                 ir_entity        *member    = get_compound_member(type, i);
441                                 ir_type          *subtype   = get_entity_type(member);
442                                 ir_initializer_t *sub_initializer;
443
444                                 assert(i < get_initializer_compound_n_entries(initializer));
445                                 sub_initializer
446                                         = get_initializer_compound_value(initializer, i);
447
448                                 if (need_nl) {
449                                         fprintf(F, "\n%s    ", prefix);
450                                         need_nl = 0;
451                                 }
452                                 ir_fprintf(F, ".%F", member);
453                                 dump_ir_initializers_to_file(F, prefix, sub_initializer, subtype);
454                         }
455                 }
456                 break;
457         default:
458                 panic("invalid ir_initializer kind found");
459         }
460         need_nl = 1;
461 }
462
463 static void dump_entity_linkage(FILE *F, const ir_entity *entity)
464 {
465         ir_linkage linkage = get_entity_linkage(entity);
466
467         if (linkage == IR_LINKAGE_DEFAULT) {
468                 fprintf(F, " default");
469                 return;
470         }
471         if (linkage & IR_LINKAGE_CONSTANT)
472                 fprintf(F, " constant");
473         if (linkage & IR_LINKAGE_WEAK)
474                 fprintf(F, " weak");
475         if (linkage & IR_LINKAGE_GARBAGE_COLLECT)
476                 fprintf(F, " garbage_collect");
477         if (linkage & IR_LINKAGE_MERGE)
478                 fprintf(F, " merge");
479         if (linkage & IR_LINKAGE_HIDDEN_USER)
480                 fprintf(F, " hidden_user");
481 }
482
483 static void dump_entity_to_file_prefix(FILE *F, ir_entity *ent, const char *prefix)
484 {
485         ir_type *owner, *type;
486
487         assert(is_entity(ent));
488         owner = get_entity_owner(ent);
489         type  = get_entity_type(ent);
490         if (verbosity & dump_verbosity_onlynames) {
491                 fprintf(F, "%sentity %s.%s (%ld)\n", prefix, get_compound_name(get_entity_owner(ent)),
492                         get_entity_name(ent), get_entity_nr(ent));
493                 return;
494         }
495
496         if (verbosity & dump_verbosity_entattrs) {
497                 fprintf(F, "%sentity %s (%ld)\n", prefix, get_entity_name(ent), get_entity_nr(ent));
498                 ir_fprintf(F, "%s  type:  %+F\n", prefix, type);
499                 ir_fprintf(F, "%s  owner: %+F\n", prefix, owner);
500
501                 if (is_Class_type(get_entity_owner(ent))) {
502                         if (get_entity_n_overwrites(ent) > 0) {
503                                 size_t i;
504                                 fprintf(F, "%s  overwrites:\n", prefix);
505                                 for (i = 0; i < get_entity_n_overwrites(ent); ++i) {
506                                         ir_entity *ov = get_entity_overwrites(ent, i);
507                                         ir_fprintf(F, "%s    %d: %s of class %+F\n", prefix, i,
508                                                 get_entity_name(ov), get_entity_owner(ov));
509                                 }
510                         } else {
511                                 fprintf(F, "%s  Does not overwrite other entities.\n", prefix);
512                         }
513                         if (get_entity_n_overwrittenby(ent) > 0) {
514                                 size_t i;
515                                 fprintf(F, "%s  overwritten by:\n", prefix);
516                                 for (i = 0; i < get_entity_n_overwrittenby(ent); ++i) {
517                                         ir_entity *ov = get_entity_overwrittenby(ent, i);
518                                         ir_fprintf(F, "%s    %d: %s of class %+F\n", prefix, i,
519                                                    get_entity_name(ov), get_entity_owner(ov));
520                                 }
521                         } else {
522                                 fprintf(F, "%s  Is not overwritten by other entities.\n",
523                                         prefix);
524                         }
525
526                         if (get_irp_inh_transitive_closure_state() != inh_transitive_closure_none) {
527                                 ir_entity *ov;
528                                 fprintf(F, "%s  transitive overwrites:\n", prefix);
529                                 for (ov = get_entity_trans_overwrites_first(ent);
530                                 ov;
531                                 ov = get_entity_trans_overwrites_next(ent)) {
532                                         ir_fprintf(F, "%s    : %s of class %+F\n", prefix,
533                                                    get_entity_name(ov), get_entity_owner(ov));
534                                 }
535                                 fprintf(F, "%s  transitive overwritten by:\n", prefix);
536                                 for (ov = get_entity_trans_overwrittenby_first(ent);
537                                 ov;
538                                 ov = get_entity_trans_overwrittenby_next(ent)) {
539                                         ir_fprintf(F, "%s    : %s of class %+F\n", prefix,
540                                                    get_entity_name(ov), get_entity_owner(ov));
541                                 }
542                         }
543                 }
544
545                 if (is_Method_type(get_entity_type(ent))) {
546                         unsigned mask = get_entity_additional_properties(ent);
547                         unsigned cc   = get_method_calling_convention(get_entity_type(ent));
548                         ir_graph *irg = get_entity_irg(ent);
549
550                         if (irg) {
551                                 fprintf(F, "%s  estimated node count: %u\n", prefix, get_irg_estimated_node_cnt(irg));
552                                 fprintf(F, "%s  maximum node index:   %u\n", prefix, get_irg_last_idx(irg));
553                         }
554
555                         if (mask) {
556                                 fprintf(F, "%s  additional prop: ", prefix);
557
558                                 if (mask & mtp_property_const)         fputs("const_function, ", F);
559                                 if (mask & mtp_property_pure)          fputs("pure_function, ", F);
560                                 if (mask & mtp_property_noreturn)      fputs("noreturn_function, ", F);
561                                 if (mask & mtp_property_nothrow)       fputs("nothrow_function, ", F);
562                                 if (mask & mtp_property_naked)         fputs("naked_function, ", F);
563                                 if (mask & mtp_property_malloc)        fputs("malloc_function, ", F);
564                                 if (mask & mtp_property_returns_twice) fputs("weak_function, ", F);
565                                 if (mask & mtp_property_intrinsic)     fputs("intrinsic_function, ", F);
566                                 if (mask & mtp_property_runtime)       fputs("runtime_function, ", F);
567                                 if (mask & mtp_property_private)       fputs("private_function, ", F);
568                                 if (mask & mtp_property_has_loop)      fputs("has_loop_function, ", F);
569                                 fputc('\n', F);
570                         }
571                         fprintf(F, "%s  calling convention: ", prefix);
572                         if (cc & cc_reg_param)           fputs("regparam, ", F);
573                         if (cc & cc_this_call)           fputs("thiscall, ", F);
574                         if (cc & cc_compound_ret)        fputs("compound_ret, ", F);
575                         if (cc & cc_frame_on_caller_stk) fputs("frame on caller's stack, ", F);
576                         cc &= ~(cc_compound_ret|cc_frame_on_caller_stk);
577                         if (IS_CDECL(cc))
578                                 fputs("cdecl", F);
579                         else if (IS_STDCALL(cc))
580                                 fputs("stdcall", F);
581                         else {
582                                 fputs(cc & cc_last_on_top      ? "last param on top, " : "first param on top, ", F);
583                                 fputs(cc & cc_callee_clear_stk ? "callee clear stack" : "caller clear stack", F);
584                         }
585                         fprintf(F, "\n%s  vtable number:        %u\n", prefix, get_entity_vtable_number(ent));
586                 }
587         } else {  /* no entattrs */
588                 ir_fprintf(F, "%s(%3d:%d) %+F: %s", prefix,
589                         get_entity_offset(ent), get_entity_offset_bits_remainder(ent),
590                         get_entity_type(ent), get_entity_name(ent));
591                 if (is_Method_type(get_entity_type(ent))) fputs("(...)", F);
592
593                 if (verbosity & dump_verbosity_accessStats) {
594                         dump_entity_linkage(F, ent);
595                 }
596                 fputc('\n', F);
597         }
598
599         if (verbosity & dump_verbosity_entconsts) {
600                 if (ent->initializer != NULL) {
601                         const ir_initializer_t *initializer = get_entity_initializer(ent);
602                         fprintf(F, "\n%s  Initializers:", prefix);
603                         need_nl = 1;
604                         dump_ir_initializers_to_file(F, prefix, initializer, get_entity_type(ent));
605                         fputc('\n', F);
606                 } else if (entity_has_compound_ent_values(ent)) {
607                         size_t i;
608                         fprintf(F, "%s  compound values:", prefix);
609                         for (i = 0; i < get_compound_ent_n_values(ent); ++i) {
610                                 size_t j;
611                                 compound_graph_path *path = get_compound_ent_value_path(ent, i);
612                                 ir_entity *ent0 = get_compound_graph_path_node(path, 0);
613                                 fprintf(F, "\n%s    %3d:%d ", prefix, get_entity_offset(ent0), get_entity_offset_bits_remainder(ent0));
614                                 if (get_type_state(type) == layout_fixed)
615                                         fprintf(F, "(%3u:%u) ",   get_compound_ent_value_offset_bytes(ent, i), get_compound_ent_value_offset_bit_remainder(ent, i));
616                                 fprintf(F, "%s", get_entity_name(ent));
617                                 for (j = 0; j < get_compound_graph_path_length(path); ++j) {
618                                         ir_entity *node = get_compound_graph_path_node(path, j);
619                                         fprintf(F, ".%s", get_entity_name(node));
620                                         if (is_Array_type(get_entity_owner(node)))
621                                                 fprintf(F, "[%ld]", get_compound_graph_path_array_index(path, j));
622                                 }
623                                 fprintf(F, "\t = ");
624                                 dump_node_opcode(F, get_compound_ent_value(ent, i));
625                         }
626                         fputc('\n', F);
627                 }
628         }
629
630         if (verbosity & dump_verbosity_entattrs) {
631                 fprintf(F, "%s  linkage:", prefix);
632                 dump_entity_linkage(F, ent);
633                 fprintf(F, "\n%s  volatility:  %s", prefix, get_volatility_name(get_entity_volatility(ent)));
634                 fprintf(F, "\n%s  aligned:  %s", prefix, get_align_name(get_entity_aligned(ent)));
635                 fprintf(F, "\n%s  alignment:  %u", prefix, get_entity_alignment(ent));
636                 fprintf(F, "\n%s  ld_name: %s", prefix, ent->ld_name ? get_entity_ld_name(ent) : "no yet set");
637                 fprintf(F, "\n%s  offset:  %d bytes, %d rem bits", prefix, get_entity_offset(ent), get_entity_offset_bits_remainder(ent));
638                 if (is_Method_type(get_entity_type(ent))) {
639                         if (get_entity_irg(ent))   /* can be null */ {
640                                 fprintf(F, "\n%s  irg = %ld", prefix, get_irg_graph_nr(get_entity_irg(ent)));
641                         } else {
642                                 fprintf(F, "\n%s  irg = NULL", prefix);
643                         }
644                 }
645                 fputc('\n', F);
646         }
647 }
648
649 void dump_entity_to_file(FILE *out, ir_entity *ent)
650 {
651         dump_entity_to_file_prefix(out, ent, "");
652         fprintf(out, "\n");
653 }
654
655 void dump_type_to_file(FILE *F, ir_type *tp)
656 {
657         size_t i;
658
659         if ((is_Class_type(tp))       && (verbosity & dump_verbosity_noClassTypes)) return;
660         if ((is_Struct_type(tp))      && (verbosity & dump_verbosity_noStructTypes)) return;
661         if ((is_Union_type(tp))       && (verbosity & dump_verbosity_noUnionTypes)) return;
662         if ((is_Array_type(tp))       && (verbosity & dump_verbosity_noArrayTypes)) return;
663         if ((is_Pointer_type(tp))     && (verbosity & dump_verbosity_noPointerTypes)) return;
664         if ((is_Method_type(tp))      && (verbosity & dump_verbosity_noMethodTypes)) return;
665         if ((is_Primitive_type(tp))   && (verbosity & dump_verbosity_noPrimitiveTypes)) return;
666         if ((is_Enumeration_type(tp)) && (verbosity & dump_verbosity_noEnumerationTypes)) return;
667
668         ir_fprintf(F, "%+F", tp);
669         if (verbosity & dump_verbosity_onlynames) { fprintf(F, "\n"); return; }
670
671         switch (get_type_tpop_code(tp)) {
672
673         case tpo_class:
674                 if ((verbosity & dump_verbosity_methods) || (verbosity & dump_verbosity_fields)) {
675                         fprintf(F, "\n  members:\n");
676                 }
677                 for (i = 0; i < get_class_n_members(tp); ++i) {
678                         ir_entity *mem = get_class_member(tp, i);
679                         if (((verbosity & dump_verbosity_methods) &&  is_Method_type(get_entity_type(mem))) ||
680                                 ((verbosity & dump_verbosity_fields)  && !is_Method_type(get_entity_type(mem)))   ) {
681                                 if (!(verbosity & dump_verbosity_nostatic)) {
682                                         dump_entity_to_file_prefix(F, mem, "    ");
683                                 }
684                         }
685                 }
686                 if (verbosity & dump_verbosity_typeattrs) {
687                         fprintf(F, "  supertypes: ");
688                         for (i = 0; i < get_class_n_supertypes(tp); ++i) {
689                                 ir_type *stp = get_class_supertype(tp, i);
690                                 ir_fprintf(F, "\n    %d %+F", i, stp);
691                         }
692                         fprintf(F, "\n  subtypes: ");
693                         for (i = 0; i < get_class_n_subtypes(tp); ++i) {
694                                 ir_type *stp = get_class_subtype(tp, i);
695                                 ir_fprintf(F, "\n    %d %+F", i, stp);
696                         }
697
698                         if (get_irp_inh_transitive_closure_state() != inh_transitive_closure_none) {
699                                 ir_type *stp;
700                                 fprintf(F, "\n  transitive supertypes: ");
701                                 for (stp = get_class_trans_supertype_first(tp);
702                                 stp;
703                                 stp = get_class_trans_supertype_next(tp)) {
704                                         ir_fprintf(F, "\n    %+F", stp);
705                                 }
706                                 fprintf(F, "\n  transitive subtypes: ");
707                                 for (stp = get_class_trans_subtype_first(tp);
708                                 stp;
709                                 stp = get_class_trans_subtype_next(tp)) {
710                                         ir_fprintf(F, "\n    %+F", stp);
711                                 }
712                         }
713
714                         fprintf(F, "\n  flags:       ");
715                         if (is_class_final(tp))
716                                 fprintf(F, "final, ");
717                         if (is_class_interface(tp))
718                                 fprintf(F, "interface, ");
719                         if (is_class_abstract(tp))
720                                 fprintf(F, "abstract, ");
721                         fprintf(F, "\n");
722                 }
723                 break;
724
725         case tpo_union:
726         case tpo_struct:
727                 if (verbosity & dump_verbosity_fields) fprintf(F, "\n  members: ");
728                 for (i = 0; i < get_compound_n_members(tp); ++i) {
729                         ir_entity *mem = get_compound_member(tp, i);
730                         if (verbosity & dump_verbosity_fields) {
731                                 dump_entity_to_file_prefix(F, mem, "    ");
732                         }
733                 }
734                 break;
735
736         case tpo_array:
737                 if (verbosity & dump_verbosity_typeattrs) {
738                         size_t n_dim;
739                         ir_type *elem_tp = get_array_element_type(tp);
740
741                         fprintf(F, "\n  array ");
742
743                         n_dim = get_array_n_dimensions(tp);
744                         for (i = 0; i < n_dim; ++i) {
745                                 ir_node *lower, *upper;
746
747                                 lower = get_array_lower_bound(tp, i);
748                                 upper = get_array_upper_bound(tp, i);
749
750                                 fprintf(F, "[");
751
752                                 if (is_Const(lower)) {
753                                         fprintf(F, "%ld .. ", get_tarval_long(get_Const_tarval(lower)));
754                                 } else {
755                                         dump_node_opcode(F, lower);
756                                         fprintf(F, " %ld .. ", get_irn_node_nr(lower));
757                                 }
758
759                                 if (is_Const(upper)) {
760                                         fprintf(F, "%ld]", get_tarval_long(get_Const_tarval(lower)));
761                                 } else {
762                                         dump_node_opcode(F, upper);
763                                         fprintf(F, " %ld]", get_irn_node_nr(upper));
764                                 }
765                         }
766                         ir_fprintf(F, " of <%+F>", elem_tp);
767
768                         fprintf(F, "\n  order: ");
769                         for (i = 0; i < n_dim; ++i)
770                                 fprintf(F, "<%zu>", get_array_order(tp, i));
771
772                         fprintf(F, "\n");
773
774                         if (verbosity & dump_verbosity_fields) {
775                                 dump_entity_to_file_prefix(F, get_array_element_entity(tp),
776                                                            "    ");
777                         }
778                 }
779                 break;
780
781         case tpo_pointer:
782                 if (verbosity & dump_verbosity_typeattrs) {
783                         ir_type *tt = get_pointer_points_to_type(tp);
784                         ir_fprintf(F, "\n  points to %+F\n", tt);
785                 }
786                 break;
787
788         case tpo_method:
789                 if (verbosity & dump_verbosity_typeattrs) {
790                         mtp_additional_properties mtp = get_method_additional_properties(tp);
791                         unsigned cconv = get_method_calling_convention(tp);
792                         fprintf(F, "\n  variadicity: %s", get_variadicity_name(get_method_variadicity(tp)));
793                         fprintf(F, "\n  return types: %lu",
794                                 (unsigned long) get_method_n_ress(tp));
795                         for (i = 0; i < get_method_n_ress(tp); ++i) {
796                                 ir_type *rtp = get_method_res_type(tp, i);
797                                 ir_fprintf(F, "\n    %+F", rtp);
798                         }
799
800                         fprintf(F, "\n  parameter types: %lu",
801                                 (unsigned long) get_method_n_params(tp));
802                         for (i = 0; i < get_method_n_params(tp); ++i) {
803                                 ir_type *ptp = get_method_param_type(tp, i);
804                                 ir_fprintf(F, "\n    %+F", ptp);
805                         }
806                         fprintf(F, "\n  properties:");
807                         if (mtp & mtp_property_const)
808                                 fputs(" const", F);
809                         if (mtp & mtp_property_pure)
810                                 fputs(" pure", F);
811                         if (mtp & mtp_property_noreturn)
812                                 fputs(" noreturn", F);
813                         if (mtp & mtp_property_nothrow)
814                                 fputs(" nothrow", F);
815                         if (mtp & mtp_property_naked)
816                                 fputs(" naked", F);
817                         if (mtp & mtp_property_malloc)
818                                 fputs(" malloc", F);
819                         if (mtp & mtp_property_returns_twice)
820                                 fputs(" returns_twice", F);
821                         if (mtp & mtp_property_intrinsic)
822                                 fputs(" intrinsic", F);
823                         if (mtp & mtp_property_runtime)
824                                 fputs(" runtime", F);
825                         if (mtp & mtp_property_private)
826                                 fputs(" private", F);
827                         if (mtp & mtp_property_has_loop)
828                                 fputs(" has_Loop", F);
829
830                         fprintf(F, "\n  calling convention:");
831                         if (cconv & cc_reg_param)
832                                 fputs(" regparam", F);
833                         if (cconv & cc_last_on_top)
834                                 fputs(" last_on_top", F);
835                         if (cconv & cc_callee_clear_stk)
836                                 fputs(" calle_clear_stk", F);
837                         if (cconv & cc_this_call)
838                                 fputs(" this_call", F);
839                         if (cconv & cc_compound_ret)
840                                 fputs(" compound_ret", F);
841                         if (cconv & cc_frame_on_caller_stk)
842                                 fputs(" frame_on_caller_stk", F);
843                         if (cconv & cc_fpreg_param)
844                                 fputs(" fpreg_param", F);
845
846                         if (get_method_variadicity(tp)) {
847                                 fprintf(F, "\n    ...");
848                         }
849                         fprintf(F, "\n");
850                 }
851                 break;
852
853         case tpo_primitive:
854                 if (verbosity & dump_verbosity_typeattrs) {
855                         ir_type *base_tp = get_primitive_base_type(tp);
856                         if (base_tp != NULL)
857                                 ir_fprintf(F, "\n  base type: %+F", tp);
858                         fprintf(F, "\n");
859                 }
860                 break;
861
862         case tpo_none:
863         case tpo_unknown:
864                 fprintf(F, "\n");
865                 break;
866
867         default:
868                 if (verbosity & dump_verbosity_typeattrs) {
869                         fprintf(F, ": details not implemented\n");
870                 }
871         }
872
873         fprintf(F, "  state:      %s,\n", get_type_state_name(get_type_state(tp)));
874         fprintf(F, "  size:       %2u Bytes,\n", get_type_size_bytes(tp));
875         fprintf(F, "  alignment:  %2u Bytes,\n", get_type_alignment_bytes(tp));
876         if (is_atomic_type(tp) || is_Method_type(tp))
877                 fprintf(F, "  mode:       %s,\n",  get_mode_name(get_type_mode(tp)));
878
879         fprintf(F, "\n\n");
880 }
881
882 void dump_types_as_text(FILE *out)
883 {
884         size_t i, n_types = get_irp_n_types();
885
886         for (i = 0; i < n_types; ++i) {
887                 ir_type *type = get_irp_type(i);
888                 dump_type_to_file(out, type);
889         }
890 }
891
892 void dump_globals_as_text(FILE *out)
893 {
894         ir_type *global_type = get_glob_type();
895         size_t   n_members   = get_class_n_members(global_type);
896         size_t   i;
897
898         for (i = 0; i < n_members; ++i) {
899                 ir_entity *entity = get_class_member(global_type, i);
900                 dump_entity_to_file(out, entity);
901         }
902 }