This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[lto] Add nth_parm_type_p, alloc_parm_types, vec_heap2parm_types.
- From: Kazu Hirata <kazu at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: mark at codesourcery dot com
- Date: Sun, 16 Jul 2006 21:08:35 -0700
- Subject: [lto] Add nth_parm_type_p, alloc_parm_types, vec_heap2parm_types.
Hi,
Attached is a patch to add three new functions.
At some places, we need write access to members of TYPE_ARG_TYPES.
With nth_parm_type_p, we can do:
*(nth_parm_type_p (parm_types, 3)) = some_type;
So far, I've been addressing consumers of TYPE_ARG_TYPES, but there
are producers, too. For those, we can use alloc_parm_types to
allocate parm_types filled with NULL.
Fianlly, this patch introduces vec_heap2parm_types. This new function
is useful in a function like build_function_type_list, which takes a
variable number of parameters to specify a parameter type list, we
need to put those parameters into a VEC first and then convert that to
a TREE_VEC since TREE_VEC cannot grow on the fly.
To simplify the review process, this patch does not add any use of the
new functions except the use of nth_parm_type_p in
vec_heap2parm_types.
Tested on x86_64-pc-linux-gnu. OK to apply?
Kazu Hirata
2006-07-16 Kazu Hirata <kazu@codesourcery.com>
* tree.c (nth_parm_type_p, alloc_parm_types,
vec_heap2parm_types): New.
* tree.h: Add prototypes to the new functions.
Index: tree.c
===================================================================
--- tree.c (revision 115414)
+++ tree.c (working copy)
@@ -1587,6 +1587,56 @@ nth_parm_type (tree parmtypes, int n)
return TREE_VALUE (parmtypes);
}
+/* Return the pointer to the Nth element of PARMTYPES, a list of
+ parameter types. */
+
+tree *
+nth_parm_type_p (tree parmtypes, int n)
+{
+ while (n--)
+ {
+ gcc_assert (parmtypes);
+ parmtypes = TREE_CHAIN (parmtypes);
+ }
+
+ gcc_assert (parmtypes);
+ return &(TREE_VALUE (parmtypes));
+}
+
+/* Allocate parameter types of length LEN. */
+
+tree
+alloc_parm_types (int len)
+{
+ tree t = NULL;
+
+ while (len--)
+ t = tree_cons (NULL, NULL, t);
+
+ return t;
+}
+
+/* Make a parameter list containing types given in V. Return NULL if
+ V is empty. */
+
+tree
+vec_heap2parm_types (VEC(tree,heap) *v)
+{
+ tree parm_types = NULL_TREE;
+
+ if (!VEC_empty (tree, v))
+ {
+ tree t;
+ int i;
+
+ parm_types = alloc_parm_types (VEC_length (tree, v));
+ for (i = 0; VEC_iterate (tree, v, i, t); i++)
+ *(nth_parm_type_p (parm_types, i)) = t;
+ }
+
+ return parm_types;
+}
+
/* Returns the number of FIELD_DECLs in TYPE. */
int
Index: tree.h
===================================================================
--- tree.h (revision 115414)
+++ tree.h (working copy)
@@ -4162,6 +4162,9 @@ extern bool more_call_expr_args_p (const
extern int call_expr_nargs (tree);
extern tree call_expr_arg (tree, int);
extern tree *call_expr_argp (tree, int);
+extern tree *nth_parm_type_p (tree, int);
+extern tree alloc_parm_types (int);
+extern tree vec_heap2parm_types (VEC(tree,heap) *);
/* In stmt.c */