1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
48 int line_nr
; /* nr complete lines written, curr line is line_nr+1 */
53 lf_file_references references
;
61 lf_file_references references
,
65 /* create a file object */
66 lf
*new_lf
= ZALLOC(lf
);
67 ASSERT (new_lf
!= NULL
);
68 new_lf
->references
= references
;
70 new_lf
->name
= (real_name
== NULL
? name
: real_name
);
71 new_lf
->program
= program
;
72 /* attach to stdout if pipe */
73 if (!strcmp(name
, "-")) {
74 new_lf
->stream
= stdout
;
77 /* create a new file */
78 new_lf
->stream
= fopen(name
, "w");
79 if (new_lf
->stream
== NULL
) {
91 if (file
->stream
!= stdout
) {
92 if (fclose(file
->stream
)) {
93 perror("lf_close.fclose");
108 file
->line_blank
= 1;
110 else if (file
->line_blank
) {
112 for (pad
= file
->indent
; pad
> 0; pad
--)
113 putc(' ', file
->stream
);
115 file
->line_blank
= 0;
117 putc(chr
, file
->stream
);
129 for (i
= 0; i
< strlen_string
; i
++)
130 nr
+= lf_putchr (file
, string
[i
]);
136 lf_indent_suppress(lf
*file
)
138 file
->line_blank
= 0;
148 if (string
!= NULL
) {
149 for (chp
= string
; *chp
!= '\0'; chp
++) {
150 nr
+= lf_putchr(file
, *chp
);
157 do_lf_putunsigned(lf
*file
,
162 nr
+= do_lf_putunsigned(file
, u
/ 10);
163 nr
+= lf_putchr(file
, (u
% 10) + '0');
175 nr
+= lf_putchr(file
, '0');
176 else if (decimal
< 0) {
177 nr
+= lf_putchr(file
, '-');
178 nr
+= do_lf_putunsigned(file
, -decimal
);
180 else if (decimal
> 0) {
181 nr
+= do_lf_putunsigned(file
, decimal
);
199 vsprintf (buf
, fmt
, ap
);
200 /* FIXME - this is really stuffed but so is vsprintf() on a sun! */
201 ASSERT (strlen (buf
) < sizeof (buf
));
202 nr
+= lf_putstr (file
, buf
);
209 lf_print__line_ref (lf
*file
,
212 return lf_print__external_ref (file
, line
->line_nr
, line
->file_name
);
216 lf_print__external_ref (lf
*file
,
218 const char *file_name
)
221 switch (file
->references
)
223 case lf_include_references
:
224 lf_indent_suppress(file
);
225 nr
+= lf_putstr (file
, "#line ");
226 nr
+= lf_putint (file
, line_nr
);
227 nr
+= lf_putstr (file
, " \"");
228 nr
+= lf_putstr (file
, file_name
);
229 nr
+= lf_putstr (file
, "\"\n");
231 case lf_omit_references
:
232 nr
+= lf_putstr (file
, "/* ");
233 nr
+= lf_putstr (file
, file_name
);
234 nr
+= lf_putstr (file
, ":");
235 nr
+= lf_putint (file
, line_nr
);
236 nr
+= lf_putstr (file
, "*/\n");
243 lf_print__internal_ref (lf
*file
)
246 nr
+= lf_print__external_ref (file
, file
->line_nr
+2, file
->name
);
247 /* line_nr == last_line, want to number from next */
252 lf_indent (lf
*file
, int delta
)
254 file
->indent
+= delta
;
259 lf_print__gnu_copyleft (lf
*file
)
262 switch (file
->type
) {
265 nr
+= lf_printf(file
, "\
266 /* This file is part of GDB.\n\
268 Copyright 2002 Free Software Foundation, Inc.\n\
270 This program is free software; you can redistribute it and/or modify\n\
271 it under the terms of the GNU General Public License as published by\n\
272 the Free Software Foundation; either version 2 of the License, or\n\
273 (at your option) any later version.\n\
275 This program is distributed in the hope that it will be useful,\n\
276 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
277 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
278 GNU General Public License for more details.\n\
280 You should have received a copy of the GNU General Public License\n\
281 along with this program; if not, write to the Free Software\n\
282 Foundation, Inc., 59 Temple Place - Suite 330,\n\
283 Boston, MA 02111-1307, USA.\n\
287 This file was generated by the program %s */\n\
288 ", filter_filename(file
->program
));
299 lf_putbin(lf
*file
, int decimal
, int width
)
304 for (bit
= 1 << (width
-1); bit
!= 0; bit
>>= 1) {
306 nr
+= lf_putchr(file
, '1');
308 nr
+= lf_putchr(file
, '0');
314 lf_print__this_file_is_empty(lf
*file
,
318 switch (file
->type
) {
321 nr
+= lf_printf (file
,
322 "/* This generated file (%s) is intentionally left blank",
325 nr
+= lf_printf (file
, " - %s", reason
);
326 nr
+= lf_printf (file
, " */\n");
329 ERROR ("Bad switch");
335 lf_print__ucase_filename(lf
*file
)
338 const char *chp
= file
->name
;
339 while (*chp
!= '\0') {
342 nr
+= lf_putchr(file
, toupper(ch
));
345 nr
+= lf_putchr(file
, '_');
347 nr
+= lf_putchr(file
, ch
);
354 lf_print__file_start(lf
*file
)
357 switch (file
->type
) {
360 nr
+= lf_print__gnu_copyleft(file
);
361 nr
+= lf_printf(file
, "\n");
362 nr
+= lf_printf(file
, "#ifndef ");
363 nr
+= lf_print__ucase_filename(file
);
364 nr
+= lf_printf(file
, "\n");
365 nr
+= lf_printf(file
, "#define ");
366 nr
+= lf_print__ucase_filename(file
);
367 nr
+= lf_printf(file
, "\n");
368 nr
+= lf_printf(file
, "\n");
378 lf_print__file_finish(lf
*file
)
381 switch (file
->type
) {
384 nr
+= lf_printf(file
, "\n");
385 nr
+= lf_printf(file
, "#endif /* _");
386 nr
+= lf_print__ucase_filename(file
);
387 nr
+= lf_printf(file
, "_*/\n");
397 lf_print__function_type (lf
*file
,
400 const char *trailing_space
)
403 nr
+= lf_printf (file
, "%s\\\n(%s)", prefix
, type
);
404 if (trailing_space
!= NULL
)
405 nr
+= lf_printf (file
, "%s", trailing_space
);
410 lf_print__function_type_function (lf
*file
,
411 print_function
*print_type
,
413 const char *trailing_space
)
416 nr
+= lf_printf (file
, "%s\\\n(", prefix
);
417 nr
+= print_type (file
);
418 nr
+= lf_printf (file
, ")");
419 if (trailing_space
!= NULL
)
420 nr
+= lf_printf (file
, "%s", trailing_space
);