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