tree.c (tree_node_structure_for_code): TRANSLATION_UNIT_DECL is TS_TRANSLATION_UNIT_DECL.

2010-09-16  Richard Guenther  <rguenther@suse.de>

	* tree.c (tree_node_structure_for_code): TRANSLATION_UNIT_DECL
	is TS_TRANSLATION_UNIT_DECL.
	(initialize_tree_contains_struct): Adjust.
	(all_translation_units): New global vector.
	(build_translation_unit_decl): New function.
	* tree.h (TRANSLATION_UNIT_LANGUAGE): New macro.
	(struct tree_translation_unit_decl): New.
	(all_translation_units): Declare.
	(union tree_node): Add translation_unit_decl member.
	(build_translation_unit_decl): Declare.
	* treestruct.def (TS_TRANSLATION_UNIT_DECL): New.
	* lto-streamer-out.c (pack_ts_translation_unit_decl_value_fields):
	New function.
	(pack_value_fields): Call it.
	(lto_output_tree_ref): Handle references to TRANSLATION_UNIT_DECL.
	(lto_output_ts_translation_unit_decl_tree_pointers): New function.
	(lto_output_tree_pointers): Call it.
	* lto-streamer-in.c (lto_input_tree_ref): Handle references
	to TRANSLATION_UNIT_DECL.
	(unpack_ts_translation_unit_decl_value_fields): New function.
	(unpack_value_fields): Call it.
	(lto_input_ts_translation_unit_decl_tree_pointers): New function.
	(lto_input_tree_pointers): Call it.
	* lto-streamer.c (check_handled_ts_structures): Adjust.
	* lto-streamer.h (enum LTO_tags): Add LTO_translation_unit_decl_ref.
	* c-decl.c (all_translation_units): Remove.
	(pop_scope): Use build_translation_unit_decl.
	(collect_all_refs): Adjust.
	(for_each_global_decl): Likewise.
	(c_write_global_declarations): Likewise.

	java/
	* jcf-parse.c (current_file_list): Remove.
	(java_parse_file): Use build_translation_unit_decl.  Adjust.

From-SVN: r164331
This commit is contained in:
Richard Guenther 2010-09-16 09:38:13 +00:00 committed by Richard Biener
parent 0c3dbcf057
commit 6be14c0ebc
11 changed files with 149 additions and 26 deletions

View File

@ -1,3 +1,36 @@
2010-09-16 Richard Guenther <rguenther@suse.de>
* tree.c (tree_node_structure_for_code): TRANSLATION_UNIT_DECL
is TS_TRANSLATION_UNIT_DECL.
(initialize_tree_contains_struct): Adjust.
(all_translation_units): New global vector.
(build_translation_unit_decl): New function.
* tree.h (TRANSLATION_UNIT_LANGUAGE): New macro.
(struct tree_translation_unit_decl): New.
(all_translation_units): Declare.
(union tree_node): Add translation_unit_decl member.
(build_translation_unit_decl): Declare.
* treestruct.def (TS_TRANSLATION_UNIT_DECL): New.
* lto-streamer-out.c (pack_ts_translation_unit_decl_value_fields):
New function.
(pack_value_fields): Call it.
(lto_output_tree_ref): Handle references to TRANSLATION_UNIT_DECL.
(lto_output_ts_translation_unit_decl_tree_pointers): New function.
(lto_output_tree_pointers): Call it.
* lto-streamer-in.c (lto_input_tree_ref): Handle references
to TRANSLATION_UNIT_DECL.
(unpack_ts_translation_unit_decl_value_fields): New function.
(unpack_value_fields): Call it.
(lto_input_ts_translation_unit_decl_tree_pointers): New function.
(lto_input_tree_pointers): Call it.
* lto-streamer.c (check_handled_ts_structures): Adjust.
* lto-streamer.h (enum LTO_tags): Add LTO_translation_unit_decl_ref.
* c-decl.c (all_translation_units): Remove.
(pop_scope): Use build_translation_unit_decl.
(collect_all_refs): Adjust.
(for_each_global_decl): Likewise.
(c_write_global_declarations): Likewise.
2010-09-16 Jakub Jelinek <jakub@redhat.com>
PR bootstrap/45686

View File

@ -118,12 +118,6 @@ static GTY(()) struct stmt_tree_s c_stmt_tree;
tree c_break_label;
tree c_cont_label;
/* Linked list of TRANSLATION_UNIT_DECLS for the translation units
included in this invocation. Note that the current translation
unit is not included in this list. */
static GTY(()) tree all_translation_units;
/* A list of decls to be made automatically visible in each file scope. */
static GTY(()) tree visible_builtins;
@ -1072,10 +1066,7 @@ pop_scope (void)
context = current_function_decl;
else if (scope == file_scope)
{
tree file_decl = build_decl (UNKNOWN_LOCATION,
TRANSLATION_UNIT_DECL, 0, 0);
DECL_CHAIN (file_decl) = all_translation_units;
all_translation_units = file_decl;
tree file_decl = build_translation_unit_decl (NULL_TREE);
context = file_decl;
}
else
@ -9664,8 +9655,9 @@ static void
collect_all_refs (const char *source_file)
{
tree t;
unsigned i;
for (t = all_translation_units; t; t = TREE_CHAIN (t))
FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
collect_ada_nodes (BLOCK_VARS (DECL_INITIAL (t)), source_file);
}
@ -9677,8 +9669,9 @@ for_each_global_decl (void (*callback) (tree decl))
tree t;
tree decls;
tree decl;
unsigned i;
for (t = all_translation_units; t; t = TREE_CHAIN (t))
FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
{
decls = DECL_INITIAL (t);
for (decl = BLOCK_VARS (decls); decl; decl = TREE_CHAIN (decl))
@ -9693,6 +9686,7 @@ void
c_write_global_declarations (void)
{
tree t;
unsigned i;
/* We don't want to do this if generating a PCH. */
if (pch_file)
@ -9729,7 +9723,7 @@ c_write_global_declarations (void)
/* Process all file scopes in this compilation, and the external_scope,
through wrapup_global_declarations and check_global_declarations. */
for (t = all_translation_units; t; t = DECL_CHAIN (t))
FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
c_write_global_declarations_1 (BLOCK_VARS (ext_block));
@ -9742,7 +9736,7 @@ c_write_global_declarations (void)
if (!seen_error ())
{
timevar_push (TV_SYMOUT);
for (t = all_translation_units; t; t = DECL_CHAIN (t))
FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t)));
c_write_global_declarations_2 (BLOCK_VARS (ext_block));
timevar_pop (TV_SYMOUT);

View File

@ -1,3 +1,8 @@
2010-09-16 Richard Guenther <rguenther@suse.de>
* jcf-parse.c (current_file_list): Remove.
(java_parse_file): Use build_translation_unit_decl. Adjust.
2010-09-03 Joseph Myers <joseph@codesourcery.com>
* lang.opt (d): New.

View File

@ -80,9 +80,6 @@ static GTY(()) tree parse_roots[2];
/* The METHOD_DECL for the current method. */
#define current_method parse_roots[1]
/* A list of TRANSLATION_UNIT_DECLs for the files to be compiled. */
static GTY(()) VEC(tree,gc) *current_file_list;
/* Line 0 in current file, if compiling from bytecode. */
static location_t file_start_location;
@ -1840,9 +1837,7 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
duplicate_class_warning (IDENTIFIER_POINTER (node));
else
{
tree file_decl = build_decl (input_location,
TRANSLATION_UNIT_DECL, node, NULL);
VEC_safe_push (tree, gc, current_file_list, file_decl);
build_translation_unit_decl (node);
IS_A_COMMAND_LINE_FILENAME_P (node) = 1;
}
}
@ -1860,16 +1855,18 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
const char *resource_filename;
/* Only one resource file may be compiled at a time. */
assert (VEC_length (tree, current_file_list) == 1);
assert (VEC_length (tree, all_translation_units) == 1);
resource_filename = IDENTIFIER_POINTER (DECL_NAME (VEC_index (tree, current_file_list, 0)));
resource_filename
= IDENTIFIER_POINTER
(DECL_NAME (VEC_index (tree, all_translation_units, 0)));
compile_resource_file (resource_name, resource_filename);
goto finish;
}
current_jcf = main_jcf;
FOR_EACH_VEC_ELT (tree, current_file_list, ix, node)
FOR_EACH_VEC_ELT (tree, all_translation_units, ix, node)
{
unsigned char magic_string[4];
char *real_path;
@ -1956,7 +1953,7 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
}
}
FOR_EACH_VEC_ELT (tree, current_file_list, ix, node)
FOR_EACH_VEC_ELT (tree, all_translation_units, ix, node)
{
input_location = DECL_SOURCE_LOCATION (node);
if (CLASS_FILE_P (node))

View File

@ -355,6 +355,7 @@ lto_input_tree_ref (struct lto_input_block *ib, struct data_in *data_in,
case LTO_const_decl_ref:
case LTO_imported_decl_ref:
case LTO_label_decl_ref:
case LTO_translation_unit_decl_ref:
ix_u = lto_input_uleb128 (ib);
result = lto_file_decl_data_get_var_decl (data_in->file_data, ix_u);
break;
@ -1683,6 +1684,13 @@ unpack_ts_block_value_fields (struct bitpack_d *bp, tree expr)
BLOCK_NUMBER (expr) = (unsigned) bp_unpack_value (bp, 31);
}
/* Unpack all the non-pointer fields of the TS_TRANSLATION_UNIT_DECL
structure of expression EXPR from bitpack BP. */
static void
unpack_ts_translation_unit_decl_value_fields (struct bitpack_d *bp ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
{
}
/* Unpack all the non-pointer fields in EXPR into a bit pack. */
@ -1738,6 +1746,9 @@ unpack_value_fields (struct bitpack_d *bp, tree expr)
/* This is only used by High GIMPLE. */
gcc_unreachable ();
}
if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
unpack_ts_translation_unit_decl_value_fields (bp, expr);
}
@ -2223,6 +2234,17 @@ lto_input_ts_target_option (struct lto_input_block *ib, tree expr)
fatal_error ("cl_target_option size mismatch in LTO reader and writer");
}
/* Input a TS_TRANSLATION_UNIT_DECL tree from IB and DATA_IN into EXPR. */
static void
lto_input_ts_translation_unit_decl_tree_pointers (struct lto_input_block *ib,
struct data_in *data_in,
tree expr)
{
TRANSLATION_UNIT_LANGUAGE (expr) = input_string (data_in, ib);
VEC_safe_push (tree, gc, all_translation_units, expr);
}
/* Helper for lto_input_tree. Read all pointer fields in EXPR from
input block IB. DATA_IN contains tables and descriptors for the
file being read. */
@ -2308,6 +2330,9 @@ lto_input_tree_pointers (struct lto_input_block *ib, struct data_in *data_in,
if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION))
lto_input_ts_target_option (ib, expr);
if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
lto_input_ts_translation_unit_decl_tree_pointers (ib, data_in, expr);
}

View File

@ -533,6 +533,13 @@ pack_ts_block_value_fields (struct bitpack_d *bp, tree expr)
bp_pack_value (bp, BLOCK_NUMBER (expr), 31);
}
/* Pack all the non-pointer fields of the TS_TRANSLATION_UNIT_DECL structure
of expression EXPR into bitpack BP. */
static void
pack_ts_translation_unit_decl_value_fields (struct bitpack_d *bp ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
{
}
/* Pack all the non-pointer fields in EXPR into a bit pack. */
@ -588,6 +595,9 @@ pack_value_fields (struct bitpack_d *bp, tree expr)
/* This is only used by High GIMPLE. */
gcc_unreachable ();
}
if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
pack_ts_translation_unit_decl_value_fields (bp, expr);
}
@ -721,6 +731,11 @@ lto_output_tree_ref (struct output_block *ob, tree expr)
lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
break;
case TRANSLATION_UNIT_DECL:
output_record_start (ob, LTO_translation_unit_decl_ref);
lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
break;
default:
/* No other node is indexable, so it should have been handled
by lto_output_tree. */
@ -1127,6 +1142,15 @@ lto_output_ts_target_option (struct output_block *ob, tree expr)
lto_output_bitpack (&bp);
}
/* Write a TS_TRANSLATION_UNIT_DECL tree in EXPR to OB. */
static void
lto_output_ts_translation_unit_decl_tree_pointers (struct output_block *ob,
tree expr)
{
output_string (ob, ob->main_stream, TRANSLATION_UNIT_LANGUAGE (expr));
}
/* Helper for lto_output_tree. Write all pointer fields in EXPR to output
block OB. If REF_P is true, the leaves of EXPR are emitted as
references. */
@ -1209,6 +1233,9 @@ lto_output_tree_pointers (struct output_block *ob, tree expr, bool ref_p)
if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION))
lto_output_ts_target_option (ob, expr);
if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
lto_output_ts_translation_unit_decl_tree_pointers (ob, expr);
}

View File

@ -303,6 +303,7 @@ check_handled_ts_structures (void)
handled_p[TS_OMP_CLAUSE] = true;
handled_p[TS_OPTIMIZATION] = true;
handled_p[TS_TARGET_OPTION] = true;
handled_p[TS_TRANSLATION_UNIT_DECL] = true;
/* Anything not marked above will trigger the following assertion.
If this assertion triggers, it means that there is a new TS_*

View File

@ -235,6 +235,7 @@ enum LTO_tags
LTO_type_ref,
LTO_const_decl_ref,
LTO_imported_decl_ref,
LTO_translation_unit_decl_ref,
LTO_global_decl_ref, /* Do not change. */
/* This tag must always be last. */

View File

@ -294,6 +294,8 @@ tree_node_structure_for_code (enum tree_code code)
return TS_TYPE_DECL;
case FUNCTION_DECL:
return TS_FUNCTION_DECL;
case TRANSLATION_UNIT_DECL:
return TS_TRANSLATION_UNIT_DECL;
default:
return TS_DECL_NON_COMMON;
}
@ -464,6 +466,10 @@ initialize_tree_contains_struct (void)
MARK_TS_DECL_NON_COMMON (code);
break;
case TS_TRANSLATION_UNIT_DECL:
MARK_TS_DECL_COMMON (code);
break;
default:
gcc_unreachable ();
}
@ -471,7 +477,6 @@ initialize_tree_contains_struct (void)
/* Basic consistency checks for attributes used in fold. */
gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_NON_COMMON]);
gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
@ -500,7 +505,6 @@ initialize_tree_contains_struct (void)
gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_WITH_VIS]);
gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
@ -4034,6 +4038,21 @@ build_fn_decl (const char *name, tree type)
return decl;
}
VEC(tree,gc) *all_translation_units;
/* Builds a new translation-unit decl with name NAME, queues it in the
global list of translation-unit decls and returns it. */
tree
build_translation_unit_decl (tree name)
{
tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
name, NULL_TREE);
TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
VEC_safe_push (tree, gc, all_translation_units, tu);
return tu;
}
/* BLOCK nodes are used to represent the structure of binding contours
and declarations, once those contours have been exited and their contents

View File

@ -3385,6 +3385,23 @@ struct GTY(()) tree_function_decl {
/* 3 bits left */
};
/* The source language of the translation-unit. */
#define TRANSLATION_UNIT_LANGUAGE(NODE) \
(TRANSLATION_UNIT_DECL_CHECK (NODE)->translation_unit_decl.language)
/* TRANSLATION_UNIT_DECL inherits from DECL_MINIMAL. */
struct GTY(()) tree_translation_unit_decl {
struct tree_decl_common common;
/* Source language of this translation unit. Used for DWARF output. */
const char * GTY((skip(""))) language;
/* TODO: Non-optimization used to build this translation unit. */
/* TODO: Root of a partial DWARF tree for global types and decls. */
};
/* A vector of all translation-units. */
extern GTY (()) VEC(tree,gc) *all_translation_units;
/* For a TYPE_DECL, holds the "original" type. (TREE_TYPE has the copy.) */
#define DECL_ORIGINAL_TYPE(NODE) \
(TYPE_DECL_CHECK (NODE)->decl_non_common.result)
@ -3490,6 +3507,8 @@ union GTY ((ptr_alias (union lang_tree_node),
struct tree_const_decl GTY ((tag ("TS_CONST_DECL"))) const_decl;
struct tree_type_decl GTY ((tag ("TS_TYPE_DECL"))) type_decl;
struct tree_function_decl GTY ((tag ("TS_FUNCTION_DECL"))) function_decl;
struct tree_translation_unit_decl GTY ((tag ("TS_TRANSLATION_UNIT_DECL")))
translation_unit_decl;
struct tree_type GTY ((tag ("TS_TYPE"))) type;
struct tree_list GTY ((tag ("TS_LIST"))) list;
struct tree_vec GTY ((tag ("TS_VEC"))) vec;
@ -4048,6 +4067,7 @@ extern tree build_decl_stat (location_t, enum tree_code,
tree, tree MEM_STAT_DECL);
extern tree build_fn_decl (const char *, tree);
#define build_decl(l,c,t,q) build_decl_stat (l,c,t,q MEM_STAT_INFO)
extern tree build_translation_unit_decl (tree);
extern tree build_block (tree, tree, tree, tree);
extern tree build_empty_stmt (location_t);
extern tree build_omp_clause (location_t, enum omp_clause_code);

View File

@ -52,6 +52,7 @@ DEFTREESTRUCT(TS_RESULT_DECL, "result decl")
DEFTREESTRUCT(TS_CONST_DECL, "const decl")
DEFTREESTRUCT(TS_TYPE_DECL, "label decl")
DEFTREESTRUCT(TS_FUNCTION_DECL, "function decl")
DEFTREESTRUCT(TS_TRANSLATION_UNIT_DECL, "translation-unit decl")
DEFTREESTRUCT(TS_TYPE, "type")
DEFTREESTRUCT(TS_LIST, "list")
DEFTREESTRUCT(TS_VEC, "vec")