Commit 11a67599 by Zack Weinberg Committed by Zack Weinberg

gengtype.c: Don't include gtyp-gen.h.

	* gengtype.c: Don't include gtyp-gen.h.
	(srcdir): Declare here.
	(base_files, lang_dir_names): Allocate dynamically.
	(gt_files, num_gt_files, num_lang_dirs): New globals.
	(measure_input_list, read_input_line, read_input_list)
	(set_lang_bitmap): New functions.
	(get_base_file_bitmap): Rename get_lang_bitmap and drastically
	simplify, relying on read_input_list to set up the bitmaps.
	(main): Arguments are no longer unused.  Check for correct number
	of command line arguments, set srcdir and srcdir_len, then call
	read_input_list, before doing anything else.  No need to worry
	about duplicates in main loop.
	* configure.ac: Simplify the calculation of all_gtfiles.
	Put language tags in there.  Don't set or substitute
	all_gtfiles_files_langs or all_gtfiles_files_frags.
	* Makefile.in: Revamp the way gengtype is invoked, now that it
	takes a file on its command line with a much simpler format.
	Remove or replace with gtyp-input.list all references to gtyp-gen.h.
	(GTFILES): Remove duplicates and C source files.
	* c-config-lang.in, cp/config-lang.in, objc/config-lang.in
	* objcp/config-lang.in: Add c-pragma.h to gtfiles.
	* configure: Regenerate.

From-SVN: r123234
parent 065ae611
This source diff could not be displayed because it is too large. You can view the blob instead.
2007-03-26 Zack Weinberg <zackw@panix.com> 2007-03-26 Zack Weinberg <zackw@panix.com>
* gengtype.c: Don't include gtyp-gen.h.
(srcdir): Declare here.
(base_files, lang_dir_names): Allocate dynamically.
(gt_files, num_gt_files, num_lang_dirs): New globals.
(measure_input_list, read_input_line, read_input_list)
(set_lang_bitmap): New functions.
(get_base_file_bitmap): Rename get_lang_bitmap and drastically
simplify, relying on read_input_list to set up the bitmaps.
(main): Arguments are no longer unused. Check for correct number
of command line arguments, set srcdir and srcdir_len, then call
read_input_list, before doing anything else. No need to worry
about duplicates in main loop.
* configure.ac: Simplify the calculation of all_gtfiles.
Put language tags in there. Don't set or substitute
all_gtfiles_files_langs or all_gtfiles_files_frags.
* Makefile.in: Revamp the way gengtype is invoked, now that it
takes a file on its command line with a much simpler format.
Remove or replace with gtyp-input.list all references to gtyp-gen.h.
(GTFILES): Remove duplicates and C source files.
* c-config-lang.in, cp/config-lang.in, objc/config-lang.in
* objcp/config-lang.in: Add c-pragma.h to gtfiles.
* configure: Regenerate.
* gengtype.h: Remove all type definitions to gengtype.c; leave * gengtype.h: Remove all type definitions to gengtype.c; leave
only definitions of options_p, type_p, and pair_p as opaque only definitions of options_p, type_p, and pair_p as opaque
pointers. Update prototypes. pointers. Update prototypes.
......
...@@ -1189,7 +1189,7 @@ MOSTLYCLEANFILES = insn-flags.h insn-config.h insn-codes.h \ ...@@ -1189,7 +1189,7 @@ MOSTLYCLEANFILES = insn-flags.h insn-config.h insn-codes.h \
insn-attr.h insn-attrtab.c insn-opinit.c insn-preds.c insn-constants.h \ insn-attr.h insn-attrtab.c insn-opinit.c insn-preds.c insn-constants.h \
tm-preds.h tm-constrs.h \ tm-preds.h tm-constrs.h \
tree-check.h min-insn-modes.c insn-modes.c insn-modes.h \ tree-check.h min-insn-modes.c insn-modes.c insn-modes.h \
genrtl.c genrtl.h gt-*.h gtype-*.h gtype-desc.c gtyp-gen.h \ genrtl.c genrtl.h gt-*.h gtype-*.h gtype-desc.c gtyp-input.list \
xgcc$(exeext) cpp$(exeext) cc1$(exeext) cc1*-dummy$(exeext) $(EXTRA_PASSES) \ xgcc$(exeext) cpp$(exeext) cc1$(exeext) cc1*-dummy$(exeext) $(EXTRA_PASSES) \
$(EXTRA_PARTS) $(EXTRA_PROGRAMS) gcc-cross$(exeext) \ $(EXTRA_PARTS) $(EXTRA_PROGRAMS) gcc-cross$(exeext) \
protoize$(exeext) unprotoize$(exeext) \ protoize$(exeext) unprotoize$(exeext) \
...@@ -2988,11 +2988,11 @@ GTFILES = $(srcdir)/input.h $(srcdir)/coretypes.h \ ...@@ -2988,11 +2988,11 @@ GTFILES = $(srcdir)/input.h $(srcdir)/coretypes.h \
$(srcdir)/real.h $(srcdir)/varray.h $(srcdir)/insn-addr.h $(srcdir)/hwint.h \ $(srcdir)/real.h $(srcdir)/varray.h $(srcdir)/insn-addr.h $(srcdir)/hwint.h \
$(srcdir)/ipa-reference.h $(srcdir)/output.h \ $(srcdir)/ipa-reference.h $(srcdir)/output.h \
$(srcdir)/cselib.h $(srcdir)/basic-block.h $(srcdir)/cgraph.h \ $(srcdir)/cselib.h $(srcdir)/basic-block.h $(srcdir)/cgraph.h \
$(srcdir)/c-common.h $(srcdir)/c-tree.h $(srcdir)/reload.h \ $(srcdir)/reload.h \
$(srcdir)/alias.c $(srcdir)/bitmap.c $(srcdir)/cselib.c $(srcdir)/cgraph.c \ $(srcdir)/alias.c $(srcdir)/bitmap.c $(srcdir)/cselib.c $(srcdir)/cgraph.c \
$(srcdir)/ipa-prop.c $(srcdir)/ipa-cp.c $(srcdir)/ipa-inline.c \ $(srcdir)/ipa-prop.c $(srcdir)/ipa-cp.c $(srcdir)/ipa-inline.c \
$(srcdir)/dbxout.c $(srcdir)/dwarf2out.c $(srcdir)/dwarf2asm.c \ $(srcdir)/dbxout.c $(srcdir)/dwarf2out.c $(srcdir)/dwarf2asm.c \
$(srcdir)/dojump.c $(srcdir)/tree-profile.c \ $(srcdir)/dojump.c \
$(srcdir)/emit-rtl.c $(srcdir)/except.c $(srcdir)/explow.c $(srcdir)/expr.c \ $(srcdir)/emit-rtl.c $(srcdir)/except.c $(srcdir)/explow.c $(srcdir)/expr.c \
$(srcdir)/function.c $(srcdir)/except.h \ $(srcdir)/function.c $(srcdir)/except.h \
$(srcdir)/gcse.c $(srcdir)/integrate.c $(srcdir)/lists.c $(srcdir)/optabs.c \ $(srcdir)/gcse.c $(srcdir)/integrate.c $(srcdir)/lists.c $(srcdir)/optabs.c \
...@@ -3001,7 +3001,6 @@ GTFILES = $(srcdir)/input.h $(srcdir)/coretypes.h \ ...@@ -3001,7 +3001,6 @@ GTFILES = $(srcdir)/input.h $(srcdir)/coretypes.h \
$(srcdir)/sdbout.c $(srcdir)/stor-layout.c \ $(srcdir)/sdbout.c $(srcdir)/stor-layout.c \
$(srcdir)/stringpool.c $(srcdir)/tree.c $(srcdir)/varasm.c \ $(srcdir)/stringpool.c $(srcdir)/tree.c $(srcdir)/varasm.c \
$(srcdir)/tree-mudflap.c $(srcdir)/tree-flow.h \ $(srcdir)/tree-mudflap.c $(srcdir)/tree-flow.h \
$(srcdir)/c-objc-common.c $(srcdir)/c-common.c $(srcdir)/c-parser.c \
$(srcdir)/tree-ssanames.c $(srcdir)/tree-eh.c $(srcdir)/tree-ssa-address.c \ $(srcdir)/tree-ssanames.c $(srcdir)/tree-eh.c $(srcdir)/tree-ssa-address.c \
$(srcdir)/tree-phinodes.c $(srcdir)/tree-cfg.c \ $(srcdir)/tree-phinodes.c $(srcdir)/tree-cfg.c \
$(srcdir)/tree-dfa.c $(srcdir)/tree-ssa-propagate.c \ $(srcdir)/tree-dfa.c $(srcdir)/tree-ssa-propagate.c \
...@@ -3011,69 +3010,38 @@ GTFILES = $(srcdir)/input.h $(srcdir)/coretypes.h \ ...@@ -3011,69 +3010,38 @@ GTFILES = $(srcdir)/input.h $(srcdir)/coretypes.h \
$(srcdir)/tree-profile.c $(srcdir)/tree-nested.c \ $(srcdir)/tree-profile.c $(srcdir)/tree-nested.c \
$(srcdir)/ipa-reference.c $(srcdir)/tree-ssa-structalias.h \ $(srcdir)/ipa-reference.c $(srcdir)/tree-ssa-structalias.h \
$(srcdir)/tree-ssa-structalias.c \ $(srcdir)/tree-ssa-structalias.c \
$(srcdir)/c-pragma.h $(srcdir)/omp-low.c $(srcdir)/varpool.c \ $(srcdir)/omp-low.c $(srcdir)/varpool.c \
$(srcdir)/targhooks.c $(out_file) $(srcdir)/passes.c\ $(srcdir)/targhooks.c $(out_file) $(srcdir)/passes.c \
@all_gtfiles@ @all_gtfiles@
GTFILES_FILES_LANGS = @all_gtfiles_files_langs@ GTFILES_H = $(subst /,-, $(subst $(srcdir)/,gt-, $(subst .c,.h, \
GTFILES_FILES_FILES = @all_gtfiles_files_files@ $(filter %.c, $(GTFILES)))))
GTFILES_LANG_DIR_NAMES = @subdirs@
GTFILES_SRCDIR = @srcdir@ GTFILES_LANG_H = $(patsubst [%], gtype-%.h, $(filter [%], $(GTFILES)))
ALL_GTFILES_H := $(sort $(GTFILES_H) $(GTFILES_LANG_H))
GTFILES_FILES_FILES_C = $(subst $(srcdir)/,, \
$(filter %.c, $(GTFILES_FILES_FILES))) # $(GTFILES) may be too long to put on a command line, so we have to
GTFILES_FILES_FILES_H = $(addprefix gt-, \ # write it out to a file (taking care not to do that in a way that
$(subst /,-,$(GTFILES_FILES_FILES_C:.c=.h))) # overflows a command line!) and then have gengtype read the file in.
GTFILES_LANG_DIR_NAMES_H = $(foreach d,$(GTFILES_LANG_DIR_NAMES), gtype-$(d).h) # The extra blank line in this definition is crucial: it makes the
ALL_GTFILES_H := $(sort $(GTFILES_FILES_FILES_H) $(GTFILES_LANG_DIR_NAMES_H)) # $(foreach ...) below expand to many lines instead of one.
$(ALL_GTFILES_H) : s-gtype ; @true define echo_to_gi.list
echo '$(gtyp)' >> tmp-gi.list
gt-cgraph.h gt-coverage.h gtype-desc.h gtype-desc.c gt-except.h \
gt-function.h gt-integrate.h gt-tree.h gt-varasm.h \
gt-emit-rtl.h gt-explow.h gt-stor-layout.h gt-regclass.h \
gt-lists.h gt-alias.h gt-cselib.h gt-gcse.h \
gt-expr.h gt-sdbout.h gt-optabs.h gt-bitmap.h gt-dojump.h \
gt-dwarf2out.h gt-dwarf2asm.h \
gt-dbxout.h \
gtype-c.h gt-cfglayout.h \
gt-tree-mudflap.h gt-tree-vect-generic.h \
gt-tree-profile.h gt-tree-ssa-address.h \
gt-tree-iterator.h gt-gimplify.h \
gt-tree-phinodes.h gt-tree-nested.h \
gt-tree-ssa-propagate.h gt-varpool.h \
gt-tree-ssa-structalias.h gt-ipa-inline.h gt-passes.h \
gt-stringpool.h gt-targhooks.h gt-omp-low.h : s-gtype ; @true
define echo_quoted_to_gtyp
echo "\"$(gtyp)\", " >> tmp-gtyp.h
endef endef
gtyp-gen.h: s-gtyp-gen ; @true $(ALL_GTFILES_H) gtype-desc.c gtype-desc.h : s-gtype ; @true
s-gtyp-gen: Makefile
echo "/* This file is machine generated. Do not edit. */" > tmp-gtyp.h gtyp-input.list: s-gtyp-input ; @true
echo "static const char *const srcdir = " >> tmp-gtyp.h s-gtyp-input: Makefile
echo "\"$(GTFILES_SRCDIR)\"" >> tmp-gtyp.h $(foreach gtyp, $(GTFILES), $(echo_to_gi.list))
echo ";" >> tmp-gtyp.h $(SHELL) $(srcdir)/../move-if-change tmp-gi.list gtyp-input.list
echo "static const char *const lang_files[] = {" >> tmp-gtyp.h $(STAMP) s-gtyp-input
$(foreach gtyp,$(GTFILES_FILES_FILES),$(echo_quoted_to_gtyp))
echo "NULL};" >> tmp-gtyp.h s-gtype: build/gengtype$(build_exeext) $(filter-out [%], $(GTFILES)) \
echo "static const char *const langs_for_lang_files[] = {" >> tmp-gtyp.h gtyp-input.list
$(foreach gtyp,$(GTFILES_FILES_LANGS),$(echo_quoted_to_gtyp)) $(RUN_GEN) build/gengtype$(build_exeext) $(srcdir) gtyp-input.list
echo "NULL};" >> tmp-gtyp.h
echo "static const char *const all_files[] = {" >> tmp-gtyp.h
$(foreach gtyp,$(GTFILES),$(echo_quoted_to_gtyp))
echo " NULL};" >> tmp-gtyp.h
echo "static const char *const lang_dir_names[] = { \"c\", " >> tmp-gtyp.h
$(foreach gtyp,$(GTFILES_LANG_DIR_NAMES),$(echo_quoted_to_gtyp))
echo "NULL};" >> tmp-gtyp.h
$(SHELL) $(srcdir)/../move-if-change tmp-gtyp.h gtyp-gen.h
$(STAMP) s-gtyp-gen
s-gtype: build/gengtype$(build_exeext) $(GTFILES)
$(RUN_GEN) build/gengtype$(build_exeext)
$(STAMP) s-gtype $(STAMP) s-gtype
# #
...@@ -3142,7 +3110,7 @@ build/gengtype-lex.o : gengtype-lex.c gengtype.h gengtype-yacc.h \ ...@@ -3142,7 +3110,7 @@ build/gengtype-lex.o : gengtype-lex.c gengtype.h gengtype-yacc.h \
build/gengtype-yacc.o : gengtype-yacc.c gengtype.h $(BCONFIG_H) \ build/gengtype-yacc.o : gengtype-yacc.c gengtype.h $(BCONFIG_H) \
$(SYSTEM_H) $(SYSTEM_H)
build/gengtype.o : gengtype.c $(BCONFIG_H) $(SYSTEM_H) gengtype.h \ build/gengtype.o : gengtype.c $(BCONFIG_H) $(SYSTEM_H) gengtype.h \
gtyp-gen.h rtl.def insn-notes.def errors.h rtl.def insn-notes.def errors.h
build/genmddeps.o: genmddeps.c $(BCONFIG_H) $(SYSTEM_H) coretypes.h \ build/genmddeps.o: genmddeps.c $(BCONFIG_H) $(SYSTEM_H) coretypes.h \
$(GTM_H) $(RTL_BASE_H) errors.h gensupport.h $(GTM_H) $(RTL_BASE_H) errors.h gensupport.h
build/genmodes.o : genmodes.c $(BCONFIG_H) $(SYSTEM_H) errors.h \ build/genmodes.o : genmodes.c $(BCONFIG_H) $(SYSTEM_H) errors.h \
...@@ -3761,8 +3729,8 @@ mostlyclean: lang.mostlyclean ...@@ -3761,8 +3729,8 @@ mostlyclean: lang.mostlyclean
-rm -f gcc.vrs gcc.kys gcc.tps gcc.pgs gcc.fns -rm -f gcc.vrs gcc.kys gcc.tps gcc.pgs gcc.fns
# Delete core dumps. # Delete core dumps.
-rm -f core */core -rm -f core */core
# Delete file generated for gengtype.c # Delete file generated for gengtype
-rm -f gtyp-gen.h -rm -f gtyp-input.list
# Delete files generated by gengtype.c # Delete files generated by gengtype.c
-rm -f gtype-* -rm -f gtype-*
-rm -f gt-* -rm -f gt-*
......
...@@ -23,4 +23,4 @@ ...@@ -23,4 +23,4 @@
# files used by C that have garbage collection GTY macros in them # files used by C that have garbage collection GTY macros in them
# which therefore need to be scanned by gengtype.c. # which therefore need to be scanned by gengtype.c.
gtfiles="\$(srcdir)/c-lang.c \$(srcdir)/c-tree.h \$(srcdir)/c-decl.c \$(srcdir)/c-common.c \$(srcdir)/c-common.h \$(srcdir)/c-pragma.c \$(srcdir)/c-objc-common.c \$(srcdir)/c-parser.c" gtfiles="\$(srcdir)/c-lang.c \$(srcdir)/c-tree.h \$(srcdir)/c-decl.c \$(srcdir)/c-common.c \$(srcdir)/c-common.h \$(srcdir)/c-pragma.h \$(srcdir)/c-pragma.c \$(srcdir)/c-objc-common.c \$(srcdir)/c-parser.c"
...@@ -3532,11 +3532,8 @@ all_outputs='Makefile gccbug libada-mk' ...@@ -3532,11 +3532,8 @@ all_outputs='Makefile gccbug libada-mk'
all_lang_makefrags= all_lang_makefrags=
# List of language subdirectory makefiles. Deprecated. # List of language subdirectory makefiles. Deprecated.
all_lang_makefiles= all_lang_makefiles=
# Files for gengtype # Additional files for gengtype
all_gtfiles="$target_gtfiles" all_gtfiles="$target_gtfiles"
# Files for gengtype with language
all_gtfiles_files_langs=
all_gtfiles_files_files=
# These are the languages that are set in --enable-languages, # These are the languages that are set in --enable-languages,
# and are available in the GCC tree. # and are available in the GCC tree.
...@@ -3613,24 +3610,13 @@ changequote([,])dnl ...@@ -3613,24 +3610,13 @@ changequote([,])dnl
all_languages="$all_languages $language" all_languages="$all_languages $language"
all_compilers="$all_compilers $compilers" all_compilers="$all_compilers $compilers"
all_outputs="$all_outputs $outputs" all_outputs="$all_outputs $outputs"
all_gtfiles="$all_gtfiles $gtfiles" all_gtfiles="$all_gtfiles [[$subdir]] $gtfiles"
for f in $gtfiles
do
all_gtfiles_files_langs="$all_gtfiles_files_langs ${subdir} "
all_gtfiles_files_files="$all_gtfiles_files_files ${f} "
done
done done
# Pick up gtfiles for c # Pick up gtfiles for c
gtfiles= gtfiles=
subdir="c"
. ${srcdir}/c-config-lang.in . ${srcdir}/c-config-lang.in
all_gtfiles="$all_gtfiles $gtfiles" all_gtfiles="$all_gtfiles [[c]] $gtfiles"
for f in $gtfiles
do
all_gtfiles_files_langs="$all_gtfiles_files_langs ${subdir} "
all_gtfiles_files_files="$all_gtfiles_files_files ${f} "
done
check_languages= check_languages=
for language in $all_selected_languages for language in $all_selected_languages
...@@ -3762,8 +3748,6 @@ AC_SUBST(subdirs) ...@@ -3762,8 +3748,6 @@ AC_SUBST(subdirs)
AC_SUBST(srcdir) AC_SUBST(srcdir)
AC_SUBST(all_compilers) AC_SUBST(all_compilers)
AC_SUBST(all_gtfiles) AC_SUBST(all_gtfiles)
AC_SUBST(all_gtfiles_files_langs)
AC_SUBST(all_gtfiles_files_files)
AC_SUBST(all_lang_makefrags) AC_SUBST(all_lang_makefrags)
AC_SUBST(all_lang_makefiles) AC_SUBST(all_lang_makefiles)
AC_SUBST(all_languages) AC_SUBST(all_languages)
......
...@@ -31,4 +31,4 @@ compilers="cc1plus\$(exeext)" ...@@ -31,4 +31,4 @@ compilers="cc1plus\$(exeext)"
target_libs="target-libstdc++-v3" target_libs="target-libstdc++-v3"
gtfiles="\$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-common.c \$(srcdir)/c-common.h \$(srcdir)/c-lex.c \$(srcdir)/c-pragma.c \$(srcdir)/cp/class.c \$(srcdir)/cp/cp-objcp-common.c" gtfiles="\$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-common.c \$(srcdir)/c-common.h \$(srcdir)/c-lex.c \$(srcdir)/c-pragma.h \$(srcdir)/c-pragma.c \$(srcdir)/cp/class.c \$(srcdir)/cp/cp-objcp-common.c"
...@@ -133,13 +133,6 @@ extern outf_p get_output_file_with_visibility ...@@ -133,13 +133,6 @@ extern outf_p get_output_file_with_visibility
(const char *input_file); (const char *input_file);
const char *get_output_file_name (const char *); const char *get_output_file_name (const char *);
#include "gtyp-gen.h"
/* A bitmap that specifies which of BASE_FILES should be used to
output a definition that is different for each language and must be
defined once in each language that uses INPUT_FILE. */
static lang_bitmap get_base_file_bitmap (const char *input_file);
/* Print, like fprintf, to O. */ /* Print, like fprintf, to O. */
static void oprintf (outf_p o, const char *S, ...) static void oprintf (outf_p o, const char *S, ...)
ATTRIBUTE_PRINTF_2; ATTRIBUTE_PRINTF_2;
...@@ -151,20 +144,12 @@ static outf_p output_files; ...@@ -151,20 +144,12 @@ static outf_p output_files;
source file. */ source file. */
static outf_p header_file; static outf_p header_file;
/* Number of files specified in gtfiles. */ /* Source directory. */
#define NUM_GT_FILES (ARRAY_SIZE (all_files) - 1) static const char *srcdir;
/* Number of files in the language files array. */
#define NUM_LANG_FILES (ARRAY_SIZE (lang_files) - 1)
/* Length of srcdir name. */ /* Length of srcdir name. */
static int srcdir_len = 0; static int srcdir_len = 0;
/* A list of output files suitable for definitions. There is one
BASE_FILES entry for each language. */
#define NUM_BASE_FILES (ARRAY_SIZE (lang_dir_names) - 1)
static outf_p base_files[NUM_BASE_FILES];
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 *);
...@@ -211,6 +196,284 @@ xasprintf (const char *format, ...) ...@@ -211,6 +196,284 @@ xasprintf (const char *format, ...)
return result; return result;
} }
/* Input file handling. */
/* Table of all input files. */
static const char **gt_files;
static size_t num_gt_files;
/* Vector of per-language directories. */
static const char **lang_dir_names;
static size_t num_lang_dirs;
/* An array of output files suitable for definitions. There is one
BASE_FILES entry for each language. */
static outf_p *base_files;
/* Return a bitmap which has bit `1 << BASE_FILE_<lang>' set iff
INPUT_FILE is used by <lang>.
This function should be written to assume that a file _is_ used
if the situation is unclear. If it wrongly assumes a file _is_ used,
a linker error will result. If it wrongly assumes a file _is not_ used,
some GC roots may be missed, which is a much harder-to-debug problem.
The relevant bitmap is stored immediately before the file's name in the
buffer set up by read_input_list. It may be unaligned, so we have to
read it byte-by-byte. */
static lang_bitmap
get_lang_bitmap (const char *gtfile)
{
lang_bitmap n = 0;
int i;
for (i = -(int) sizeof (lang_bitmap); i < 0; i++)
n = (n << CHAR_BIT) + (unsigned char)gtfile[i];
return n;
}
/* Set the bitmap returned by get_lang_bitmap. The only legitimate
caller of this function is read_input_list. */
static void
set_lang_bitmap (char *gtfile, lang_bitmap n)
{
int i;
for (i = -1; i >= -(int) sizeof (lang_bitmap); i--)
{
gtfile[i] = n & ((1U << CHAR_BIT)-1);
n >>= CHAR_BIT;
}
}
/* Scan the input file, LIST, and determine how much space we need to
store strings in. Also, count the number of language directories
and files. The numbers returned are overestimates as they does not
consider repeated files. */
static size_t
measure_input_list (FILE *list)
{
size_t n = 0;
int c;
bool atbol = true;
num_lang_dirs = 0;
num_gt_files = 0;
while ((c = getc (list)) != EOF)
{
n++;
if (atbol)
{
if (c == '[')
num_lang_dirs++;
else
{
/* Add space for a lang_bitmap before the input file name. */
n += sizeof (lang_bitmap);
num_gt_files++;
}
atbol = false;
}
if (c == '\n')
atbol = true;
}
rewind (list);
return n;
}
/* Read one input line from LIST to HEREP (which is updated). A
pointer to the string is returned via LINEP. If it was a language
subdirectory in square brackets, strip off the square brackets and
return true. Otherwise, leave space before the string for a
lang_bitmap, and return false. At EOF, returns false, does not
touch *HEREP, and sets *LINEP to NULL. POS is used for
diagnostics. */
static bool
read_input_line (FILE *list, char **herep, char **linep,
struct fileloc *pos)
{
char *here = *herep;
char *line;
int c = getc (list);
if (c == EOF)
{
*linep = 0;
return false;
}
else if (c == '[')
{
/* No space for a lang_bitmap is necessary. Discard the '['. */
c = getc (list);
line = here;
while (c != ']' && c != '\n' && c != EOF)
{
*here++ = c;
c = getc (list);
}
*here++ = '\0';
if (c == ']')
{
c = getc (list); /* eat what should be a newline */
if (c != '\n' && c != EOF)
error_at_line (pos, "junk on line after language tag [%s]", line);
}
else
error_at_line (pos, "missing close bracket for language tag [%s", line);
*herep = here;
*linep = line;
return true;
}
else
{
/* Leave space for a lang_bitmap. */
memset (here, 0, sizeof (lang_bitmap));
here += sizeof (lang_bitmap);
line = here;
do
{
*here++ = c;
c = getc (list);
}
while (c != EOF && c != '\n');
*here++ = '\0';
*herep = here;
*linep = line;
return false;
}
}
/* Read the list of input files from LIST and compute all of the
relevant tables. There is one file per line of the list. At
first, all the files on the list are language-generic, but
eventually a line will appear which is the name of a language
subdirectory in square brackets, like this: [cp]. All subsequent
files are specific to that language, until another language
subdirectory tag appears. Files can appear more than once, if
they apply to more than one language. */
static void
read_input_list (const char *listname)
{
FILE *list = fopen (listname, "r");
if (!list)
fatal ("cannot open %s: %s", listname, strerror (errno));
else
{
struct fileloc epos;
size_t bufsz = measure_input_list (list);
char *buf = XNEWVEC (char, bufsz);
char *here = buf;
char *committed = buf;
char *limit = buf + bufsz;
char *line;
bool is_language;
size_t langno = 0;
size_t nfiles = 0;
lang_bitmap curlangs = (1 << num_lang_dirs) - 1;
epos.file = listname;
epos.line = 0;
lang_dir_names = XNEWVEC (const char *, num_lang_dirs);
gt_files = XNEWVEC (const char *, num_gt_files);
for (;;)
{
next_line:
epos.line++;
committed = here;
is_language = read_input_line (list, &here, &line, &epos);
gcc_assert (here <= limit);
if (line == 0)
break;
else if (is_language)
{
size_t i;
gcc_assert (langno <= num_lang_dirs);
for (i = 0; i < langno; i++)
if (strcmp (lang_dir_names[i], line) == 0)
{
error_at_line (&epos, "duplicate language tag [%s]", line);
curlangs = 1 << i;
here = committed;
goto next_line;
}
curlangs = 1 << langno;
lang_dir_names[langno++] = line;
}
else
{
size_t i;
gcc_assert (nfiles <= num_gt_files);
for (i = 0; i < nfiles; i++)
if (strcmp (gt_files[i], line) == 0)
{
/* Throw away the string we just read, and add the
current language to the existing string's bitmap. */
lang_bitmap bmap = get_lang_bitmap (gt_files[i]);
if (bmap & curlangs)
error_at_line (&epos, "file %s specified more than once "
"for language %s", line, langno == 0
? "(all)"
: lang_dir_names[langno - 1]);
bmap |= curlangs;
set_lang_bitmap ((char *)gt_files[i], bmap);
here = committed;
goto next_line;
}
set_lang_bitmap (line, curlangs);
gt_files[nfiles++] = line;
}
}
/* Update the global counts now that we know accurately how many
things there are. (We do not bother resizing the arrays down.) */
num_lang_dirs = langno;
num_gt_files = nfiles;
}
/* Sanity check: any file that resides in a language subdirectory
(e.g. 'cp') ought to belong to the corresponding language.
??? Still true if for instance ObjC++ is enabled and C++ isn't?
(Can you even do that? Should you be allowed to?) */
{
size_t f;
for (f = 0; f < num_gt_files; f++)
{
lang_bitmap bitmap = get_lang_bitmap (gt_files[f]);
const char *basename = get_file_basename (gt_files[f]);
const char *slashpos = strchr (basename, '/');
if (slashpos)
{
size_t l;
for (l = 0; l < num_lang_dirs; l++)
if ((size_t)(slashpos - basename) == strlen (lang_dir_names [l])
&& memcmp (basename, lang_dir_names[l],
strlen (lang_dir_names[l])) == 0)
{
if (!(bitmap & (1 << l)))
error ("%s is in language directory '%s' but is not "
"tagged for that language",
basename, lang_dir_names[l]);
break;
}
}
}
}
if (ferror (list))
fatal ("error reading %s: %s", listname, strerror (errno));
fclose (list);
}
/* The one and only TYPE_STRING. */ /* The one and only TYPE_STRING. */
static struct type string_type = { static struct type string_type = {
...@@ -297,7 +560,7 @@ new_structure (const char *name, int isunion, struct fileloc *pos, ...@@ -297,7 +560,7 @@ new_structure (const char *name, int isunion, struct fileloc *pos,
{ {
type_p si; type_p si;
type_p s = NULL; type_p s = NULL;
lang_bitmap bitmap = get_base_file_bitmap (pos->file); lang_bitmap bitmap = get_lang_bitmap (pos->file);
for (si = structures; si != NULL; si = si->next) for (si = structures; si != NULL; si = si->next)
if (strcmp (name, si->u.s.tag) == 0 if (strcmp (name, si->u.s.tag) == 0
...@@ -1202,7 +1465,9 @@ open_base_files (void) ...@@ -1202,7 +1465,9 @@ open_base_files (void)
header_file = create_file ("GCC", "gtype-desc.h"); header_file = create_file ("GCC", "gtype-desc.h");
for (i = 0; i < NUM_BASE_FILES; i++) base_files = XNEWVEC (outf_p, num_lang_dirs);
for (i = 0; i < num_lang_dirs; i++)
base_files[i] = create_file (lang_dir_names[i], base_files[i] = create_file (lang_dir_names[i],
xasprintf ("gtype-%s.h", lang_dir_names[i])); xasprintf ("gtype-%s.h", lang_dir_names[i]));
...@@ -1242,7 +1507,7 @@ get_file_basename (const char *f) ...@@ -1242,7 +1507,7 @@ get_file_basename (const char *f)
basename++; basename++;
for (i = 1; i < NUM_BASE_FILES; i++) for (i = 0; i < num_lang_dirs; i++)
{ {
const char * s1; const char * s1;
const char * s2; const char * s2;
...@@ -1264,63 +1529,6 @@ get_file_basename (const char *f) ...@@ -1264,63 +1529,6 @@ get_file_basename (const char *f)
return basename; return basename;
} }
/* Return a bitmap which has bit `1 << BASE_FILE_<lang>' set iff
INPUT_FILE is used by <lang>.
This function should be written to assume that a file _is_ used
if the situation is unclear. If it wrongly assumes a file _is_ used,
a linker error will result. If it wrongly assumes a file _is not_ used,
some GC roots may be missed, which is a much harder-to-debug problem. */
unsigned
get_base_file_bitmap (const char *input_file)
{
const char *basename = get_file_basename (input_file);
const char *slashpos = strchr (basename, '/');
unsigned j;
unsigned k;
unsigned bitmap;
/* If the file resides in a language subdirectory (e.g., 'cp'), assume that
it belongs to the corresponding language. The file may belong to other
languages as well (which is checked for below). */
if (slashpos)
{
size_t i;
for (i = 1; i < NUM_BASE_FILES; i++)
if ((size_t)(slashpos - basename) == strlen (lang_dir_names [i])
&& memcmp (basename, lang_dir_names[i], strlen (lang_dir_names[i])) == 0)
{
/* It's in a language directory, set that language. */
bitmap = 1 << i;
}
}
/* If it's in any config-lang.in, then set for the languages
specified. */
bitmap = 0;
for (j = 0; j < NUM_LANG_FILES; j++)
{
if (!strcmp(input_file, lang_files[j]))
{
for (k = 0; k < NUM_BASE_FILES; k++)
{
if (!strcmp(lang_dir_names[k], langs_for_lang_files[j]))
bitmap |= (1 << k);
}
}
}
/* Otherwise, set all languages. */
if (!bitmap)
bitmap = (1 << NUM_BASE_FILES) - 1;
return bitmap;
}
/* 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. */
...@@ -1382,7 +1590,7 @@ get_output_file_with_visibility (const char *input_file) ...@@ -1382,7 +1590,7 @@ get_output_file_with_visibility (const char *input_file)
{ {
size_t i; size_t i;
for (i = 0; i < NUM_BASE_FILES; i++) for (i = 0; i < num_lang_dirs; i++)
if (memcmp (basename, lang_dir_names[i], strlen (lang_dir_names[i])) == 0 if (memcmp (basename, lang_dir_names[i], strlen (lang_dir_names[i])) == 0
&& basename[strlen(lang_dir_names[i])] == '/') && basename[strlen(lang_dir_names[i])] == '/')
return base_files[i]; return base_files[i];
...@@ -2644,7 +2852,7 @@ finish_root_table (struct flist *flp, const char *pfx, const char *lastname, ...@@ -2644,7 +2852,7 @@ finish_root_table (struct flist *flp, const char *pfx, const char *lastname,
for (fli2 = flp; fli2; fli2 = fli2->next) for (fli2 = flp; fli2; fli2 = fli2->next)
if (fli2->started_p) if (fli2->started_p)
{ {
lang_bitmap bitmap = get_base_file_bitmap (fli2->name); lang_bitmap bitmap = get_lang_bitmap (fli2->name);
int fnum; int fnum;
for (fnum = 0; bitmap != 0; fnum++, bitmap >>= 1) for (fnum = 0; bitmap != 0; fnum++, bitmap >>= 1)
...@@ -2660,7 +2868,7 @@ finish_root_table (struct flist *flp, const char *pfx, const char *lastname, ...@@ -2660,7 +2868,7 @@ finish_root_table (struct flist *flp, const char *pfx, const char *lastname,
{ {
size_t fnum; size_t fnum;
for (fnum = 0; fnum < NUM_BASE_FILES; fnum++) for (fnum = 0; fnum < num_lang_dirs; fnum++)
oprintf (base_files [fnum], oprintf (base_files [fnum],
"const struct %s * const %s[] = {\n", "const struct %s * const %s[] = {\n",
tname, name); tname, name);
...@@ -2670,7 +2878,7 @@ finish_root_table (struct flist *flp, const char *pfx, const char *lastname, ...@@ -2670,7 +2878,7 @@ finish_root_table (struct flist *flp, const char *pfx, const char *lastname,
for (fli2 = flp; fli2; fli2 = fli2->next) for (fli2 = flp; fli2; fli2 = fli2->next)
if (fli2->started_p) if (fli2->started_p)
{ {
lang_bitmap bitmap = get_base_file_bitmap (fli2->name); lang_bitmap bitmap = get_lang_bitmap (fli2->name);
int fnum; int fnum;
fli2->started_p = 0; fli2->started_p = 0;
...@@ -2686,7 +2894,7 @@ finish_root_table (struct flist *flp, const char *pfx, const char *lastname, ...@@ -2686,7 +2894,7 @@ finish_root_table (struct flist *flp, const char *pfx, const char *lastname,
{ {
size_t fnum; size_t fnum;
for (fnum = 0; fnum < NUM_BASE_FILES; fnum++) for (fnum = 0; fnum < num_lang_dirs; fnum++)
{ {
oprintf (base_files[fnum], " NULL\n"); oprintf (base_files[fnum], " NULL\n");
oprintf (base_files[fnum], "};\n"); oprintf (base_files[fnum], "};\n");
...@@ -2870,7 +3078,7 @@ write_array (outf_p f, pair_p v, const struct write_types_data *wtd) ...@@ -2870,7 +3078,7 @@ write_array (outf_p f, pair_p v, const struct write_types_data *wtd)
d.indent = 2; d.indent = 2;
d.line = &v->line; d.line = &v->line;
d.opt = v->opt; d.opt = v->opt;
d.bitmap = get_base_file_bitmap (v->line.file); d.bitmap = get_lang_bitmap (v->line.file);
d.param = NULL; d.param = NULL;
d.prev_val[3] = prevval3 = xasprintf ("&%s", v->name); d.prev_val[3] = prevval3 = xasprintf ("&%s", v->name);
...@@ -3213,22 +3421,27 @@ note_def_vec_alloc (const char *type, const char *astrat, struct fileloc *pos) ...@@ -3213,22 +3421,27 @@ note_def_vec_alloc (const char *type, const char *astrat, struct fileloc *pos)
} }
extern int main (int argc, char **argv);
int int
main (int ARG_UNUSED (argc), char ** ARG_UNUSED (argv)) main (int argc, char **argv)
{ {
unsigned i; size_t i;
static struct fileloc pos = { __FILE__, __LINE__ }; static struct fileloc pos = { __FILE__, __LINE__ };
unsigned j;
/* fatal uses this */
progname = "gengtype";
if (argc != 3)
fatal ("usage: gengtype srcdir input-list");
srcdir = argv[1];
srcdir_len = strlen (srcdir); srcdir_len = strlen (srcdir);
read_input_list (argv[2]);
if (hit_error)
return 1;
scalar_char.u.scalar_is_char = true; scalar_char.u.scalar_is_char = true;
scalar_nonchar.u.scalar_is_char = false; scalar_nonchar.u.scalar_is_char = false;
/* fatal uses this */
progname = "gengtype";
gen_rtx_next (); gen_rtx_next ();
do_scalar_typedef ("CUMULATIVE_ARGS", &pos); do_scalar_typedef ("CUMULATIVE_ARGS", &pos);
...@@ -3247,20 +3460,9 @@ main (int ARG_UNUSED (argc), char ** ARG_UNUSED (argv)) ...@@ -3247,20 +3460,9 @@ main (int ARG_UNUSED (argc), char ** ARG_UNUSED (argv))
do_typedef ("HARD_REG_SET", create_array (&scalar_nonchar, "2"), &pos); do_typedef ("HARD_REG_SET", create_array (&scalar_nonchar, "2"), &pos);
for (i = 0; i < NUM_GT_FILES; i++) for (i = 0; i < num_gt_files; i++)
{
int dupflag = 0;
/* Omit if already seen. */
for (j = 0; j < i; j++)
{ {
if (!strcmp (all_files[i], all_files[j])) parse_file (gt_files[i]);
{
dupflag = 1;
break;
}
}
if (!dupflag)
parse_file (all_files[i]);
#ifndef USE_MAPPED_LOCATION #ifndef USE_MAPPED_LOCATION
/* temporary kludge - gengtype doesn't handle conditionals. /* temporary kludge - gengtype doesn't handle conditionals.
Manually add source_locus *after* we've processed input.h. */ Manually add source_locus *after* we've processed input.h. */
......
...@@ -34,4 +34,4 @@ target_libs=target-libobjc ...@@ -34,4 +34,4 @@ target_libs=target-libobjc
# Most of the object files for cc1obj actually come from C. # Most of the object files for cc1obj actually come from C.
lang_requires="c" lang_requires="c"
gtfiles="\$(srcdir)/objc/objc-act.h \$(srcdir)/c-parser.c \$(srcdir)/c-tree.h \$(srcdir)/c-decl.c \$(srcdir)/c-objc-common.c \$(srcdir)/c-common.c \$(srcdir)/c-common.h \$(srcdir)/c-pragma.c \$(srcdir)/objc/objc-act.c" gtfiles="\$(srcdir)/objc/objc-act.h \$(srcdir)/c-parser.c \$(srcdir)/c-tree.h \$(srcdir)/c-decl.c \$(srcdir)/c-objc-common.c \$(srcdir)/c-common.c \$(srcdir)/c-common.h \$(srcdir)/c-pragma.h \$(srcdir)/c-pragma.c \$(srcdir)/objc/objc-act.c"
...@@ -38,4 +38,4 @@ build_by_default="no" ...@@ -38,4 +38,4 @@ build_by_default="no"
lang_requires="objc c++" lang_requires="objc c++"
subdir_requires="objc cp" subdir_requires="objc cp"
gtfiles="\$(srcdir)/objcp/objcp-decl.c \$(srcdir)/objc/objc-act.c \$(srcdir)/objc/objc-act.h \$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-common.c \$(srcdir)/c-common.h \$(srcdir)/c-lex.c \$(srcdir)/c-pragma.c \$(srcdir)/cp/cp-objcp-common.c" gtfiles="\$(srcdir)/objcp/objcp-decl.c \$(srcdir)/objc/objc-act.c \$(srcdir)/objc/objc-act.h \$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-common.c \$(srcdir)/c-common.h \$(srcdir)/c-lex.c \$(srcdir)/c-pragma.h \$(srcdir)/c-pragma.c \$(srcdir)/cp/cp-objcp-common.c"
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