Commit 1d32bbcd by Basile Starynkevitch Committed by Basile Starynkevitch

gengtype.c (verbosity_level): Added variable.

2010-10-18  Basile Starynkevitch  <basile@starynkevitch.net>
	    Jeremie Salvucci  <jeremie.salvucci@free.fr>

	* gengtype.c (verbosity_level): Added variable.
	(set_gc_used): Count variables for verbosity.
	(close_output_files): Backing up files, counting written ones
	verbosily.
	(write_types): Count emitted functions for verbosity. Added
	debug messages.
	(write_enum_defn): Count structures for verbosity. Added debug
	messages.
	(gengtype_long_options): Added "verbose" & "backupdir".
	(print_usage): Ditto.
	(main): Verbose display of parsed files.

	* gengtype.h (verbosity_level): Added declaration.


Co-Authored-By: Jeremie Salvucci <jeremie.salvucci@free.fr>

From-SVN: r165609
parent dad22268
2010-10-18 Basile Starynkevitch <basile@starynkevitch.net> 2010-10-18 Basile Starynkevitch <basile@starynkevitch.net>
Jeremie Salvucci <jeremie.salvucci@free.fr>
* gengtype.c (verbosity_level): Added variable.
(set_gc_used): Count variables for verbosity.
(close_output_files): Backing up files, counting written ones
verbosily.
(write_types): Count emitted functions for verbosity. Added
debug messages.
(write_enum_defn): Count structures for verbosity. Added debug
messages.
(gengtype_long_options): Added "verbose" & "backupdir".
(print_usage): Ditto.
(main): Verbose display of parsed files.
* gengtype.h (verbosity_level): Added declaration.
2010-10-18 Basile Starynkevitch <basile@starynkevitch.net>
* gengtype.c (parse_program_options): Added allocation of * gengtype.c (parse_program_options): Added allocation of
plugin_files, and corrected test on nb_plugin_files. plugin_files, and corrected test on nb_plugin_files.
...@@ -163,6 +163,15 @@ const char *write_state_filename; ...@@ -163,6 +163,15 @@ const char *write_state_filename;
int do_dump; int do_dump;
int do_debug; int do_debug;
/* Level for verbose messages. */
int verbosity_level;
/* The backup directory should be in the same file system as the
generated files, otherwise the rename(2) system call would fail.
If NULL, no backup is made when overwriting a generated file. */
static const char* backup_dir; /* (-B) program option. */
static outf_p create_file (const char *, const char *); static outf_p create_file (const char *, const char *);
static const char *get_file_basename (const char *); static const char *get_file_basename (const char *);
...@@ -1515,9 +1524,15 @@ set_gc_used_type (type_p t, enum gc_used_enum level, type_p param[NUM_PARAM]) ...@@ -1515,9 +1524,15 @@ set_gc_used_type (type_p t, enum gc_used_enum level, type_p param[NUM_PARAM])
static void static void
set_gc_used (pair_p variables) set_gc_used (pair_p variables)
{ {
int nbvars = 0;
pair_p p; pair_p p;
for (p = variables; p; p = p->next) for (p = variables; p; p = p->next)
set_gc_used_type (p->type, GC_USED, NULL); {
set_gc_used_type (p->type, GC_USED, NULL);
nbvars++;
};
if (verbosity_level >= 2)
printf ("%s used %d GTY-ed variables\n", progname, nbvars);
} }
/* File mapping routines. For each input file, there is one output .c file /* File mapping routines. For each input file, there is one output .c file
...@@ -1907,6 +1922,7 @@ is_file_equal (outf_p of) ...@@ -1907,6 +1922,7 @@ is_file_equal (outf_p of)
static void static void
close_output_files (void) close_output_files (void)
{ {
int nbwrittenfiles = 0;
outf_p of; outf_p of;
for (of = output_files; of; of = of->next) for (of = output_files; of; of = of->next)
...@@ -1914,18 +1930,46 @@ close_output_files (void) ...@@ -1914,18 +1930,46 @@ close_output_files (void)
if (!is_file_equal (of)) if (!is_file_equal (of))
{ {
FILE *newfile = fopen (of->name, "w"); FILE *newfile = NULL;
char *backupname = NULL;
/* Back up the old version of the output file gt-FOO.c as
BACKUPDIR/gt-FOO.c~ if we have a backup directory. */
if (backup_dir)
{
backupname = concat (backup_dir, "/",
lbasename (of->name), "~", NULL);
if (!access (of->name, F_OK) && rename (of->name, backupname))
fatal ("failed to back up %s as %s: %s",
of->name, backupname, xstrerror (errno));
}
newfile = fopen (of->name, "w");
if (newfile == NULL) if (newfile == NULL)
fatal ("opening output file %s: %s", of->name, xstrerror (errno)); fatal ("opening output file %s: %s", of->name, xstrerror (errno));
if (fwrite (of->buf, 1, of->bufused, newfile) != of->bufused) if (fwrite (of->buf, 1, of->bufused, newfile) != of->bufused)
fatal ("writing output file %s: %s", of->name, xstrerror (errno)); fatal ("writing output file %s: %s", of->name, xstrerror (errno));
if (fclose (newfile) != 0) if (fclose (newfile) != 0)
fatal ("closing output file %s: %s", of->name, xstrerror (errno)); fatal ("closing output file %s: %s", of->name, xstrerror (errno));
nbwrittenfiles++;
if (verbosity_level >= 2 && backupname)
printf ("%s wrote #%-3d %s backed-up in %s\n",
progname, nbwrittenfiles, of->name, backupname);
else if (verbosity_level >= 1)
printf ("%s write #%-3d %s\n", progname, nbwrittenfiles, of->name);
free (backupname);
}
else
{
/* output file remains unchanged. */
if (verbosity_level >= 2)
printf ("%s keep %s\n", progname, of->name);
} }
free (of->buf); free (of->buf);
of->buf = NULL; of->buf = NULL;
of->bufused = of->buflength = 0; of->bufused = of->buflength = 0;
} }
if (verbosity_level >= 1)
printf ("%s wrote %d files.\n", progname, nbwrittenfiles);
} }
struct flist struct flist
...@@ -2801,6 +2845,7 @@ static void ...@@ -2801,6 +2845,7 @@ static void
write_types (outf_p output_header, type_p structures, type_p param_structs, write_types (outf_p output_header, type_p structures, type_p param_structs,
const struct write_types_data *wtd) const struct write_types_data *wtd)
{ {
int nbfun = 0; /* Count the emitted functions. */
type_p s; type_p s;
oprintf (output_header, "\n/* %s*/\n", wtd->comment); oprintf (output_header, "\n/* %s*/\n", wtd->comment);
...@@ -2890,11 +2935,29 @@ write_types (outf_p output_header, type_p structures, type_p param_structs, ...@@ -2890,11 +2935,29 @@ write_types (outf_p output_header, type_p structures, type_p param_structs,
{ {
type_p ss; type_p ss;
for (ss = s->u.s.lang_struct; ss; ss = ss->next) for (ss = s->u.s.lang_struct; ss; ss = ss->next)
write_func_for_structure (s, ss, NULL, wtd); {
nbfun++;
DBGPRINTF ("writing func #%d lang_struct ss @ %p '%s'",
nbfun, (void*) ss, ss->u.s.tag);
write_func_for_structure (s, ss, NULL, wtd);
}
} }
else else
write_func_for_structure (s, s, NULL, wtd); {
nbfun++;
DBGPRINTF ("writing func #%d struct s @ %p '%s'",
nbfun, (void*) s, s->u.s.tag);
write_func_for_structure (s, s, NULL, wtd);
}
} }
else
{
/* Structure s is not possibly pointed to, so can be ignored. */
DBGPRINTF ("ignored s @ %p '%s' gc_used#%d",
(void*)s, s->u.s.tag,
(int) s->gc_used);
}
for (s = param_structs; s; s = s->next) for (s = param_structs; s; s = s->next)
if (s->gc_used == GC_POINTED_TO) if (s->gc_used == GC_POINTED_TO)
{ {
...@@ -2906,11 +2969,30 @@ write_types (outf_p output_header, type_p structures, type_p param_structs, ...@@ -2906,11 +2969,30 @@ write_types (outf_p output_header, type_p structures, type_p param_structs,
{ {
type_p ss; type_p ss;
for (ss = stru->u.s.lang_struct; ss; ss = ss->next) for (ss = stru->u.s.lang_struct; ss; ss = ss->next)
write_func_for_structure (s, ss, param, wtd); {
nbfun++;
DBGPRINTF ("writing func #%d param lang_struct ss @ %p '%s'",
nbfun, (void*) ss, ss->u.s.tag);
write_func_for_structure (s, ss, param, wtd);
}
} }
else else
write_func_for_structure (s, stru, param, wtd); {
nbfun++;
DBGPRINTF ("writing func #%d param struct s @ %p stru @ %p '%s'",
nbfun, (void*) s,
(void*) stru, stru->u.s.tag);
write_func_for_structure (s, stru, param, wtd);
}
}
else
{
/* Param structure s is not pointed to, so should be ignored. */
DBGPRINTF ("ignored s @ %p", (void*)s);
} }
if (verbosity_level >= 2)
printf ("%s emitted %d routines for %s\n",
progname, nbfun, wtd->comment);
} }
static const struct write_types_data ggc_wtd = { static const struct write_types_data ggc_wtd = {
...@@ -3100,6 +3182,8 @@ static void ...@@ -3100,6 +3182,8 @@ static void
write_enum_defn (type_p structures, type_p param_structs) write_enum_defn (type_p structures, type_p param_structs)
{ {
type_p s; type_p s;
int nbstruct = 0;
int nbparamstruct = 0;
if (!header_file) if (!header_file)
return; return;
...@@ -3108,6 +3192,12 @@ write_enum_defn (type_p structures, type_p param_structs) ...@@ -3108,6 +3192,12 @@ write_enum_defn (type_p structures, type_p param_structs)
for (s = structures; s; s = s->next) for (s = structures; s; s = s->next)
if (USED_BY_TYPED_GC_P (s)) if (USED_BY_TYPED_GC_P (s))
{ {
nbstruct++;
DBGPRINTF ("write_enum_defn s @ %p nbstruct %d",
(void*) s, nbstruct);
if (UNION_OR_STRUCT_P (s))
DBGPRINTF ("write_enum_defn s %p #%d is unionorstruct tagged %s",
(void*) s, nbstruct, s->u.s.tag);
oprintf (header_file, " gt_ggc_e_"); oprintf (header_file, " gt_ggc_e_");
output_mangled_typename (header_file, s); output_mangled_typename (header_file, s);
oprintf (header_file, ",\n"); oprintf (header_file, ",\n");
...@@ -3115,12 +3205,19 @@ write_enum_defn (type_p structures, type_p param_structs) ...@@ -3115,12 +3205,19 @@ write_enum_defn (type_p structures, type_p param_structs)
for (s = param_structs; s; s = s->next) for (s = param_structs; s; s = s->next)
if (s->gc_used == GC_POINTED_TO) if (s->gc_used == GC_POINTED_TO)
{ {
nbparamstruct++;
DBGPRINTF ("write_enum_defn s %p nbparamstruct %d",
(void*) s, nbparamstruct);
oprintf (header_file, " gt_e_"); oprintf (header_file, " gt_e_");
output_mangled_typename (header_file, s); output_mangled_typename (header_file, s);
oprintf (header_file, ",\n"); oprintf (header_file, ",\n");
} }
oprintf (header_file, " gt_types_enum_last\n"); oprintf (header_file, " gt_types_enum_last\n");
oprintf (header_file, "};\n"); oprintf (header_file, "};\n");
if (verbosity_level >= 2)
printf ("%s handled %d GTY-ed structures & %d parameterized structures.\n",
progname, nbstruct, nbparamstruct);
} }
/* Might T contain any non-pointer elements? */ /* Might T contain any non-pointer elements? */
...@@ -4289,10 +4386,12 @@ dump_everything (void) ...@@ -4289,10 +4386,12 @@ dump_everything (void)
static const struct option gengtype_long_options[] = { static const struct option gengtype_long_options[] = {
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'}, {"version", no_argument, NULL, 'V'},
{"verbose", no_argument, NULL, 'v'},
{"dump", no_argument, NULL, 'd'}, {"dump", no_argument, NULL, 'd'},
{"debug", no_argument, NULL, 'D'}, {"debug", no_argument, NULL, 'D'},
{"plugin", required_argument, NULL, 'P'}, {"plugin", required_argument, NULL, 'P'},
{"srcdir", required_argument, NULL, 'S'}, {"srcdir", required_argument, NULL, 'S'},
{"backupdir", required_argument, NULL, 'B'},
{"inputs", required_argument, NULL, 'I'}, {"inputs", required_argument, NULL, 'I'},
{"read-state", required_argument, NULL, 'r'}, {"read-state", required_argument, NULL, 'r'},
{"write-state", required_argument, NULL, 'w'}, {"write-state", required_argument, NULL, 'w'},
...@@ -4309,11 +4408,14 @@ print_usage (void) ...@@ -4309,11 +4408,14 @@ print_usage (void)
printf ("\t -D | --debug " printf ("\t -D | --debug "
" \t# Give debug output to debug %s itself.\n", progname); " \t# Give debug output to debug %s itself.\n", progname);
printf ("\t -V | --version " " \t# Give version information.\n"); printf ("\t -V | --version " " \t# Give version information.\n");
printf ("\t -v | --verbose \t# Increase verbosity. Can be given several times.\n");
printf ("\t -d | --dump " " \t# Dump state for debugging.\n"); printf ("\t -d | --dump " " \t# Dump state for debugging.\n");
printf ("\t -P | --plugin <output-file> <plugin-src> ... " printf ("\t -P | --plugin <output-file> <plugin-src> ... "
" \t# Generate for plugin.\n"); " \t# Generate for plugin.\n");
printf ("\t -S | --srcdir <GCC-directory> " printf ("\t -S | --srcdir <GCC-directory> "
" \t# Specify the GCC source directory.\n"); " \t# Specify the GCC source directory.\n");
printf ("\t -B | --backupdir <directory> "
" \t# Specify the backup directory for updated files.\n");
printf ("\t -I | --inputs <input-list> " printf ("\t -I | --inputs <input-list> "
" \t# Specify the file with source files list.\n"); " \t# Specify the file with source files list.\n");
printf ("\t -w | --write-state <state-file> " " \t# Write a state file.\n"); printf ("\t -w | --write-state <state-file> " " \t# Write a state file.\n");
...@@ -4332,7 +4434,7 @@ static void ...@@ -4332,7 +4434,7 @@ static void
parse_program_options (int argc, char **argv) parse_program_options (int argc, char **argv)
{ {
int opt = -1; int opt = -1;
while ((opt = getopt_long (argc, argv, "hVdP:S:I:w:r:D", while ((opt = getopt_long (argc, argv, "hVvdP:S:B:I:w:r:D",
gengtype_long_options, NULL)) >= 0) gengtype_long_options, NULL)) >= 0)
{ {
switch (opt) switch (opt)
...@@ -4349,6 +4451,9 @@ parse_program_options (int argc, char **argv) ...@@ -4349,6 +4451,9 @@ parse_program_options (int argc, char **argv)
case 'D': /* --debug */ case 'D': /* --debug */
do_debug = 1; do_debug = 1;
break; break;
case 'v': /* --verbose */
verbosity_level++;
break;
case 'P': /* --plugin */ case 'P': /* --plugin */
if (optarg) if (optarg)
plugin_output_filename = optarg; plugin_output_filename = optarg;
...@@ -4362,6 +4467,12 @@ parse_program_options (int argc, char **argv) ...@@ -4362,6 +4467,12 @@ parse_program_options (int argc, char **argv)
fatal ("missing source directory"); fatal ("missing source directory");
srcdir_len = strlen (srcdir); srcdir_len = strlen (srcdir);
break; break;
case 'B': /* --backupdir */
if (optarg)
backup_dir = optarg;
else
fatal ("missing backup directory");
break;
case 'I': /* --inputs */ case 'I': /* --inputs */
if (optarg) if (optarg)
inputlist = optarg; inputlist = optarg;
...@@ -4470,6 +4581,9 @@ main (int argc, char **argv) ...@@ -4470,6 +4581,9 @@ main (int argc, char **argv)
parse_file (gt_files[i]); parse_file (gt_files[i]);
DBGPRINTF ("parsed file #%d %s", (int) i, gt_files[i]); DBGPRINTF ("parsed file #%d %s", (int) i, gt_files[i]);
} }
if (verbosity_level >= 1)
printf ("%s parsed %d files\n", progname, (int) num_gt_files);
DBGPRINT_COUNT_TYPE ("structures after parsing", structures); DBGPRINT_COUNT_TYPE ("structures after parsing", structures);
DBGPRINT_COUNT_TYPE ("param_structs after parsing", param_structs); DBGPRINT_COUNT_TYPE ("param_structs after parsing", param_structs);
......
...@@ -160,6 +160,9 @@ enum ...@@ -160,6 +160,9 @@ enum
}; };
/* Level for verbose messages, e.g. output file generation... */
extern int verbosity_level; /* (-v) program argument. */
/* For debugging purposes we provide two flags. */ /* For debugging purposes we provide two flags. */
/* Dump everything to understand gengtype's state. Might be useful to /* Dump everything to understand gengtype's state. Might be useful to
......
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