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