diff options
Diffstat (limited to 'gcc/tree.c')
-rw-r--r-- | gcc/tree.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/gcc/tree.c b/gcc/tree.c index cf7e362eff3..de16549a099 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -76,6 +76,7 @@ along with GCC; see the file COPYING3. If not see #include "debug.h" #include "intl.h" #include "wide-int.h" +#include "builtins.h" /* Tree code classes. */ @@ -10467,6 +10468,91 @@ build_call_vec (tree return_type, tree fn, vec<tree, va_gc> *args) return ret; } +/* Conveniently construct a function call expression. FNDECL names the + function to be called and N arguments are passed in the array + ARGARRAY. */ + +tree +build_call_expr_loc_array (location_t loc, tree fndecl, int n, tree *argarray) +{ + tree fntype = TREE_TYPE (fndecl); + tree fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl); + + return fold_builtin_call_array (loc, TREE_TYPE (fntype), fn, n, argarray); +} + +/* Conveniently construct a function call expression. FNDECL names the + function to be called and the arguments are passed in the vector + VEC. */ + +tree +build_call_expr_loc_vec (location_t loc, tree fndecl, vec<tree, va_gc> *vec) +{ + return build_call_expr_loc_array (loc, fndecl, vec_safe_length (vec), + vec_safe_address (vec)); +} + + +/* Conveniently construct a function call expression. FNDECL names the + function to be called, N is the number of arguments, and the "..." + parameters are the argument expressions. */ + +tree +build_call_expr_loc (location_t loc, tree fndecl, int n, ...) +{ + va_list ap; + tree *argarray = XALLOCAVEC (tree, n); + int i; + + va_start (ap, n); + for (i = 0; i < n; i++) + argarray[i] = va_arg (ap, tree); + va_end (ap); + return build_call_expr_loc_array (loc, fndecl, n, argarray); +} + +/* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because + varargs macros aren't supported by all bootstrap compilers. */ + +tree +build_call_expr (tree fndecl, int n, ...) +{ + va_list ap; + tree *argarray = XALLOCAVEC (tree, n); + int i; + + va_start (ap, n); + for (i = 0; i < n; i++) + argarray[i] = va_arg (ap, tree); + va_end (ap); + return build_call_expr_loc_array (UNKNOWN_LOCATION, fndecl, n, argarray); +} + +/* Create a new constant string literal and return a char* pointer to it. + The STRING_CST value is the LEN characters at STR. */ +tree +build_string_literal (int len, const char *str) +{ + tree t, elem, index, type; + + t = build_string (len, str); + elem = build_type_variant (char_type_node, 1, 0); + index = build_index_type (size_int (len - 1)); + type = build_array_type (elem, index); + TREE_TYPE (t) = type; + TREE_CONSTANT (t) = 1; + TREE_READONLY (t) = 1; + TREE_STATIC (t) = 1; + + type = build_pointer_type (elem); + t = build1 (ADDR_EXPR, type, + build4 (ARRAY_REF, elem, + t, integer_zero_node, NULL_TREE, NULL_TREE)); + return t; +} + + + /* Return true if T (assumed to be a DECL) must be assigned a memory location. */ |