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