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