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