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