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