* the builtin_function hook
@ 2006-02-12 20:52 Rafael Espíndola
0 siblings, 0 replies; only message in thread
From: Rafael Espíndola @ 2006-02-12 20:52 UTC (permalink / raw)
To: gcc
[-- Attachment #1: Type: text/plain, Size: 905 bytes --]
There is a lot of duplicated code in the hooks implementation in the
various front ends. I am trying to factor it a little bit.
I started with the builtin_function hook. Doing a mostly mechanical
work I came up with the attached patch. The patch doesn't touches the
C++ front end because it is organised a little differently and would
require more work.
I don't want to apply this patch right now because I think that it can
be made a little better. To do this I need some clarifications:
*) Why does a front end needs to know when a new builtin is added?
*) If the internal representation used is language independent, can we
change the signature of builtin_function to receive just the decl
node?
The next thing I will try to do is wrap all calls to
lang_hooks.builtin_function in a add_builtin_function (in which file
should it be?) and move the common code into it.
Any comments?
Thanks,
Rafael
[-- Attachment #2: builtin.patch --]
[-- Type: application/octet-stream, Size: 12959 bytes --]
Index: gcc/java/decl.c
===================================================================
--- gcc/java/decl.c (revisão 110852)
+++ gcc/java/decl.c (cópia de trabalho)
@@ -554,21 +554,17 @@ push_promoted_type (const char *name, tr
ATTRS is nonzero, use that for the function's attribute list. */
tree
-builtin_function (const char *name,
- tree type,
- int function_code,
- enum built_in_class cl,
- const char *library_name,
- tree ARG_UNUSED (attrs))
-{
- tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
- DECL_EXTERNAL (decl) = 1;
- TREE_PUBLIC (decl) = 1;
- if (library_name)
- SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
+java_builtin_function (const char *name,
+ tree type,
+ int function_code,
+ enum built_in_class cl,
+ const char *library_name,
+ tree ARG_UNUSED (attrs))
+{
+ tree decl = lhd_builtin_function (name, type, function_code, cl,
+ library_name, attrs);
+
pushdecl (decl);
- DECL_BUILT_IN_CLASS (decl) = cl;
- DECL_FUNCTION_CODE (decl) = function_code;
return decl;
}
Index: gcc/java/lang.c
===================================================================
--- gcc/java/lang.c (revisão 110852)
+++ gcc/java/lang.c (cópia de trabalho)
@@ -213,6 +213,9 @@ struct language_function GTY(())
#undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
#define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME java_mangle_decl
+#undef LANG_HOOKS_BUILTIN_FUNCTION
+#define LANG_HOOKS_BUILTIN_FUNCTION java_builtin_function
+
/* Each front end provides its own. */
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
Index: gcc/cp/cp-objcp-common.h
===================================================================
--- gcc/cp/cp-objcp-common.h (revisão 110852)
+++ gcc/cp/cp-objcp-common.h (cópia de trabalho)
@@ -85,6 +85,8 @@ extern tree objcp_tsubst_copy_and_build
#define LANG_HOOKS_WRITE_GLOBALS lhd_do_nothing
#undef LANG_HOOKS_COMDAT_GROUP
#define LANG_HOOKS_COMDAT_GROUP cxx_comdat_group
+#undef LANG_HOOKS_BUILTIN_FUNCTION
+#define LANG_HOOKS_BUILTIN_FUNCTION builtin_function
#undef LANG_HOOKS_FUNCTION_INIT
#define LANG_HOOKS_FUNCTION_INIT cxx_push_function_context
Index: gcc/c-objc-common.h
===================================================================
--- gcc/c-objc-common.h (revisão 110852)
+++ gcc/c-objc-common.h (cópia de trabalho)
@@ -74,6 +74,8 @@ extern void c_initialize_diagnostics (di
#define LANG_HOOKS_FUNCTION_MISSING_NORETURN_OK_P c_missing_noreturn_ok_p
#undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
#define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL c_dup_lang_specific_decl
+#undef LANG_HOOKS_BUILTIN_FUNCTION
+#define LANG_HOOKS_BUILTIN_FUNCTION builtin_function
/* Attribute hooks. */
#undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
Index: gcc/ada/utils.c
===================================================================
--- gcc/ada/utils.c (revisão 110852)
+++ gcc/ada/utils.c (cópia de trabalho)
@@ -1812,20 +1812,14 @@ gnat_gimplify_function (tree fndecl)
ATTRS is nonzero, use that for the function attribute list. */
tree
-builtin_function (const char *name, tree type, int function_code,
- enum built_in_class class, const char *library_name,
- tree attrs)
-{
- tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
-
- DECL_EXTERNAL (decl) = 1;
- TREE_PUBLIC (decl) = 1;
- if (library_name)
- SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
+gnat_builtin_function (const char *name, tree type, int function_code,
+ enum built_in_class class, const char *library_name,
+ tree attrs)
+{
+ tree decl = lhd_builtin_function (name, type, function_code, class,
+ library_name, attrs);
gnat_pushdecl (decl, Empty);
- DECL_BUILT_IN_CLASS (decl) = class;
- DECL_FUNCTION_CODE (decl) = function_code;
if (attrs)
decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
return decl;
Index: gcc/ada/misc.c
===================================================================
--- gcc/ada/misc.c (revisão 110852)
+++ gcc/ada/misc.c (cópia de trabalho)
@@ -158,6 +158,8 @@ static tree gnat_type_max_size (tree);
#define LANG_HOOKS_UNSIGNED_TYPE gnat_unsigned_type
#undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
#define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE gnat_signed_or_unsigned_type
+#undef LANG_HOOKS_BUILTIN_FUNCTION
+#define LANG_HOOKS_BUILTIN_FUNCTION gnat_builtin_function
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
Index: gcc/ada/gigi.h
===================================================================
--- gcc/ada/gigi.h (revisão 110852)
+++ gcc/ada/gigi.h (cópia de trabalho)
@@ -761,9 +761,10 @@ extern tree fill_vms_descriptor (tree ex
extern bool gnat_mark_addressable (tree expr_node);
/* Implementation of the builtin_function langhook. */
-extern tree builtin_function (const char *name, tree type, int function_code,
- enum built_in_class class,
- const char *library_name, tree attrs);
+extern tree gnat_builtin_function (const char *name, tree type,
+ int function_code,
+ enum built_in_class class,
+ const char *library_name, tree attrs);
/* Search the chain of currently reachable declarations for a builtin
FUNCTION_DECL node corresponding to function NAME (an IDENTIFIER_NODE).
Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c (revisão 110852)
+++ gcc/c-decl.c (cópia de trabalho)
@@ -2807,16 +2807,12 @@ builtin_function (const char *name, tree
enum built_in_class cl, const char *library_name,
tree attrs)
{
+ tree decl = lhd_builtin_function (name, type, function_code, cl,
+ library_name, attrs);
+
tree id = get_identifier (name);
- tree decl = build_decl (FUNCTION_DECL, id, type);
- TREE_PUBLIC (decl) = 1;
- DECL_EXTERNAL (decl) = 1;
DECL_LANG_SPECIFIC (decl) = GGC_CNEW (struct lang_decl);
- DECL_BUILT_IN_CLASS (decl) = cl;
- DECL_FUNCTION_CODE (decl) = function_code;
C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0);
- if (library_name)
- SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
/* Should never be called on a symbol with a preexisting meaning. */
gcc_assert (!I_SYMBOL_BINDING (id));
Index: gcc/fortran/trans.h
===================================================================
--- gcc/fortran/trans.h (revisão 110852)
+++ gcc/fortran/trans.h (cópia de trabalho)
@@ -436,8 +436,8 @@ void pushlevel (int);
tree poplevel (int, int, int);
tree getdecls (void);
tree gfc_truthvalue_conversion (tree);
-tree builtin_function (const char *, tree, int, enum built_in_class,
- const char *, tree);
+tree gfc_builtin_function (const char *, tree, int, enum built_in_class,
+ const char *, tree);
/* Runtime library function decls. */
extern GTY(()) tree gfor_fndecl_internal_malloc;
Index: gcc/fortran/f95-lang.c
===================================================================
--- gcc/fortran/f95-lang.c (revisão 110852)
+++ gcc/fortran/f95-lang.c (cópia de trabalho)
@@ -134,6 +134,8 @@ static void gfc_expand_function (tree);
#define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE gfc_signed_or_unsigned_type
#define LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION gfc_expand_function
#define LANG_HOOKS_CLEAR_BINDING_STACK gfc_clear_binding_stack
+#undef LANG_HOOKS_BUILTIN_FUNCTION
+#define LANG_HOOKS_BUILTIN_FUNCTION gfc_builtin_function
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
@@ -699,23 +701,18 @@ int ggc_p = 1;
ATTRS is nonzero, use that for the function's attribute list. */
tree
-builtin_function (const char *name,
- tree type,
- int function_code,
- enum built_in_class class,
- const char *library_name,
- tree attrs)
-{
- tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
- DECL_EXTERNAL (decl) = 1;
- TREE_PUBLIC (decl) = 1;
- if (library_name)
- SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
+gfc_builtin_function (const char *name,
+ tree type,
+ int function_code,
+ enum built_in_class class,
+ const char *library_name,
+ tree attrs)
+{
+ tree decl = lhd_builtin_function (name, type, function_code, class,
+ library_name, attrs);
+
make_decl_rtl (decl);
pushdecl (decl);
- DECL_BUILT_IN_CLASS (decl) = class;
- DECL_FUNCTION_CODE (decl) = function_code;
-
/* Possibly apply some default attributes to this built-in function. */
if (attrs)
{
@@ -739,8 +736,8 @@ gfc_define_builtin (const char * name,
{
tree decl;
- decl = builtin_function (name, type, code, BUILT_IN_NORMAL,
- library_name, NULL_TREE);
+ decl = gfc_builtin_function (name, type, code, BUILT_IN_NORMAL,
+ library_name, NULL_TREE);
if (const_p)
TREE_READONLY (decl) = 1;
Index: gcc/langhooks.c
===================================================================
--- gcc/langhooks.c (revisão 110852)
+++ gcc/langhooks.c (cópia de trabalho)
@@ -578,3 +578,22 @@ lhd_omp_firstprivatize_type_sizes (struc
tree t ATTRIBUTE_UNUSED)
{
}
+
+tree
+lhd_builtin_function (const char *name,
+ tree type,
+ int function_code,
+ enum built_in_class cl,
+ const char *library_name,
+ tree ARG_UNUSED (attrs))
+{
+ tree id = get_identifier (name);
+ tree decl = build_decl (FUNCTION_DECL, id, type);
+ TREE_PUBLIC (decl) = 1;
+ DECL_EXTERNAL (decl) = 1;
+ if (library_name)
+ SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
+ DECL_BUILT_IN_CLASS (decl) = cl;
+ DECL_FUNCTION_CODE (decl) = function_code;
+ return decl;
+}
Index: gcc/treelang/treetree.c
===================================================================
--- gcc/treelang/treetree.c (revisão 110852)
+++ gcc/treelang/treetree.c (cópia de trabalho)
@@ -138,10 +138,11 @@ static tree pushdecl (tree decl);
static tree* getstmtlist (void);
/* Langhooks. */
-static tree builtin_function (const char *name, tree type, int function_code,
- enum built_in_class class,
- const char *library_name,
- tree attrs);
+static tree treelang_builtin_function (const char *name, tree type,
+ int function_code,
+ enum built_in_class class,
+ const char *library_name,
+ tree attrs);
extern const struct attribute_spec treelang_attribute_table[];
static tree getdecls (void);
static int global_bindings_p (void);
@@ -189,6 +190,8 @@ static void treelang_expand_function (tr
#define LANG_HOOKS_INIT_OPTIONS treelang_init_options
#undef LANG_HOOKS_HANDLE_OPTION
#define LANG_HOOKS_HANDLE_OPTION treelang_handle_option
+#undef LANG_HOOKS_BUILTIN_FUNCTION
+#define LANG_HOOKS_BUILTIN_FUNCTION treelang_builtin_function
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
/* Tree code type/name/code tables. */
@@ -1237,18 +1240,13 @@ const struct attribute_spec treelang_att
*/
static tree
-builtin_function (const char *name, tree type, int function_code,
+treelang_builtin_function (const char *name, tree type, int function_code,
enum built_in_class class, const char *library_name,
tree attrs)
{
- tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
- DECL_EXTERNAL (decl) = 1;
- TREE_PUBLIC (decl) = 1;
- if (library_name)
- SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
+ tree decl = lhd_builtin_function (name, type, function_code, class,
+ library_name, attrs);
pushdecl (decl);
- DECL_BUILT_IN_CLASS (decl) = class;
- DECL_FUNCTION_CODE (decl) = function_code;
/* Possibly apply some default attributes to this built-in function. */
if (attrs)
Index: gcc/langhooks-def.h
===================================================================
--- gcc/langhooks-def.h (revisão 110852)
+++ gcc/langhooks-def.h (cópia de trabalho)
@@ -70,6 +70,10 @@ extern tree lhd_expr_size (tree);
extern size_t lhd_tree_size (enum tree_code);
extern HOST_WIDE_INT lhd_to_target_charset (HOST_WIDE_INT);
extern tree lhd_expr_to_decl (tree, bool *, bool *, bool *);
+extern tree lhd_builtin_function (const char *name, tree type,
+ int function_code, enum built_in_class cl,
+ const char *library_name,
+ tree ARG_UNUSED (attrs));
/* Declarations of default tree inlining hooks. */
extern tree lhd_tree_inlining_walk_subtrees (tree *, int *, walk_tree_fn,
@@ -128,7 +132,7 @@ extern void lhd_omp_firstprivatize_type_
#define LANG_HOOKS_EXPR_SIZE lhd_expr_size
#define LANG_HOOKS_TREE_SIZE lhd_tree_size
#define LANG_HOOKS_TYPES_COMPATIBLE_P lhd_types_compatible_p
-#define LANG_HOOKS_BUILTIN_FUNCTION builtin_function
+#define LANG_HOOKS_BUILTIN_FUNCTION lhd_builtin_function
#define LANG_HOOKS_EXPR_TO_DECL lhd_expr_to_decl
#define LANG_HOOKS_TO_TARGET_CHARSET lhd_to_target_charset
#define LANG_HOOKS_INIT_TS lhd_do_nothing
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-02-12 20:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-12 20:52 the builtin_function hook Rafael Espíndola
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).