- remove some now unnecessary firm_config.h
[libfirm] / include / libfirm / irprintf.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief    A little printf understanding some firm types.
23  * @author   Sebastian Hack
24  * @date     29.11.2004
25  * @version  $Id$
26  */
27 #ifndef FIRM_IR_IRPRINTF_H
28 #define FIRM_IR_IRPRINTF_H
29
30 #include <stddef.h>
31 #include <stdarg.h>
32 #include <stdio.h>
33
34 /* forward definition */
35 struct obstack;
36
37 /**
38  * Something that can append strings and chars to something.
39  */
40 typedef struct _appender_t {
41         void (*init)(void *object, size_t n);
42         void (*append_char)(void *object, size_t n, char ch);
43         void (*append_str)(void *object, size_t n, const char *str);
44 } appender_t;
45
46 /**
47  * A callback function type to add something to an appender.
48  *
49  * @param app    The appender.
50  * @param object The object for the appender.
51  * @param limit  The limit for the appender.
52  * @param arg    The thing to append.
53  */
54 typedef void (ir_printf_cb_t)(const appender_t *app, void *object, size_t limit, const void *arg);
55
56 /**
57  * A string formatting routine for ir objects.
58  *
59  * @param fmt  The format string.
60  *
61  * This function rudimentary implements a kind of printf(3) for ir
62  * nodes. Following conversion specifiers. No length, special or field
63  * width specifiers are accepted.
64  * - @%% Print a '%' character.
65  * - @%> Print as many white spaces as given in the parameter.
66  * - @%c Print a character
67  * - @%s A string.
68  * - @%p A pointer.
69  * - @%d A decimal integer.
70  * - @%x A hexadecimal integer.
71  * - @%o An octal integer.
72  * - @%I An ident.
73  * - @%t A type name.
74  * - @%e An entity name.
75  * - @%E An entity ld name.
76  * - @%T A tarval.
77  * - @%n A full description of a node.
78  * - @%O The opcode name of an ir node.
79  * - @%N The node number of an ir node.
80  * - @%m The mode name of an ir mode.
81  * - @%B The block node number of the nodes block.
82  * - @%b A bitset.
83  * - @%= A pnc value
84  * - @%G A debug info (if available)
85  * - @%P A compound graph path
86  *
87  * Each of these can be prepend by a '+' which means, that the given
88  * pointer is a collection of items specified by the format. In this
89  * case you also have to pass an iterator interface to ir_printf()
90  * suitable for the instance of the collection. So, imagine you have a
91  * @c pset of ir_nodes and want to dump it, you write:
92  * @code
93  *   pset *nodes;
94  *   ...
95  *   ir_printf("Some nodes: %*n\n", it_pset, nodes);
96  * @endcode
97  * The @c it_pset is an iterator interface (of type
98  * @c iterator_t that allows the dumper to traverse the set.
99  *
100  * As special case when working with collections, you can also give a
101  * callback function which will be invoked on each element in the
102  * collection. It gets the appender (the thing where the textual
103  * representation of the element is written to) and its parameters
104  * passed by the dumping function. Suppose you have your own data type
105  * @c xyz_t and want to dump a pset of it, you have:
106  * @code
107  *   void xyz_dump(const appender_t *app, void *object, size_t limit,
108  *       const void *arg)
109  *   {
110  *     const xyz_t *xyz = arg;
111  *     app->append_str(object, limit, xyz->name);
112  *   }
113  *   ...
114  *   pset *xyzs;
115  *
116  *   ir_printf("A set of xyz\'s: %*C\n", it_pset, xyzs, xyz_dump);
117  * @endcode
118  */
119 void ir_printf(const char *fmt, ...);
120
121 /**
122  * @see irn_printf.
123  */
124 void ir_fprintf(FILE *f, const char *fmt, ...);
125
126 /**
127  * @see irn_printf.
128  */
129 void ir_snprintf(char *buf, size_t n, const char *fmt, ...);
130
131 /**
132  * @see irn_printf.
133  */
134 void ir_vprintf(const char *fmt, va_list args);
135
136 /**
137  * @see irn_printf.
138  */
139 void ir_vfprintf(FILE *f, const char *fmt, va_list args);
140
141 /**
142  * @see irn_printf.
143  */
144 void ir_vsnprintf(char *buf, size_t len, const char *fmt, va_list args);
145
146 /**
147  * @see irn_printf.
148  */
149 void ir_obst_vprintf(struct obstack *obst, const char *fmt, va_list args);
150
151 #endif