Commit 50f59cd7 by Per Bothner Committed by Per Bothner

Move cpp_reader's line_maps field to a shared global.

	* cpphash.h (cpp_reader):  Rename line_maps field to line_table
	and change the type to a pointer rather than a struct.
	* cppinit.c (cpp_push_main_field):  Adjust accordingly.
	* cpplib.c (do_include_common, _cpp_do_file_change, cpp_get_callbacks):
	Likewise.
	* cppfiles.c (validate_pch):  Likewise.
	* cppmacro.c (_cpp_warn_if_unused_macro, _cpp_builtin_macro_text):
	Likewise.
	* cpperror.c (print_location):  Likewise.
	* cpplib.h (cpp_create_reader):  New line_maps pointer parameter.
	* cppinit.c (cpp_create_reader):  Handle new parameter.
	(cpp_destroy):  Don't free line_maps - that's no longer our job.
	* input.h (line_table):  New variable.
	* toplev.c (line_table):  Declare variable.
	(general_init):  Initialize line_table.
	* c-opts.c (c_common_init_options):  Pass line_table to
	cpp_create_reader.
	* fix-header.c (read_scan_file):  New local variable line_table.
	Initialize, and pass it to cpp_create_reader.
	* Makefile.in (LIBS, LIBDEPS):  Add libcpp.a.
	(C_AND_OBJC_OBJS, fix-header):  Remove redundant libcpp.a.

From-SVN: r76198
parent 9132fbb7
2003-01-20 Per Bothner <pbothner@apple.com> 2004-01-19 Per Bothner <per@bothner.com>
Move cpp_reader's line_maps field to a shared global.
* cpphash.h (cpp_reader): Rename line_maps field to line_table
and change the type to a pointer rather than a struct.
* cppinit.c (cpp_push_main_field): Adjust accordingly.
* cpplib.c (do_include_common, _cpp_do_file_change, cpp_get_callbacks):
Likewise.
* cppfiles.c (validate_pch): Likewise.
* cppmacro.c (_cpp_warn_if_unused_macro, _cpp_builtin_macro_text):
Likewise.
* cpperror.c (print_location): Likewise.
* cpplib.h (cpp_create_reader): New line_maps pointer parameter.
* cppinit.c (cpp_create_reader): Handle new parameter.
(cpp_destroy): Don't free line_maps - that's no longer our job.
* input.h (line_table): New variable.
* toplev.c (line_table): Declare variable.
(general_init): Initialize line_table.
* c-opts.c (c_common_init_options): Pass line_table to
cpp_create_reader.
* fix-header.c (read_scan_file): New local variable line_table.
Initialize, and pass it to cpp_create_reader.
* Makefile.in (LIBS, LIBDEPS): Add libcpp.a.
(C_AND_OBJC_OBJS, fix-header): Remove redundant libcpp.a.
2004-01-19 Per Bothner <per@bothner.com>
Implement a cache for linemap_lookup. Implement a cache for linemap_lookup.
* line-map.h (struct_line_maps): Add cache field. * line-map.h (struct_line_maps): Add cache field.
......
...@@ -714,7 +714,7 @@ LIBIBERTY = ../libiberty/libiberty.a ...@@ -714,7 +714,7 @@ LIBIBERTY = ../libiberty/libiberty.a
BUILD_LIBIBERTY = @FORBUILD@/libiberty/libiberty.a BUILD_LIBIBERTY = @FORBUILD@/libiberty/libiberty.a
# Dependencies on the intl and portability libraries. # Dependencies on the intl and portability libraries.
LIBDEPS= $(LIBIBERTY) $(LIBINTL_DEP) $(LIBICONV_DEP) LIBDEPS= $(LIBIBERTY) $(LIBINTL_DEP) $(LIBICONV_DEP) libcpp.a
# Likewise, for use in the tools that must run on this machine # Likewise, for use in the tools that must run on this machine
# even if we are cross-building GCC. # even if we are cross-building GCC.
...@@ -722,7 +722,7 @@ BUILD_LIBDEPS= $(BUILD_LIBIBERTY) ...@@ -722,7 +722,7 @@ BUILD_LIBDEPS= $(BUILD_LIBIBERTY)
# How to link with both our special library facilities # How to link with both our special library facilities
# and the system's installed libraries. # and the system's installed libraries.
LIBS = @LIBS@ $(LIBIBERTY) $(LIBINTL) $(LIBICONV) LIBS = @LIBS@ libcpp.a $(LIBIBERTY) $(LIBINTL) $(LIBICONV)
# Any system libraries needed just for GNAT. # Any system libraries needed just for GNAT.
SYSLIBS = @GNAT_LIBEXC@ SYSLIBS = @GNAT_LIBEXC@
...@@ -839,7 +839,7 @@ CXX_TARGET_OBJS=@cxx_target_objs@ ...@@ -839,7 +839,7 @@ CXX_TARGET_OBJS=@cxx_target_objs@
C_AND_OBJC_OBJS = attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o c-typeck.o \ C_AND_OBJC_OBJS = attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o c-typeck.o \
c-convert.o c-aux-info.o c-common.o c-opts.o c-format.o c-semantics.o \ c-convert.o c-aux-info.o c-common.o c-opts.o c-format.o c-semantics.o \
c-incpath.o cppdefault.o c-ppoutput.o c-cppbuiltin.o prefix.o \ c-incpath.o cppdefault.o c-ppoutput.o c-cppbuiltin.o prefix.o \
c-objc-common.o c-dump.o c-pch.o libcpp.a $(C_TARGET_OBJS) c-objc-common.o c-dump.o c-pch.o $(C_TARGET_OBJS)
# Language-specific object files for C. # Language-specific object files for C.
C_OBJS = c-parse.o c-lang.o c-pretty-print.o stub-objc.o $(C_AND_OBJC_OBJS) C_OBJS = c-parse.o c-lang.o c-pretty-print.o stub-objc.o $(C_AND_OBJC_OBJS)
...@@ -2571,7 +2571,7 @@ xsys-protos.h: $(GCC_PASSES) $(srcdir)/sys-protos.h deduced.h gen-protos$(build_ ...@@ -2571,7 +2571,7 @@ xsys-protos.h: $(GCC_PASSES) $(srcdir)/sys-protos.h deduced.h gen-protos$(build_
fix-header$(build_exeext): fix-header.o scan-decls.o scan.o xsys-protos.h \ fix-header$(build_exeext): fix-header.o scan-decls.o scan.o xsys-protos.h \
c-incpath.o cppdefault.o prefix.o $(LIBDEPS) libcpp.a c-incpath.o cppdefault.o prefix.o $(LIBDEPS) libcpp.a
$(CC_FOR_BUILD) $(BUILD_CFLAGS) $(BUILD_LDFLAGS) -o $@ fix-header.o \ $(CC_FOR_BUILD) $(BUILD_CFLAGS) $(BUILD_LDFLAGS) -o $@ fix-header.o \
c-incpath.o cppdefault.o scan-decls.o prefix.o scan.o libcpp.a $(LIBS) c-incpath.o cppdefault.o scan-decls.o prefix.o scan.o $(LIBS)
fix-header.o: fix-header.c $(OBSTACK_H) scan.h \ fix-header.o: fix-header.c $(OBSTACK_H) scan.h \
xsys-protos.h $(BCONFIG_H) $(SYSTEM_H) coretypes.h $(GTM_H) $(CPPLIB_H) xsys-protos.h $(BCONFIG_H) $(SYSTEM_H) coretypes.h $(GTM_H) $(CPPLIB_H)
......
...@@ -203,7 +203,7 @@ c_common_init_options (unsigned int argc, const char **argv ATTRIBUTE_UNUSED) ...@@ -203,7 +203,7 @@ c_common_init_options (unsigned int argc, const char **argv ATTRIBUTE_UNUSED)
} }
parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89, parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
ident_hash); ident_hash, &line_table);
cpp_opts = cpp_get_options (parse_in); cpp_opts = cpp_get_options (parse_in);
cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS; cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
......
...@@ -45,8 +45,8 @@ print_location (cpp_reader *pfile, fileline line, unsigned int col) ...@@ -45,8 +45,8 @@ print_location (cpp_reader *pfile, fileline line, unsigned int col)
const struct line_map *map; const struct line_map *map;
unsigned int lin; unsigned int lin;
map = linemap_lookup (&pfile->line_maps, line); map = linemap_lookup (pfile->line_table, line);
linemap_print_containing_files (&pfile->line_maps, map); linemap_print_containing_files (pfile->line_table, map);
lin = SOURCE_LINE (map, line); lin = SOURCE_LINE (map, line);
if (col == 0) if (col == 0)
......
...@@ -334,7 +334,7 @@ struct cpp_reader ...@@ -334,7 +334,7 @@ struct cpp_reader
struct lexer_state state; struct lexer_state state;
/* Source line tracking. */ /* Source line tracking. */
struct line_maps line_maps; struct line_maps *line_table;
const struct line_map *map; const struct line_map *map;
fileline line; fileline line;
......
...@@ -124,7 +124,8 @@ init_library (void) ...@@ -124,7 +124,8 @@ init_library (void)
/* Initialize a cpp_reader structure. */ /* Initialize a cpp_reader structure. */
cpp_reader * cpp_reader *
cpp_create_reader (enum c_lang lang, hash_table *table) cpp_create_reader (enum c_lang lang, hash_table *table,
struct line_maps *line_table)
{ {
cpp_reader *pfile; cpp_reader *pfile;
...@@ -172,7 +173,7 @@ cpp_create_reader (enum c_lang lang, hash_table *table) ...@@ -172,7 +173,7 @@ cpp_create_reader (enum c_lang lang, hash_table *table)
/* Initialize the line map. Start at logical line 1, so we can use /* Initialize the line map. Start at logical line 1, so we can use
a line number of zero for special states. */ a line number of zero for special states. */
linemap_init (&pfile->line_maps); pfile->line_table = line_table;
pfile->line = 1; pfile->line = 1;
/* Initialize lexer state. */ /* Initialize lexer state. */
...@@ -262,7 +263,6 @@ cpp_destroy (cpp_reader *pfile) ...@@ -262,7 +263,6 @@ cpp_destroy (cpp_reader *pfile)
free (context); free (context);
} }
linemap_free (&pfile->line_maps);
free (pfile); free (pfile);
} }
...@@ -501,7 +501,7 @@ cpp_push_main_file (cpp_reader *pfile) ...@@ -501,7 +501,7 @@ cpp_push_main_file (cpp_reader *pfile)
/* Set this here so the client can change the option if it wishes, /* Set this here so the client can change the option if it wishes,
and after stacking the main file so we don't trace the main and after stacking the main file so we don't trace the main
file. */ file. */
pfile->line_maps.trace_includes = CPP_OPTION (pfile, print_include_names); pfile->line_table->trace_includes = CPP_OPTION (pfile, print_include_names);
} }
/* For preprocessed files, if the first tokens are of the form # NUM. /* For preprocessed files, if the first tokens are of the form # NUM.
......
...@@ -681,7 +681,7 @@ do_include_common (cpp_reader *pfile, enum include_type type) ...@@ -681,7 +681,7 @@ do_include_common (cpp_reader *pfile, enum include_type type)
return; return;
/* Prevent #include recursion. */ /* Prevent #include recursion. */
if (pfile->line_maps.depth >= CPP_STACK_MAX) if (pfile->line_table->depth >= CPP_STACK_MAX)
cpp_error (pfile, CPP_DL_ERROR, "#include nested too deeply"); cpp_error (pfile, CPP_DL_ERROR, "#include nested too deeply");
else else
{ {
...@@ -900,7 +900,7 @@ _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason, ...@@ -900,7 +900,7 @@ _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason,
const char *to_file, unsigned int file_line, const char *to_file, unsigned int file_line,
unsigned int sysp) unsigned int sysp)
{ {
pfile->map = linemap_add (&pfile->line_maps, reason, sysp, pfile->map = linemap_add (pfile->line_table, reason, sysp,
pfile->line, to_file, file_line); pfile->line, to_file, file_line);
if (pfile->cb.file_change) if (pfile->cb.file_change)
...@@ -1907,7 +1907,7 @@ cpp_get_callbacks (cpp_reader *pfile) ...@@ -1907,7 +1907,7 @@ cpp_get_callbacks (cpp_reader *pfile)
const struct line_maps * const struct line_maps *
cpp_get_line_maps (cpp_reader *pfile) cpp_get_line_maps (cpp_reader *pfile)
{ {
return &pfile->line_maps; return pfile->line_table;
} }
/* Copy the given callbacks structure to our own. */ /* Copy the given callbacks structure to our own. */
......
...@@ -510,7 +510,8 @@ struct cpp_hashnode GTY(()) ...@@ -510,7 +510,8 @@ struct cpp_hashnode GTY(())
pointer. Otherwise you should pass in an initialized hash table pointer. Otherwise you should pass in an initialized hash table
that cpplib will share; this technique is used by the C front that cpplib will share; this technique is used by the C front
ends. */ ends. */
extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *); extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *,
struct line_maps *);
/* Call this to change the selected language standard (e.g. because of /* Call this to change the selected language standard (e.g. because of
command line options). */ command line options). */
......
...@@ -80,7 +80,7 @@ _cpp_warn_if_unused_macro (cpp_reader *pfile, cpp_hashnode *node, ...@@ -80,7 +80,7 @@ _cpp_warn_if_unused_macro (cpp_reader *pfile, cpp_hashnode *node,
cpp_macro *macro = node->value.macro; cpp_macro *macro = node->value.macro;
if (!macro->used if (!macro->used
&& MAIN_FILE_P (linemap_lookup (&pfile->line_maps, macro->line))) && MAIN_FILE_P (linemap_lookup (pfile->line_table, macro->line)))
cpp_error_with_line (pfile, CPP_DL_WARNING, macro->line, 0, cpp_error_with_line (pfile, CPP_DL_WARNING, macro->line, 0,
"macro \"%s\" is not used", NODE_NAME (node)); "macro \"%s\" is not used", NODE_NAME (node));
} }
...@@ -136,7 +136,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) ...@@ -136,7 +136,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
if (node->value.builtin == BT_BASE_FILE) if (node->value.builtin == BT_BASE_FILE)
while (! MAIN_FILE_P (map)) while (! MAIN_FILE_P (map))
map = INCLUDED_FROM (&pfile->line_maps, map); map = INCLUDED_FROM (pfile->line_table, map);
name = map->to_file; name = map->to_file;
len = strlen (name); len = strlen (name);
...@@ -153,7 +153,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) ...@@ -153,7 +153,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
/* The line map depth counts the primary source as level 1, but /* The line map depth counts the primary source as level 1, but
historically __INCLUDE_DEPTH__ has called the primary source historically __INCLUDE_DEPTH__ has called the primary source
level 0. */ level 0. */
number = pfile->line_maps.depth - 1; number = pfile->line_table->depth - 1;
break; break;
case BT_SPECLINE: case BT_SPECLINE:
......
...@@ -590,10 +590,12 @@ read_scan_file (char *in_fname, int argc, char **argv) ...@@ -590,10 +590,12 @@ read_scan_file (char *in_fname, int argc, char **argv)
struct fn_decl *fn; struct fn_decl *fn;
int i, strings_processed; int i, strings_processed;
struct symbol_list *cur_symbols; struct symbol_list *cur_symbols;
struct line_maps line_table;
obstack_init (&scan_file_obstack); obstack_init (&scan_file_obstack);
scan_in = cpp_create_reader (CLK_GNUC89, NULL); linemap_init (&line_table);
scan_in = cpp_create_reader (CLK_GNUC89, NULL, &line_table);
cb = cpp_get_callbacks (scan_in); cb = cpp_get_callbacks (scan_in);
cb->file_change = cb_file_change; cb->file_change = cb_file_change;
......
...@@ -22,6 +22,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA ...@@ -22,6 +22,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#ifndef GCC_INPUT_H #ifndef GCC_INPUT_H
#define GCC_INPUT_H #define GCC_INPUT_H
#include "line-map.h"
extern struct line_maps line_table;
/* The data structure used to record a location in a translation unit. */ /* The data structure used to record a location in a translation unit. */
/* Long-term, we want to get rid of this and typedef fileline location_t. */ /* Long-term, we want to get rid of this and typedef fileline location_t. */
struct location_s GTY (()) struct location_s GTY (())
......
...@@ -189,6 +189,8 @@ const char *main_input_filename; ...@@ -189,6 +189,8 @@ const char *main_input_filename;
location_t input_location; location_t input_location;
struct line_maps line_table;
/* Nonzero if it is unsafe to create any new pseudo registers. */ /* Nonzero if it is unsafe to create any new pseudo registers. */
int no_new_pseudos; int no_new_pseudos;
...@@ -4228,6 +4230,7 @@ general_init (const char *argv0) ...@@ -4228,6 +4230,7 @@ general_init (const char *argv0)
table. */ table. */
init_ggc (); init_ggc ();
init_stringpool (); init_stringpool ();
linemap_init (&line_table);
init_ttree (); init_ttree ();
/* Initialize register usage now so switches may override. */ /* Initialize register usage now so switches may override. */
......
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