aboutsummaryrefslogtreecommitdiff
path: root/gcc/langhooks.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2021-11-02 10:51:23 +0000
committerRichard Sandiford <richard.sandiford@arm.com>2021-11-02 10:51:23 +0000
commitd5c6604f42034e36b149f899c5ddb93025a645b4 (patch)
tree3febb7400753ff374b3d69fb256da9e0a581a6a7 /gcc/langhooks.c
parentd8fe39f417bebd34498ea60a3815c2f420116ecf (diff)
downloadgcc-d5c6604f42034e36b149f899c5ddb93025a645b4.zip
gcc-d5c6604f42034e36b149f899c5ddb93025a645b4.tar.gz
gcc-d5c6604f42034e36b149f899c5ddb93025a645b4.tar.bz2
Add a simulate_record_decl lang hook
This patch adds a lang hook for defining a struct/RECORD_TYPE “as if” it had appeared directly in the source code. It follows the similar existing hook for enums. It's the caller's responsibility to create the fields (as FIELD_DECLs) but the hook's responsibility to create and declare the associated RECORD_TYPE. For now the hook is hard-coded to do the equivalent of: typedef struct NAME { FIELDS } NAME; but this could be controlled by an extra parameter if some callers want a different behaviour in future. The motivating use case is to allow the long list of struct definitions in arm_neon.h to be provided by the compiler, which in turn unblocks various arm_neon.h optimisations. gcc/ * langhooks.h (lang_hooks_for_types::simulate_record_decl): New hook. * langhooks-def.h (lhd_simulate_record_decl): Declare. (LANG_HOOKS_SIMULATE_RECORD_DECL): Define. (LANG_HOOKS_FOR_TYPES_INITIALIZER): Include it. * langhooks.c (lhd_simulate_record_decl): New function. gcc/c/ * c-tree.h (c_simulate_record_decl): Declare. * c-objc-common.h (LANG_HOOKS_SIMULATE_RECORD_DECL): Override. * c-decl.c (c_simulate_record_decl): New function. gcc/cp/ * decl.c: Include langhooks-def.h. (cxx_simulate_record_decl): New function. * cp-objcp-common.h (cxx_simulate_record_decl): Declare. (LANG_HOOKS_SIMULATE_RECORD_DECL): Override.
Diffstat (limited to 'gcc/langhooks.c')
-rw-r--r--gcc/langhooks.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/langhooks.c b/gcc/langhooks.c
index 48c7237..49613b4 100644
--- a/gcc/langhooks.c
+++ b/gcc/langhooks.c
@@ -516,6 +516,25 @@ lhd_simulate_enum_decl (location_t loc, const char *name,
return enumtype;
}
+/* Default implementation of LANG_HOOKS_SIMULATE_RECORD_DECL.
+ Just create a normal RECORD_TYPE and a TYPE_DECL for it. */
+tree
+lhd_simulate_record_decl (location_t loc, const char *name,
+ array_slice<const tree> fields)
+{
+ for (unsigned int i = 1; i < fields.size (); ++i)
+ /* Reversed by finish_builtin_struct. */
+ DECL_CHAIN (fields[i]) = fields[i - 1];
+
+ tree type = lang_hooks.types.make_type (RECORD_TYPE);
+ finish_builtin_struct (type, name, fields.back (), NULL_TREE);
+
+ tree decl = build_decl (loc, TYPE_DECL, get_identifier (name), type);
+ lang_hooks.decls.pushdecl (decl);
+
+ return type;
+}
+
/* Default implementation of LANG_HOOKS_TYPE_FOR_SIZE.
Return an integer type with PRECISION bits of precision,
that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */