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