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
26 * Something that can append strings and chars to something.
28 typedef struct _appender_t {
29 void (*append_char)(void *object, size_t n, char ch);
30 void (*append_str)(void *object, size_t n, const char *str);
34 * A callback function type to add something to an appender.
36 * @param app The appender.
37 * @param object The object for the appender.
38 * @param limit The limit for the appender.
39 * @param arg The thing to append.
41 typedef void (ir_printf_cb_t)(const appender_t *app, void *object, size_t limit, const void *arg);
44 * A string formatting routine for ir objects.
45 * This function rudimentarily implements a kind of printf(3) for ir
46 * nodes. Following conversion specifiers. No length, special or field
47 * width specifiers are accepted.
51 * - @%e An entity name.
52 * - @%E An entity ld_name.
53 * - @%n A full description of a node.
54 * - @%o The opcode name of an ir node.
55 * - @%m The mode name of an ir mode.
56 * - @%N The node number of an ir node.
57 * - @%b The block node number of the nodes block.
60 * Each of these can be prepended by a '+' which means, that the given
61 * pointer is a collection of items specified by the format. In this
62 * case you also have to pass an iterator interface to ir_printf()
63 * suitable for the instance of the collection. So, imagine you have a
64 * @c pset of ir_nodes and want to dump it, you write:
68 * ir_printf("Some nodes: %+n\n", it_pset, nodes);
70 * The @c it_pset is an iterator interface (of type
71 * @c iterator_t that allows the dumper to traverse the set.
73 * As special case when working with collections, you can also give a
74 * callback function which will be invoked on each element in the
75 * collection. It gets the appender (the thing where the textual
76 * representation of the element is written to) and its parameters
77 * passed by the dumping function. Suppose you have your own datatype
78 * @c xyz_t and want to dump a pset of it, you have:
80 * void xyz_dump(const appender_t *app, void *object, size_t limit,
83 * const xyz_t *xyz = arg;
84 * app->append_str(object, limit, xyz->name);
89 * ir_printf("A set of xyz\'s: %+C\n", it_pset, xyzs, xyz_dump);
92 * @param fmt The format string.
94 void ir_printf(const char *fmt, ...);
99 void ir_fprintf(FILE *f, const char *fmt, ...);
104 void ir_snprintf(char *buf, size_t n, const char *fmt, ...);
108 #define ir_debugf ir_printf
109 #define ir_fdebugf ir_fprintf
113 static INLINE void ir_debugf(const char *fmt, ...)
117 static INLINE void ir_fdebugf(FILE *, const char *fmt, ...)