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