c-decl.c (static_ctors, [...]): Make static.

* c-decl.c (static_ctors, static_dtors): Make static.
	(pop_file_scope): Call c_common_write_pch and
	cgraph_finalize_compilation_unit here.
	(build_cdtor): Moved here from c-objc-common.c; simplify.
	(c_write_global_declarations_1): Clarify comment.
	(c_write_global_declarations): Close the external scope before
	doing anything else.  Call build_cdtor, cgraph_optimize, and
	mudflap_finish_file here.
	* c-lang.c (finish_file): Don't call c_objc_common_finish_file.
	Clarify comment.
	* c-objc-common.c: No need to include cgraph.h.
	(build_cdtor): Moved to c-decl.c.
	(c_objc_common_finish_file): Delete.
	* c-tree.h: Update to match.
	* objc/objc-act.c (finish_file): Don't call c_objc_common_finish_file.
	(generate_static_references): Set TREE_USED before calling finish_decl.
	Eliminate unnecessary dummy declaration.  Call rest_of_decl_compilation
	on the static_instances_decl.

From-SVN: r84307
This commit is contained in:
Zack Weinberg 2004-07-08 19:50:17 +00:00 committed by Zack Weinberg
parent 5b02f0e004
commit 36c1b0def4
6 changed files with 80 additions and 72 deletions

View File

@ -1,3 +1,24 @@
2004-07-08 Zack Weinberg <zack@codesourcery.com>
* c-decl.c (static_ctors, static_dtors): Make static.
(pop_file_scope): Call c_common_write_pch and
cgraph_finalize_compilation_unit here.
(build_cdtor): Moved here from c-objc-common.c; simplify.
(c_write_global_declarations_1): Clarify comment.
(c_write_global_declarations): Close the external scope before
doing anything else. Call build_cdtor, cgraph_optimize, and
mudflap_finish_file here.
* c-lang.c (finish_file): Don't call c_objc_common_finish_file.
Clarify comment.
* c-objc-common.c: No need to include cgraph.h.
(build_cdtor): Moved to c-decl.c.
(c_objc_common_finish_file): Delete.
* c-tree.h: Update to match.
* objc/objc-act.c (finish_file): Don't call c_objc_common_finish_file.
(generate_static_references): Set TREE_USED before calling finish_decl.
Eliminate unnecessary dummy declaration. Call rest_of_decl_compilation
on the static_instances_decl.
2004-07-08 Zack Weinberg <zack@codesourcery.com>
* c-decl.c (pop_scope): Do not set DECL_CONTEXT on file-scope

View File

@ -377,7 +377,8 @@ static bool next_is_function_body;
/* Functions called automatically at the beginning and end of execution. */
tree static_ctors, static_dtors;
static GTY(()) tree static_ctors;
static GTY(()) tree static_dtors;
/* Forward declarations. */
static tree lookup_name_in_scope (tree, struct c_scope *);
@ -853,17 +854,19 @@ pop_file_scope (void)
still works without it. */
finish_fname_decls ();
/* Kludge: don't actually pop the file scope if generating a
precompiled header, so that macros and local symbols are still
visible to the PCH generator. */
/* This is the point to write out a PCH if we're doing that.
In that case we do not want to do anything else. */
if (pch_file)
return;
{
c_common_write_pch ();
return;
}
/* And pop off the file scope. */
/* Pop off the file scope and close this translation unit. */
pop_scope ();
file_scope = 0;
cpp_undef_all (parse_in);
cgraph_finalize_compilation_unit ();
}
/* Insert BLOCK at the end of the list of subblocks of the current
@ -6580,7 +6583,26 @@ make_pointer_declarator (tree type_quals_attrs, tree target)
return build1 (INDIRECT_REF, quals, itarget);
}
/* Perform final processing on file-scope data. */
/* Synthesize a function which calls all the global ctors or global
dtors in this file. This is only used for targets which do not
support .ctors/.dtors sections. FIXME: Migrate into cgraph. */
static void
build_cdtor (int method_type, tree cdtors)
{
tree body = 0;
if (!cdtors)
return;
for (; cdtors; cdtors = TREE_CHAIN (cdtors))
append_to_statement_list (build_function_call (TREE_VALUE (cdtors), 0),
&body);
cgraph_build_static_cdtor (method_type, body);
}
/* Perform final processing on one file scope's declarations (or the
external scope's declarations), GLOBALS. */
static void
c_write_global_declarations_1 (tree globals)
{
@ -6602,20 +6624,38 @@ c_write_global_declarations_1 (tree globals)
void
c_write_global_declarations (void)
{
tree t;
tree ext_block, t;
/* We don't want to do this if generating a PCH. */
if (pch_file)
return;
/* Process all file scopes in this compilation. */
/* Close the external scope. */
ext_block = pop_scope ();
external_scope = 0;
if (current_scope)
abort ();
/* 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 = TREE_CHAIN (t))
c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
c_write_global_declarations_1 (BLOCK_VARS (ext_block));
/* Now do the same for the externals scope. */
t = pop_scope ();
if (t)
c_write_global_declarations_1 (BLOCK_VARS (t));
/* Generate functions to call static constructors and destructors
for targets that do not support .ctors/.dtors sections. These
functions have magic names which are detected by collect2. */
build_cdtor ('I', static_ctors); static_ctors = 0;
build_cdtor ('D', static_dtors); static_dtors = 0;
/* We're done parsing; proceed to optimize and emit assembly.
FIXME: shouldn't be the front end's responsibility to call this. */
cgraph_optimize ();
/* Presently this has to happen after cgraph_optimize.
FIXME: shouldn't be the front end's responsibility to call this. */
if (flag_mudflap)
mudflap_finish_file ();
}
#include "gt-c-decl.h"

View File

@ -197,10 +197,11 @@ const char *const tree_code_name[] = {
};
#undef DEFTREECODE
/* Final processing of file-scope data. The Objective-C version of
this function still does something. */
void
finish_file (void)
{
c_objc_common_finish_file ();
}
int

View File

@ -38,7 +38,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include "langhooks.h"
#include "tree-mudflap.h"
#include "target.h"
#include "cgraph.h"
static bool c_tree_printer (pretty_printer *, text_info *);
@ -183,50 +182,6 @@ c_objc_common_init (void)
return true;
}
/* Synthesize a function which calls all the global ctors or global dtors
in this file. */
static void
build_cdtor (int method_type, tree cdtors)
{
tree body;
body = push_stmt_list ();
for (; cdtors; cdtors = TREE_CHAIN (cdtors))
add_stmt (build_function_call (TREE_VALUE (cdtors), NULL_TREE));
body = pop_stmt_list (body);
cgraph_build_static_cdtor (method_type, body);
}
/* Called at end of parsing, but before end-of-file processing. */
void
c_objc_common_finish_file (void)
{
if (pch_file)
c_common_write_pch ();
if (static_ctors)
{
build_cdtor ('I', static_ctors);
static_ctors = 0;
}
if (static_dtors)
{
build_cdtor ('D', static_dtors);
static_dtors = 0;
}
cgraph_finalize_compilation_unit ();
cgraph_optimize ();
if (flag_mudflap)
mudflap_finish_file ();
}
/* Called during diagnostic message formatting process to print a
source-level entity onto BUFFER. The meaning of the format specifiers
is as follows:

View File

@ -197,7 +197,6 @@ extern int c_cannot_inline_tree_fn (tree *);
extern bool c_objc_common_init (void);
extern bool c_missing_noreturn_ok_p (tree);
extern tree c_objc_common_truthvalue_conversion (tree expr);
extern void c_objc_common_finish_file (void);
extern int defer_fn (tree);
extern bool c_warn_unused_global_decl (tree);
extern void c_initialize_diagnostics (diagnostic_context *);
@ -298,9 +297,6 @@ extern void *get_current_scope (void);
extern void objc_mark_locals_volatile (void *);
extern void c_write_global_declarations (void);
extern GTY(()) tree static_ctors;
extern GTY(()) tree static_dtors;
/* In order for the format checking to accept the C frontend
diagnostic framework extensions, you must include this file before
toplev.h, not after. */

View File

@ -519,7 +519,6 @@ void
finish_file (void)
{
mark_referenced_methods ();
c_objc_common_finish_file ();
/* Finalize Objective-C runtime data. No need to generate tables
and code if only checking syntax. */
@ -1959,7 +1958,7 @@ generate_static_references (void)
{
tree decls = NULL_TREE, ident, decl_spec, expr_decl, expr = NULL_TREE;
tree class_name, class, decl, initlist;
tree cl_chain, in_chain, type;
tree cl_chain, in_chain;
int num_inst, num_class;
char buf[256];
@ -1982,6 +1981,7 @@ generate_static_references (void)
decl = start_decl (expr_decl, decl_spec, 1, NULL_TREE);
DECL_CONTEXT (decl) = 0;
DECL_ARTIFICIAL (decl) = 1;
TREE_USED (decl) = 1;
/* Output {class_name, ...}. */
class = TREE_VALUE (cl_chain);
@ -2002,12 +2002,6 @@ generate_static_references (void)
expr = objc_build_constructor (TREE_TYPE (decl), nreverse (initlist));
finish_decl (decl, expr, NULL_TREE);
TREE_USED (decl) = 1;
type = build_array_type (build_pointer_type (void_type_node), 0);
decl = build_decl (VAR_DECL, ident, type);
TREE_USED (decl) = 1;
TREE_STATIC (decl) = 1;
decls
= tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, decl, 1), decls);
}
@ -2026,6 +2020,7 @@ generate_static_references (void)
expr = objc_build_constructor (TREE_TYPE (static_instances_decl),
nreverse (decls));
finish_decl (static_instances_decl, expr, NULL_TREE);
rest_of_decl_compilation (static_instances_decl, 0, 0, 0);
}
/* Output all strings. */