gentype-state.c: Add new file.

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

	* gentype-state.c: Add new file.

	* gengtype.c (type count): New variable.
	(new_structure, find_param_structure, create_pointer)
	(create_array): Use it to set state_number in types.
	(dump_everything): Improve comment.
	(main): Call read_state and write_state. Print type_count.

	* gengtype.h (type_lineloc): New function.
	(read_state, write_state): New declarations.

	* Makefile.in (GENGTYPE_FLAGS): New variable.
	(s-gtype): Run gengtype twice and generate gtype.state.
	(build/gengtype-state.o): New rule.
	(build/gengtype$(build_exeext)): Link gengtype-state.o.
	(mostlyclean): Update comment.  Remove gtype.state.


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

From-SVN: r167150
This commit is contained in:
Basile Starynkevitch 2010-11-25 19:03:27 +00:00 committed by Basile Starynkevitch
parent f759884521
commit 92724e1d70
5 changed files with 2533 additions and 11 deletions

View File

@ -1,3 +1,23 @@
2010-11-25 Basile Starynkevitch <basile@starynkevitch.net>
Jeremie Salvucci <jeremie.salvucci@free.fr>
* gentype-state.c: Add new file.
* gengtype.c (type count): New variable.
(new_structure, find_param_structure, create_pointer)
(create_array): Use it to set state_number in types.
(dump_everything): Improve comment.
(main): Call read_state and write_state. Print type_count.
* gengtype.h (type_lineloc): New function.
(read_state, write_state): New declarations.
* Makefile.in (GENGTYPE_FLAGS): New variable.
(s-gtype): Run gengtype twice and generate gtype.state.
(build/gengtype-state.o): New rule.
(build/gengtype$(build_exeext)): Link gengtype-state.o.
(mostlyclean): Update comment. Remove gtype.state.
2010-11-25 Jakub Jelinek <jakub@redhat.com> 2010-11-25 Jakub Jelinek <jakub@redhat.com>
PR middle-end/46637 PR middle-end/46637

View File

@ -3819,6 +3819,9 @@ ALL_GTFILES_H := $(sort $(GTFILES_H) $(GTFILES_LANG_H))
$(ALL_GTFILES_H) gtype-desc.c gtype-desc.h : s-gtype ; @true $(ALL_GTFILES_H) gtype-desc.c gtype-desc.h : s-gtype ; @true
### Common flags to gengtype [e.g. -v or -B backupdir]
GENGTYPE_FLAGS=
gtyp-input.list: s-gtyp-input ; @true gtyp-input.list: s-gtyp-input ; @true
s-gtyp-input: Makefile s-gtyp-input: Makefile
@: $(call write_entries_to_file,$(GTFILES),tmp-gi.list) @: $(call write_entries_to_file,$(GTFILES),tmp-gi.list)
@ -3827,7 +3830,13 @@ s-gtyp-input: Makefile
s-gtype: build/gengtype$(build_exeext) $(filter-out [%], $(GTFILES)) \ s-gtype: build/gengtype$(build_exeext) $(filter-out [%], $(GTFILES)) \
gtyp-input.list gtyp-input.list
$(RUN_GEN) build/gengtype$(build_exeext) -S $(srcdir) -I gtyp-input.list # First, parse all files and save a state file.
$(RUN_GEN) build/gengtype$(build_exeext) $(GENGTYPE_FLAGS) \
-S $(srcdir) -I gtyp-input.list -w gtype.state
# Second, read the state file and generate all files. This ensure that
# gtype.state is correctly read:
$(RUN_GEN) build/gengtype$(build_exeext) $(GENGTYPE_FLAGS) \
-r gtype.state
$(STAMP) s-gtype $(STAMP) s-gtype
generated_files = config.h tm.h $(TM_P_H) $(TM_H) multilib.h \ generated_files = config.h tm.h $(TM_P_H) $(TM_H) multilib.h \
@ -3923,6 +3932,8 @@ build/gengenrtl.o : gengenrtl.c $(BCONFIG_H) $(SYSTEM_H) rtl.def
build/gengtype-lex.o : gengtype-lex.c gengtype.h $(BCONFIG_H) $(SYSTEM_H) build/gengtype-lex.o : gengtype-lex.c gengtype.h $(BCONFIG_H) $(SYSTEM_H)
build/gengtype-parse.o : gengtype-parse.c gengtype.h $(BCONFIG_H) \ build/gengtype-parse.o : gengtype-parse.c gengtype.h $(BCONFIG_H) \
$(SYSTEM_H) $(SYSTEM_H)
build/gengtype-state.o: gengtype-state.c gengtype.h $(BCONFIG_H) \
$(SYSTEM_H) errors.h
build/gengtype.o : gengtype.c $(BCONFIG_H) $(SYSTEM_H) gengtype.h \ build/gengtype.o : gengtype.c $(BCONFIG_H) $(SYSTEM_H) gengtype.h \
rtl.def insn-notes.def errors.h double-int.h $(HASHTAB_H) \ rtl.def insn-notes.def errors.h double-int.h $(HASHTAB_H) \
$(OBSTACK_H) $(XREGEX_H) $(OBSTACK_H) $(XREGEX_H)
@ -3968,7 +3979,7 @@ build/genautomata$(build_exeext) : BUILD_LIBS += -lm
# These programs are not linked with the MD reader. # These programs are not linked with the MD reader.
build/gengtype$(build_exeext) : build/gengtype-lex.o build/gengtype-parse.o \ build/gengtype$(build_exeext) : build/gengtype-lex.o build/gengtype-parse.o \
build/version.o build/gengtype-state.o build/version.o
# Rule for the generator programs: # Rule for the generator programs:
$(genprog:%=build/gen%$(build_exeext)): build/gen%$(build_exeext): build/gen%.o $(BUILD_LIBDEPS) $(genprog:%=build/gen%$(build_exeext)): build/gen%$(build_exeext): build/gen%.o $(BUILD_LIBDEPS)
@ -4441,9 +4452,10 @@ mostlyclean: lang.mostlyclean
-rm -f core */core -rm -f core */core
# Delete file generated for gengtype # Delete file generated for gengtype
-rm -f gtyp-input.list -rm -f gtyp-input.list
# Delete files generated by gengtype.c # Delete files generated by gengtype
-rm -f gtype-* -rm -f gtype-*
-rm -f gt-* -rm -f gt-*
-rm -f gtype.state
# Delete genchecksum outputs # Delete genchecksum outputs
-rm -f *-checksum.c -rm -f *-checksum.c

2439
gcc/gengtype-state.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -67,6 +67,10 @@ int do_debug;
/* Level for verbose messages. */ /* Level for verbose messages. */
int verbosity_level; int verbosity_level;
/* We have a type count and use it to set the state_number of newly
allocated types to some unique negative number. */
static int type_count;
/* The backup directory should be in the same file system as the /* The backup directory should be in the same file system as the
generated files, otherwise the rename(2) system call would fail. generated files, otherwise the rename(2) system call would fail.
If NULL, no backup is made when overwriting a generated file. */ If NULL, no backup is made when overwriting a generated file. */
@ -563,12 +567,14 @@ new_structure (const char *name, int isunion, struct fileloc *pos,
else if (si->u.s.line.file != NULL && si->u.s.bitmap != bitmap) else if (si->u.s.line.file != NULL && si->u.s.bitmap != bitmap)
{ {
ls = si; ls = si;
type_count++;
si = XCNEW (struct type); si = XCNEW (struct type);
memcpy (si, ls, sizeof (struct type)); memcpy (si, ls, sizeof (struct type));
ls->kind = TYPE_LANG_STRUCT; ls->kind = TYPE_LANG_STRUCT;
ls->u.s.lang_struct = si; ls->u.s.lang_struct = si;
ls->u.s.fields = NULL; ls->u.s.fields = NULL;
si->next = NULL; si->next = NULL;
si->state_number = -type_count;
si->pointer_to = NULL; si->pointer_to = NULL;
si->u.s.lang_struct = ls; si->u.s.lang_struct = ls;
} }
@ -577,7 +583,9 @@ new_structure (const char *name, int isunion, struct fileloc *pos,
if (ls != NULL && s == NULL) if (ls != NULL && s == NULL)
{ {
type_count++;
s = XCNEW (struct type); s = XCNEW (struct type);
s->state_number = -type_count;
s->next = ls->u.s.lang_struct; s->next = ls->u.s.lang_struct;
ls->u.s.lang_struct = s; ls->u.s.lang_struct = s;
s->u.s.lang_struct = ls; s->u.s.lang_struct = ls;
@ -587,7 +595,9 @@ new_structure (const char *name, int isunion, struct fileloc *pos,
if (s == NULL) if (s == NULL)
{ {
type_count++;
s = XCNEW (struct type); s = XCNEW (struct type);
s->state_number = -type_count;
s->next = structures; s->next = structures;
structures = s; structures = s;
} }
@ -625,8 +635,10 @@ find_structure (const char *name, int isunion)
if (strcmp (name, s->u.s.tag) == 0 && UNION_P (s) == isunion) if (strcmp (name, s->u.s.tag) == 0 && UNION_P (s) == isunion)
return s; return s;
type_count++;
s = XCNEW (struct type); s = XCNEW (struct type);
s->next = structures; s->next = structures;
s->state_number = -type_count;
structures = s; structures = s;
s->kind = isunion ? TYPE_UNION : TYPE_STRUCT; s->kind = isunion ? TYPE_UNION : TYPE_STRUCT;
s->u.s.tag = name; s->u.s.tag = name;
@ -650,9 +662,11 @@ find_param_structure (type_p t, type_p param[NUM_PARAM])
break; break;
if (res == NULL) if (res == NULL)
{ {
type_count++;
res = XCNEW (struct type); res = XCNEW (struct type);
res->kind = TYPE_PARAM_STRUCT; res->kind = TYPE_PARAM_STRUCT;
res->next = param_structs; res->next = param_structs;
res->state_number = -type_count;
param_structs = res; param_structs = res;
res->u.param_struct.stru = t; res->u.param_struct.stru = t;
memcpy (res->u.param_struct.param, param, sizeof (type_p) * NUM_PARAM); memcpy (res->u.param_struct.param, param, sizeof (type_p) * NUM_PARAM);
@ -679,6 +693,8 @@ create_pointer (type_p t)
if (!t->pointer_to) if (!t->pointer_to)
{ {
type_p r = XCNEW (struct type); type_p r = XCNEW (struct type);
type_count++;
r->state_number = -type_count;
r->kind = TYPE_POINTER; r->kind = TYPE_POINTER;
r->u.p = t; r->u.p = t;
t->pointer_to = r; t->pointer_to = r;
@ -693,8 +709,10 @@ create_array (type_p t, const char *len)
{ {
type_p v; type_p v;
type_count++;
v = XCNEW (struct type); v = XCNEW (struct type);
v->kind = TYPE_ARRAY; v->kind = TYPE_ARRAY;
v->state_number = -type_count;
v->u.a.p = t; v->u.a.p = t;
v->u.a.len = len; v->u.a.len = len;
return v; return v;
@ -4600,7 +4618,9 @@ dump_structures (const char *name, type_p structures)
printf ("End of %s\n\n", name); printf ("End of %s\n\n", name);
} }
/* Dumps the internal structures of gengtype. */ /* Dumps the internal structures of gengtype. This is useful to debug
gengtype itself, or to understand what it does, e.g. for plugin
developers. */
static void static void
dump_everything (void) dump_everything (void)
@ -4836,8 +4856,12 @@ main (int argc, char **argv)
DBGPRINTF ("inputlist %s", inputlist); DBGPRINTF ("inputlist %s", inputlist);
if (read_state_filename) if (read_state_filename)
{ {
fatal ("read state %s not implemented yet", read_state_filename); if (inputlist)
/* TODO: implement read state. */ fatal ("input list %s cannot be given with a read state file %s",
inputlist, read_state_filename);
read_state (read_state_filename);
DBGPRINT_COUNT_TYPE ("structures after read_state", structures);
DBGPRINT_COUNT_TYPE ("param_structs after read_state", param_structs);
} }
else if (inputlist) else if (inputlist)
{ {
@ -4867,7 +4891,8 @@ main (int argc, char **argv)
(int) i, get_input_file_name (gt_files[i])); (int) i, get_input_file_name (gt_files[i]));
} }
if (verbosity_level >= 1) if (verbosity_level >= 1)
printf ("%s parsed %d files\n", progname, (int) num_gt_files); printf ("%s parsed %d files with %d GTY types\n",
progname, (int) num_gt_files, type_count);
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);
@ -4892,7 +4917,7 @@ main (int argc, char **argv)
fatal ("No plugin files given in plugin mode for %s", fatal ("No plugin files given in plugin mode for %s",
plugin_output_filename); plugin_output_filename);
/* Parse our plugin files. */ /* Parse our plugin files and augment the state. */
for (ix = 0; ix < nb_plugin_files; ix++) for (ix = 0; ix < nb_plugin_files; ix++)
parse_file (get_input_file_name (plugin_files[ix])); parse_file (get_input_file_name (plugin_files[ix]));
@ -4917,11 +4942,30 @@ main (int argc, char **argv)
hence enlarge the param_structs list of types. */ hence enlarge the param_structs list of types. */
set_gc_used (variables); set_gc_used (variables);
/* We should write the state here, but it is not yet implemented. */ /* The state at this point is read from the state input file or by
parsing source files and optionally augmented by parsing plugin
source files. Write it now. */
if (write_state_filename) if (write_state_filename)
{ {
fatal ("write state %s in not yet implemented", write_state_filename); DBGPRINT_COUNT_TYPE ("structures before write_state", structures);
/* TODO: implement write state. */ DBGPRINT_COUNT_TYPE ("param_structs before write_state", param_structs);
if (hit_error)
fatal ("didn't write state file %s after errors",
write_state_filename);
DBGPRINTF ("before write_state %s", write_state_filename);
write_state (write_state_filename);
if (do_dump)
dump_everything ();
/* After having written the state file we return immediately to
avoid generating any output file. */
if (hit_error)
return 1;
else
return 0;
} }

View File

@ -374,6 +374,13 @@ extern size_t srcdir_len;
extern const char *read_state_filename; /* (-r) program argument. */ extern const char *read_state_filename; /* (-r) program argument. */
extern const char *write_state_filename; /* (-w) program argument. */ extern const char *write_state_filename; /* (-w) program argument. */
/* Functions reading and writing the entire gengtype state, called from
main, and implemented in file gengtype-state.c. */
void read_state (const char* path);
/* Write the state, and update the state_number field in types. */
void write_state (const char* path);
/* Print an error message. */ /* Print an error message. */
extern void error_at_line extern void error_at_line
(const struct fileloc *pos, const char *msg, ...) ATTRIBUTE_PRINTF_2; (const struct fileloc *pos, const char *msg, ...) ATTRIBUTE_PRINTF_2;