updated docu
[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 "config.h"
24
25 /**
26  * Something that can append strings and chars to something.
27  */
28 typedef struct _appender_t {
29         void (*append_char)(void *object, size_t n, char ch);
30         void (*append_str)(void *object, size_t n, const char *str);
31 } appender_t;
32
33 /**
34  * A callback function type to add something to an appender.
35  *
36  * @param app    The appender.
37  * @param object The object for the appender.
38  * @param limit  The limit for the appender.
39  * @param arg    The thing to append.
40  */
41 typedef void (ir_printf_cb_t)(const appender_t *app, void *object, size_t limit, const void *arg);
42
43 /**
44  * A string formatting routine for ir objects.
45  * This function rudimentarily implements a kind of printf(3) for ir
46  * nodes. Following conversion specifiers. No length, special or field
47  * width specifiers are accepted.
48  * - @%p A pointer.
49  * - @%s A string.
50  * - @%I An ident.
51  * - @%e An entity name.
52  * - @%E An entity ld_name.
53  * - @%n A full description of a node.
54  * - @%o The opcode name of an ir node.
55  * - @%m The mode name of an ir mode.
56  * - @%N The node number of an ir node.
57  * - @%b The block node number of the nodes block.
58  * - @%t A tarval.
59  *
60  * Each of these can be prepended by a '+' which means, that the given
61  * pointer is a collection of items specified by the format. In this
62  * case you also have to pass an iterator interface to ir_printf()
63  * suitable for the instance of the collection. So, imagine you have a
64  * @c pset of ir_nodes and want to dump it, you write:
65  * @code
66  *   pset *nodes;
67  *   ...
68  *   ir_printf("Some nodes: %+n\n", it_pset, nodes);
69  * @endcode
70  * The @c it_pset is an iterator interface (of type
71  * @c iterator_t that allows the dumper to traverse the set.
72  *
73  * As special case when working with collections, you can also give a
74  * callback function which will be invoked on each element in the
75  * collection. It gets the appender (the thing where the textual
76  * representation of the element is written to) and its parameters
77  * passed by the dumping function. Suppose you have your own datatype
78  * @c xyz_t and want to dump a pset of it, you have:
79  * @code
80  *   void xyz_dump(const appender_t *app, void *object, size_t limit,
81  *       const void *arg)
82  *   {
83  *     const xyz_t *xyz = arg;
84  *     app->append_str(object, limit, xyz->name);
85  *   }
86  *   ...
87  *   pset *xyzs;
88  *
89  *   ir_printf("A set of xyz\'s: %+C\n", it_pset, xyzs, xyz_dump);
90  * @endcode
91  *
92  * @param fmt The format string.
93  */
94 void ir_printf(const char *fmt, ...);
95
96 /**
97  * @see irn_printf.
98  */
99 void ir_fprintf(FILE *f, const char *fmt, ...);
100
101 /**
102  * @see irn_printf.
103  */
104 void ir_snprintf(char *buf, size_t n, const char *fmt, ...);
105
106 #ifdef DEBUG_libfirm
107
108 #define ir_debugf ir_printf
109 #define ir_fdebugf ir_fprintf
110
111 #else
112
113 static INLINE void ir_debugf(const char *fmt, ...)
114 {
115 }
116
117 static INLINE void ir_fdebugf(FILE *, const char *fmt, ...)
118 {
119 }
120
121
122 #endif
123
124 #endif