3 * File name: ir/ir/irprintf.h
4 * Purpose: A little printf understanding some firm types.
5 * Author: Sebastian Hack
8 * Copyright: (c) 1998-2004 Universität Karlsruhe
9 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
15 * A little printf understanding some firm types.
16 * @author Sebastian Hack
24 * Something that can append strings and chars to something.
26 typedef struct _appender_t {
27 void (*append_char)(void *object, size_t n, char ch);
28 void (*append_str)(void *object, size_t n, const char *str);
32 * A callback function type to add something to an appender.
34 * @param app The appender.
35 * @param object The object for the appender.
36 * @param limit The limit for the appender.
37 * @param arg The thing to append.
39 typedef void (ir_printf_cb_t)(const appender_t *app, void *object, size_t limit, const void *arg);
42 * A string formatting routine for ir objects.
43 * This function rudimentarily implements a kind of printf(3) for ir
44 * nodes. Following conversion specifiers. No length, special or field
45 * width specifiers are accepted.
49 * - @%e An entity name.
50 * - @%E An entity ld_name.
51 * - @%n A full description of a node.
52 * - @%o The opcode name of an ir node.
53 * - @%m The mode name of an ir mode.
54 * - @%N The node number of an ir node.
55 * - @%b The block node number of the nodes block.
58 * Each of these can be prepended by a '+' which means, that the given
59 * pointer is a collection of items specified by the format. In this
60 * case you also have to pass an iterator interface to ir_printf()
61 * suitable for the instance of the collection. So, imagine you have a
62 * @c pset of ir_nodes and want to dump it, you write:
66 * ir_printf("Some nodes: %+n\n", it_pset, nodes);
68 * The @c it_pset is an iterator interface (of type
69 * @c iterator_t that allows the dumper to traverse the set.
71 * As special case when working with collections, you can also give a
72 * callback function which will be invoked on each element in the
73 * collection. It gets the appender (the thing where the textual
74 * representation of the element is written to) and its parameters
75 * passed by the dumping function. Suppose you have your own datatype
76 * @c xyz_t and want to dump a pset of it, you have:
78 * void xyz_dump(const appender_t *app, void *object, size_t limit,
81 * const xyz_t *xyz = arg;
82 * app->append_str(object, limit, xyz->name);
87 * ir_printf("A set of xyz\'s: %+C\n", it_pset, xyzs, xyz_dump);
90 * @param fmt The format string.
92 void ir_printf(const char *fmt, ...);
97 void ir_fprintf(FILE *f, const char *fmt, ...);
102 void ir_snprintf(char *buf, size_t n, const char *fmt, ...);
106 #define ir_debugf(p) ir_printf p
107 #define ir_fdebugf(p) ir_fprintf p
112 #define ir_fdebugf(p)