2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief A little printf understanding some firm types.
23 * @author Sebastian Hack
27 #ifndef FIRM_IR_IRPRINTF_H
28 #define FIRM_IR_IRPRINTF_H
30 #include "firm_config.h"
36 /* forward definition */
40 * Something that can append strings and chars to something.
42 typedef struct _appender_t {
43 void (*init)(void *object, size_t n);
44 void (*append_char)(void *object, size_t n, char ch);
45 void (*append_str)(void *object, size_t n, const char *str);
49 * A callback function type to add something to an appender.
51 * @param app The appender.
52 * @param object The object for the appender.
53 * @param limit The limit for the appender.
54 * @param arg The thing to append.
56 typedef void (ir_printf_cb_t)(const appender_t *app, void *object, size_t limit, const void *arg);
59 * A string formatting routine for ir objects.
61 * @param fmt The format string.
63 * This function rudimentary implements a kind of printf(3) for ir
64 * nodes. Following conversion specifiers. No length, special or field
65 * width specifiers are accepted.
66 * - @%% Print a '%' character.
67 * - @%> Print as many white spaces as given in the parameter.
68 * - @%c Print a character
71 * - @%d A decimal integer.
72 * - @%x A hexadecimal integer.
73 * - @%o An octal integer.
76 * - @%e An entity name.
77 * - @%E An entity ld name.
79 * - @%n A full description of a node.
80 * - @%O The opcode name of an ir node.
81 * - @%N The node number of an ir node.
82 * - @%m The mode name of an ir mode.
83 * - @%B The block node number of the nodes block.
86 * - @%G A debug info (if available)
87 * - @%P A compound graph path
89 * Each of these can be prepend by a '+' which means, that the given
90 * pointer is a collection of items specified by the format. In this
91 * case you also have to pass an iterator interface to ir_printf()
92 * suitable for the instance of the collection. So, imagine you have a
93 * @c pset of ir_nodes and want to dump it, you write:
97 * ir_printf("Some nodes: %*n\n", it_pset, nodes);
99 * The @c it_pset is an iterator interface (of type
100 * @c iterator_t that allows the dumper to traverse the set.
102 * As special case when working with collections, you can also give a
103 * callback function which will be invoked on each element in the
104 * collection. It gets the appender (the thing where the textual
105 * representation of the element is written to) and its parameters
106 * passed by the dumping function. Suppose you have your own data type
107 * @c xyz_t and want to dump a pset of it, you have:
109 * void xyz_dump(const appender_t *app, void *object, size_t limit,
112 * const xyz_t *xyz = arg;
113 * app->append_str(object, limit, xyz->name);
118 * ir_printf("A set of xyz\'s: %*C\n", it_pset, xyzs, xyz_dump);
121 void ir_printf(const char *fmt, ...);
126 void ir_fprintf(FILE *f, const char *fmt, ...);
131 void ir_snprintf(char *buf, size_t n, const char *fmt, ...);
136 void ir_vprintf(const char *fmt, va_list args);
141 void ir_vfprintf(FILE *f, const char *fmt, va_list args);
146 void ir_vsnprintf(char *buf, size_t len, const char *fmt, va_list args);
151 void ir_obst_vprintf(struct obstack *obst, const char *fmt, va_list args);