irdumptxt.c 28.1 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
Matthias Braun's avatar
Matthias Braun committed
25
 * @version $Id$
Götz Lindenmaier's avatar
Götz Lindenmaier committed
26
 */
Michael Beck's avatar
Michael Beck committed
27
#include "config.h"
Götz Lindenmaier's avatar
Götz Lindenmaier committed
28
29
30
31

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

34
#include "irdump_t.h"
35
#include "irgraph_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
/* Write the irnode and all its attributes to the file passed. */
60
void dump_irnode_to_file(FILE *F, ir_node *n)
61
{
Michael Beck's avatar
Michael Beck committed
62
	char     comma;
Michael Beck's avatar
Michael Beck committed
63
64
65
66
67
68
	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));
69
	if (ir_get_dump_flags() & ir_dump_flag_analysed_types)
70
		fprintf (F, "  addr:    %p\n", (void *)n);
Michael Beck's avatar
Michael Beck committed
71
	fprintf (F, "  mode:    %s\n", get_mode_name(get_irn_mode(n)));
72
	fprintf (F, "  visited: %lu\n", get_irn_visited(n));
Michael Beck's avatar
Michael Beck committed
73
74
75
76
77
78
79
	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 ");
80
81
		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
82
83
	}

84
85
	fprintf(F, "  arity:   %d\n", get_irn_arity(n));
	/* show all predecessor nodes */
86
	fprintf(F, "  pred nodes:\n");
87
88
89
90
91
	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)));
	}
92
93
94
95
96
97
98
99

	{
		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)));
		}
100
	}
Michael Beck's avatar
Michael Beck committed
101
102
103

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

Michael Beck's avatar
Michael Beck committed
104
	if (is_Proj(n))
Michael Beck's avatar
Michael Beck committed
105
106
107
108
109
110
111
112
		fprintf(F, "  proj nr: %ld\n", get_Proj_proj(n));

	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. */
113
114
	if (is_Block(n) || get_irn_op(n) == op_Phi) {
	    int i;
Michael Beck's avatar
Michael Beck committed
115
116
117
118
119
120
121
122
		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 ... */
123
	if (is_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_LOOPINFO)) {
Michael Beck's avatar
Michael Beck committed
124
		ir_loop *loop = get_irn_loop(n);
125
		if (loop != NULL) {
Matthias Braun's avatar
Matthias Braun committed
126
127
			fprintf(F, "  in loop %ld with depth %u\n",
			        get_loop_loop_nr(loop), get_loop_depth(loop));
128
		}
Michael Beck's avatar
Michael Beck committed
129
130
131
132
133
	}

	/* Source types */
	switch (get_irn_opcode(n)) {
	case iro_Block: {
134
135
		if (has_Block_entity(n))
			fprintf(F, "  Label: %lu\n", get_entity_label(get_Block_entity(n)));
136
		fprintf(F, "  block visited: %lu\n", get_Block_block_visited(n));
Michael Beck's avatar
Michael Beck committed
137
		fprintf(F, "  block marked: %u\n", get_Block_mark(n));
138
		if (is_irg_state(get_irn_irg(n), IR_GRAPH_STATE_CONSISTENT_DOMINANCE)) {
Michael Beck's avatar
Michael Beck committed
139
			fprintf(F, "  dom depth %d\n", get_Block_dom_depth(n));
140
141
			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
142
		}
143
		if (is_irg_state(get_irn_irg(n), IR_GRAPH_STATE_CONSISTENT_POSTDOMINANCE)) {
144
			fprintf(F, "  pdom depth %d\n", get_Block_postdom_depth(n));
145
146
			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));
147
		}
Michael Beck's avatar
Michael Beck committed
148
149
150
151
152

		/* not dumped: graph_arr */
		/* not dumped: mature    */
	}  break;
	case iro_Start: {
153
		size_t   i;
Michael Beck's avatar
Michael Beck committed
154
		ir_type *tp = get_entity_type(get_irg_entity(get_irn_irg(n)));
155
		ir_fprintf(F, "  start of method of type %+F\n", tp);
Michael Beck's avatar
Michael Beck committed
156
		for (i = 0; i < get_method_n_params(tp); ++i)
157
			ir_fprintf(F, "    param %d type: %+F\n", i, get_method_param_type(tp, i));
Michael Beck's avatar
Michael Beck committed
158
159
	} break;
	case iro_Cond: {
160
		fprintf(F, "  default ProjNr: %ld\n", get_Cond_default_proj(n));
161
162
163
164
		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
165
166
	} break;
	case iro_Alloc: {
167
		ir_fprintf(F, "  allocating entity of type: %+F\n", get_Alloc_type(n));
Michael Beck's avatar
Michael Beck committed
168
169
170
		fprintf(F, "  allocating on: the %s\n", (get_Alloc_where(n) == stack_alloc) ? "stack" : "heap");
	} break;
	case iro_Free: {
171
		ir_fprintf(F, "  freeing entity of type %+F\n", get_Free_type(n));
Michael Beck's avatar
Michael Beck committed
172
173
174
175
176
177
		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));
178
179
			ir_fprintf(F, "    of type    %+F\n",  get_entity_type(ent));
			ir_fprintf(F, "    with owner %+F.\n", get_entity_owner(ent));
180
		} else {
Michael Beck's avatar
Michael Beck committed
181
182
183
184
185
			fprintf(F, "  <NULL entity>\n");
		}
	} break;
	case iro_Call: {
		ir_type *tp = get_Call_type(n);
186
187
		if (get_Call_tail_call(n))
			fprintf(F, "  tail call\n");
188
		ir_fprintf(F, "  calling method of type %+F\n", tp);
189
		if (get_unknown_type() != tp) {
190
			size_t i;
Michael Beck's avatar
Michael Beck committed
191
			for (i = 0; i < get_method_n_params(tp); ++i)
192
				ir_fprintf(F, "    param %d type: %+F\n", i, get_method_param_type(tp, i));
Michael Beck's avatar
Michael Beck committed
193
			for (i = 0; i < get_method_n_ress(tp); ++i)
194
				ir_fprintf(F, "    result %d type: %+F\n", i, get_method_res_type(tp, i));
Michael Beck's avatar
Michael Beck committed
195
196
		}
		if (Call_has_callees(n)) {
Matthias Braun's avatar
Matthias Braun committed
197
			size_t i;
198
			fprintf(F, "  possible callees:\n");
Michael Beck's avatar
Michael Beck committed
199
			for (i = 0; i < get_Call_n_callees(n); i++) {
Michael Beck's avatar
Michael Beck committed
200
				ir_fprintf(F, "    %zu: %s\n", i, get_ent_dump_name(get_Call_callee(n, i)));
Michael Beck's avatar
Michael Beck committed
201
202
203
204
			}
		}
	} break;
	case iro_Cast: {
205
		ir_fprintf(F, "  cast to type: %+F\n", get_Cast_type(n));
Michael Beck's avatar
Michael Beck committed
206
	} break;
207
208
209
210
	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
211
	case iro_Return: {
212
		size_t   i;
213
214
215
216
217
		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
218
219
220
		}
	} break;
	case iro_SymConst: {
221
		switch (get_SymConst_kind(n)) {
Michael Beck's avatar
Michael Beck committed
222
223
224
		case symconst_addr_ent:
			fprintf(F, "  kind:   addr_ent\n");
			fprintf(F, "  entity: ");
225
			dump_entity_to_file(F, get_SymConst_entity(n));
Michael Beck's avatar
Michael Beck committed
226
227
228
229
			break;
		case symconst_ofs_ent:
			fprintf(F, "  kind:   offset\n");
			fprintf(F, "  entity: ");
230
			dump_entity_to_file(F, get_SymConst_entity(n));
Michael Beck's avatar
Michael Beck committed
231
232
233
234
			break;
		case symconst_type_tag:
			fprintf(F, "  kind: type_tag\n");
			fprintf(F, "  type: ");
235
			dump_type_to_file(F, get_SymConst_type(n));
Michael Beck's avatar
Michael Beck committed
236
237
238
239
			break;
		case symconst_type_size:
			fprintf(F, "  kind: size\n");
			fprintf(F, "  type: ");
240
			dump_type_to_file(F, get_SymConst_type(n));
Michael Beck's avatar
Michael Beck committed
241
242
243
244
			break;
		case symconst_type_align:
			fprintf(F, "  kind: alignment\n");
			fprintf(F, "  type: ");
245
			dump_type_to_file(F, get_SymConst_type(n));
Michael Beck's avatar
Michael Beck committed
246
247
248
			break;
		case symconst_enum_const:
			fprintf(F, "  kind: enumeration\n");
249
			fprintf(F, "  name: %s\n", get_enumeration_const_name(get_SymConst_enum(n)));
Michael Beck's avatar
Michael Beck committed
250
251
252
253
			break;
		}
	} break;
	case iro_Load:
254
		fprintf(F, "  mode of loaded value: %s\n", get_mode_name_ex(get_Load_mode(n), NULL));
Michael Beck's avatar
Michael Beck committed
255
		fprintf(F, "  volatility: %s\n", get_volatility_name(get_Load_volatility(n)));
256
		fprintf(F, "  align: %s\n", get_align_name(get_Load_unaligned(n)));
Michael Beck's avatar
Michael Beck committed
257
258
259
		break;
	case iro_Store:
		fprintf(F, "  volatility: %s\n", get_volatility_name(get_Store_volatility(n)));
260
		fprintf(F, "  align: %s\n", get_align_name(get_Store_unaligned(n)));
Michael Beck's avatar
Michael Beck committed
261
262
		break;
	case iro_Confirm:
263
		fprintf(F, "  compare operation: %s\n", get_relation_string(get_Confirm_relation(n)));
Michael Beck's avatar
Michael Beck committed
264
265
266
267
268
269
		break;
	case iro_ASM: {
		const ir_asm_constraint *cons;
		ident **clobber;
		int l;

Matthias Braun's avatar
Matthias Braun committed
270
		fprintf(F, "  assembler text: %s", get_id_str(get_ASM_text(n)));
Michael Beck's avatar
Michael Beck committed
271
272
		l = get_ASM_n_input_constraints(n);
		if (l > 0) {
273
			int i;
Michael Beck's avatar
Michael Beck committed
274
275
276
277
278
279
280
			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) {
281
			int i;
Michael Beck's avatar
Michael Beck committed
282
283
284
285
286
287
288
			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) {
289
			int i;
Michael Beck's avatar
Michael Beck committed
290
291
292
293
294
295
296
297
298
			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
299
300
301

	default:
		break;
Michael Beck's avatar
Michael Beck committed
302
303
304
305
306
	}

	if (get_irg_typeinfo_state(get_irn_irg(n)) == ir_typeinfo_consistent  ||
		get_irg_typeinfo_state(get_irn_irg(n)) == ir_typeinfo_inconsistent  )
		if (get_irn_typeinfo_type(n) != firm_none_type)
307
			ir_fprintf (F, "  Analysed type: %s\n", get_irn_typeinfo_type(n));
308
309
}

310
void dump_graph_as_text(FILE *out, ir_graph *irg)
311
{
312
	fprintf(out, "graph %s\n", get_irg_dump_name(irg));
313
314
}

315
316
static int need_nl = 1;

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
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);
		ir_tarval*              const tv  = get_initializer_tarval_value(val);
		long                          v;

		if (!tarval_is_constant(tv))
			return false;

		v = get_tarval_long(tv);
		if (v != 0 && v != 0x09 && v != 0x0A && v != 0x0C && v != 0x0D && v != 0x1B && (v < 0x20 || 0x80 <= v) && (v < 0xA0 || 0x100 <= v))
			return false;
	}

	return true;
}

348
349
350
351
/**
 * Dump initializers.
 */
static void dump_ir_initializers_to_file(FILE *F, const char *prefix,
352
353
                                         const ir_initializer_t *initializer,
                                         ir_type *type)
354
{
Matthias Braun's avatar
Matthias Braun committed
355
356
	ir_tarval *tv;
	ir_node   *value;
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371

	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);
372
		ir_fprintf(F, "\t = %F", value);
373
374
375
		break;
	case IR_INITIALIZER_COMPOUND:
		if (is_Array_type(type)) {
376
377
378
379
380
381
382
383
384
385
386
			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) {
387
388
389
390
391
392
393
394
						case 0x00: fprintf(F, "\\\\000");  break;
						case 0x09: fprintf(F, "\\\\t");    break;
						case 0x0A: fprintf(F, "\\\\n");    break;
						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;
395
396
397
398
399
400
401
402
403
404
						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);
405

406
407
408
409
410
411
					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);
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
				}
			}
		} 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
442
443
444
445
static void dump_entity_linkage(FILE *F, const ir_entity *entity)
{
	ir_linkage linkage = get_entity_linkage(entity);

446
447
448
449
	if (linkage == IR_LINKAGE_DEFAULT) {
		fprintf(F, " default");
		return;
	}
Matthias Braun's avatar
Matthias Braun committed
450
451
452
453
454
455
456
457
458
459
460
	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");
}
461

462
static void dump_entity_to_file_prefix(FILE *F, ir_entity *ent, const char *prefix)
463
{
Michael Beck's avatar
Michael Beck committed
464
465
466
467
468
469
	ir_type *owner, *type;

	assert(is_entity(ent));
	owner = get_entity_owner(ent);
	type  = get_entity_type(ent);
	if (verbosity & dump_verbosity_onlynames) {
470
		fprintf(F, "%sentity %s.%s (%ld)\n", prefix, get_compound_name(get_entity_owner(ent)),
Michael Beck's avatar
Michael Beck committed
471
472
473
474
475
476
			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));
477
478
		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
479
480
481

		if (is_Class_type(get_entity_owner(ent))) {
			if (get_entity_n_overwrites(ent) > 0) {
482
				size_t i;
Michael Beck's avatar
Michael Beck committed
483
484
485
				fprintf(F, "%s  overwrites:\n", prefix);
				for (i = 0; i < get_entity_n_overwrites(ent); ++i) {
					ir_entity *ov = get_entity_overwrites(ent, i);
486
487
					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
488
489
				}
			} else {
490
				fprintf(F, "%s  Does not overwrite other entities.\n", prefix);
Michael Beck's avatar
Michael Beck committed
491
492
			}
			if (get_entity_n_overwrittenby(ent) > 0) {
493
				size_t i;
Michael Beck's avatar
Michael Beck committed
494
495
496
				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);
497
498
					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
499
500
				}
			} else {
501
502
				fprintf(F, "%s  Is not overwritten by other entities.\n",
				        prefix);
Michael Beck's avatar
Michael Beck committed
503
504
505
506
507
508
509
510
			}

			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)) {
511
512
					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
513
514
515
516
517
				}
				fprintf(F, "%s  transitive overwritten by:\n", prefix);
				for (ov = get_entity_trans_overwrittenby_first(ent);
				ov;
				ov = get_entity_trans_overwrittenby_next(ent)) {
518
519
					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
520
521
522
523
524
525
526
527
528
529
				}
			}
		}

		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) {
530
531
				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
532
533
534
			}

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

537
538
539
540
541
542
543
544
545
546
547
				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);
548
				fputc('\n', F);
Michael Beck's avatar
Michael Beck committed
549
			}
550
			fprintf(F, "%s  calling convention: ", prefix);
551
552
553
554
			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);
555
			cc &= ~(cc_compound_ret|cc_frame_on_caller_stk);
Michael Beck's avatar
Michael Beck committed
556
			if (IS_CDECL(cc))
557
				fputs("cdecl", F);
Michael Beck's avatar
Michael Beck committed
558
			else if (IS_STDCALL(cc))
559
				fputs("stdcall", F);
Michael Beck's avatar
Michael Beck committed
560
			else {
561
562
				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
563
			}
564
			fprintf(F, "\n%s  vtable number:        %u\n", prefix, get_entity_vtable_number(ent));
Michael Beck's avatar
Michael Beck committed
565
566
		}
	} else {  /* no entattrs */
567
		ir_fprintf(F, "%s(%3d:%d) %+F: %s", prefix,
Michael Beck's avatar
Michael Beck committed
568
			get_entity_offset(ent), get_entity_offset_bits_remainder(ent),
569
			get_entity_type(ent), get_entity_name(ent));
570
		if (is_Method_type(get_entity_type(ent))) fputs("(...)", F);
Michael Beck's avatar
Michael Beck committed
571
572

		if (verbosity & dump_verbosity_accessStats) {
Matthias Braun's avatar
Matthias Braun committed
573
			dump_entity_linkage(F, ent);
Michael Beck's avatar
Michael Beck committed
574
		}
575
		fputc('\n', F);
Michael Beck's avatar
Michael Beck committed
576
577
578
	}

	if (verbosity & dump_verbosity_entconsts) {
Matthias Braun's avatar
Matthias Braun committed
579
580
581
582
583
		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));
584
			fputc('\n', F);
Matthias Braun's avatar
Matthias Braun committed
585
		} else if (entity_has_compound_ent_values(ent)) {
Matthias Braun's avatar
Matthias Braun committed
586
			size_t i;
Matthias Braun's avatar
Matthias Braun committed
587
588
			fprintf(F, "%s  compound values:", prefix);
			for (i = 0; i < get_compound_ent_n_values(ent); ++i) {
Matthias Braun's avatar
Matthias Braun committed
589
				size_t j;
Matthias Braun's avatar
Matthias Braun committed
590
591
				compound_graph_path *path = get_compound_ent_value_path(ent, i);
				ir_entity *ent0 = get_compound_graph_path_node(path, 0);
592
				fprintf(F, "\n%s    %3d:%d ", prefix, get_entity_offset(ent0), get_entity_offset_bits_remainder(ent0));
Matthias Braun's avatar
Matthias Braun committed
593
594
595
596
597
598
599
				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
600
						fprintf(F, "[%ld]", get_compound_graph_path_array_index(path, j));
Michael Beck's avatar
Michael Beck committed
601
				}
Matthias Braun's avatar
Matthias Braun committed
602
603
				fprintf(F, "\t = ");
				dump_node_opcode(F, get_compound_ent_value(ent, i));
Michael Beck's avatar
Michael Beck committed
604
			}
605
			fputc('\n', F);
Michael Beck's avatar
Michael Beck committed
606
607
608
609
		}
	}

	if (verbosity & dump_verbosity_entattrs) {
Matthias Braun's avatar
Matthias Braun committed
610
611
		fprintf(F, "%s  linkage:", prefix);
		dump_entity_linkage(F, ent);
612
		fprintf(F, "\n%s  volatility:  %s", prefix, get_volatility_name(get_entity_volatility(ent)));
Matthias Braun's avatar
Matthias Braun committed
613
614
		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
615
616
617
618
619
620
621
622
623
		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);
			}
		}
624
		fputc('\n', F);
Michael Beck's avatar
Michael Beck committed
625
	}
Götz Lindenmaier's avatar
Götz Lindenmaier committed
626
627
}

628
void dump_entity_to_file(FILE *out, ir_entity *ent)
629
{
630
631
	dump_entity_to_file_prefix(out, ent, "");
	fprintf(out, "\n");
Götz Lindenmaier's avatar
Götz Lindenmaier committed
632
633
}

634
void dump_type_to_file(FILE *F, ir_type *tp)
635
{
636
	size_t i;
Michael Beck's avatar
Michael Beck committed
637
638
639
640
641
642
643
644
645
646

	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;

647
	ir_fprintf(F, "%+F", tp);
Michael Beck's avatar
Michael Beck committed
648
649
650
651
652
653
	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)) {
654
			fprintf(F, "\n  members:\n");
Michael Beck's avatar
Michael Beck committed
655
656
657
658
659
		}
		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
660
				if (!(verbosity & dump_verbosity_nostatic)) {
661
					dump_entity_to_file_prefix(F, mem, "    ");
Michael Beck's avatar
Michael Beck committed
662
663
664
665
666
667
668
				}
			}
		}
		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);
669
				ir_fprintf(F, "\n    %d %+F", i, stp);
Michael Beck's avatar
Michael Beck committed
670
671
672
673
			}
			fprintf(F, "\n  subtypes: ");
			for (i = 0; i < get_class_n_subtypes(tp); ++i) {
				ir_type *stp = get_class_subtype(tp, i);
674
				ir_fprintf(F, "\n    %d %+F", i, stp);
Michael Beck's avatar
Michael Beck committed
675
676
677
678
679
680
681
682
			}

			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)) {
683
					ir_fprintf(F, "\n    %+F", stp);
Michael Beck's avatar
Michael Beck committed
684
685
686
687
688
				}
				fprintf(F, "\n  transitive subtypes: ");
				for (stp = get_class_trans_subtype_first(tp);
				stp;
				stp = get_class_trans_subtype_next(tp)) {
689
					ir_fprintf(F, "\n    %+F", stp);
Michael Beck's avatar
Michael Beck committed
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
				}
			}

			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) {
710
				dump_entity_to_file_prefix(F, mem, "    ");
Michael Beck's avatar
Michael Beck committed
711
712
713
714
715
716
			}
		}
		break;

	case tpo_array:
		if (verbosity & dump_verbosity_typeattrs) {
717
			size_t n_dim;
Michael Beck's avatar
Michael Beck committed
718
719
720
721
722
723
724
725
726
727
728
729
730
			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, "[");

731
				if (is_Const(lower)) {
Michael Beck's avatar
Michael Beck committed
732
					fprintf(F, "%ld .. ", get_tarval_long(get_Const_tarval(lower)));
733
				} else {
Michael Beck's avatar
Michael Beck committed
734
735
736
737
					dump_node_opcode(F, lower);
					fprintf(F, " %ld .. ", get_irn_node_nr(lower));
				}

738
				if (is_Const(upper)) {
Michael Beck's avatar
Michael Beck committed
739
					fprintf(F, "%ld]", get_tarval_long(get_Const_tarval(lower)));
740
				} else {
Michael Beck's avatar
Michael Beck committed
741
742
743
744
					dump_node_opcode(F, upper);
					fprintf(F, " %ld]", get_irn_node_nr(upper));
				}
			}
745
			ir_fprintf(F, " of <%+F>", elem_tp);
Michael Beck's avatar
Michael Beck committed
746
747
748

			fprintf(F, "\n  order: ");
			for (i = 0; i < n_dim; ++i)
749
				fprintf(F, "<%zu>", get_array_order(tp, i));
Michael Beck's avatar
Michael Beck committed
750
751
752
753
754

			fprintf(F, "\n");

			if (verbosity & dump_verbosity_fields) {
				dump_entity_to_file_prefix(F, get_array_element_entity(tp),
755
				                           "    ");
Michael Beck's avatar
Michael Beck committed
756
757
758
759
760
761
762
			}
		}
		break;

	case tpo_pointer:
		if (verbosity & dump_verbosity_typeattrs) {
			ir_type *tt = get_pointer_points_to_type(tp);
763
			ir_fprintf(F, "\n  points to %+F\n", tt);
Michael Beck's avatar
Michael Beck committed
764
765
766
767
768
		}
		break;

	case tpo_method:
		if (verbosity & dump_verbosity_typeattrs) {
769
770
			mtp_additional_properties mtp = get_method_additional_properties(tp);
			unsigned cconv = get_method_calling_convention(tp);
Michael Beck's avatar
Michael Beck committed
771
			fprintf(F, "\n  variadicity: %s", get_variadicity_name(get_method_variadicity(tp)));
772
773
			fprintf(F, "\n  return types: %lu",
			        (unsigned long) get_method_n_ress(tp));
Michael Beck's avatar
Michael Beck committed
774
775
			for (i = 0; i < get_method_n_ress(tp); ++i) {
				ir_type *rtp = get_method_res_type(tp, i);
776
				ir_fprintf(F, "\n    %+F", rtp);
Michael Beck's avatar
Michael Beck committed
777
778
			}

779
780
			fprintf(F, "\n  parameter types: %lu",
			        (unsigned long) get_method_n_params(tp));
Michael Beck's avatar
Michael Beck committed
781
782
			for (i = 0; i < get_method_n_params(tp); ++i) {
				ir_type *ptp = get_method_param_type(tp, i);
783
				ir_fprintf(F, "\n    %+F", ptp);
Michael Beck's avatar
Michael Beck committed
784
			}
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
			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
825
826
827
828
829
830
831
832
			if (get_method_variadicity(tp)) {
				fprintf(F, "\n    ...");
			}
			fprintf(F, "\n");
		}
		break;

	case tpo_primitive:
833
834
835
		if (verbosity & dump_verbosity_typeattrs) {
			ir_type *base_tp = get_primitive_base_type(tp);
			if (base_tp != NULL)
836
				ir_fprintf(F, "\n  base type: %+F", tp);
837
838
839
840
			fprintf(F, "\n");
		}
		break;

Michael Beck's avatar
Michael Beck committed
841
842
843
844
845
846
847
848
849
850
851
852
	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)));
853
854
	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
855
856
857
858
	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
859
860
}

861
void dump_types_as_text(FILE *out)
862
{
863
	size_t i, n_types = get_irp_n_types();
864

Michael Beck's avatar
Michael Beck committed
865
	for (i = 0; i < n_types; ++i) {
866
867
		ir_type *type = get_irp_type(i);
		dump_type_to_file(out, type);
Michael Beck's avatar
Michael Beck committed
868
	}
Götz Lindenmaier's avatar
Götz Lindenmaier committed
869
}
Götz Lindenmaier's avatar
Götz Lindenmaier committed
870

871
void dump_globals_as_text(FILE *out)
872
{
873
	ir_type *global_type = get_glob_type();
874
875
	size_t   n_members   = get_class_n_members(global_type);
	size_t   i;
Michael Beck's avatar
Michael Beck committed
876

877
878
879
	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
880
	}
Götz Lindenmaier's avatar
Götz Lindenmaier committed
881
}