irdumptxt.c 28.6 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
/*
2
 * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
Christian Würdig's avatar
Christian Würdig committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

Matthias Braun's avatar
Matthias Braun committed
20
21
/**
 * @file
22
23
24
 * @brief   Write text representation of firm to file.
 * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Hubert Schmidt,
 *          Matthias Braun
Götz Lindenmaier's avatar
Götz Lindenmaier committed
25
 */
Michael Beck's avatar
Michael Beck committed
26
#include "config.h"
Götz Lindenmaier's avatar
Götz Lindenmaier committed
27
28
29
30

#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
31
#include <stdbool.h>
Götz Lindenmaier's avatar
Götz Lindenmaier committed
32

33
#include "irdump_t.h"
34
#include "irgraph_t.h"
Matthias Braun's avatar
Matthias Braun committed
35
#include "irnode_t.h"
Götz Lindenmaier's avatar
Götz Lindenmaier committed
36
37
38

#include "irprog_t.h"
#include "entity_t.h"
39
#include "trouts.h"
40
#include "irgwalk.h"
Michael Beck's avatar
Michael Beck committed
41
#include "tv_t.h"
Michael Beck's avatar
Michael Beck committed
42
#include "irprintf.h"
43
#include "error.h"
Götz Lindenmaier's avatar
Götz Lindenmaier committed
44

Götz Lindenmaier's avatar
Götz Lindenmaier committed
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
52
	verbosity = new_verbosity;
}
Michael Beck's avatar
Michael Beck committed
53

54
55
56
ir_dump_verbosity_t ir_get_dump_verbosity(void)
{
	return verbosity;
57
58
}

59
void dump_irnode_to_file(FILE *F, const ir_node *n)
60
{
Michael Beck's avatar
Michael Beck committed
61
	char     comma;
Michael Beck's avatar
Michael Beck committed
62
63
64
65
66
67
	ir_graph *irg;

	dump_node_opcode(F, n);
	fprintf(F, " %ld\n", get_irn_node_nr(n));

	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);
Michael Beck's avatar
Michael Beck committed
70
	fprintf (F, "  mode:    %s\n", get_mode_name(get_irn_mode(n)));
71
	fprintf (F, "  visited: %lu\n", get_irn_visited(n));
Michael Beck's avatar
Michael Beck committed
72
73
74
75
76
77
78
	irg = get_irn_irg(n);
	if (irg != get_const_code_irg())
		fprintf (F, "  irg:     %s\n", get_ent_dump_name(get_irg_entity(irg)));

	if (get_irn_pinned(n) == op_pin_state_floats &&
		get_irg_pinned(get_irn_irg(n)) == op_pin_state_floats) {
		fprintf(F, "  node was pinned in ");
79
80
		dump_node_opcode(F, get_irn_n(n, -1));
		fprintf(F, " %ld\n", get_irn_node_nr(get_irn_n(n, -1)));
Michael Beck's avatar
Michael Beck committed
81
82
	}

83
84
	fprintf(F, "  arity:   %d\n", get_irn_arity(n));
	/* show all predecessor nodes */
85
	fprintf(F, "  pred nodes:\n");
86
87
88
89
90
	if (!is_Block(n)) {
		fprintf(F, "    -1:    ");
		dump_node_opcode(F, get_irn_n(n, -1));
		fprintf(F, " %ld\n", get_irn_node_nr(get_irn_n(n, -1)));
	}
91
92
93
94
95
96
97
98

	{
		int i;
		for (i = 0; i < get_irn_arity(n); ++i) {
			fprintf(F, "     %d: %s ", i, is_backedge(n, i) ? "be" : "  ");
			dump_node_opcode(F, get_irn_n(n, i));
			fprintf(F, " %ld\n", get_irn_node_nr(get_irn_n(n, i)));
		}
99
	}
Michael Beck's avatar
Michael Beck committed
100
101
102

	fprintf(F, "  Private Attributes:\n");

Matthias Braun's avatar
Matthias Braun committed
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
	if (is_Proj(n)) {
		ir_node *pred = get_Proj_pred(n);
		long     pn   = get_Proj_proj(n);
		fprintf(F, "  proj nr: %ld\n", pn);
		if (is_Switch(pred)) {
			const ir_switch_table *table = get_Switch_table(pred);
			size_t n_entries = ir_switch_table_get_n_entries(table);
			size_t i;
			for (i = 0; i < n_entries; ++i) {
				const ir_switch_table_entry *entry
					= ir_switch_table_get_entry_const(table, i);
				if (entry->pn == pn && entry->min != NULL && entry->max != NULL) {
					ir_tarval *min = entry->min;
					ir_tarval *max = entry->max;
					if (min != max) {
						ir_fprintf(F, "  switch case %+F .. %+F\n", min, max);
					} else {
						ir_fprintf(F, "  switch case %+F\n", min);
					}
				}
			}
		}
	}
Michael Beck's avatar
Michael Beck committed
126
127
128
129
130
131
132

	if (is_fragile_op(n)) {
		fprintf(F, "  pinned state: %s\n", get_op_pin_state_name(get_irn_pinned(n)));
		/* not dumped: frag array */
	}

	/* This is not nice, output it as a marker in the predecessor list. */
133
134
	if (is_Block(n) || get_irn_op(n) == op_Phi) {
	    int i;
Michael Beck's avatar
Michael Beck committed
135
136
137
138
139
140
141
142
		fprintf(F, "  backedges:");
		comma = ' ';
		for (i = 0; i < get_irn_arity(n); i++)
			if (is_backedge(n, i)) { fprintf(F, "%c %d", comma, i); comma = ','; }
			fprintf(F, "\n");
	}

	/* Loop node.   Someone else please tell me what's wrong ... */
143
	if (is_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_LOOPINFO)) {
Michael Beck's avatar
Michael Beck committed
144
		ir_loop *loop = get_irn_loop(n);
145
		if (loop != NULL) {
Matthias Braun's avatar
Matthias Braun committed
146
147
			fprintf(F, "  in loop %ld with depth %u\n",
			        get_loop_loop_nr(loop), get_loop_depth(loop));
148
		}
Michael Beck's avatar
Michael Beck committed
149
150
151
152
153
	}

	/* Source types */
	switch (get_irn_opcode(n)) {
	case iro_Block: {
154
		if (get_Block_entity(n) != NULL)
155
			fprintf(F, "  Label: %lu\n", get_entity_label(get_Block_entity(n)));
156
		fprintf(F, "  block visited: %lu\n", get_Block_block_visited(n));
Michael Beck's avatar
Michael Beck committed
157
		fprintf(F, "  block marked: %u\n", get_Block_mark(n));
158
		if (is_irg_state(get_irn_irg(n), IR_GRAPH_STATE_CONSISTENT_DOMINANCE)) {
Michael Beck's avatar
Michael Beck committed
159
			fprintf(F, "  dom depth %d\n", get_Block_dom_depth(n));
160
161
			fprintf(F, "  domtree pre num %u\n", get_Block_dom_tree_pre_num(n));
			fprintf(F, "  max subtree pre num %u\n", get_Block_dom_max_subtree_pre_num(n));
Michael Beck's avatar
Michael Beck committed
162
		}
163
		if (is_irg_state(get_irn_irg(n), IR_GRAPH_STATE_CONSISTENT_POSTDOMINANCE)) {
164
			fprintf(F, "  pdom depth %d\n", get_Block_postdom_depth(n));
165
166
			fprintf(F, "  pdomtree pre num %u\n", get_Block_pdom_tree_pre_num(n));
			fprintf(F, "  max pdomsubtree pre num %u\n", get_Block_pdom_max_subtree_pre_num(n));
167
		}
Michael Beck's avatar
Michael Beck committed
168
169
170
171
172

		/* not dumped: graph_arr */
		/* not dumped: mature    */
	}  break;
	case iro_Start: {
173
		size_t   i;
Michael Beck's avatar
Michael Beck committed
174
		ir_type *tp = get_entity_type(get_irg_entity(get_irn_irg(n)));
175
		ir_fprintf(F, "  start of method of type %+F\n", tp);
Michael Beck's avatar
Michael Beck committed
176
		for (i = 0; i < get_method_n_params(tp); ++i)
177
			ir_fprintf(F, "    param %d type: %+F\n", i, get_method_param_type(tp, i));
Michael Beck's avatar
Michael Beck committed
178
179
	} break;
	case iro_Cond: {
180
181
182
183
		if (get_Cond_jmp_pred(n) != COND_JMP_PRED_NONE) {
			fprintf(F, "  jump prediction: %s\n",
			        get_cond_jmp_predicate_name(get_Cond_jmp_pred(n)));
		}
Michael Beck's avatar
Michael Beck committed
184
185
	} break;
	case iro_Alloc: {
186
		ir_fprintf(F, "  allocating entity of type: %+F\n", get_Alloc_type(n));
Michael Beck's avatar
Michael Beck committed
187
188
189
		fprintf(F, "  allocating on: the %s\n", (get_Alloc_where(n) == stack_alloc) ? "stack" : "heap");
	} break;
	case iro_Free: {
190
		ir_fprintf(F, "  freeing entity of type %+F\n", get_Free_type(n));
Michael Beck's avatar
Michael Beck committed
191
192
193
194
195
196
		fprintf(F, "  allocated on: the %s\n", (get_Free_where(n) == stack_alloc) ? "stack" : "heap");
	} break;
	case iro_Sel: {
		ir_entity *ent = get_Sel_entity(n);
		if (ent) {
			fprintf(F, "  Selecting entity %s (%ld)\n", get_entity_name(ent), get_entity_nr(ent));
197
198
			ir_fprintf(F, "    of type    %+F\n",  get_entity_type(ent));
			ir_fprintf(F, "    with owner %+F.\n", get_entity_owner(ent));
199
		} else {
Michael Beck's avatar
Michael Beck committed
200
201
202
203
204
			fprintf(F, "  <NULL entity>\n");
		}
	} break;
	case iro_Call: {
		ir_type *tp = get_Call_type(n);
205
		ir_fprintf(F, "  calling method of type %+F\n", tp);
206
		if (get_unknown_type() != tp) {
207
			size_t i;
Michael Beck's avatar
Michael Beck committed
208
			for (i = 0; i < get_method_n_params(tp); ++i)
209
				ir_fprintf(F, "    param %d type: %+F\n", i, get_method_param_type(tp, i));
Michael Beck's avatar
Michael Beck committed
210
			for (i = 0; i < get_method_n_ress(tp); ++i)
211
				ir_fprintf(F, "    result %d type: %+F\n", i, get_method_res_type(tp, i));
Michael Beck's avatar
Michael Beck committed
212
213
		}
		if (Call_has_callees(n)) {
Matthias Braun's avatar
Matthias Braun committed
214
			size_t i;
215
			fprintf(F, "  possible callees:\n");
Michael Beck's avatar
Michael Beck committed
216
			for (i = 0; i < get_Call_n_callees(n); i++) {
Michael Beck's avatar
Michael Beck committed
217
				ir_fprintf(F, "    %zu: %s\n", i, get_ent_dump_name(get_Call_callee(n, i)));
Michael Beck's avatar
Michael Beck committed
218
219
220
221
			}
		}
	} break;
	case iro_Cast: {
222
		ir_fprintf(F, "  cast to type: %+F\n", get_Cast_type(n));
Michael Beck's avatar
Michael Beck committed
223
	} break;
224
225
226
227
	case iro_Cmp: {
		ir_relation relation = get_Cmp_relation(n);
		ir_fprintf(F, "  relation: %s\n", get_relation_string(relation));
	} break;
Michael Beck's avatar
Michael Beck committed
228
	case iro_Return: {
229
		size_t   i;
230
231
232
233
234
		ir_type *tp = get_entity_type(get_irg_entity(get_irn_irg(n)));
		ir_fprintf(F, "  return in method of type %+F\n", tp);
		for (i = 0; i < get_method_n_ress(tp); ++i) {
			ir_fprintf(F, "    result %d type: %+F\n", i,
					   get_method_res_type(tp, i));
Michael Beck's avatar
Michael Beck committed
235
236
237
		}
	} break;
	case iro_SymConst: {
238
		switch (get_SymConst_kind(n)) {
Michael Beck's avatar
Michael Beck committed
239
240
241
		case symconst_addr_ent:
			fprintf(F, "  kind:   addr_ent\n");
			fprintf(F, "  entity: ");
242
			dump_entity_to_file(F, get_SymConst_entity(n));
Michael Beck's avatar
Michael Beck committed
243
244
245
246
			break;
		case symconst_ofs_ent:
			fprintf(F, "  kind:   offset\n");
			fprintf(F, "  entity: ");
247
			dump_entity_to_file(F, get_SymConst_entity(n));
Michael Beck's avatar
Michael Beck committed
248
249
250
251
			break;
		case symconst_type_size:
			fprintf(F, "  kind: size\n");
			fprintf(F, "  type: ");
252
			dump_type_to_file(F, get_SymConst_type(n));
Michael Beck's avatar
Michael Beck committed
253
254
255
256
			break;
		case symconst_type_align:
			fprintf(F, "  kind: alignment\n");
			fprintf(F, "  type: ");
257
			dump_type_to_file(F, get_SymConst_type(n));
Michael Beck's avatar
Michael Beck committed
258
259
260
			break;
		case symconst_enum_const:
			fprintf(F, "  kind: enumeration\n");
261
			fprintf(F, "  name: %s\n", get_enumeration_const_name(get_SymConst_enum(n)));
Michael Beck's avatar
Michael Beck committed
262
263
264
265
			break;
		}
	} break;
	case iro_Load:
266
		fprintf(F, "  mode of loaded value: %s\n", get_mode_name_ex(get_Load_mode(n), NULL));
Michael Beck's avatar
Michael Beck committed
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)));
Michael Beck's avatar
Michael Beck committed
269
270
271
		break;
	case iro_Store:
		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)));
Michael Beck's avatar
Michael Beck committed
273
274
		break;
	case iro_Confirm:
275
		fprintf(F, "  compare operation: %s\n", get_relation_string(get_Confirm_relation(n)));
Michael Beck's avatar
Michael Beck committed
276
277
278
279
280
281
		break;
	case iro_ASM: {
		const ir_asm_constraint *cons;
		ident **clobber;
		int l;

Matthias Braun's avatar
Matthias Braun committed
282
		fprintf(F, "  assembler text: %s", get_id_str(get_ASM_text(n)));
Michael Beck's avatar
Michael Beck committed
283
284
		l = get_ASM_n_input_constraints(n);
		if (l > 0) {
285
			int i;
Michael Beck's avatar
Michael Beck committed
286
287
288
289
290
291
292
			fprintf(F, "\n  inputs:  ");
			cons = get_ASM_input_constraints(n);
			for (i = 0; i < l; ++i)
				fprintf(F, "%%%u %s ", cons[i].pos, get_id_str(cons[i].constraint));
		}
		l = get_ASM_n_output_constraints(n);
		if (l > 0) {
293
			int i;
Michael Beck's avatar
Michael Beck committed
294
295
296
297
298
299
300
			fprintf(F, "\n  outputs: ");
			cons = get_ASM_output_constraints(n);
			for (i = 0; i < l; ++i)
				fprintf(F, "%%%u %s ", cons[i].pos, get_id_str(cons[i].constraint));
		}
		l = get_ASM_n_clobbers(n);
		if (l > 0) {
301
			int i;
Michael Beck's avatar
Michael Beck committed
302
303
304
305
306
307
308
309
310
			fprintf(F, "\n  clobber: ");
			clobber = get_ASM_clobbers(n);
			for (i = 0; i < l; ++i)
				fprintf(F, "%s ", get_id_str(clobber[i]));
		}
		if (get_irn_pinned(n) != op_pin_state_floats)
			fprintf(F, "\n  volatile");
		fprintf(F, "\n");
	} break;
Michael Beck's avatar
Michael Beck committed
311
312
313

	default:
		break;
Michael Beck's avatar
Michael Beck committed
314
315
316
317
	}

	if (get_irg_typeinfo_state(get_irn_irg(n)) == ir_typeinfo_consistent  ||
		get_irg_typeinfo_state(get_irn_irg(n)) == ir_typeinfo_inconsistent  )
318
		if (get_irn_typeinfo_type(n) != get_none_type())
319
			ir_fprintf (F, "  Analysed type: %s\n", get_irn_typeinfo_type(n));
320
321
}

322
void dump_graph_as_text(FILE *out, ir_graph *irg)
323
{
324
	fprintf(out, "graph %s\n", get_irg_dump_name(irg));
325
326
}

327
328
static int need_nl = 1;

329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
static bool is_init_string(ir_initializer_t const* const init, ir_type *const type)
{
	ir_type *const element_type = get_array_element_type(type);
	ir_mode *      mode;
	size_t         n;
	size_t         i;

	if (!is_Primitive_type(element_type))
		return false;

	mode = get_type_mode(element_type);
	if (!mode_is_int(mode) || get_mode_size_bits(mode) != 8)
		return false;

	n = get_initializer_compound_n_entries(init);
	for (i = 0; i != n; ++i) {
		ir_initializer_t const* const val = get_initializer_compound_value(init, i);
Matthias Braun's avatar
Matthias Braun committed
346
		ir_tarval*                    tv;
347
348
		long                          v;

Matthias Braun's avatar
Matthias Braun committed
349
350
351
352
		if (get_initializer_kind(val) != IR_INITIALIZER_TARVAL)
			return false;
		tv = get_initializer_tarval_value(val);

353
354
355
356
		if (!tarval_is_constant(tv))
			return false;

		v = get_tarval_long(tv);
357
		if (v != 0 && (v < 0x07 || 0x0D < v) && v != 0x1B && (v < 0x20 || 0x80 <= v) && (v < 0xA0 || 0x100 <= v))
358
359
360
361
362
363
			return false;
	}

	return true;
}

364
365
366
367
/**
 * Dump initializers.
 */
static void dump_ir_initializers_to_file(FILE *F, const char *prefix,
368
369
                                         const ir_initializer_t *initializer,
                                         ir_type *type)
370
{
Matthias Braun's avatar
Matthias Braun committed
371
372
	ir_tarval *tv;
	ir_node   *value;
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387

	if (need_nl) {
		fprintf(F, "\n%s    ", prefix);
		need_nl = 0;
	}
	switch (get_initializer_kind(initializer)) {
	case IR_INITIALIZER_NULL:
		fprintf(F, "\t = <NOT_SET>");
		break;
	case IR_INITIALIZER_TARVAL:
		tv = get_initializer_tarval_value(initializer);
		ir_fprintf(F, "\t = <TV>%F", tv);
		break;
	case IR_INITIALIZER_CONST:
		value = get_initializer_const_value(initializer);
388
		ir_fprintf(F, "\t = %F", value);
389
390
391
		break;
	case IR_INITIALIZER_COMPOUND:
		if (is_Array_type(type)) {
392
393
394
395
396
397
398
399
400
401
402
			size_t const n = get_initializer_compound_n_entries(initializer);
			size_t       i;

			if (is_init_string(initializer, type)) {
				fprintf(F, "\t[0...%u] = '", (unsigned)n - 1);
				for (i = 0; i != n; ++i) {
					ir_initializer_t const* const val = get_initializer_compound_value(initializer, i);
					ir_tarval*              const tv  = get_initializer_tarval_value(val);
					long                    const v   = get_tarval_long(tv);

					switch (v) {
403
						case 0x00: fprintf(F, "\\\\000");  break;
404
405
						case 0x07: fprintf(F, "\\\\a");    break;
						case 0x08: fprintf(F, "\\\\b");    break;
406
407
						case 0x09: fprintf(F, "\\\\t");    break;
						case 0x0A: fprintf(F, "\\\\n");    break;
408
						case 0x0B: fprintf(F, "\\\\v");    break;
409
410
411
412
413
						case 0x0C: fprintf(F, "\\\\f");    break;
						case 0x0D: fprintf(F, "\\\\r");    break;
						case 0x1B: fprintf(F, "\\\\033");  break;
						case 0x22: fprintf(F, "\\\\\\\""); break;
						case 0x5C: fprintf(F, "\\\\\\\\"); break;
414
415
416
417
418
419
420
421
422
423
						default:   fprintf(F, "%c", (unsigned char)v); break;
					}
				}
				fprintf(F, "'");
			} else {
				ir_type *const element_type = get_array_element_type(type);

				for (i = 0; i < n; ++i) {
					ir_initializer_t *sub_initializer
						= get_initializer_compound_value(initializer, i);
424

425
426
427
428
429
430
					if (need_nl) {
						fprintf(F, "\n%s    ", prefix);
						need_nl = 0;
					}
					fprintf(F, "[%d]", (int) i);
					dump_ir_initializers_to_file(F, prefix, sub_initializer, element_type);
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
				}
			}
		} else {
			size_t i, n;
			assert(is_compound_type(type));
			n = get_compound_n_members(type);
			for (i = 0; i < n; ++i) {
				ir_entity        *member    = get_compound_member(type, i);
				ir_type          *subtype   = get_entity_type(member);
				ir_initializer_t *sub_initializer;

				assert(i < get_initializer_compound_n_entries(initializer));
				sub_initializer
					= get_initializer_compound_value(initializer, i);

				if (need_nl) {
					fprintf(F, "\n%s    ", prefix);
					need_nl = 0;
				}
				ir_fprintf(F, ".%F", member);
				dump_ir_initializers_to_file(F, prefix, sub_initializer, subtype);
			}
		}
		break;
	default:
		panic("invalid ir_initializer kind found");
	}
	need_nl = 1;
}

Matthias Braun's avatar
Matthias Braun committed
461
462
463
464
static void dump_entity_linkage(FILE *F, const ir_entity *entity)
{
	ir_linkage linkage = get_entity_linkage(entity);

465
466
467
468
	if (linkage == IR_LINKAGE_DEFAULT) {
		fprintf(F, " default");
		return;
	}
Matthias Braun's avatar
Matthias Braun committed
469
470
471
472
473
474
475
476
477
478
479
	if (linkage & IR_LINKAGE_CONSTANT)
		fprintf(F, " constant");
	if (linkage & IR_LINKAGE_WEAK)
		fprintf(F, " weak");
	if (linkage & IR_LINKAGE_GARBAGE_COLLECT)
		fprintf(F, " garbage_collect");
	if (linkage & IR_LINKAGE_MERGE)
		fprintf(F, " merge");
	if (linkage & IR_LINKAGE_HIDDEN_USER)
		fprintf(F, " hidden_user");
}
480

481
static void dump_entity_to_file_prefix(FILE *F, ir_entity *ent, const char *prefix)
482
{
Michael Beck's avatar
Michael Beck committed
483
484
485
486
487
488
	ir_type *owner, *type;

	assert(is_entity(ent));
	owner = get_entity_owner(ent);
	type  = get_entity_type(ent);
	if (verbosity & dump_verbosity_onlynames) {
489
		fprintf(F, "%sentity %s.%s (%ld)\n", prefix, get_compound_name(get_entity_owner(ent)),
Michael Beck's avatar
Michael Beck committed
490
491
492
493
494
495
			get_entity_name(ent), get_entity_nr(ent));
		return;
	}

	if (verbosity & dump_verbosity_entattrs) {
		fprintf(F, "%sentity %s (%ld)\n", prefix, get_entity_name(ent), get_entity_nr(ent));
496
497
		ir_fprintf(F, "%s  type:  %+F\n", prefix, type);
		ir_fprintf(F, "%s  owner: %+F\n", prefix, owner);
Michael Beck's avatar
Michael Beck committed
498
499
500

		if (is_Class_type(get_entity_owner(ent))) {
			if (get_entity_n_overwrites(ent) > 0) {
501
				size_t i;
Michael Beck's avatar
Michael Beck committed
502
503
504
				fprintf(F, "%s  overwrites:\n", prefix);
				for (i = 0; i < get_entity_n_overwrites(ent); ++i) {
					ir_entity *ov = get_entity_overwrites(ent, i);
505
506
					ir_fprintf(F, "%s    %d: %s of class %+F\n", prefix, i,
					        get_entity_name(ov), get_entity_owner(ov));
Michael Beck's avatar
Michael Beck committed
507
508
				}
			} else {
509
				fprintf(F, "%s  Does not overwrite other entities.\n", prefix);
Michael Beck's avatar
Michael Beck committed
510
511
			}
			if (get_entity_n_overwrittenby(ent) > 0) {
512
				size_t i;
Michael Beck's avatar
Michael Beck committed
513
514
515
				fprintf(F, "%s  overwritten by:\n", prefix);
				for (i = 0; i < get_entity_n_overwrittenby(ent); ++i) {
					ir_entity *ov = get_entity_overwrittenby(ent, i);
516
517
					ir_fprintf(F, "%s    %d: %s of class %+F\n", prefix, i,
					           get_entity_name(ov), get_entity_owner(ov));
Michael Beck's avatar
Michael Beck committed
518
519
				}
			} else {
520
521
				fprintf(F, "%s  Is not overwritten by other entities.\n",
				        prefix);
Michael Beck's avatar
Michael Beck committed
522
523
524
525
526
527
528
529
			}

			if (get_irp_inh_transitive_closure_state() != inh_transitive_closure_none) {
				ir_entity *ov;
				fprintf(F, "%s  transitive overwrites:\n", prefix);
				for (ov = get_entity_trans_overwrites_first(ent);
				ov;
				ov = get_entity_trans_overwrites_next(ent)) {
530
531
					ir_fprintf(F, "%s    : %s of class %+F\n", prefix,
					           get_entity_name(ov), get_entity_owner(ov));
Michael Beck's avatar
Michael Beck committed
532
533
534
535
536
				}
				fprintf(F, "%s  transitive overwritten by:\n", prefix);
				for (ov = get_entity_trans_overwrittenby_first(ent);
				ov;
				ov = get_entity_trans_overwrittenby_next(ent)) {
537
538
					ir_fprintf(F, "%s    : %s of class %+F\n", prefix,
					           get_entity_name(ov), get_entity_owner(ov));
Michael Beck's avatar
Michael Beck committed
539
540
541
542
543
544
545
546
547
548
				}
			}
		}

		if (is_Method_type(get_entity_type(ent))) {
			unsigned mask = get_entity_additional_properties(ent);
			unsigned cc   = get_method_calling_convention(get_entity_type(ent));
			ir_graph *irg = get_entity_irg(ent);

			if (irg) {
549
550
				fprintf(F, "%s  estimated node count: %u\n", prefix, get_irg_estimated_node_cnt(irg));
				fprintf(F, "%s  maximum node index:   %u\n", prefix, get_irg_last_idx(irg));
Michael Beck's avatar
Michael Beck committed
551
552
553
			}

			if (mask) {
554
				fprintf(F, "%s  additional prop: ", prefix);
Michael Beck's avatar
Michael Beck committed
555

556
557
558
559
560
561
562
563
564
565
566
				if (mask & mtp_property_const)         fputs("const_function, ", F);
				if (mask & mtp_property_pure)          fputs("pure_function, ", F);
				if (mask & mtp_property_noreturn)      fputs("noreturn_function, ", F);
				if (mask & mtp_property_nothrow)       fputs("nothrow_function, ", F);
				if (mask & mtp_property_naked)         fputs("naked_function, ", F);
				if (mask & mtp_property_malloc)        fputs("malloc_function, ", F);
				if (mask & mtp_property_returns_twice) fputs("weak_function, ", F);
				if (mask & mtp_property_intrinsic)     fputs("intrinsic_function, ", F);
				if (mask & mtp_property_runtime)       fputs("runtime_function, ", F);
				if (mask & mtp_property_private)       fputs("private_function, ", F);
				if (mask & mtp_property_has_loop)      fputs("has_loop_function, ", F);
567
				fputc('\n', F);
Michael Beck's avatar
Michael Beck committed
568
			}
569
			fprintf(F, "%s  calling convention: ", prefix);
570
571
572
573
			if (cc & cc_reg_param)           fputs("regparam, ", F);
			if (cc & cc_this_call)           fputs("thiscall, ", F);
			if (cc & cc_compound_ret)        fputs("compound_ret, ", F);
			if (cc & cc_frame_on_caller_stk) fputs("frame on caller's stack, ", F);
574
			cc &= ~(cc_compound_ret|cc_frame_on_caller_stk);
Michael Beck's avatar
Michael Beck committed
575
			if (IS_CDECL(cc))
576
				fputs("cdecl", F);
Michael Beck's avatar
Michael Beck committed
577
			else if (IS_STDCALL(cc))
578
				fputs("stdcall", F);
Michael Beck's avatar
Michael Beck committed
579
			else {
580
581
				fputs(cc & cc_last_on_top      ? "last param on top, " : "first param on top, ", F);
				fputs(cc & cc_callee_clear_stk ? "callee clear stack" : "caller clear stack", F);
Michael Beck's avatar
Michael Beck committed
582
			}
583
			fprintf(F, "\n%s  vtable number:        %u\n", prefix, get_entity_vtable_number(ent));
Michael Beck's avatar
Michael Beck committed
584
585
		}
	} else {  /* no entattrs */
586
		ir_fprintf(F, "%s(%3d:%d) %+F: %s", prefix,
Michael Beck's avatar
Michael Beck committed
587
			get_entity_offset(ent), get_entity_offset_bits_remainder(ent),
588
			get_entity_type(ent), get_entity_name(ent));
589
		if (is_Method_type(get_entity_type(ent))) fputs("(...)", F);
Michael Beck's avatar
Michael Beck committed
590
591

		if (verbosity & dump_verbosity_accessStats) {
Matthias Braun's avatar
Matthias Braun committed
592
			dump_entity_linkage(F, ent);
Michael Beck's avatar
Michael Beck committed
593
		}
594
		fputc('\n', F);
Michael Beck's avatar
Michael Beck committed
595
596
597
	}

	if (verbosity & dump_verbosity_entconsts) {
Matthias Braun's avatar
Matthias Braun committed
598
599
600
601
602
		if (ent->initializer != NULL) {
			const ir_initializer_t *initializer = get_entity_initializer(ent);
			fprintf(F, "\n%s  Initializers:", prefix);
			need_nl = 1;
			dump_ir_initializers_to_file(F, prefix, initializer, get_entity_type(ent));
603
			fputc('\n', F);
Matthias Braun's avatar
Matthias Braun committed
604
		} else if (entity_has_compound_ent_values(ent)) {
Matthias Braun's avatar
Matthias Braun committed
605
			size_t i;
Matthias Braun's avatar
Matthias Braun committed
606
607
			fprintf(F, "%s  compound values:", prefix);
			for (i = 0; i < get_compound_ent_n_values(ent); ++i) {
Matthias Braun's avatar
Matthias Braun committed
608
				size_t j;
Matthias Braun's avatar
Matthias Braun committed
609
610
				compound_graph_path *path = get_compound_ent_value_path(ent, i);
				ir_entity *ent0 = get_compound_graph_path_node(path, 0);
611
				fprintf(F, "\n%s    %3d:%d ", prefix, get_entity_offset(ent0), get_entity_offset_bits_remainder(ent0));
Matthias Braun's avatar
Matthias Braun committed
612
613
614
615
616
617
618
				if (get_type_state(type) == layout_fixed)
					fprintf(F, "(%3u:%u) ",   get_compound_ent_value_offset_bytes(ent, i), get_compound_ent_value_offset_bit_remainder(ent, i));
				fprintf(F, "%s", get_entity_name(ent));
				for (j = 0; j < get_compound_graph_path_length(path); ++j) {
					ir_entity *node = get_compound_graph_path_node(path, j);
					fprintf(F, ".%s", get_entity_name(node));
					if (is_Array_type(get_entity_owner(node)))
Matthias Braun's avatar
Matthias Braun committed
619
						fprintf(F, "[%ld]", get_compound_graph_path_array_index(path, j));
Michael Beck's avatar
Michael Beck committed
620
				}
Matthias Braun's avatar
Matthias Braun committed
621
622
				fprintf(F, "\t = ");
				dump_node_opcode(F, get_compound_ent_value(ent, i));
Michael Beck's avatar
Michael Beck committed
623
			}
624
			fputc('\n', F);
Michael Beck's avatar
Michael Beck committed
625
626
627
628
		}
	}

	if (verbosity & dump_verbosity_entattrs) {
Matthias Braun's avatar
Matthias Braun committed
629
630
		fprintf(F, "%s  linkage:", prefix);
		dump_entity_linkage(F, ent);
631
		fprintf(F, "\n%s  volatility:  %s", prefix, get_volatility_name(get_entity_volatility(ent)));
Matthias Braun's avatar
Matthias Braun committed
632
633
		fprintf(F, "\n%s  aligned:  %s", prefix, get_align_name(get_entity_aligned(ent)));
		fprintf(F, "\n%s  alignment:  %u", prefix, get_entity_alignment(ent));
Michael Beck's avatar
Michael Beck committed
634
635
636
637
638
639
640
641
642
		fprintf(F, "\n%s  ld_name: %s", prefix, ent->ld_name ? get_entity_ld_name(ent) : "no yet set");
		fprintf(F, "\n%s  offset:  %d bytes, %d rem bits", prefix, get_entity_offset(ent), get_entity_offset_bits_remainder(ent));
		if (is_Method_type(get_entity_type(ent))) {
			if (get_entity_irg(ent))   /* can be null */ {
				fprintf(F, "\n%s  irg = %ld", prefix, get_irg_graph_nr(get_entity_irg(ent)));
			} else {
				fprintf(F, "\n%s  irg = NULL", prefix);
			}
		}
643
		fputc('\n', F);
Michael Beck's avatar
Michael Beck committed
644
	}
Götz Lindenmaier's avatar
Götz Lindenmaier committed
645
646
}

647
void dump_entity_to_file(FILE *out, ir_entity *ent)
648
{
649
650
	dump_entity_to_file_prefix(out, ent, "");
	fprintf(out, "\n");
Götz Lindenmaier's avatar
Götz Lindenmaier committed
651
652
}

653
void dump_type_to_file(FILE *F, ir_type *tp)
654
{
655
	size_t i;
Michael Beck's avatar
Michael Beck committed
656
657
658
659
660
661
662
663
664
665

	if ((is_Class_type(tp))       && (verbosity & dump_verbosity_noClassTypes)) return;
	if ((is_Struct_type(tp))      && (verbosity & dump_verbosity_noStructTypes)) return;
	if ((is_Union_type(tp))       && (verbosity & dump_verbosity_noUnionTypes)) return;
	if ((is_Array_type(tp))       && (verbosity & dump_verbosity_noArrayTypes)) return;
	if ((is_Pointer_type(tp))     && (verbosity & dump_verbosity_noPointerTypes)) return;
	if ((is_Method_type(tp))      && (verbosity & dump_verbosity_noMethodTypes)) return;
	if ((is_Primitive_type(tp))   && (verbosity & dump_verbosity_noPrimitiveTypes)) return;
	if ((is_Enumeration_type(tp)) && (verbosity & dump_verbosity_noEnumerationTypes)) return;

666
	ir_fprintf(F, "%+F", tp);
Michael Beck's avatar
Michael Beck committed
667
668
669
670
671
672
	if (verbosity & dump_verbosity_onlynames) { fprintf(F, "\n"); return; }

	switch (get_type_tpop_code(tp)) {

	case tpo_class:
		if ((verbosity & dump_verbosity_methods) || (verbosity & dump_verbosity_fields)) {
673
			fprintf(F, "\n  members:\n");
Michael Beck's avatar
Michael Beck committed
674
675
676
677
678
		}
		for (i = 0; i < get_class_n_members(tp); ++i) {
			ir_entity *mem = get_class_member(tp, i);
			if (((verbosity & dump_verbosity_methods) &&  is_Method_type(get_entity_type(mem))) ||
				((verbosity & dump_verbosity_fields)  && !is_Method_type(get_entity_type(mem)))   ) {
Matthias Braun's avatar
Matthias Braun committed
679
				if (!(verbosity & dump_verbosity_nostatic)) {
680
					dump_entity_to_file_prefix(F, mem, "    ");
Michael Beck's avatar
Michael Beck committed
681
682
683
684
685
686
687
				}
			}
		}
		if (verbosity & dump_verbosity_typeattrs) {
			fprintf(F, "  supertypes: ");
			for (i = 0; i < get_class_n_supertypes(tp); ++i) {
				ir_type *stp = get_class_supertype(tp, i);
688
				ir_fprintf(F, "\n    %d %+F", i, stp);
Michael Beck's avatar
Michael Beck committed
689
690
691
692
			}
			fprintf(F, "\n  subtypes: ");
			for (i = 0; i < get_class_n_subtypes(tp); ++i) {
				ir_type *stp = get_class_subtype(tp, i);
693
				ir_fprintf(F, "\n    %d %+F", i, stp);
Michael Beck's avatar
Michael Beck committed
694
695
696
697
698
699
700
701
			}

			if (get_irp_inh_transitive_closure_state() != inh_transitive_closure_none) {
				ir_type *stp;
				fprintf(F, "\n  transitive supertypes: ");
				for (stp = get_class_trans_supertype_first(tp);
				stp;
				stp = get_class_trans_supertype_next(tp)) {
702
					ir_fprintf(F, "\n    %+F", stp);
Michael Beck's avatar
Michael Beck committed
703
704
705
706
707
				}
				fprintf(F, "\n  transitive subtypes: ");
				for (stp = get_class_trans_subtype_first(tp);
				stp;
				stp = get_class_trans_subtype_next(tp)) {
708
					ir_fprintf(F, "\n    %+F", stp);
Michael Beck's avatar
Michael Beck committed
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
				}
			}

			fprintf(F, "\n  flags:       ");
			if (is_class_final(tp))
				fprintf(F, "final, ");
			if (is_class_interface(tp))
				fprintf(F, "interface, ");
			if (is_class_abstract(tp))
				fprintf(F, "abstract, ");
			fprintf(F, "\n");
		}
		break;

	case tpo_union:
	case tpo_struct:
		if (verbosity & dump_verbosity_fields) fprintf(F, "\n  members: ");
		for (i = 0; i < get_compound_n_members(tp); ++i) {
			ir_entity *mem = get_compound_member(tp, i);
			if (verbosity & dump_verbosity_fields) {
729
				dump_entity_to_file_prefix(F, mem, "    ");
Michael Beck's avatar
Michael Beck committed
730
731
732
733
734
735
			}
		}
		break;

	case tpo_array:
		if (verbosity & dump_verbosity_typeattrs) {
736
			size_t n_dim;
Michael Beck's avatar
Michael Beck committed
737
738
739
740
741
742
743
744
745
746
747
748
749
			ir_type *elem_tp = get_array_element_type(tp);

			fprintf(F, "\n  array ");

			n_dim = get_array_n_dimensions(tp);
			for (i = 0; i < n_dim; ++i) {
				ir_node *lower, *upper;

				lower = get_array_lower_bound(tp, i);
				upper = get_array_upper_bound(tp, i);

				fprintf(F, "[");

750
				if (is_Const(lower)) {
Michael Beck's avatar
Michael Beck committed
751
					fprintf(F, "%ld .. ", get_tarval_long(get_Const_tarval(lower)));
752
				} else {
Michael Beck's avatar
Michael Beck committed
753
754
755
756
					dump_node_opcode(F, lower);
					fprintf(F, " %ld .. ", get_irn_node_nr(lower));
				}

757
				if (is_Const(upper)) {
Michael Beck's avatar
Michael Beck committed
758
					fprintf(F, "%ld]", get_tarval_long(get_Const_tarval(lower)));
759
				} else {
Michael Beck's avatar
Michael Beck committed
760
761
762
763
					dump_node_opcode(F, upper);
					fprintf(F, " %ld]", get_irn_node_nr(upper));
				}
			}
764
			ir_fprintf(F, " of <%+F>", elem_tp);
Michael Beck's avatar
Michael Beck committed
765
766
767

			fprintf(F, "\n  order: ");
			for (i = 0; i < n_dim; ++i)
768
				fprintf(F, "<%zu>", get_array_order(tp, i));
Michael Beck's avatar
Michael Beck committed
769
770
771
772
773

			fprintf(F, "\n");

			if (verbosity & dump_verbosity_fields) {
				dump_entity_to_file_prefix(F, get_array_element_entity(tp),
774
				                           "    ");
Michael Beck's avatar
Michael Beck committed
775
776
777
778
779
780
781
			}
		}
		break;

	case tpo_pointer:
		if (verbosity & dump_verbosity_typeattrs) {
			ir_type *tt = get_pointer_points_to_type(tp);
782
			ir_fprintf(F, "\n  points to %+F\n", tt);
Michael Beck's avatar
Michael Beck committed
783
784
785
786
787
		}
		break;

	case tpo_method:
		if (verbosity & dump_verbosity_typeattrs) {
788
789
			mtp_additional_properties mtp = get_method_additional_properties(tp);
			unsigned cconv = get_method_calling_convention(tp);
Michael Beck's avatar
Michael Beck committed
790
			fprintf(F, "\n  variadicity: %s", get_variadicity_name(get_method_variadicity(tp)));
791
792
			fprintf(F, "\n  return types: %lu",
			        (unsigned long) get_method_n_ress(tp));
Michael Beck's avatar
Michael Beck committed
793
794
			for (i = 0; i < get_method_n_ress(tp); ++i) {
				ir_type *rtp = get_method_res_type(tp, i);
795
				ir_fprintf(F, "\n    %+F", rtp);
Michael Beck's avatar
Michael Beck committed
796
797
			}

798
799
			fprintf(F, "\n  parameter types: %lu",
			        (unsigned long) get_method_n_params(tp));
Michael Beck's avatar
Michael Beck committed
800
801
			for (i = 0; i < get_method_n_params(tp); ++i) {
				ir_type *ptp = get_method_param_type(tp, i);
802
				ir_fprintf(F, "\n    %+F", ptp);
Michael Beck's avatar
Michael Beck committed
803
			}
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
			fprintf(F, "\n  properties:");
			if (mtp & mtp_property_const)
				fputs(" const", F);
			if (mtp & mtp_property_pure)
				fputs(" pure", F);
			if (mtp & mtp_property_noreturn)
				fputs(" noreturn", F);
			if (mtp & mtp_property_nothrow)
				fputs(" nothrow", F);
			if (mtp & mtp_property_naked)
				fputs(" naked", F);
			if (mtp & mtp_property_malloc)
				fputs(" malloc", F);
			if (mtp & mtp_property_returns_twice)
				fputs(" returns_twice", F);
			if (mtp & mtp_property_intrinsic)
				fputs(" intrinsic", F);
			if (mtp & mtp_property_runtime)
				fputs(" runtime", F);
			if (mtp & mtp_property_private)
				fputs(" private", F);
			if (mtp & mtp_property_has_loop)
				fputs(" has_Loop", F);

			fprintf(F, "\n  calling convention:");
			if (cconv & cc_reg_param)
				fputs(" regparam", F);
			if (cconv & cc_last_on_top)
				fputs(" last_on_top", F);
			if (cconv & cc_callee_clear_stk)
				fputs(" calle_clear_stk", F);
			if (cconv & cc_this_call)
				fputs(" this_call", F);
			if (cconv & cc_compound_ret)
				fputs(" compound_ret", F);
			if (cconv & cc_frame_on_caller_stk)
				fputs(" frame_on_caller_stk", F);
			if (cconv & cc_fpreg_param)
				fputs(" fpreg_param", F);

Michael Beck's avatar
Michael Beck committed
844
845
846
847
848
849
850
851
			if (get_method_variadicity(tp)) {
				fprintf(F, "\n    ...");
			}
			fprintf(F, "\n");
		}
		break;

	case tpo_primitive:
852
853
854
		if (verbosity & dump_verbosity_typeattrs) {
			ir_type *base_tp = get_primitive_base_type(tp);
			if (base_tp != NULL)
855
				ir_fprintf(F, "\n  base type: %+F", tp);
856
857
858
859
			fprintf(F, "\n");
		}
		break;

Michael Beck's avatar
Michael Beck committed
860
861
862
863
864
865
866
867
868
869
870
871
	case tpo_none:
	case tpo_unknown:
		fprintf(F, "\n");
		break;

	default:
		if (verbosity & dump_verbosity_typeattrs) {
			fprintf(F, ": details not implemented\n");
		}
	}

	fprintf(F, "  state:      %s,\n", get_type_state_name(get_type_state(tp)));
872
873
	fprintf(F, "  size:       %2u Bytes,\n", get_type_size_bytes(tp));
	fprintf(F, "  alignment:  %2u Bytes,\n", get_type_alignment_bytes(tp));
Michael Beck's avatar
Michael Beck committed
874
875
876
877
	if (is_atomic_type(tp) || is_Method_type(tp))
		fprintf(F, "  mode:       %s,\n",  get_mode_name(get_type_mode(tp)));

	fprintf(F, "\n\n");
Götz Lindenmaier's avatar
Götz Lindenmaier committed
878
879
}

880
void dump_types_as_text(FILE *out)
881
{
882
	size_t i, n_types = get_irp_n_types();
883

Michael Beck's avatar
Michael Beck committed
884
	for (i = 0; i < n_types; ++i) {
885
886
		ir_type *type = get_irp_type(i);
		dump_type_to_file(out, type);
Michael Beck's avatar
Michael Beck committed
887
	}
Götz Lindenmaier's avatar
Götz Lindenmaier committed
888
}
Götz Lindenmaier's avatar
Götz Lindenmaier committed
889

890
void dump_globals_as_text(FILE *out)
891
{
892
	ir_type *global_type = get_glob_type();
893
894
	size_t   n_members   = get_class_n_members(global_type);
	size_t   i;
Michael Beck's avatar
Michael Beck committed
895

896
897
898
	for (i = 0; i < n_members; ++i) {
		ir_entity *entity = get_class_member(global_type, i);
		dump_entity_to_file(out, entity);
Michael Beck's avatar
Michael Beck committed
899
	}
Götz Lindenmaier's avatar
Götz Lindenmaier committed
900
}