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
19 #ifndef _FIRM_IR_IRPRINTF_H_
20 #define _FIRM_IR_IRPRINTF_H_
22 #include "firm_config.h"
28 /* forward definition */
32 * Something that can append strings and chars to something.
34 typedef struct _appender_t {
35 void (*init)(void *object, size_t n);
36 void (*append_char)(void *object, size_t n, char ch);
37 void (*append_str)(void *object, size_t n, const char *str);
41 * A callback function type to add something to an appender.
43 * @param app The appender.
44 * @param object The object for the appender.
45 * @param limit The limit for the appender.
46 * @param arg The thing to append.
48 typedef void (ir_printf_cb_t)(const appender_t *app, void *object, size_t limit, const void *arg);
51 * A string formatting routine for ir objects.
53 * @param fmt The format string.
55 * This function rudimentary implements a kind of printf(3) for ir
56 * nodes. Following conversion specifiers. No length, special or field
57 * width specifiers are accepted.
58 * - @%% Print a '%' character.
59 * - @%> Print as many white spaces as given in the parameter.
60 * - @%c Print a character
63 * - @%d A decimal integer.
64 * - @%x A hexadecimal integer.
65 * - @%o An octal integer.
68 * - @%e An entity name.
69 * - @%E An entity ld name.
71 * - @%n A full description of a node.
72 * - @%O The opcode name of an ir node.
73 * - @%N The node number of an ir node.
74 * - @%m The mode name of an ir mode.
75 * - @%B The block node number of the nodes block.
78 * - @%G A debug info (if available)
79 * - @%P A compound graph path
81 * Each of these can be prepend by a '+' which means, that the given
82 * pointer is a collection of items specified by the format. In this
83 * case you also have to pass an iterator interface to ir_printf()
84 * suitable for the instance of the collection. So, imagine you have a
85 * @c pset of ir_nodes and want to dump it, you write:
89 * ir_printf("Some nodes: %*n\n", it_pset, nodes);
91 * The @c it_pset is an iterator interface (of type
92 * @c iterator_t that allows the dumper to traverse the set.
94 * As special case when working with collections, you can also give a
95 * callback function which will be invoked on each element in the
96 * collection. It gets the appender (the thing where the textual
97 * representation of the element is written to) and its parameters
98 * passed by the dumping function. Suppose you have your own data type
99 * @c xyz_t and want to dump a pset of it, you have:
101 * void xyz_dump(const appender_t *app, void *object, size_t limit,
104 * const xyz_t *xyz = arg;
105 * app->append_str(object, limit, xyz->name);
110 * ir_printf("A set of xyz\'s: %*C\n", it_pset, xyzs, xyz_dump);
113 void ir_printf(const char *fmt, ...);
118 void ir_fprintf(FILE *f, const char *fmt, ...);
123 void ir_snprintf(char *buf, size_t n, const char *fmt, ...);
128 void ir_vprintf(const char *fmt, va_list args);
133 void ir_vfprintf(FILE *f, const char *fmt, va_list args);
138 void ir_vsnprintf(char *buf, size_t len, const char *fmt, va_list args);
143 void ir_obst_vprintf(struct obstack *obst, const char *fmt, va_list args);
146 #include <libcore/lc_printf.h>
147 #endif /* WITH_LIBCORE */
149 #endif /* _FIRM_IR_IRPRINTF_H_ */