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