- get_Block_cfgpred_arr() IS supported, but should not be in the official
[libfirm] / ir / ir / irprintf.c
1 /*
2  * Copyright (C) 1995-2008 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  * @file
22  * @brief   A little printf helper unterstanding firm types
23  * @author  Sebastian Hack
24  * @date    29.11.2004
25  * @version $Id$
26  */
27 #include "config.h"
28
29 #include <string.h>
30 #ifdef HAVE_INTTYPES_H
31 #include <inttypes.h>
32 #endif
33
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <stdarg.h>
37
38 #include <ctype.h>
39
40 #include "ident.h"
41 #include "irmode_t.h"
42 #include "irnode_t.h"
43 #include "entity_t.h"
44 #include "type_t.h"
45 #include "tv_t.h"
46 #include "irprintf.h"
47 #include "obst.h"
48 #include "pset.h"
49 #include "iterator.h"
50 #include "bitset.h"
51 #include "dbginfo_t.h"
52
53 #define STRNIL "(nil)"
54
55 /**
56  * Init the string.
57  */
58 static void str_init(void *object, size_t n)
59 {
60         (void) n;
61         strcpy(object, "");
62 }
63
64 /**
65  * append a char to a string buffer.
66  */
67 static void str_append_char(void *object, size_t n, char ch)
68 {
69   char buf[2];
70
71   buf[0] = ch;
72   buf[1] = 0;
73
74   strncat(object, buf, n);
75 }
76
77 /**
78  * append a string to a string buffer.
79  */
80 static void str_append_str(void *object, size_t n, const char *str)
81 {
82   strncat(object, str, n);
83 }
84
85
86 /**
87  * Init the file. i.e. do nothing.
88  */
89 static void file_init(void *object, size_t n)
90 {
91         (void) object;
92         (void) n;
93 }
94
95 /**
96  * append a char to a file.
97  */
98 static void file_append_char(void *object, size_t n, char ch)
99 {
100         (void) n;
101         fputc(ch, object);
102 }
103
104 /**
105  * append a string to a file.
106  */
107 static void file_append_str(void *object, size_t n, const char *str)
108 {
109         (void) n;
110         fputs(str, object);
111 }
112
113 /**
114  * Init the obstack. i.e. do nothing.
115  */
116 static void obst_init(void *object, size_t n)
117 {
118         (void) object;
119         (void) n;
120 }
121
122 /**
123  * append a char to a obstack.
124  */
125 static void obst_append_char(void *object, size_t n, char ch)
126 {
127         struct obstack *obst = object;
128         (void) n;
129         obstack_1grow(obst, ch);
130 }
131
132 /**
133  * append a string to a obstack.
134  */
135 static void obst_append_str(void *object, size_t n, const char *str)
136 {
137         struct obstack *obst = object;
138         (void) n;
139         obstack_grow(obst, str, strlen(str));
140 }
141
142
143 /**
144  * the file appender
145  */
146 static const appender_t file_appender = {
147   file_init,
148   file_append_char,
149   file_append_str
150 };
151
152 /**
153  * the string buffer appender
154  */
155 static const appender_t str_appender = {
156   str_init,
157   str_append_char,
158   str_append_str
159 };
160
161 /**
162  * the obstack appender.
163  */
164 static const appender_t obst_appender = {
165   obst_init,
166   obst_append_char,
167   obst_append_str
168 };
169
170 #include "irargs_t.h"
171
172 void ir_printf(const char *fmt, ...)
173 {
174         va_list args;
175
176         va_start(args, fmt);
177         lc_evprintf(firm_get_arg_env(), fmt, args);
178         va_end(args);
179 }
180
181 void ir_fprintf(FILE *f, const char *fmt, ...)
182 {
183         va_list args;
184
185         va_start(args, fmt);
186         lc_evfprintf(firm_get_arg_env(), f, fmt, args);
187         va_end(args);
188 }
189
190 void ir_snprintf(char *buf, size_t n, const char *fmt, ...)
191 {
192         va_list args;
193
194         va_start(args, fmt);
195         lc_evsnprintf(firm_get_arg_env(), buf, n, fmt, args);
196         va_end(args);
197 }
198
199 void ir_vprintf(const char *fmt, va_list args)
200 {
201         lc_evprintf(firm_get_arg_env(), fmt, args);
202 }
203
204 void ir_vfprintf(FILE *f, const char *fmt, va_list args)
205 {
206         lc_evfprintf(firm_get_arg_env(), f, fmt, args);
207 }
208
209 void ir_vsnprintf(char *buf, size_t len, const char *fmt, va_list args)
210 {
211         lc_evsnprintf(firm_get_arg_env(), buf, len, fmt, args);
212 }
213
214 void ir_obst_vprintf(struct obstack *obst, const char *fmt, va_list args)
215 {
216         lc_evoprintf(firm_get_arg_env(), obst, fmt, args);
217 }