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