irprintf.h 3.12 KB
Newer Older
Michael Beck's avatar
Michael Beck committed
1
2
3
4
5
6
7
8
9
10
11
/*
 * Project:     libFIRM
 * File name:   ir/ir/irprintf.h
 * Purpose:     A little printf understanding some firm types.
 * Author:      Sebastian Hack
 * Created:     29.11.2004
 * CVS-ID:      $Id$
 * Copyright:   (c) 1998-2004 Universität Karlsruhe
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */

12
/**
Michael Beck's avatar
Michael Beck committed
13
14
 * @file irprintf.h
 *
15
16
17
18
19
20
21
22
 * A little printf understanding some firm types.
 * @author Sebastian Hack
 * @date 29.11.2004
 */

#ifndef _IRPRINTF_H
#define _IRPRINTF_H

Sebastian Hack's avatar
Sebastian Hack committed
23
24
25
#include <stddef.h>
#include <stdio.h>

26
27
28
29
30
31
32
33
34
35
/**
 * Something that can append strings and chars to something.
 */
typedef struct _appender_t {
	void (*append_char)(void *object, size_t n, char ch);
	void (*append_str)(void *object, size_t n, const char *str);
} appender_t;

/**
 * A callback function type to add something to an appender.
Michael Beck's avatar
Michael Beck committed
36
37
 *
 * @param app    The appender.
38
 * @param object The object for the appender.
Michael Beck's avatar
Michael Beck committed
39
40
 * @param limit  The limit for the appender.
 * @param arg    The thing to append.
41
42
43
 */
typedef void (ir_printf_cb_t)(const appender_t *app, void *object, size_t limit, const void *arg);

44
/**
Michael Beck's avatar
Michael Beck committed
45
 * A string formatting routine for ir objects.
46
47
48
 * This function rudimentarily implements a kind of printf(3) for ir
 * nodes. Following conversion specifiers. No length, special or field
 * width specifiers are accepted.
Michael Beck's avatar
Michael Beck committed
49
50
51
52
53
54
 * - @%p A pointer.
 * - @%s A string.
 * - @%I An ident.
 * - @%e An entity name.
 * - @%E An entity ld_name.
 * - @%n A full description of a node.
55
 * - @%O The opcode name of an ir node.
Michael Beck's avatar
Michael Beck committed
56
57
 * - @%m The mode name of an ir mode.
 * - @%N The node number of an ir node.
58
59
 * - @%B The block node number of the nodes block.
 * - @%b A bitset.
Michael Beck's avatar
Michael Beck committed
60
 * - @%t A tarval.
61
 *
62
63
 * Each of these can be prepended by a '+' which means, that the given
 * pointer is a collection of items specified by the format. In this
Michael Beck's avatar
Michael Beck committed
64
 * case you also have to pass an iterator interface to ir_printf()
65
 * suitable for the instance of the collection. So, imagine you have a
Michael Beck's avatar
Michael Beck committed
66
67
 * @c pset of ir_nodes and want to dump it, you write:
 * @code
68
69
70
 *   pset *nodes;
 *   ...
 *   ir_printf("Some nodes: %+n\n", it_pset, nodes);
Michael Beck's avatar
Michael Beck committed
71
72
73
 * @endcode
 * The @c it_pset is an iterator interface (of type
 * @c iterator_t that allows the dumper to traverse the set.
74
75
76
77
78
79
 *
 * As special case when working with collections, you can also give a
 * callback function which will be invoked on each element in the
 * collection. It gets the appender (the thing where the textual
 * representation of the element is written to) and its parameters
 * passed by the dumping function. Suppose you have your own datatype
Michael Beck's avatar
Michael Beck committed
80
81
 * @c xyz_t and want to dump a pset of it, you have:
 * @code
82
83
84
85
86
87
88
89
90
91
 *   void xyz_dump(const appender_t *app, void *object, size_t limit,
 *       const void *arg)
 *   {
 *     const xyz_t *xyz = arg;
 *     app->append_str(object, limit, xyz->name);
 *   }
 *   ...
 *   pset *xyzs;
 *
 *   ir_printf("A set of xyz\'s: %+C\n", it_pset, xyzs, xyz_dump);
Michael Beck's avatar
Michael Beck committed
92
 * @endcode
93
 *
94
95
96
97
98
99
100
101
102
103
104
105
106
107
 * @param fmt The format string.
 */
void ir_printf(const char *fmt, ...);

/**
 * @see irn_printf.
 */
void ir_fprintf(FILE *f, const char *fmt, ...);

/**
 * @see irn_printf.
 */
void ir_snprintf(char *buf, size_t n, const char *fmt, ...);

108

109
#endif