Commit e03856fe by Geoffrey Keating Committed by Geoffrey Keating

gengtype.h (xvasprintf): New prototype.

	* gengtype.h (xvasprintf): New prototype.
	(xasprintf): New prototype.
	(struct outf): New.
	(get_output_file): Return an outf_p.
	(header_file): Is now an outf_p.
	(base_files): Now are outf_p.
	(oprintf): New.
	* gengtype.c: Replace all output FILE * with outf_p; use oprintf
	rather than stdio operations.  Use xasprintf in a few places,
	when appropriate.
	(xvasprintf): New.
	(xasprintf): New.
	(struct filemap): Delete.
	(files): Delete.
	(output_files): New.
	(oprintf): New.
	(create_file): Create an outf_p.  Add parameter to indicate output
	file name, change all callers.
	(open_base_files): Create gtype-desc.c here.
	(get_output_file_with_visibility): Rewrite.
	(get_output_file_name): Just look at 'name' field in struct outf.
	(close_output_files): Rewrite.

From-SVN: r54566
parent 83144cfc
2002-06-12 Geoffrey Keating <geoffk@redhat.com>
* gengtype.h (xvasprintf): New prototype.
(xasprintf): New prototype.
(struct outf): New.
(get_output_file): Return an outf_p.
(header_file): Is now an outf_p.
(base_files): Now are outf_p.
(oprintf): New.
* gengtype.c: Replace all output FILE * with outf_p; use oprintf
rather than stdio operations. Use xasprintf in a few places,
when appropriate.
(xvasprintf): New.
(xasprintf): New.
(struct filemap): Delete.
(files): Delete.
(output_files): New.
(oprintf): New.
(create_file): Create an outf_p. Add parameter to indicate output
file name, change all callers.
(open_base_files): Create gtype-desc.c here.
(get_output_file_with_visibility): Rewrite.
(get_output_file_name): Just look at 'name' field in struct outf.
(close_output_files): Rewrite.
2002-06-12 Jason Thorpe <thorpej@wasabisystems.com> 2002-06-12 Jason Thorpe <thorpej@wasabisystems.com>
* config/vax/vax.h (MASK_UNIX_ASM, MASK_VAXC_ALIGNMENT) * config/vax/vax.h (MASK_UNIX_ASM, MASK_VAXC_ALIGNMENT)
......
...@@ -42,6 +42,34 @@ error_at_line VPARAMS ((struct fileloc *pos, const char *msg, ...)) ...@@ -42,6 +42,34 @@ error_at_line VPARAMS ((struct fileloc *pos, const char *msg, ...))
VA_CLOSE (ap); VA_CLOSE (ap);
} }
/* vasprintf, but produces fatal message on out-of-memory. */
int
xvasprintf (result, format, args)
char ** result;
const char *format;
va_list args;
{
int ret = vasprintf (result, format, args);
if (*result == NULL || ret < 0)
{
fputs ("gengtype: out of memory", stderr);
xexit (1);
}
return ret;
}
/* Wrapper for xvasprintf. */
char *
xasprintf VPARAMS ((const char *format, ...))
{
char *result;
VA_OPEN (ap, format);
VA_FIXEDARG (ap, const char *, format);
xvasprintf (&result, format, ap);
VA_CLOSE (ap);
return result;
}
/* The one and only TYPE_STRING. */ /* The one and only TYPE_STRING. */
struct type string_type = { struct type string_type = {
...@@ -479,23 +507,12 @@ set_gc_used (variables) ...@@ -479,23 +507,12 @@ set_gc_used (variables)
(but some output files have many input files), and there is one .h file (but some output files have many input files), and there is one .h file
for the whole build. */ for the whole build. */
typedef struct filemap *filemap_p;
struct filemap {
filemap_p next;
const char *input_name;
const char *output_name;
FILE *output;
};
/* The list of output files. */ /* The list of output files. */
static outf_p output_files;
static filemap_p files;
/* The output header file that is included into pretty much every /* The output header file that is included into pretty much every
source file. */ source file. */
outf_p header_file;
FILE * header_file;
enum { enum {
BASE_FILE_C, BASE_FILE_C,
...@@ -509,16 +526,18 @@ static const char *lang_names[] = { ...@@ -509,16 +526,18 @@ static const char *lang_names[] = {
"c", "objc", "cp", "treelang", "cobol", "f", "ada", "java" "c", "objc", "cp", "treelang", "cobol", "f", "ada", "java"
}; };
#define NUM_BASE_FILES (sizeof (lang_names) / sizeof (lang_names[0])) #define NUM_BASE_FILES (sizeof (lang_names) / sizeof (lang_names[0]))
FILE *base_files[NUM_BASE_FILES]; outf_p base_files[NUM_BASE_FILES];
static FILE * create_file PARAMS ((const char *)); static outf_p create_file PARAMS ((const char *, const char *));
static const char * get_file_basename PARAMS ((const char *)); static const char * get_file_basename PARAMS ((const char *));
/* Create and return a FILE* for a new header file to be called NAME. */ /* Create and return an outf_p for a new file for NAME, to be called
ONAME. */
static FILE * static outf_p
create_file (name) create_file (name, oname)
const char *name; const char *name;
const char *oname;
{ {
static const char *const hdr[] = { static const char *const hdr[] = {
" Copyright (C) 2002 Free Software Foundation, Inc.\n", " Copyright (C) 2002 Free Software Foundation, Inc.\n",
...@@ -542,21 +561,49 @@ create_file (name) ...@@ -542,21 +561,49 @@ create_file (name)
"\n", "\n",
"/* This file is machine generated. Do not edit. */\n" "/* This file is machine generated. Do not edit. */\n"
}; };
FILE *f; outf_p f;
size_t i; size_t i;
f = tmpfile(); f = xcalloc (sizeof (*f), 1);
if (f == NULL) f->next = output_files;
{ f->name = oname;
perror ("couldn't create temporary file"); output_files = f;
exit (1);
} oprintf (f, "/* Type information for %s.\n", name);
fprintf (f, "/* Type information for %s.\n", name);
for (i = 0; i < sizeof(hdr)/sizeof(hdr[0]); i++) for (i = 0; i < sizeof(hdr)/sizeof(hdr[0]); i++)
fputs (hdr[i], f); oprintf (f, "%s", hdr[i]);
return f; return f;
} }
/* Print, like fprintf, to O. */
void
oprintf VPARAMS ((outf_p o, const char *format, ...))
{
char *s;
size_t slength;
VA_OPEN (ap, format);
VA_FIXEDARG (ap, outf_p, o);
VA_FIXEDARG (ap, const char *, format);
slength = xvasprintf (&s, format, ap);
VA_CLOSE (ap);
if (o->bufused + slength > o->buflength)
{
size_t new_len = o->buflength;
if (new_len == 0)
new_len = 1024;
do {
new_len *= 2;
} while (o->bufused + slength >= new_len);
o->buf = xrealloc (o->buf, new_len);
o->buflength = new_len;
}
memcpy (o->buf + o->bufused, s, slength);
o->bufused += slength;
free (s);
}
/* Open the global header file and the language-specific header files. */ /* Open the global header file and the language-specific header files. */
static void static void
...@@ -564,21 +611,29 @@ open_base_files (void) ...@@ -564,21 +611,29 @@ open_base_files (void)
{ {
size_t i; size_t i;
header_file = create_file ("GCC"); header_file = create_file ("GCC", "gtype-desc.h");
for (i = 0; i < NUM_BASE_FILES; i++) for (i = 0; i < NUM_BASE_FILES; i++)
{ base_files[i] = create_file (lang_names[i],
filemap_p newf; xasprintf ("gtype-%s.h", lang_names[i]));
char *s;
/* gtype-desc.c is a little special, so we create it here. */
{
/* The order of files here matters very much. */
static const char *const ifiles [] = {
"config.h", "system.h", "varray.h", "hashtab.h",
"bitmap.h", "tree.h", "rtl.h", "function.h", "insn-config.h",
"expr.h", "hard-reg-set.h", "basic-block.h", "cselib.h",
"insn-addr.h", "ssa.h", "optabs.h", "libfuncs.h",
"debug.h", "ggc.h",
NULL
};
const char *const *ifp;
outf_p gtype_desc_c;
base_files[i] = create_file (lang_names[i]); gtype_desc_c = create_file ("GCC", "gtype-desc.c");
newf = xmalloc (sizeof (*newf)); for (ifp = ifiles; *ifp; ifp++)
newf->next = files; oprintf (gtype_desc_c, "#include \"%s\"\n", *ifp);
files = newf;
newf->input_name = NULL;
newf->output = base_files[i];
newf->output_name = s = xmalloc (16);
sprintf (s, "gtype-%s.h", lang_names[i]);
} }
} }
...@@ -664,24 +719,21 @@ get_base_file_bitmap (input_file) ...@@ -664,24 +719,21 @@ get_base_file_bitmap (input_file)
made in INPUT_FILE and is linked into every language that uses made in INPUT_FILE and is linked into every language that uses
INPUT_FILE. */ INPUT_FILE. */
FILE * outf_p
get_output_file_with_visibility (input_file) get_output_file_with_visibility (input_file)
const char *input_file; const char *input_file;
{ {
filemap_p fm, fmo; outf_p r;
size_t len; size_t len;
const char *basename; const char *basename;
const char *for_name;
const char *output_name;
/* Do we already know the file? */ /* This can happen when we need a file with visibility on a
for (fm = files; fm; fm = fm->next) structure that we've never seen. We have to just hope that it's
if (input_file == fm->input_name) globally visible. */
return fm->output; if (input_file == NULL)
input_file = "system.h";
/* No, we'll be creating a new filemap. */
fm = xmalloc (sizeof (*fm));
fm->next = files;
files = fm;
fm->input_name = input_file;
/* Determine the output file name. */ /* Determine the output file name. */
basename = get_file_basename (input_file); basename = get_file_basename (input_file);
...@@ -693,72 +745,39 @@ get_output_file_with_visibility (input_file) ...@@ -693,72 +745,39 @@ get_output_file_with_visibility (input_file)
{ {
char *s; char *s;
fm->output_name = s = xmalloc (sizeof ("gt-") + len); output_name = s = xasprintf ("gt-%s", basename);
sprintf (s, "gt-%s", basename);
for (; *s != '.'; s++) for (; *s != '.'; s++)
if (! ISALNUM (*s) && *s != '-') if (! ISALNUM (*s) && *s != '-')
*s = '-'; *s = '-';
memcpy (s, ".h", sizeof (".h")); memcpy (s, ".h", sizeof (".h"));
for_name = basename;
} }
else if (strcmp (basename, "c-common.h") == 0) else if (strcmp (basename, "c-common.h") == 0)
fm->output_name = "gt-c-common.h"; output_name = "gt-c-common.h", for_name = "c-common.c";
else if (strcmp (basename, "c-tree.h") == 0) else if (strcmp (basename, "c-tree.h") == 0)
fm->output_name = "gt-c-decl.h"; output_name = "gt-c-decl.h", for_name = "c-decl.c";
else else
{ {
size_t i; size_t i;
fm->output_name = "gtype-desc.c";
for (i = 0; i < NUM_BASE_FILES; i++) for (i = 0; i < NUM_BASE_FILES; i++)
if (memcmp (basename, lang_names[i], strlen (lang_names[i])) == 0 if (memcmp (basename, lang_names[i], strlen (lang_names[i])) == 0
&& basename[strlen(lang_names[i])] == '/') && basename[strlen(lang_names[i])] == '/')
{ return base_files[i];
char *s;
s = xmalloc (16); output_name = "gtype-desc.c";
sprintf (s, "gtype-%s.h", lang_names[i]); for_name = NULL;
fm->output_name = s;
break;
}
} }
/* Look through to see if we've ever seen this output filename before. */ /* Look through to see if we've ever seen this output filename before. */
for (fmo = fm->next; fmo; fmo = fmo->next) for (r = output_files; r; r = r->next)
if (strcmp (fmo->output_name, fm->output_name) == 0) if (strcmp (r->name, output_name) == 0)
{ return r;
fm->output = fmo->output;
break;
}
/* If not, create it. */ /* If not, create it. */
if (fmo == NULL) r = create_file (for_name, output_name);
{
fm->output = create_file (fm->output_name); return r;
if (strcmp (fm->output_name, "gtype-desc.c") == 0)
{
fputs ("#include \"config.h\"\n", fm->output);
fputs ("#include \"system.h\"\n", fm->output);
fputs ("#include \"varray.h\"\n", fm->output);
fputs ("#include \"hashtab.h\"\n", fm->output);
fputs ("#include \"bitmap.h\"\n", fm->output);
fputs ("#include \"tree.h\"\n", fm->output);
fputs ("#include \"rtl.h\"\n", fm->output);
fputs ("#include \"function.h\"\n", fm->output);
fputs ("#include \"insn-config.h\"\n", fm->output);
fputs ("#include \"expr.h\"\n", fm->output);
fputs ("#include \"hard-reg-set.h\"\n", fm->output);
fputs ("#include \"basic-block.h\"\n", fm->output);
fputs ("#include \"cselib.h\"\n", fm->output);
fputs ("#include \"insn-addr.h\"\n", fm->output);
fputs ("#include \"ssa.h\"\n", fm->output);
fputs ("#include \"optabs.h\"\n", fm->output);
fputs ("#include \"libfuncs.h\"\n", fm->output);
fputs ("#include \"debug.h\"\n", fm->output);
fputs ("#include \"ggc.h\"\n", fm->output);
}
}
return fm->output;
} }
/* The name of an output file, suitable for definitions, that can see /* The name of an output file, suitable for definitions, that can see
...@@ -769,82 +788,57 @@ const char * ...@@ -769,82 +788,57 @@ const char *
get_output_file_name (input_file) get_output_file_name (input_file)
const char *input_file; const char *input_file;
{ {
filemap_p fm; return get_output_file_with_visibility (input_file)->name;
for (fm = files; fm; fm = fm->next)
if (input_file == fm->input_name)
return fm->output_name;
(void) get_output_file_with_visibility (input_file);
return get_output_file_name (input_file);
} }
/* Close all output files and copy them to their final destinations, /* Copy the output to its final destination,
but don't unnecessarily change modification times. */ but don't unnecessarily change modification times. */
static void static void
close_output_files PARAMS ((void)) close_output_files PARAMS ((void))
{ {
filemap_p fm; outf_p of;
struct filemap header;
header.next = files;
header.output_name = "gtype-desc.h";
header.output = header_file;
for (fm = &header; fm; fm = fm->next) for (of = output_files; of; of = of->next)
{ {
int no_write_p; FILE * newfile;
filemap_p ofm;
FILE *newfile;
/* Handle each output file once. */
if (fm->output == NULL)
continue;
for (ofm = fm->next; ofm; ofm = ofm->next) newfile = fopen (of->name, "r");
if (fm->output == ofm->output) if (newfile != NULL )
ofm->output = NULL;
/* Compare the output file with the file to be created, avoiding
unnecessarily changing timestamps. */
newfile = fopen (fm->output_name, "r");
if (newfile != NULL)
{ {
int ch1, ch2; int no_write_p;
size_t i;
rewind (fm->output);
do {
ch1 = fgetc (fm->output);
ch2 = fgetc (newfile);
} while (ch1 != EOF && ch1 == ch2);
fclose (newfile);
no_write_p = ch1 == ch2; for (i = 0; i < of->bufused; i++)
{
int ch;
ch = fgetc (newfile);
if (ch == EOF || ch != (unsigned char) of->buf[i])
break;
} }
else no_write_p = i == of->bufused && fgetc (newfile) == EOF;
no_write_p = 0; fclose (newfile);
/* Nothing interesting to do. Close the output file. */
if (no_write_p) if (no_write_p)
{
fclose (fm->output);
continue; continue;
} }
newfile = fopen (fm->output_name, "w"); newfile = fopen (of->name, "w");
if (newfile == NULL) if (newfile == NULL)
{ {
perror ("opening output file"); perror ("opening output file");
exit (1); exit (1);
} }
if (fwrite (of->buf, 1, of->bufused, newfile) != of->bufused)
{ {
int ch; perror ("writing output file");
rewind (fm->output); exit (1);
while ((ch = fgetc (fm->output)) != EOF) }
fputc (ch, newfile); if (fclose (newfile) != 0)
{
perror ("closing output file");
exit (1);
} }
fclose (newfile);
fclose (fm->output);
} }
} }
...@@ -852,22 +846,22 @@ struct flist { ...@@ -852,22 +846,22 @@ struct flist {
struct flist *next; struct flist *next;
int started_p; int started_p;
const char *name; const char *name;
FILE *f; outf_p f;
}; };
static void output_escaped_param PARAMS ((FILE *, const char *, const char *, static void output_escaped_param PARAMS ((outf_p , const char *, const char *,
const char *, const char *, const char *, const char *,
struct fileloc *)); struct fileloc *));
static void write_gc_structure_fields static void write_gc_structure_fields
PARAMS ((FILE *, type_p, const char *, const char *, options_p, PARAMS ((outf_p , type_p, const char *, const char *, options_p,
int, struct fileloc *, lang_bitmap, type_p)); int, struct fileloc *, lang_bitmap, type_p));
static void write_gc_marker_routine_for_structure PARAMS ((type_p, type_p)); static void write_gc_marker_routine_for_structure PARAMS ((type_p, type_p));
static void write_gc_types PARAMS ((type_p structures, type_p param_structs)); static void write_gc_types PARAMS ((type_p structures, type_p param_structs));
static void put_mangled_filename PARAMS ((FILE *, const char *)); static void put_mangled_filename PARAMS ((outf_p , const char *));
static void finish_root_table PARAMS ((struct flist *flp, const char *pfx, static void finish_root_table PARAMS ((struct flist *flp, const char *pfx,
const char *tname, const char *lastname, const char *tname, const char *lastname,
const char *name)); const char *name));
static void write_gc_root PARAMS ((FILE *, pair_p, type_p, const char *, int, static void write_gc_root PARAMS ((outf_p , pair_p, type_p, const char *, int,
struct fileloc *, const char *)); struct fileloc *, const char *));
static void write_gc_roots PARAMS ((pair_p)); static void write_gc_roots PARAMS ((pair_p));
...@@ -879,7 +873,7 @@ static int gc_counter; ...@@ -879,7 +873,7 @@ static int gc_counter;
static void static void
output_escaped_param (of, param, val, prev_val, oname, line) output_escaped_param (of, param, val, prev_val, oname, line)
FILE *of; outf_p of;
const char *param; const char *param;
const char *val; const char *val;
const char *prev_val; const char *prev_val;
...@@ -890,13 +884,13 @@ output_escaped_param (of, param, val, prev_val, oname, line) ...@@ -890,13 +884,13 @@ output_escaped_param (of, param, val, prev_val, oname, line)
for (p = param; *p; p++) for (p = param; *p; p++)
if (*p != '%') if (*p != '%')
fputc (*p, of); oprintf (of, "%c", *p);
else if (*++p == 'h') else if (*++p == 'h')
fprintf (of, "(%s)", val); oprintf (of, "(%s)", val);
else if (*p == '0') else if (*p == '0')
fputs ("(*x)", of); oprintf (of, "(*x)");
else if (*p == '1') else if (*p == '1')
fprintf (of, "(%s)", prev_val); oprintf (of, "(%s)", prev_val);
else else
error_at_line (line, "`%s' option contains bad escape %c%c", error_at_line (line, "`%s' option contains bad escape %c%c",
oname, '%', *p); oname, '%', *p);
...@@ -912,7 +906,7 @@ output_escaped_param (of, param, val, prev_val, oname, line) ...@@ -912,7 +906,7 @@ output_escaped_param (of, param, val, prev_val, oname, line)
static void static void
write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
param) param)
FILE *of; outf_p of;
type_p s; type_p s;
const char *val; const char *val;
const char *prev_val; const char *prev_val;
...@@ -948,11 +942,11 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -948,11 +942,11 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
error_at_line (line, "missing `desc' option"); error_at_line (line, "missing `desc' option");
} }
fprintf (of, "%*s{\n", indent, ""); oprintf (of, "%*s{\n", indent, "");
indent += 2; indent += 2;
fprintf (of, "%*sunsigned int tag%d = (", indent, "", tagcounter); oprintf (of, "%*sunsigned int tag%d = (", indent, "", tagcounter);
output_escaped_param (of, tagexpr, val, prev_val, "desc", line); output_escaped_param (of, tagexpr, val, prev_val, "desc", line);
fputs (");\n", of); oprintf (of, ");\n");
} }
for (f = s->u.s.fields; f; f = f->next) for (f = s->u.s.fields; f; f = f->next)
...@@ -1034,7 +1028,7 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -1034,7 +1028,7 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
error_at_line (&f->line, "field `%s' has no tag", f->name); error_at_line (&f->line, "field `%s' has no tag", f->name);
continue; continue;
} }
fprintf (of, "%*sif (tag%d == (%s)) {\n", indent, "", oprintf (of, "%*sif (tag%d == (%s)) {\n", indent, "",
tagcounter, tagid); tagcounter, tagid);
indent += 2; indent += 2;
} }
...@@ -1067,8 +1061,7 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -1067,8 +1061,7 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
{ {
char *newval; char *newval;
newval = xmalloc (strlen (val) + sizeof (".") + strlen (f->name)); newval = xasprintf ("%s.%s", val, f->name);
sprintf (newval, "%s.%s", val, f->name);
write_gc_structure_fields (of, t, newval, val, f->opt, indent, write_gc_structure_fields (of, t, newval, val, f->opt, indent,
&f->line, bitmap, param); &f->line, bitmap, param);
free (newval); free (newval);
...@@ -1080,13 +1073,13 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -1080,13 +1073,13 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
{ {
if (maybe_undef_p if (maybe_undef_p
&& t->u.p->u.s.line.file == NULL) && t->u.p->u.s.line.file == NULL)
fprintf (of, "%*sif (%s.%s) abort();\n", indent, "", oprintf (of, "%*sif (%s.%s) abort();\n", indent, "",
val, f->name); val, f->name);
else if (UNION_OR_STRUCT_P (t->u.p)) else if (UNION_OR_STRUCT_P (t->u.p))
fprintf (of, "%*sgt_ggc_m_%s (%s.%s);\n", indent, "", oprintf (of, "%*sgt_ggc_m_%s (%s.%s);\n", indent, "",
t->u.p->u.s.tag, val, f->name); t->u.p->u.s.tag, val, f->name);
else if (t->u.p->kind == TYPE_PARAM_STRUCT) else if (t->u.p->kind == TYPE_PARAM_STRUCT)
fprintf (of, "%*sgt_ggc_mm_%d%s_%s (%s.%s);\n", indent, "", oprintf (of, "%*sgt_ggc_mm_%d%s_%s (%s.%s);\n", indent, "",
(int) strlen (t->u.p->u.param_struct.param->u.s.tag), (int) strlen (t->u.p->u.param_struct.param->u.s.tag),
t->u.p->u.param_struct.param->u.s.tag, t->u.p->u.param_struct.param->u.s.tag,
t->u.p->u.param_struct.stru->u.s.tag, t->u.p->u.param_struct.stru->u.s.tag,
...@@ -1098,22 +1091,22 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -1098,22 +1091,22 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
} }
else if (t->u.p->kind == TYPE_SCALAR else if (t->u.p->kind == TYPE_SCALAR
|| t->u.p->kind == TYPE_STRING) || t->u.p->kind == TYPE_STRING)
fprintf (of, "%*sggc_mark (%s.%s);\n", indent, "", oprintf (of, "%*sggc_mark (%s.%s);\n", indent, "",
val, f->name); val, f->name);
else else
{ {
int loopcounter = ++gc_counter; int loopcounter = ++gc_counter;
fprintf (of, "%*sif (%s.%s != NULL) {\n", indent, "", oprintf (of, "%*sif (%s.%s != NULL) {\n", indent, "",
val, f->name); val, f->name);
indent += 2; indent += 2;
fprintf (of, "%*ssize_t i%d;\n", indent, "", loopcounter); oprintf (of, "%*ssize_t i%d;\n", indent, "", loopcounter);
fprintf (of, "%*sggc_set_mark (%s.%s);\n", indent, "", oprintf (of, "%*sggc_set_mark (%s.%s);\n", indent, "",
val, f->name); val, f->name);
fprintf (of, "%*sfor (i%d = 0; i%d < (", indent, "", oprintf (of, "%*sfor (i%d = 0; i%d < (", indent, "",
loopcounter, loopcounter); loopcounter, loopcounter);
output_escaped_param (of, length, val, prev_val, "length", line); output_escaped_param (of, length, val, prev_val, "length", line);
fprintf (of, "); i%d++) {\n", loopcounter); oprintf (of, "); i%d++) {\n", loopcounter);
indent += 2; indent += 2;
switch (t->u.p->kind) switch (t->u.p->kind)
{ {
...@@ -1122,8 +1115,8 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -1122,8 +1115,8 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
{ {
char *newval; char *newval;
newval = xmalloc (strlen (val) + 8 + strlen (f->name)); newval = xasprintf ("%s.%s[i%d]", val, f->name,
sprintf (newval, "%s.%s[i%d]", val, f->name, loopcounter); loopcounter);
write_gc_structure_fields (of, t->u.p, newval, val, write_gc_structure_fields (of, t->u.p, newval, val,
f->opt, indent, &f->line, f->opt, indent, &f->line,
bitmap, param); bitmap, param);
...@@ -1132,7 +1125,7 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -1132,7 +1125,7 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
} }
case TYPE_POINTER: case TYPE_POINTER:
if (UNION_OR_STRUCT_P (t->u.p->u.p)) if (UNION_OR_STRUCT_P (t->u.p->u.p))
fprintf (of, "%*sgt_ggc_m_%s (%s.%s[i%d]);\n", indent, "", oprintf (of, "%*sgt_ggc_m_%s (%s.%s[i%d]);\n", indent, "",
t->u.p->u.p->u.s.tag, val, f->name, t->u.p->u.p->u.s.tag, val, f->name,
loopcounter); loopcounter);
else else
...@@ -1147,9 +1140,9 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -1147,9 +1140,9 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
break; break;
} }
indent -= 2; indent -= 2;
fprintf (of, "%*s}\n", indent, ""); oprintf (of, "%*s}\n", indent, "");
indent -= 2; indent -= 2;
fprintf (of, "%*s}\n", indent, ""); oprintf (of, "%*s}\n", indent, "");
} }
break; break;
...@@ -1173,37 +1166,37 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -1173,37 +1166,37 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
|| ta->kind == TYPE_STRING) || ta->kind == TYPE_STRING)
break; break;
fprintf (of, "%*s{\n", indent, ""); oprintf (of, "%*s{\n", indent, "");
indent += 2; indent += 2;
if (special != NULL && strcmp (special, "tree_exp") == 0) if (special != NULL && strcmp (special, "tree_exp") == 0)
{ {
fprintf (of, "%*sconst size_t tree_exp_size = (", oprintf (of, "%*sconst size_t tree_exp_size = (",
indent, ""); indent, "");
output_escaped_param (of, length, val, prev_val, output_escaped_param (of, length, val, prev_val,
"length", line); "length", line);
fputs (");\n", of); oprintf (of, ");\n");
length = "first_rtl_op (TREE_CODE ((tree)&%h))"; length = "first_rtl_op (TREE_CODE ((tree)&%h))";
} }
for (ta = t, i = 0; ta->kind == TYPE_ARRAY; ta = ta->u.a.p, i++) for (ta = t, i = 0; ta->kind == TYPE_ARRAY; ta = ta->u.a.p, i++)
{ {
fprintf (of, "%*ssize_t i%d_%d;\n", oprintf (of, "%*ssize_t i%d_%d;\n",
indent, "", loopcounter, i); indent, "", loopcounter, i);
fprintf (of, "%*sconst size_t ilimit%d_%d = (", oprintf (of, "%*sconst size_t ilimit%d_%d = (",
indent, "", loopcounter, i); indent, "", loopcounter, i);
if (i == 0 && length != NULL) if (i == 0 && length != NULL)
output_escaped_param (of, length, val, prev_val, output_escaped_param (of, length, val, prev_val,
"length", line); "length", line);
else else
fputs (ta->u.a.len, of); oprintf (of, "%s", ta->u.a.len);
fputs (");\n", of); oprintf (of, ");\n");
} }
for (ta = t, i = 0; ta->kind == TYPE_ARRAY; ta = ta->u.a.p, i++) for (ta = t, i = 0; ta->kind == TYPE_ARRAY; ta = ta->u.a.p, i++)
{ {
fprintf (of, oprintf (of,
"%*sfor (i%d_%d = 0; i%d_%d < ilimit%d_%d; i%d_%d++) {\n", "%*sfor (i%d_%d = 0; i%d_%d < ilimit%d_%d; i%d_%d++) {\n",
indent, "", loopcounter, i, loopcounter, i, indent, "", loopcounter, i, loopcounter, i,
loopcounter, i, loopcounter, i); loopcounter, i, loopcounter, i);
...@@ -1214,13 +1207,13 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -1214,13 +1207,13 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
&& (ta->u.p->kind == TYPE_STRUCT && (ta->u.p->kind == TYPE_STRUCT
|| ta->u.p->kind == TYPE_UNION)) || ta->u.p->kind == TYPE_UNION))
{ {
fprintf (of, "%*sgt_ggc_m_%s (%s.%s", oprintf (of, "%*sgt_ggc_m_%s (%s.%s",
indent, "", ta->u.p->u.s.tag, val, f->name); indent, "", ta->u.p->u.s.tag, val, f->name);
for (ta = t, i = 0; for (ta = t, i = 0;
ta->kind == TYPE_ARRAY; ta->kind == TYPE_ARRAY;
ta = ta->u.a.p, i++) ta = ta->u.a.p, i++)
fprintf (of, "[i%d_%d]", loopcounter, i); oprintf (of, "[i%d_%d]", loopcounter, i);
fputs (");\n", of); oprintf (of, ");\n");
} }
else if (ta->kind == TYPE_STRUCT || ta->kind == TYPE_UNION) else if (ta->kind == TYPE_STRUCT || ta->kind == TYPE_UNION)
{ {
...@@ -1245,7 +1238,7 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -1245,7 +1238,7 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
} }
else if (ta->kind == TYPE_POINTER && ta->u.p->kind == TYPE_SCALAR else if (ta->kind == TYPE_POINTER && ta->u.p->kind == TYPE_SCALAR
&& use_param_p && param == NULL) && use_param_p && param == NULL)
fprintf (of, "%*sabort();\n", indent, ""); oprintf (of, "%*sabort();\n", indent, "");
else else
error_at_line (&f->line, error_at_line (&f->line,
"field `%s' is array of unimplemented type", "field `%s' is array of unimplemented type",
...@@ -1253,21 +1246,21 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -1253,21 +1246,21 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
for (ta = t, i = 0; ta->kind == TYPE_ARRAY; ta = ta->u.a.p, i++) for (ta = t, i = 0; ta->kind == TYPE_ARRAY; ta = ta->u.a.p, i++)
{ {
indent -= 2; indent -= 2;
fprintf (of, "%*s}\n", indent, ""); oprintf (of, "%*s}\n", indent, "");
} }
if (special != NULL && strcmp (special, "tree_exp") == 0) if (special != NULL && strcmp (special, "tree_exp") == 0)
{ {
fprintf (of, oprintf (of,
"%*sfor (; i%d_0 < tree_exp_size; i%d_0++)\n", "%*sfor (; i%d_0 < tree_exp_size; i%d_0++)\n",
indent, "", loopcounter, loopcounter); indent, "", loopcounter, loopcounter);
fprintf (of, "%*s gt_ggc_m_rtx_def (%s.%s[i%d_0]);\n", oprintf (of, "%*s gt_ggc_m_rtx_def (%s.%s[i%d_0]);\n",
indent, "", val, f->name, loopcounter); indent, "", val, f->name, loopcounter);
special = NULL; special = NULL;
} }
indent -= 2; indent -= 2;
fprintf (of, "%*s}\n", indent, ""); oprintf (of, "%*s}\n", indent, "");
break; break;
} }
...@@ -1281,7 +1274,7 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -1281,7 +1274,7 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
if (s->kind == TYPE_UNION && ! always_p ) if (s->kind == TYPE_UNION && ! always_p )
{ {
indent -= 2; indent -= 2;
fprintf (of, "%*s}\n", indent, ""); oprintf (of, "%*s}\n", indent, "");
} }
if (special) if (special)
error_at_line (&f->line, "unhandled special `%s'", special); error_at_line (&f->line, "unhandled special `%s'", special);
...@@ -1289,7 +1282,7 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap, ...@@ -1289,7 +1282,7 @@ write_gc_structure_fields (of, s, val, prev_val, opts, indent, line, bitmap,
if (s->kind == TYPE_UNION) if (s->kind == TYPE_UNION)
{ {
indent -= 2; indent -= 2;
fprintf (of, "%*s}\n", indent, ""); oprintf (of, "%*s}\n", indent, "");
} }
} }
...@@ -1301,33 +1294,33 @@ write_gc_marker_routine_for_structure (s, param) ...@@ -1301,33 +1294,33 @@ write_gc_marker_routine_for_structure (s, param)
type_p s; type_p s;
type_p param; type_p param;
{ {
FILE *f; outf_p f;
if (param == NULL) if (param == NULL)
f = get_output_file_with_visibility (s->u.s.line.file); f = get_output_file_with_visibility (s->u.s.line.file);
else else
f = get_output_file_with_visibility (param->u.s.line.file); f = get_output_file_with_visibility (param->u.s.line.file);
fputc ('\n', f); oprintf (f, "%c", '\n');
fputs ("void\n", f); oprintf (f, "void\n");
if (param == NULL) if (param == NULL)
fprintf (f, "gt_ggc_mx_%s (x_p)\n", s->u.s.tag); oprintf (f, "gt_ggc_mx_%s (x_p)\n", s->u.s.tag);
else else
fprintf (f, "gt_ggc_mm_%d%s_%s (x_p)\n", (int) strlen (param->u.s.tag), oprintf (f, "gt_ggc_mm_%d%s_%s (x_p)\n", (int) strlen (param->u.s.tag),
param->u.s.tag, s->u.s.tag); param->u.s.tag, s->u.s.tag);
fputs (" void *x_p;\n", f); oprintf (f, " void *x_p;\n");
fputs ("{\n", f); oprintf (f, "{\n");
fprintf (f, " %s %s * const x = (%s %s *)x_p;\n", oprintf (f, " %s %s * const x = (%s %s *)x_p;\n",
s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag, s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag,
s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag); s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag);
fputs (" if (! ggc_test_and_set_mark (x))\n", f); oprintf (f, " if (! ggc_test_and_set_mark (x))\n");
fputs (" return;\n", f); oprintf (f, " return;\n");
gc_counter = 0; gc_counter = 0;
write_gc_structure_fields (f, s, "(*x)", "not valid postage", write_gc_structure_fields (f, s, "(*x)", "not valid postage",
s->u.s.opt, 2, &s->u.s.line, s->u.s.bitmap, s->u.s.opt, 2, &s->u.s.line, s->u.s.bitmap,
param); param);
fputs ("}\n", f); oprintf (f, "}\n");
} }
/* Write out marker routines for STRUCTURES and PARAM_STRUCTS. */ /* Write out marker routines for STRUCTURES and PARAM_STRUCTS. */
...@@ -1339,7 +1332,7 @@ write_gc_types (structures, param_structs) ...@@ -1339,7 +1332,7 @@ write_gc_types (structures, param_structs)
{ {
type_p s; type_p s;
fputs ("\n/* GC marker procedures. */\n", header_file); oprintf (header_file, "\n/* GC marker procedures. */\n");
for (s = structures; s; s = s->next) for (s = structures; s; s = s->next)
if (s->gc_used == GC_POINTED_TO if (s->gc_used == GC_POINTED_TO
|| s->gc_used == GC_MAYBE_POINTED_TO) || s->gc_used == GC_MAYBE_POINTED_TO)
...@@ -1350,11 +1343,11 @@ write_gc_types (structures, param_structs) ...@@ -1350,11 +1343,11 @@ write_gc_types (structures, param_structs)
&& s->u.s.line.file == NULL) && s->u.s.line.file == NULL)
continue; continue;
fprintf (header_file, oprintf (header_file,
"#define gt_ggc_m_%s(X) do { \\\n", s->u.s.tag); "#define gt_ggc_m_%s(X) do { \\\n", s->u.s.tag);
fprintf (header_file, oprintf (header_file,
" if (X != NULL) gt_ggc_mx_%s (X);\\\n", s->u.s.tag); " if (X != NULL) gt_ggc_mx_%s (X);\\\n", s->u.s.tag);
fprintf (header_file, oprintf (header_file,
" } while (0)\n"); " } while (0)\n");
for (opt = s->u.s.opt; opt; opt = opt->next) for (opt = s->u.s.opt; opt; opt = opt->next)
...@@ -1364,7 +1357,7 @@ write_gc_types (structures, param_structs) ...@@ -1364,7 +1357,7 @@ write_gc_types (structures, param_structs)
if (t->kind == TYPE_STRUCT if (t->kind == TYPE_STRUCT
|| t->kind == TYPE_UNION || t->kind == TYPE_UNION
|| t->kind == TYPE_LANG_STRUCT) || t->kind == TYPE_LANG_STRUCT)
fprintf (header_file, oprintf (header_file,
"#define gt_ggc_mx_%s gt_ggc_mx_%s\n", "#define gt_ggc_mx_%s gt_ggc_mx_%s\n",
s->u.s.tag, t->u.s.tag); s->u.s.tag, t->u.s.tag);
else else
...@@ -1376,7 +1369,7 @@ write_gc_types (structures, param_structs) ...@@ -1376,7 +1369,7 @@ write_gc_types (structures, param_structs)
continue; continue;
/* Declare the marker procedure only once. */ /* Declare the marker procedure only once. */
fprintf (header_file, oprintf (header_file,
"extern void gt_ggc_mx_%s PARAMS ((void *));\n", "extern void gt_ggc_mx_%s PARAMS ((void *));\n",
s->u.s.tag); s->u.s.tag);
...@@ -1412,7 +1405,7 @@ write_gc_types (structures, param_structs) ...@@ -1412,7 +1405,7 @@ write_gc_types (structures, param_structs)
} }
/* Declare the marker procedure. */ /* Declare the marker procedure. */
fprintf (header_file, oprintf (header_file,
"extern void gt_ggc_mm_%d%s_%s PARAMS ((void *));\n", "extern void gt_ggc_mm_%d%s_%s PARAMS ((void *));\n",
(int) strlen (param->u.s.tag), param->u.s.tag, (int) strlen (param->u.s.tag), param->u.s.tag,
stru->u.s.tag); stru->u.s.tag);
...@@ -1439,15 +1432,15 @@ write_gc_types (structures, param_structs) ...@@ -1439,15 +1432,15 @@ write_gc_types (structures, param_structs)
static void static void
put_mangled_filename (f, fn) put_mangled_filename (f, fn)
FILE *f; outf_p f;
const char *fn; const char *fn;
{ {
const char *name = get_output_file_name (fn); const char *name = get_output_file_name (fn);
for (; *name != 0; name++) for (; *name != 0; name++)
if (ISALNUM (*name)) if (ISALNUM (*name))
fputc (*name, f); oprintf (f, "%c", *name);
else else
fputc ('_', f); oprintf (f, "%c", '_');
} }
/* Finish off the currently-created root tables in FLP. PFX, TNAME, /* Finish off the currently-created root tables in FLP. PFX, TNAME,
...@@ -1468,8 +1461,8 @@ finish_root_table (flp, pfx, lastname, tname, name) ...@@ -1468,8 +1461,8 @@ finish_root_table (flp, pfx, lastname, tname, name)
for (fli2 = flp; fli2; fli2 = fli2->next) for (fli2 = flp; fli2; fli2 = fli2->next)
if (fli2->started_p) if (fli2->started_p)
{ {
fprintf (fli2->f, " %s\n", lastname); oprintf (fli2->f, " %s\n", lastname);
fputs ("};\n\n", fli2->f); oprintf (fli2->f, "};\n\n");
} }
for (fli2 = flp; fli2; fli2 = fli2->next) for (fli2 = flp; fli2; fli2 = fli2->next)
...@@ -1481,11 +1474,11 @@ finish_root_table (flp, pfx, lastname, tname, name) ...@@ -1481,11 +1474,11 @@ finish_root_table (flp, pfx, lastname, tname, name)
for (fnum = 0; bitmap != 0; fnum++, bitmap >>= 1) for (fnum = 0; bitmap != 0; fnum++, bitmap >>= 1)
if (bitmap & 1) if (bitmap & 1)
{ {
fprintf (base_files[fnum], oprintf (base_files[fnum],
"extern const struct %s gt_ggc_%s_", "extern const struct %s gt_ggc_%s_",
tname, pfx); tname, pfx);
put_mangled_filename (base_files[fnum], fli2->name); put_mangled_filename (base_files[fnum], fli2->name);
fputs ("[];\n", base_files[fnum]); oprintf (base_files[fnum], "[];\n");
} }
} }
...@@ -1502,14 +1495,14 @@ finish_root_table (flp, pfx, lastname, tname, name) ...@@ -1502,14 +1495,14 @@ finish_root_table (flp, pfx, lastname, tname, name)
{ {
if (! (started_bitmap & (1 << fnum))) if (! (started_bitmap & (1 << fnum)))
{ {
fprintf (base_files [fnum], oprintf (base_files [fnum],
"const struct %s * const %s[] = {\n", "const struct %s * const %s[] = {\n",
tname, name); tname, name);
started_bitmap |= 1 << fnum; started_bitmap |= 1 << fnum;
} }
fprintf (base_files[fnum], " gt_ggc_%s_", pfx); oprintf (base_files[fnum], " gt_ggc_%s_", pfx);
put_mangled_filename (base_files[fnum], fli2->name); put_mangled_filename (base_files[fnum], fli2->name);
fputs (",\n", base_files[fnum]); oprintf (base_files[fnum], ",\n");
} }
} }
...@@ -1520,8 +1513,8 @@ finish_root_table (flp, pfx, lastname, tname, name) ...@@ -1520,8 +1513,8 @@ finish_root_table (flp, pfx, lastname, tname, name)
for (bitmap = started_bitmap, fnum = 0; bitmap != 0; fnum++, bitmap >>= 1) for (bitmap = started_bitmap, fnum = 0; bitmap != 0; fnum++, bitmap >>= 1)
if (bitmap & 1) if (bitmap & 1)
{ {
fputs (" NULL\n", base_files[fnum]); oprintf (base_files[fnum], " NULL\n");
fputs ("};\n\n", base_files[fnum]); oprintf (base_files[fnum], "};\n\n");
} }
} }
} }
...@@ -1533,7 +1526,7 @@ finish_root_table (flp, pfx, lastname, tname, name) ...@@ -1533,7 +1526,7 @@ finish_root_table (flp, pfx, lastname, tname, name)
static void static void
write_gc_root (f, v, type, name, has_length, line, if_marked) write_gc_root (f, v, type, name, has_length, line, if_marked)
FILE *f; outf_p f;
pair_p v; pair_p v;
type_p type; type_p type;
const char *name; const char *name;
...@@ -1590,9 +1583,7 @@ write_gc_root (f, v, type, name, has_length, line, if_marked) ...@@ -1590,9 +1583,7 @@ write_gc_root (f, v, type, name, has_length, line, if_marked)
if (validf != NULL) if (validf != NULL)
{ {
char *newname; char *newname;
newname = xmalloc (strlen (name) + 3 + strlen (fld->name) newname = xasprintf ("%s.%s.%s",
+ strlen (validf->name));
sprintf (newname, "%s.%s.%s",
name, fld->name, validf->name); name, fld->name, validf->name);
write_gc_root (f, v, validf->type, newname, 0, line, write_gc_root (f, v, validf->type, newname, 0, line,
if_marked); if_marked);
...@@ -1606,8 +1597,7 @@ write_gc_root (f, v, type, name, has_length, line, if_marked) ...@@ -1606,8 +1597,7 @@ write_gc_root (f, v, type, name, has_length, line, if_marked)
else else
{ {
char *newname; char *newname;
newname = xmalloc (strlen (name) + 2 + strlen (fld->name)); newname = xasprintf ("%s.%s", name, fld->name);
sprintf (newname, "%s.%s", name, fld->name);
write_gc_root (f, v, fld->type, newname, 0, line, if_marked); write_gc_root (f, v, fld->type, newname, 0, line, if_marked);
free (newname); free (newname);
} }
...@@ -1618,8 +1608,7 @@ write_gc_root (f, v, type, name, has_length, line, if_marked) ...@@ -1618,8 +1608,7 @@ write_gc_root (f, v, type, name, has_length, line, if_marked)
case TYPE_ARRAY: case TYPE_ARRAY:
{ {
char *newname; char *newname;
newname = xmalloc (strlen (name) + 4); newname = xasprintf ("%s[0]", name);
sprintf (newname, "%s[0]", name);
write_gc_root (f, v, type->u.a.p, newname, has_length, line, if_marked); write_gc_root (f, v, type->u.a.p, newname, has_length, line, if_marked);
free (newname); free (newname);
} }
...@@ -1629,31 +1618,31 @@ write_gc_root (f, v, type, name, has_length, line, if_marked) ...@@ -1629,31 +1618,31 @@ write_gc_root (f, v, type, name, has_length, line, if_marked)
{ {
type_p ap, tp; type_p ap, tp;
fputs (" {\n", f); oprintf (f, " {\n");
fprintf (f, " &%s,\n", name); oprintf (f, " &%s,\n", name);
fputs (" 1", f); oprintf (f, " 1");
for (ap = v->type; ap->kind == TYPE_ARRAY; ap = ap->u.a.p) for (ap = v->type; ap->kind == TYPE_ARRAY; ap = ap->u.a.p)
if (ap->u.a.len[0]) if (ap->u.a.len[0])
fprintf (f, " * (%s)", ap->u.a.len); oprintf (f, " * (%s)", ap->u.a.len);
else if (ap == v->type) else if (ap == v->type)
fprintf (f, " * (sizeof (%s) / sizeof (%s[0]))", oprintf (f, " * (sizeof (%s) / sizeof (%s[0]))",
v->name, v->name); v->name, v->name);
fputs (",\n", f); oprintf (f, ",\n");
fprintf (f, " sizeof (%s", v->name); oprintf (f, " sizeof (%s", v->name);
for (ap = v->type; ap->kind == TYPE_ARRAY; ap = ap->u.a.p) for (ap = v->type; ap->kind == TYPE_ARRAY; ap = ap->u.a.p)
fputs ("[0]", f); oprintf (f, "[0]");
fputs ("),\n", f); oprintf (f, "),\n");
tp = type->u.p; tp = type->u.p;
if (! has_length && UNION_OR_STRUCT_P (tp)) if (! has_length && UNION_OR_STRUCT_P (tp))
{ {
fprintf (f, " &gt_ggc_mx_%s\n", tp->u.s.tag); oprintf (f, " &gt_ggc_mx_%s\n", tp->u.s.tag);
} }
else if (! has_length && tp->kind == TYPE_PARAM_STRUCT) else if (! has_length && tp->kind == TYPE_PARAM_STRUCT)
{ {
fprintf (f, " &gt_ggc_mm_%d%s_%s", oprintf (f, " &gt_ggc_mm_%d%s_%s",
(int) strlen (tp->u.param_struct.param->u.s.tag), (int) strlen (tp->u.param_struct.param->u.s.tag),
tp->u.param_struct.param->u.s.tag, tp->u.param_struct.param->u.s.tag,
tp->u.param_struct.stru->u.s.tag); tp->u.param_struct.stru->u.s.tag);
...@@ -1661,7 +1650,7 @@ write_gc_root (f, v, type, name, has_length, line, if_marked) ...@@ -1661,7 +1650,7 @@ write_gc_root (f, v, type, name, has_length, line, if_marked)
else if (has_length else if (has_length
&& (tp->kind == TYPE_POINTER || UNION_OR_STRUCT_P (tp))) && (tp->kind == TYPE_POINTER || UNION_OR_STRUCT_P (tp)))
{ {
fprintf (f, " &gt_ggc_ma_%s", name); oprintf (f, " &gt_ggc_ma_%s", name);
} }
else else
{ {
...@@ -1670,8 +1659,8 @@ write_gc_root (f, v, type, name, has_length, line, if_marked) ...@@ -1670,8 +1659,8 @@ write_gc_root (f, v, type, name, has_length, line, if_marked)
name); name);
} }
if (if_marked) if (if_marked)
fprintf (f, ",\n &%s", if_marked); oprintf (f, ",\n &%s", if_marked);
fputs ("\n },\n", f); oprintf (f, "\n },\n");
} }
break; break;
...@@ -1697,7 +1686,7 @@ write_gc_roots (variables) ...@@ -1697,7 +1686,7 @@ write_gc_roots (variables)
for (v = variables; v; v = v->next) for (v = variables; v; v = v->next)
{ {
FILE *f = get_output_file_with_visibility (v->line.file); outf_p f = get_output_file_with_visibility (v->line.file);
struct flist *fli; struct flist *fli;
const char *length = NULL; const char *length = NULL;
int deletable_p = 0; int deletable_p = 0;
...@@ -1729,7 +1718,7 @@ write_gc_roots (variables) ...@@ -1729,7 +1718,7 @@ write_gc_roots (variables)
fli->name = v->line.file; fli->name = v->line.file;
flp = fli; flp = fli;
fputs ("\n/* GC roots. */\n\n", f); oprintf (f, "\n/* GC roots. */\n\n");
} }
if (! deletable_p if (! deletable_p
...@@ -1738,22 +1727,22 @@ write_gc_roots (variables) ...@@ -1738,22 +1727,22 @@ write_gc_roots (variables)
&& (v->type->u.p->kind == TYPE_POINTER && (v->type->u.p->kind == TYPE_POINTER
|| v->type->u.p->kind == TYPE_STRUCT)) || v->type->u.p->kind == TYPE_STRUCT))
{ {
fprintf (f, "static void gt_ggc_ma_%s PARAMS ((void *));\n", oprintf (f, "static void gt_ggc_ma_%s PARAMS ((void *));\n",
v->name); v->name);
fprintf (f, "static void\ngt_ggc_ma_%s (x_p)\n void *x_p;\n", oprintf (f, "static void\ngt_ggc_ma_%s (x_p)\n void *x_p;\n",
v->name); v->name);
fputs ("{\n", f); oprintf (f, "{\n");
fputs (" size_t i;\n", f); oprintf (f, " size_t i;\n");
if (v->type->u.p->kind == TYPE_POINTER) if (v->type->u.p->kind == TYPE_POINTER)
{ {
type_p s = v->type->u.p->u.p; type_p s = v->type->u.p->u.p;
fprintf (f, " %s %s ** const x = (%s %s **)x_p;\n", oprintf (f, " %s %s ** const x = (%s %s **)x_p;\n",
s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag, s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag,
s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag); s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag);
fputs (" if (ggc_test_and_set_mark (x))\n", f); oprintf (f, " if (ggc_test_and_set_mark (x))\n");
fprintf (f, " for (i = 0; i < (%s); i++)\n", length); oprintf (f, " for (i = 0; i < (%s); i++)\n", length);
if (s->kind != TYPE_STRUCT && s->kind != TYPE_UNION) if (s->kind != TYPE_STRUCT && s->kind != TYPE_UNION)
{ {
error_at_line (&v->line, error_at_line (&v->line,
...@@ -1762,31 +1751,31 @@ write_gc_roots (variables) ...@@ -1762,31 +1751,31 @@ write_gc_roots (variables)
continue; continue;
} }
fprintf (f, " gt_ggc_m_%s (x[i]);\n", s->u.s.tag); oprintf (f, " gt_ggc_m_%s (x[i]);\n", s->u.s.tag);
} }
else else
{ {
type_p s = v->type->u.p; type_p s = v->type->u.p;
fprintf (f, " %s %s * const x = (%s %s *)x_p;\n", oprintf (f, " %s %s * const x = (%s %s *)x_p;\n",
s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag, s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag,
s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag); s->kind == TYPE_UNION ? "union" : "struct", s->u.s.tag);
fputs (" if (ggc_test_and_set_mark (x))\n", f); oprintf (f, " if (ggc_test_and_set_mark (x))\n");
fprintf (f, " for (i = 0; i < (%s); i++)\n", length); oprintf (f, " for (i = 0; i < (%s); i++)\n", length);
fputs (" {\n", f); oprintf (f, " {\n");
write_gc_structure_fields (f, s, "x[i]", "x[i]", write_gc_structure_fields (f, s, "x[i]", "x[i]",
v->opt, 8, &v->line, s->u.s.bitmap, v->opt, 8, &v->line, s->u.s.bitmap,
NULL); NULL);
fputs (" }\n", f); oprintf (f, " }\n");
} }
fputs ("}\n\n", f); oprintf (f, "}\n\n");
} }
} }
for (v = variables; v; v = v->next) for (v = variables; v; v = v->next)
{ {
FILE *f = get_output_file_with_visibility (v->line.file); outf_p f = get_output_file_with_visibility (v->line.file);
struct flist *fli; struct flist *fli;
int skip_p = 0; int skip_p = 0;
int length_p = 0; int length_p = 0;
...@@ -1809,9 +1798,9 @@ write_gc_roots (variables) ...@@ -1809,9 +1798,9 @@ write_gc_roots (variables)
{ {
fli->started_p = 1; fli->started_p = 1;
fputs ("const struct ggc_root_tab gt_ggc_r_", f); oprintf (f, "const struct ggc_root_tab gt_ggc_r_");
put_mangled_filename (f, v->line.file); put_mangled_filename (f, v->line.file);
fputs ("[] = {\n", f); oprintf (f, "[] = {\n");
} }
write_gc_root (f, v, v->type, v->name, length_p, &v->line, NULL); write_gc_root (f, v, v->type, v->name, length_p, &v->line, NULL);
...@@ -1822,7 +1811,7 @@ write_gc_roots (variables) ...@@ -1822,7 +1811,7 @@ write_gc_roots (variables)
for (v = variables; v; v = v->next) for (v = variables; v; v = v->next)
{ {
FILE *f = get_output_file_with_visibility (v->line.file); outf_p f = get_output_file_with_visibility (v->line.file);
struct flist *fli; struct flist *fli;
int skip_p = 1; int skip_p = 1;
options_p o; options_p o;
...@@ -1843,12 +1832,12 @@ write_gc_roots (variables) ...@@ -1843,12 +1832,12 @@ write_gc_roots (variables)
{ {
fli->started_p = 1; fli->started_p = 1;
fputs ("const struct ggc_root_tab gt_ggc_rd_", f); oprintf (f, "const struct ggc_root_tab gt_ggc_rd_");
put_mangled_filename (f, v->line.file); put_mangled_filename (f, v->line.file);
fputs ("[] = {\n", f); oprintf (f, "[] = {\n");
} }
fprintf (f, " { &%s, 1, sizeof (%s), NULL },\n", oprintf (f, " { &%s, 1, sizeof (%s), NULL },\n",
v->name, v->name); v->name, v->name);
} }
...@@ -1857,7 +1846,7 @@ write_gc_roots (variables) ...@@ -1857,7 +1846,7 @@ write_gc_roots (variables)
for (v = variables; v; v = v->next) for (v = variables; v; v = v->next)
{ {
FILE *f = get_output_file_with_visibility (v->line.file); outf_p f = get_output_file_with_visibility (v->line.file);
struct flist *fli; struct flist *fli;
const char *if_marked = NULL; const char *if_marked = NULL;
int length_p = 0; int length_p = 0;
...@@ -1887,9 +1876,9 @@ write_gc_roots (variables) ...@@ -1887,9 +1876,9 @@ write_gc_roots (variables)
{ {
fli->started_p = 1; fli->started_p = 1;
fputs ("const struct ggc_cache_tab gt_ggc_rc_", f); oprintf (f, "const struct ggc_cache_tab gt_ggc_rc_");
put_mangled_filename (f, v->line.file); put_mangled_filename (f, v->line.file);
fputs ("[] = {\n", f); oprintf (f, "[] = {\n");
} }
write_gc_root (f, v, create_pointer (v->type->u.p->u.param_struct.param), write_gc_root (f, v, create_pointer (v->type->u.p->u.param_struct.param),
......
...@@ -111,6 +111,13 @@ extern struct fileloc lexer_line; ...@@ -111,6 +111,13 @@ extern struct fileloc lexer_line;
extern void error_at_line extern void error_at_line
PARAMS ((struct fileloc *pos, const char *msg, ...)) ATTRIBUTE_PRINTF_2; PARAMS ((struct fileloc *pos, const char *msg, ...)) ATTRIBUTE_PRINTF_2;
/* Combines xmalloc() and vasprintf(). */
extern int xvasprintf PARAMS ((char **, const char *, va_list))
ATTRIBUTE_PRINTF (2, 0);
/* Like the above, but more convenient for quick coding. */
extern char * xasprintf PARAMS ((const char *, ...))
ATTRIBUTE_PRINTF_1;
/* Constructor routines for types. */ /* Constructor routines for types. */
extern void do_typedef PARAMS ((const char *s, type_p t, struct fileloc *pos)); extern void do_typedef PARAMS ((const char *s, type_p t, struct fileloc *pos));
extern type_p resolve_typedef PARAMS ((const char *s, struct fileloc *pos)); extern type_p resolve_typedef PARAMS ((const char *s, struct fileloc *pos));
...@@ -135,23 +142,38 @@ extern void parse_file PARAMS ((char *name)); ...@@ -135,23 +142,38 @@ extern void parse_file PARAMS ((char *name));
/* Output file handling. */ /* Output file handling. */
FILE *get_output_file PARAMS ((const char *input_file)); /* Structure representing an output file. */
const char *get_output_file_name PARAMS ((const char *)); struct outf
{
struct outf *next;
const char *name;
size_t buflength;
size_t bufused;
char *buf;
};
typedef struct outf * outf_p;
/* The output header file that is included into pretty much every /* The output header file that is included into pretty much every
source file. */ source file. */
extern FILE *header_file; extern outf_p header_file;
/* An output file, suitable for definitions, that can see declarations /* An output file, suitable for definitions, that can see declarations
made in INPUT_FILE and is linked into every language that uses made in INPUT_FILE and is linked into every language that uses
INPUT_FILE. */ INPUT_FILE. */
extern FILE *get_output_file_with_visibility PARAMS ((const char *input_file)); extern outf_p get_output_file_with_visibility
PARAMS ((const char *input_file));
const char *get_output_file_name PARAMS ((const char *));
/* A list of output files suitable for definitions. There is one /* A list of output files suitable for definitions. There is one
BASE_FILES entry for each language. */ BASE_FILES entry for each language. */
extern FILE *base_files[]; extern outf_p base_files[];
/* A bitmap that specifies which of BASE_FILES should be used to /* A bitmap that specifies which of BASE_FILES should be used to
output a definition that is different for each language and must be output a definition that is different for each language and must be
defined once in each language that uses INPUT_FILE. */ defined once in each language that uses INPUT_FILE. */
extern lang_bitmap get_base_file_bitmap PARAMS ((const char *input_file)); extern lang_bitmap get_base_file_bitmap PARAMS ((const char *input_file));
/* Print, like fprintf, to O. */
extern void oprintf PARAMS ((outf_p o, const char *S, ...))
ATTRIBUTE_PRINTF_2;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment