* [PATCH 0/7] move arch-specific builtins to their own table @ 2020-06-10 20:27 Luc Van Oostenryck 2020-06-10 20:27 ` [PATCH 1/7] builtin: can be initialized later Luc Van Oostenryck ` (6 more replies) 0 siblings, 7 replies; 14+ messages in thread From: Luc Van Oostenryck @ 2020-06-10 20:27 UTC (permalink / raw) To: linux-sparse; +Cc: Luc Van Oostenryck The goal of this to avoid the declaration of arch-specific builtins when the architecture doesn't match. As nice side-effects it also: * add support for arch-specific builtins in their target-<arch>.c * let these builtins declarations be done via a table (it was done via a serie of function calls, one by builtin). * add minimal support for the architectures Alpha, Blackfin & Nios2. These changes are motivated by a recent report from the kbuild test bot (which seems to find lately much more sparse-related issues in the kernel than it used to, often address-space & endianness problems). Luc Van Oostenryck (7): builtin: can be initialized later builtin: use a table for the builtins builtin: unify the 2 tables of builtins builtin: add support for arch-specific builtins arch: add specificities for Nios2 arch: add specificities for Blackfin arch: add specificities for Alpha Makefile | 3 + builtin.c | 439 ++++++++++++++++++++++--------------------------- builtin.h | 15 ++ lib.c | 2 +- machine.h | 5 + symbol.c | 1 - symbol.h | 1 - target-alpha.c | 30 ++++ target-bfin.c | 26 +++ target-nios2.c | 31 ++++ target.c | 6 + target.h | 7 + 12 files changed, 321 insertions(+), 245 deletions(-) create mode 100644 builtin.h create mode 100644 target-alpha.c create mode 100644 target-bfin.c create mode 100644 target-nios2.c base-commit: 42323db3955557b223268ec4196acb77308ab204 -- 2.27.0 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/7] builtin: can be initialized later 2020-06-10 20:27 [PATCH 0/7] move arch-specific builtins to their own table Luc Van Oostenryck @ 2020-06-10 20:27 ` Luc Van Oostenryck 2020-06-12 0:50 ` Ramsay Jones 2020-06-10 20:27 ` [PATCH 2/7] builtin: use a table for the builtins Luc Van Oostenryck ` (5 subsequent siblings) 6 siblings, 1 reply; 14+ messages in thread From: Luc Van Oostenryck @ 2020-06-10 20:27 UTC (permalink / raw) To: linux-sparse; +Cc: Luc Van Oostenryck The itialization of the buitins can be done later, after that the types have been initialized. So move the call to init_builtins() to just before declare_builtins(). This will allow some other small improvements. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- lib.c | 1 + symbol.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.c b/lib.c index 8f071bfe96ef..aa1c1d656b9d 100644 --- a/lib.c +++ b/lib.c @@ -1595,6 +1595,7 @@ struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list predefined_macros(); create_builtin_stream(); + init_builtins(0); declare_builtins(); list = sparse_initial(); diff --git a/symbol.c b/symbol.c index 7044ab3f78ce..6ee521ba48d8 100644 --- a/symbol.c +++ b/symbol.c @@ -783,7 +783,6 @@ void init_symbols(void) #include "ident-list.h" init_parser(stream); - init_builtins(stream); } // For fix-sized types -- 2.27.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 1/7] builtin: can be initialized later 2020-06-10 20:27 ` [PATCH 1/7] builtin: can be initialized later Luc Van Oostenryck @ 2020-06-12 0:50 ` Ramsay Jones 0 siblings, 0 replies; 14+ messages in thread From: Ramsay Jones @ 2020-06-12 0:50 UTC (permalink / raw) To: Luc Van Oostenryck, linux-sparse On 10/06/2020 21:27, Luc Van Oostenryck wrote: > The itialization of the buitins can be done later, s/itialization/initialization/ > after that the types have been initialized. s/that the/the/ > > So move the call to init_builtins() to just before declare_builtins(). > This will allow some other small improvements. > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> > --- > lib.c | 1 + > symbol.c | 1 - > 2 files changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib.c b/lib.c > index 8f071bfe96ef..aa1c1d656b9d 100644 > --- a/lib.c > +++ b/lib.c > @@ -1595,6 +1595,7 @@ struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list > > predefined_macros(); > create_builtin_stream();> + init_builtins(0); Hmm, if memory serves (and it may not) doesn't declare_builtins() also assume stream zero - but it had a FIXME comment against it. So, should this new call also have a FIXME? ;-) I think the last time I looked in the debugger, the first call to init_stream() was for the 'builtins' - so it seems that it would always be stream 0, but has this changed the relative location of the init_stream() calls that would invalidate this? Hmm, I guess not - the builtin init_stream() call was in the sparse_initialize() call, if memory serves. Also, I guess it would only affect the stream field of the builtin symbol token, so ... So, ignore my rambling ... :-D ATB, Ramsay Jones > declare_builtins(); > > list = sparse_initial(); > diff --git a/symbol.c b/symbol.c > index 7044ab3f78ce..6ee521ba48d8 100644 > --- a/symbol.c > +++ b/symbol.c > @@ -783,7 +783,6 @@ void init_symbols(void) > #include "ident-list.h" > > init_parser(stream); > - init_builtins(stream); > } > > // For fix-sized types > ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 2/7] builtin: use a table for the builtins 2020-06-10 20:27 [PATCH 0/7] move arch-specific builtins to their own table Luc Van Oostenryck 2020-06-10 20:27 ` [PATCH 1/7] builtin: can be initialized later Luc Van Oostenryck @ 2020-06-10 20:27 ` Luc Van Oostenryck 2020-06-12 0:56 ` Ramsay Jones 2020-06-10 20:27 ` [PATCH 3/7] builtin: unify the 2 tables of builtins Luc Van Oostenryck ` (4 subsequent siblings) 6 siblings, 1 reply; 14+ messages in thread From: Luc Van Oostenryck @ 2020-06-10 20:27 UTC (permalink / raw) To: linux-sparse; +Cc: Luc Van Oostenryck The curent way to declare the builtins is not by using a table but via a (variadic) function call, one for each builtin. A table is table is preferable but a complication for doing this is that some elements are not constant. For example, 'size_t_ctype' is dynamically set in the early steps of the type initialization. Doing a series of function calls allowed to circumvent this. Fix this by: * Using a constant temporary alias for non-constant entries. It's the value of these alias that will be used when registering the builtins. * using a table to declare the builtin functions. Note: the motivation for doing this is to be able to add sub-tables for the arch-specific builtins (and use the same mechanism as for the main table). Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- builtin.c | 411 ++++++++++++++++++++++++++++-------------------------- builtin.h | 14 ++ lib.c | 1 - symbol.h | 1 - 4 files changed, 227 insertions(+), 200 deletions(-) create mode 100644 builtin.h diff --git a/builtin.c b/builtin.c index 5ed17700d422..aa9ce09c0f40 100644 --- a/builtin.c +++ b/builtin.c @@ -23,6 +23,7 @@ * THE SOFTWARE. */ +#include "builtin.h" #include "expression.h" #include "evaluate.h" #include "expand.h" @@ -357,6 +358,217 @@ static struct symbol_op overflow_p_op = { /* * Builtin functions */ +static struct symbol size_t_alias; + +static struct symbol *get_ctype(struct symbol *sym) +{ + if (sym == &size_t_alias) + return size_t_ctype; + return sym; +} + +static void declare_one_builtin(const struct builtin_fn *entry) +{ + struct symbol *sym = create_symbol(0, entry->name, SYM_NODE, NS_SYMBOL); + struct symbol *fun = alloc_symbol(sym->pos, SYM_FN); + struct symbol *arg; + int i; + + sym->ctype.base_type = fun; + sym->ctype.modifiers = MOD_TOPLEVEL; + sym->builtin = 1; + + fun->ctype.base_type = get_ctype(entry->ret_type); + fun->variadic = entry->variadic; + + for (i = 0; (arg = entry->args[i]); i++) { + struct symbol *anode = alloc_symbol(sym->pos, SYM_NODE); + anode->ctype.base_type = get_ctype(arg); + add_symbol(&fun->arguments, anode); + } +} + +static void declare_builtins(const struct builtin_fn tbl[]) +{ + while (tbl->name) + declare_one_builtin(tbl++); +} + +static const struct builtin_fn builtins_common[] = { +#define size_t_ctype &size_t_alias +#define va_list_ctype &ptr_ctype + { "__builtin_abort", &void_ctype, 0 }, + { "__builtin_abs", &int_ctype , 0, { &int_ctype }}, + { "__builtin_alloca", &ptr_ctype, 0, { size_t_ctype }}, + { "__builtin_alpha_cmpbge", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_extbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_extwl", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_insbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_inslh", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_insql", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_inswl", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_bcmp", &int_ctype , 0, { &const_ptr_ctype, &const_ptr_ctype, size_t_ctype }}, + { "__builtin_bcopy", &void_ctype, 0, { &const_ptr_ctype, &ptr_ctype, size_t_ctype }}, + { "__builtin_bswap16", &ushort_ctype, 0, { &ushort_ctype }}, + { "__builtin_bswap32", &uint_ctype, 0, { &uint_ctype }}, + { "__builtin_bswap64", &ullong_ctype, 0, { &ullong_ctype }}, + { "__builtin_bzero", &void_ctype, 0, { &ptr_ctype, size_t_ctype }}, + { "__builtin_calloc", &ptr_ctype, 0, { size_t_ctype, size_t_ctype }}, + { "__builtin_clrsb", &int_ctype, 0, { &int_ctype }}, + { "__builtin_clrsbl", &int_ctype, 0, { &long_ctype }}, + { "__builtin_clrsbll", &int_ctype, 0, { &llong_ctype }}, + { "__builtin_clz", &int_ctype, 0, { &int_ctype }}, + { "__builtin_clzl", &int_ctype, 0, { &long_ctype }}, + { "__builtin_clzll", &int_ctype, 0, { &llong_ctype }}, + { "__builtin_ctz", &int_ctype, 0, { &int_ctype }}, + { "__builtin_ctzl", &int_ctype, 0, { &long_ctype }}, + { "__builtin_ctzll", &int_ctype, 0, { &llong_ctype }}, + { "__builtin_exit", &void_ctype, 0, { &int_ctype }}, + { "__builtin_expect", &long_ctype, 0, { &long_ctype ,&long_ctype }}, + { "__builtin_extract_return_addr", &ptr_ctype, 0, { &ptr_ctype }}, + { "__builtin_fabs", &double_ctype, 0, { &double_ctype }}, + { "__builtin_ffs", &int_ctype, 0, { &int_ctype }}, + { "__builtin_ffsl", &int_ctype, 0, { &long_ctype }}, + { "__builtin_ffsll", &int_ctype, 0, { &llong_ctype }}, + { "__builtin_frame_address", &ptr_ctype, 0, { &uint_ctype }}, + { "__builtin_free", &void_ctype, 0, { &ptr_ctype }}, + { "__builtin_huge_val", &double_ctype, 0 }, + { "__builtin_huge_valf", &float_ctype, 0 }, + { "__builtin_huge_vall", &ldouble_ctype, 0 }, + { "__builtin_index", &string_ctype, 0, { &const_string_ctype, &int_ctype }}, + { "__builtin_inf", &double_ctype, 0 }, + { "__builtin_inff", &float_ctype, 0 }, + { "__builtin_infl", &ldouble_ctype, 0 }, + { "__builtin_isfinite", &int_ctype, 1 }, + { "__builtin_isgreater", &int_ctype, 0, { &float_ctype, &float_ctype }}, + { "__builtin_isgreaterequal", &int_ctype, 0, { &float_ctype, &float_ctype }}, + { "__builtin_isinf", &int_ctype, 1 }, + { "__builtin_isinf_sign", &int_ctype, 1 }, + { "__builtin_isless", &int_ctype, 0, { &float_ctype, &float_ctype }}, + { "__builtin_islessequal", &int_ctype, 0, { &float_ctype, &float_ctype }}, + { "__builtin_islessgreater", &int_ctype, 0, { &float_ctype, &float_ctype }}, + { "__builtin_isnan", &int_ctype, 1 }, + { "__builtin_isnormal", &int_ctype, 1 }, + { "__builtin_isunordered", &int_ctype, 0, { &float_ctype, &float_ctype }}, + { "__builtin_labs", &long_ctype, 0, { &long_ctype }}, + { "__builtin_llabs", &llong_ctype, 0, { &llong_ctype }}, + { "__builtin_malloc", &ptr_ctype, 0, { size_t_ctype }}, + { "__builtin_memchr", &ptr_ctype, 0, { &const_ptr_ctype, &int_ctype, size_t_ctype }}, + { "__builtin_memcmp", &int_ctype, 0, { &const_ptr_ctype, &const_ptr_ctype, size_t_ctype }}, + { "__builtin_memcpy", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype }}, + { "__builtin_memmove", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype }}, + { "__builtin_mempcpy", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype }}, + { "__builtin_memset", &ptr_ctype, 0, { &ptr_ctype, &int_ctype, size_t_ctype }}, + { "__builtin_nan", &double_ctype, 0, { &const_string_ctype }}, + { "__builtin_nanf", &float_ctype, 0, { &const_string_ctype }}, + { "__builtin_nanl", &ldouble_ctype, 0, { &const_string_ctype }}, + { "__builtin_object_size", size_t_ctype, 0, { &const_ptr_ctype, &int_ctype }}, + { "__builtin_parity", &int_ctype, 0, { &uint_ctype }}, + { "__builtin_parityl", &int_ctype, 0, { &ulong_ctype }}, + { "__builtin_parityll", &int_ctype, 0, { &ullong_ctype }}, + { "__builtin_popcount", &int_ctype, 0, { &uint_ctype }}, + { "__builtin_popcountl", &int_ctype, 0, { &ulong_ctype }}, + { "__builtin_popcountll", &int_ctype, 0, { &ullong_ctype }}, + { "__builtin_prefetch", &void_ctype, 1, { &const_ptr_ctype }}, + { "__builtin_printf", &int_ctype, 1, { &const_string_ctype }}, + { "__builtin_puts", &int_ctype, 0, { &const_string_ctype }}, + { "__builtin_realloc", &ptr_ctype, 0, { &ptr_ctype, size_t_ctype }}, + { "__builtin_return_address", &ptr_ctype, 0, { &uint_ctype }}, + { "__builtin_rindex", &string_ctype, 0, { &const_string_ctype, &int_ctype }}, + { "__builtin_sadd_overflow", &bool_ctype, 0, { &int_ctype, &int_ctype, &int_ptr_ctype }}, + { "__builtin_saddl_overflow", &bool_ctype, 0, { &long_ctype, &long_ctype, &long_ptr_ctype }}, + { "__builtin_saddll_overflow", &bool_ctype, 0, { &llong_ctype, &llong_ctype, &llong_ptr_ctype }}, + { "__builtin_signbit", &int_ctype, 1 }, + { "__builtin_smul_overflow", &bool_ctype, 0, { &int_ctype, &int_ctype, &int_ptr_ctype }}, + { "__builtin_smull_overflow", &bool_ctype, 0, { &long_ctype, &long_ctype, &long_ptr_ctype }}, + { "__builtin_smulll_overflow", &bool_ctype, 0, { &llong_ctype, &llong_ctype, &llong_ptr_ctype }}, + { "__builtin_snprintf", &int_ctype, 1, { &string_ctype, size_t_ctype, &const_string_ctype }}, + { "__builtin_sprintf", &int_ctype, 1, { &string_ctype, &const_string_ctype }}, + { "__builtin_ssub_overflow", &bool_ctype, 0, { &int_ctype, &int_ctype, &int_ptr_ctype }}, + { "__builtin_ssubl_overflow", &bool_ctype, 0, { &long_ctype, &long_ctype, &long_ptr_ctype }}, + { "__builtin_ssubll_overflow", &bool_ctype, 0, { &llong_ctype, &llong_ctype, &llong_ptr_ctype }}, + { "__builtin_stpcpy", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }}, + { "__builtin_stpncpy", &string_ctype, 0, { &const_string_ctype, &const_string_ctype, size_t_ctype }}, + { "__builtin_strcasecmp", &int_ctype, 0, { &const_string_ctype, &const_string_ctype }}, + { "__builtin_strcasestr", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }}, + { "__builtin_strcat", &string_ctype, 0, { &string_ctype, &const_string_ctype }}, + { "__builtin_strchr", &string_ctype, 0, { &const_string_ctype, &int_ctype }}, + { "__builtin_strcmp", &int_ctype, 0, { &const_string_ctype, &const_string_ctype }}, + { "__builtin_strcpy", &string_ctype, 0, { &string_ctype, &const_string_ctype }}, + { "__builtin_strcspn", size_t_ctype, 0, { &const_string_ctype, &const_string_ctype }}, + { "__builtin_strdup", &string_ctype, 0, { &const_string_ctype }}, + { "__builtin_strlen", size_t_ctype, 0, { &const_string_ctype }}, + { "__builtin_strncasecmp", &int_ctype, 0, { &const_string_ctype, &const_string_ctype, size_t_ctype }}, + { "__builtin_strncat", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }}, + { "__builtin_strncmp", &int_ctype, 0, { &const_string_ctype, &const_string_ctype, size_t_ctype }}, + { "__builtin_strncpy", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }}, + { "__builtin_strndup", &string_ctype, 0, { &const_string_ctype, size_t_ctype }}, + { "__builtin_strnstr", &string_ctype, 0, { &const_string_ctype, &const_string_ctype, size_t_ctype }}, + { "__builtin_strpbrk", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }}, + { "__builtin_strrchr", &string_ctype, 0, { &const_string_ctype, &int_ctype }}, + { "__builtin_strspn", size_t_ctype, 0, { &const_string_ctype, &const_string_ctype }}, + { "__builtin_strstr", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }}, + { "__builtin_trap", &void_ctype, 0 }, + { "__builtin_uadd_overflow", &bool_ctype, 0, { &uint_ctype, &uint_ctype, &uint_ptr_ctype }}, + { "__builtin_uaddl_overflow", &bool_ctype, 0, { &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype }}, + { "__builtin_uaddll_overflow", &bool_ctype, 0, { &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype }}, + { "__builtin_umul_overflow", &bool_ctype, 0, { &uint_ctype, &uint_ctype, &uint_ptr_ctype }}, + { "__builtin_umull_overflow", &bool_ctype, 0, { &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype }}, + { "__builtin_umulll_overflow", &bool_ctype, 0, { &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype }}, + { "__builtin_unreachable", &void_ctype, 0 }, + { "__builtin_usub_overflow", &bool_ctype, 0, { &uint_ctype, &uint_ctype, &uint_ptr_ctype }}, + { "__builtin_usubl_overflow", &bool_ctype, 0, { &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype }}, + { "__builtin_usubll_overflow", &bool_ctype, 0, { &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype }}, + { "__builtin_va_arg_pack_len", size_t_ctype, 0 }, + { "__builtin_vprintf", &int_ctype, 0, { &const_string_ctype, va_list_ctype }}, + { "__builtin_vsnprintf", &int_ctype, 0, { &string_ctype, size_t_ctype, &const_string_ctype, va_list_ctype }}, + { "__builtin_vsprintf", &int_ctype, 0, { &string_ctype, &const_string_ctype, va_list_ctype }}, + + { "__builtin___memcpy_chk", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype }}, + { "__builtin___memmove_chk", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype }}, + { "__builtin___mempcpy_chk", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype }}, + { "__builtin___memset_chk", &ptr_ctype, 0, { &ptr_ctype, &int_ctype, size_t_ctype, size_t_ctype }}, + { "__builtin___snprintf_chk", &int_ctype, 1, { &string_ctype, size_t_ctype, &int_ctype , size_t_ctype, &const_string_ctype }}, + { "__builtin___sprintf_chk", &int_ctype, 1, { &string_ctype, &int_ctype, size_t_ctype, &const_string_ctype }}, + { "__builtin___stpcpy_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }}, + { "__builtin___strcat_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }}, + { "__builtin___strcpy_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }}, + { "__builtin___strncat_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype, size_t_ctype }}, + { "__builtin___strncpy_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype, size_t_ctype }}, + { "__builtin___vsnprintf_chk", &int_ctype, 0, { &string_ctype, size_t_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype }}, + { "__builtin___vsprintf_chk", &int_ctype, 0, { &string_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype }}, + + { "__sync_add_and_fetch", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_and_and_fetch", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_bool_compare_and_swap", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_fetch_and_add", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_fetch_and_and", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_fetch_and_nand", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_fetch_and_or", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_fetch_and_sub", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_fetch_and_xor", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_lock_release", &void_ctype, 1, { &ptr_ctype }}, + { "__sync_lock_test_and_set", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_nand_and_fetch", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_or_and_fetch", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_sub_and_fetch", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_synchronize", &void_ctype, 0 }, + { "__sync_val_compare_and_swap", &int_ctype, 1, { &ptr_ctype }}, + { "__sync_xor_and_fetch", &int_ctype, 1, { &ptr_ctype }}, + + // Blackfin-specific stuff + { "__builtin_bfin_csync", &void_ctype, 0 }, + { "__builtin_bfin_ssync", &void_ctype, 0 }, + { "__builtin_bfin_norm_fr1x32", &int_ctype, 0, { &int_ctype }}, + + // Nios-II-specific + { "__builtin_rdctl", &int_ctype, 0, { &int_ctype }}, + { "__builtin_wrctl", &void_ctype, 0, { &int_ctype, &int_ctype }}, + { "__builtin_custom_ini", &int_ctype, 0, { &int_ctype }}, + + { } +}; + static struct symbol builtin_fn_type = { .type = SYM_FN /* , .variadic =1 */ }; static struct sym_init { const char *name; @@ -420,202 +632,5 @@ void init_builtins(int stream) } init_linearized_builtins(stream); -} - -static void declare_builtin(const char *name, struct symbol *rtype, int variadic, ...) -{ - int stream = 0; // FIXME - struct symbol *sym = create_symbol(stream, name, SYM_NODE, NS_SYMBOL); - struct symbol *fun = alloc_symbol(sym->pos, SYM_FN); - struct symbol *arg; - va_list args; - - sym->ctype.base_type = fun; - sym->ctype.modifiers = MOD_TOPLEVEL; - sym->builtin = 1; - - fun->ctype.base_type = rtype; - fun->variadic = variadic; - - va_start(args, variadic); - while ((arg = va_arg(args, struct symbol *))) { - struct symbol *anode = alloc_symbol(sym->pos, SYM_NODE); - anode->ctype.base_type = arg; - add_symbol(&fun->arguments, anode); - } - va_end(args); -} - -void declare_builtins(void) -{ - struct symbol *va_list_ctype = &ptr_ctype; - - declare_builtin("__builtin_abort", &void_ctype, 0, NULL); - declare_builtin("__builtin_abs", &int_ctype , 0, &int_ctype, NULL); - declare_builtin("__builtin_alloca", &ptr_ctype, 0, size_t_ctype, NULL); - declare_builtin("__builtin_alpha_cmpbge", &long_ctype, 0, &long_ctype, &long_ctype, NULL); - declare_builtin("__builtin_alpha_extbl", &long_ctype, 0, &long_ctype, &long_ctype, NULL); - declare_builtin("__builtin_alpha_extwl", &long_ctype, 0, &long_ctype, &long_ctype, NULL); - declare_builtin("__builtin_alpha_insbl", &long_ctype, 0, &long_ctype, &long_ctype, NULL); - declare_builtin("__builtin_alpha_inslh", &long_ctype, 0, &long_ctype, &long_ctype, NULL); - declare_builtin("__builtin_alpha_insql", &long_ctype, 0, &long_ctype, &long_ctype, NULL); - declare_builtin("__builtin_alpha_inswl", &long_ctype, 0, &long_ctype, &long_ctype, NULL); - declare_builtin("__builtin_bcmp", &int_ctype , 0, &const_ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_bcopy", &void_ctype, 0, &const_ptr_ctype, &ptr_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_bswap16", &ushort_ctype, 0, &ushort_ctype, NULL); - declare_builtin("__builtin_bswap32", &uint_ctype, 0, &uint_ctype, NULL); - declare_builtin("__builtin_bswap64", &ullong_ctype, 0, &ullong_ctype, NULL); - declare_builtin("__builtin_bzero", &void_ctype, 0, &ptr_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_calloc", &ptr_ctype, 0, size_t_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_clrsb", &int_ctype, 0, &int_ctype, NULL); - declare_builtin("__builtin_clrsbl", &int_ctype, 0, &long_ctype, NULL); - declare_builtin("__builtin_clrsbll", &int_ctype, 0, &llong_ctype, NULL); - declare_builtin("__builtin_clz", &int_ctype, 0, &int_ctype, NULL); - declare_builtin("__builtin_clzl", &int_ctype, 0, &long_ctype, NULL); - declare_builtin("__builtin_clzll", &int_ctype, 0, &llong_ctype, NULL); - declare_builtin("__builtin_ctz", &int_ctype, 0, &int_ctype, NULL); - declare_builtin("__builtin_ctzl", &int_ctype, 0, &long_ctype, NULL); - declare_builtin("__builtin_ctzll", &int_ctype, 0, &llong_ctype, NULL); - declare_builtin("__builtin_exit", &void_ctype, 0, &int_ctype, NULL); - declare_builtin("__builtin_expect", &long_ctype, 0, &long_ctype ,&long_ctype, NULL); - declare_builtin("__builtin_extract_return_addr", &ptr_ctype, 0, &ptr_ctype, NULL); - declare_builtin("__builtin_fabs", &double_ctype, 0, &double_ctype, NULL); - declare_builtin("__builtin_ffs", &int_ctype, 0, &int_ctype, NULL); - declare_builtin("__builtin_ffsl", &int_ctype, 0, &long_ctype, NULL); - declare_builtin("__builtin_ffsll", &int_ctype, 0, &llong_ctype, NULL); - declare_builtin("__builtin_frame_address", &ptr_ctype, 0, &uint_ctype, NULL); - declare_builtin("__builtin_free", &void_ctype, 0, &ptr_ctype, NULL); - declare_builtin("__builtin_huge_val", &double_ctype, 0, NULL); - declare_builtin("__builtin_huge_valf", &float_ctype, 0, NULL); - declare_builtin("__builtin_huge_vall", &ldouble_ctype, 0, NULL); - declare_builtin("__builtin_index", &string_ctype, 0, &const_string_ctype, &int_ctype, NULL); - declare_builtin("__builtin_inf", &double_ctype, 0, NULL); - declare_builtin("__builtin_inff", &float_ctype, 0, NULL); - declare_builtin("__builtin_infl", &ldouble_ctype, 0, NULL); - declare_builtin("__builtin_isfinite", &int_ctype, 1, NULL); - declare_builtin("__builtin_isgreater", &int_ctype, 0, &float_ctype, &float_ctype, NULL); - declare_builtin("__builtin_isgreaterequal", &int_ctype, 0, &float_ctype, &float_ctype, NULL); - declare_builtin("__builtin_isinf", &int_ctype, 1, NULL); - declare_builtin("__builtin_isinf_sign", &int_ctype, 1, NULL); - declare_builtin("__builtin_isless", &int_ctype, 0, &float_ctype, &float_ctype, NULL); - declare_builtin("__builtin_islessequal", &int_ctype, 0, &float_ctype, &float_ctype, NULL); - declare_builtin("__builtin_islessgreater", &int_ctype, 0, &float_ctype, &float_ctype, NULL); - declare_builtin("__builtin_isnan", &int_ctype, 1, NULL); - declare_builtin("__builtin_isnormal", &int_ctype, 1, NULL); - declare_builtin("__builtin_isunordered", &int_ctype, 0, &float_ctype, &float_ctype, NULL); - declare_builtin("__builtin_labs", &long_ctype, 0, &long_ctype, NULL); - declare_builtin("__builtin_llabs", &llong_ctype, 0, &llong_ctype, NULL); - declare_builtin("__builtin_malloc", &ptr_ctype, 0, size_t_ctype, NULL); - declare_builtin("__builtin_memchr", &ptr_ctype, 0, &const_ptr_ctype, &int_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_memcmp", &int_ctype, 0, &const_ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_memcpy", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_memmove", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_mempcpy", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_memset", &ptr_ctype, 0, &ptr_ctype, &int_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_nan", &double_ctype, 0, &const_string_ctype, NULL); - declare_builtin("__builtin_nanf", &float_ctype, 0, &const_string_ctype, NULL); - declare_builtin("__builtin_nanl", &ldouble_ctype, 0, &const_string_ctype, NULL); - declare_builtin("__builtin_object_size", size_t_ctype, 0, &const_ptr_ctype, &int_ctype, NULL); - declare_builtin("__builtin_parity", &int_ctype, 0, &uint_ctype, NULL); - declare_builtin("__builtin_parityl", &int_ctype, 0, &ulong_ctype, NULL); - declare_builtin("__builtin_parityll", &int_ctype, 0, &ullong_ctype, NULL); - declare_builtin("__builtin_popcount", &int_ctype, 0, &uint_ctype, NULL); - declare_builtin("__builtin_popcountl", &int_ctype, 0, &ulong_ctype, NULL); - declare_builtin("__builtin_popcountll", &int_ctype, 0, &ullong_ctype, NULL); - declare_builtin("__builtin_prefetch", &void_ctype, 1, &const_ptr_ctype, NULL); - declare_builtin("__builtin_printf", &int_ctype, 1, &const_string_ctype, NULL); - declare_builtin("__builtin_puts", &int_ctype, 0, &const_string_ctype, NULL); - declare_builtin("__builtin_realloc", &ptr_ctype, 0, &ptr_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_return_address", &ptr_ctype, 0, &uint_ctype, NULL); - declare_builtin("__builtin_rindex", &string_ctype, 0, &const_string_ctype, &int_ctype, NULL); - declare_builtin("__builtin_sadd_overflow", &bool_ctype, 0, &int_ctype, &int_ctype, &int_ptr_ctype, NULL); - declare_builtin("__builtin_saddl_overflow", &bool_ctype, 0, &long_ctype, &long_ctype, &long_ptr_ctype, NULL); - declare_builtin("__builtin_saddll_overflow", &bool_ctype, 0, &llong_ctype, &llong_ctype, &llong_ptr_ctype, NULL); - declare_builtin("__builtin_signbit", &int_ctype, 1, NULL); - declare_builtin("__builtin_smul_overflow", &bool_ctype, 0, &int_ctype, &int_ctype, &int_ptr_ctype, NULL); - declare_builtin("__builtin_smull_overflow", &bool_ctype, 0, &long_ctype, &long_ctype, &long_ptr_ctype, NULL); - declare_builtin("__builtin_smulll_overflow", &bool_ctype, 0, &llong_ctype, &llong_ctype, &llong_ptr_ctype, NULL); - declare_builtin("__builtin_snprintf", &int_ctype, 1, &string_ctype, size_t_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin_sprintf", &int_ctype, 1, &string_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin_ssub_overflow", &bool_ctype, 0, &int_ctype, &int_ctype, &int_ptr_ctype, NULL); - declare_builtin("__builtin_ssubl_overflow", &bool_ctype, 0, &long_ctype, &long_ctype, &long_ptr_ctype, NULL); - declare_builtin("__builtin_ssubll_overflow", &bool_ctype, 0, &llong_ctype, &llong_ctype, &llong_ptr_ctype, NULL); - declare_builtin("__builtin_stpcpy", &string_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin_stpncpy", &string_ctype, 0, &const_string_ctype, &const_string_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_strcasecmp", &int_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin_strcasestr", &string_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin_strcat", &string_ctype, 0, &string_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin_strchr", &string_ctype, 0, &const_string_ctype, &int_ctype, NULL); - declare_builtin("__builtin_strcmp", &int_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin_strcpy", &string_ctype, 0, &string_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin_strcspn", size_t_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin_strdup", &string_ctype, 0, &const_string_ctype, NULL); - declare_builtin("__builtin_strlen", size_t_ctype, 0, &const_string_ctype, NULL); - declare_builtin("__builtin_strncasecmp", &int_ctype, 0, &const_string_ctype, &const_string_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_strncat", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_strncmp", &int_ctype, 0, &const_string_ctype, &const_string_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_strncpy", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_strndup", &string_ctype, 0, &const_string_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_strnstr", &string_ctype, 0, &const_string_ctype, &const_string_ctype, size_t_ctype, NULL); - declare_builtin("__builtin_strpbrk", &string_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin_strrchr", &string_ctype, 0, &const_string_ctype, &int_ctype, NULL); - declare_builtin("__builtin_strspn", size_t_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin_strstr", &string_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin_trap", &void_ctype, 0, NULL); - declare_builtin("__builtin_uadd_overflow", &bool_ctype, 0, &uint_ctype, &uint_ctype, &uint_ptr_ctype, NULL); - declare_builtin("__builtin_uaddl_overflow", &bool_ctype, 0, &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype, NULL); - declare_builtin("__builtin_uaddll_overflow", &bool_ctype, 0, &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype, NULL); - declare_builtin("__builtin_umul_overflow", &bool_ctype, 0, &uint_ctype, &uint_ctype, &uint_ptr_ctype, NULL); - declare_builtin("__builtin_umull_overflow", &bool_ctype, 0, &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype, NULL); - declare_builtin("__builtin_umulll_overflow", &bool_ctype, 0, &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype, NULL); - declare_builtin("__builtin_unreachable", &void_ctype, 0, NULL); - declare_builtin("__builtin_usub_overflow", &bool_ctype, 0, &uint_ctype, &uint_ctype, &uint_ptr_ctype, NULL); - declare_builtin("__builtin_usubl_overflow", &bool_ctype, 0, &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype, NULL); - declare_builtin("__builtin_usubll_overflow", &bool_ctype, 0, &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype, NULL); - declare_builtin("__builtin_va_arg_pack_len", size_t_ctype, 0, NULL); - declare_builtin("__builtin_vprintf", &int_ctype, 0, &const_string_ctype, va_list_ctype, NULL); - declare_builtin("__builtin_vsnprintf", &int_ctype, 0, &string_ctype, size_t_ctype, &const_string_ctype, va_list_ctype, NULL); - declare_builtin("__builtin_vsprintf", &int_ctype, 0, &string_ctype, &const_string_ctype, va_list_ctype, NULL); - - declare_builtin("__builtin___memcpy_chk", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype, NULL); - declare_builtin("__builtin___memmove_chk", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype, NULL); - declare_builtin("__builtin___mempcpy_chk", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype, NULL); - declare_builtin("__builtin___memset_chk", &ptr_ctype, 0, &ptr_ctype, &int_ctype, size_t_ctype, size_t_ctype, NULL); - declare_builtin("__builtin___snprintf_chk", &int_ctype, 1, &string_ctype, size_t_ctype, &int_ctype , size_t_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin___sprintf_chk", &int_ctype, 1, &string_ctype, &int_ctype, size_t_ctype, &const_string_ctype, NULL); - declare_builtin("__builtin___stpcpy_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL); - declare_builtin("__builtin___strcat_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL); - declare_builtin("__builtin___strcpy_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL); - declare_builtin("__builtin___strncat_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, size_t_ctype, NULL); - declare_builtin("__builtin___strncpy_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, size_t_ctype, NULL); - declare_builtin("__builtin___vsnprintf_chk", &int_ctype, 0, &string_ctype, size_t_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype, NULL); - declare_builtin("__builtin___vsprintf_chk", &int_ctype, 0, &string_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype, NULL); - - declare_builtin("__sync_add_and_fetch", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_and_and_fetch", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_bool_compare_and_swap", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_fetch_and_add", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_fetch_and_and", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_fetch_and_nand", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_fetch_and_or", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_fetch_and_sub", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_fetch_and_xor", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_lock_release", &void_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_lock_test_and_set", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_nand_and_fetch", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_or_and_fetch", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_sub_and_fetch", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_synchronize", &void_ctype, 0, NULL); - declare_builtin("__sync_val_compare_and_swap", &int_ctype, 1, &ptr_ctype, NULL); - declare_builtin("__sync_xor_and_fetch", &int_ctype, 1, &ptr_ctype, NULL); - - // Blackfin-specific stuff - declare_builtin("__builtin_bfin_csync", &void_ctype, 0, NULL); - declare_builtin("__builtin_bfin_ssync", &void_ctype, 0, NULL); - declare_builtin("__builtin_bfin_norm_fr1x32", &int_ctype, 0, &int_ctype, NULL); - - // Nios-II-specific - declare_builtin("__builtin_rdctl", &int_ctype, 0, &int_ctype, NULL); - declare_builtin("__builtin_wrctl", &void_ctype, 0, &int_ctype, &int_ctype, NULL); - declare_builtin("__builtin_custom_ini", &int_ctype, 0, &int_ctype, NULL); + declare_builtins(builtins_common); } diff --git a/builtin.h b/builtin.h new file mode 100644 index 000000000000..233cf2806760 --- /dev/null +++ b/builtin.h @@ -0,0 +1,14 @@ +#ifndef _BUILTIN_H_ +#define _BUILTIN_H_ + +#include "symbol.h" + +struct builtin_fn { + const char *name; + struct symbol *ret_type; + unsigned int variadic:1; + struct symbol *args[6]; + struct symbol *_args_null_tail; +}; + +#endif diff --git a/lib.c b/lib.c index aa1c1d656b9d..951d400ea2fa 100644 --- a/lib.c +++ b/lib.c @@ -1596,7 +1596,6 @@ struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list predefined_macros(); create_builtin_stream(); init_builtins(0); - declare_builtins(); list = sparse_initial(); diff --git a/symbol.h b/symbol.h index a16a27c24afe..13e1d90ac76d 100644 --- a/symbol.h +++ b/symbol.h @@ -325,7 +325,6 @@ extern struct symbol *create_symbol(int stream, const char *name, int type, int extern void init_symbols(void); extern void init_builtins(int stream); extern void init_linearized_builtins(int stream); -extern void declare_builtins(void); extern void init_ctype(void); extern struct symbol *alloc_symbol(struct position, int type); extern void show_type(struct symbol *); -- 2.27.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 2/7] builtin: use a table for the builtins 2020-06-10 20:27 ` [PATCH 2/7] builtin: use a table for the builtins Luc Van Oostenryck @ 2020-06-12 0:56 ` Ramsay Jones 2020-06-12 16:48 ` Luc Van Oostenryck 0 siblings, 1 reply; 14+ messages in thread From: Ramsay Jones @ 2020-06-12 0:56 UTC (permalink / raw) To: Luc Van Oostenryck, linux-sparse On 10/06/2020 21:27, Luc Van Oostenryck wrote: > The curent way to declare the builtins is not by using a table > but via a (variadic) function call, one for each builtin. > > A table is table is preferable but a complication for doing this s/table is table is/table is/ > is that some elements are not constant. For example, 'size_t_ctype' > is dynamically set in the early steps of the type initialization. > Doing a series of function calls allowed to circumvent this. > > Fix this by: > * Using a constant temporary alias for non-constant entries. It's the > value of these alias that will be used when registering the builtins. > * using a table to declare the builtin functions. > > Note: the motivation for doing this is to be able to add sub-tables > for the arch-specific builtins (and use the same mechanism > as for the main table). > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> > --- > builtin.c | 411 ++++++++++++++++++++++++++++-------------------------- > builtin.h | 14 ++ > lib.c | 1 - > symbol.h | 1 - > 4 files changed, 227 insertions(+), 200 deletions(-) > create mode 100644 builtin.h > > diff --git a/builtin.c b/builtin.c > index 5ed17700d422..aa9ce09c0f40 100644 > --- a/builtin.c > +++ b/builtin.c > @@ -23,6 +23,7 @@ > * THE SOFTWARE. > */ > > +#include "builtin.h" > #include "expression.h" > #include "evaluate.h" > #include "expand.h" > @@ -357,6 +358,217 @@ static struct symbol_op overflow_p_op = { > /* > * Builtin functions > */ > +static struct symbol size_t_alias; > + > +static struct symbol *get_ctype(struct symbol *sym) > +{ > + if (sym == &size_t_alias) > + return size_t_ctype; > + return sym; > +} > + > +static void declare_one_builtin(const struct builtin_fn *entry) > +{ > + struct symbol *sym = create_symbol(0, entry->name, SYM_NODE, NS_SYMBOL); So, assuming stream 0 here as well ... > + struct symbol *fun = alloc_symbol(sym->pos, SYM_FN); > + struct symbol *arg; > + int i; > + > + sym->ctype.base_type = fun; > + sym->ctype.modifiers = MOD_TOPLEVEL; > + sym->builtin = 1; > + > + fun->ctype.base_type = get_ctype(entry->ret_type); > + fun->variadic = entry->variadic; > + > + for (i = 0; (arg = entry->args[i]); i++) { > + struct symbol *anode = alloc_symbol(sym->pos, SYM_NODE); > + anode->ctype.base_type = get_ctype(arg); > + add_symbol(&fun->arguments, anode); > + } > +} > + > +static void declare_builtins(const struct builtin_fn tbl[]) > +{ > + while (tbl->name) > + declare_one_builtin(tbl++); > +} > + > +static const struct builtin_fn builtins_common[] = { > +#define size_t_ctype &size_t_alias > +#define va_list_ctype &ptr_ctype > + { "__builtin_abort", &void_ctype, 0 }, > + { "__builtin_abs", &int_ctype , 0, { &int_ctype }}, > + { "__builtin_alloca", &ptr_ctype, 0, { size_t_ctype }}, > + { "__builtin_alpha_cmpbge", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + { "__builtin_alpha_extbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + { "__builtin_alpha_extwl", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + { "__builtin_alpha_insbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + { "__builtin_alpha_inslh", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + { "__builtin_alpha_insql", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + { "__builtin_alpha_inswl", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + { "__builtin_bcmp", &int_ctype , 0, { &const_ptr_ctype, &const_ptr_ctype, size_t_ctype }}, > + { "__builtin_bcopy", &void_ctype, 0, { &const_ptr_ctype, &ptr_ctype, size_t_ctype }}, > + { "__builtin_bswap16", &ushort_ctype, 0, { &ushort_ctype }}, > + { "__builtin_bswap32", &uint_ctype, 0, { &uint_ctype }}, > + { "__builtin_bswap64", &ullong_ctype, 0, { &ullong_ctype }}, > + { "__builtin_bzero", &void_ctype, 0, { &ptr_ctype, size_t_ctype }}, > + { "__builtin_calloc", &ptr_ctype, 0, { size_t_ctype, size_t_ctype }}, > + { "__builtin_clrsb", &int_ctype, 0, { &int_ctype }}, > + { "__builtin_clrsbl", &int_ctype, 0, { &long_ctype }}, > + { "__builtin_clrsbll", &int_ctype, 0, { &llong_ctype }}, > + { "__builtin_clz", &int_ctype, 0, { &int_ctype }}, > + { "__builtin_clzl", &int_ctype, 0, { &long_ctype }}, > + { "__builtin_clzll", &int_ctype, 0, { &llong_ctype }}, > + { "__builtin_ctz", &int_ctype, 0, { &int_ctype }}, > + { "__builtin_ctzl", &int_ctype, 0, { &long_ctype }}, > + { "__builtin_ctzll", &int_ctype, 0, { &llong_ctype }}, > + { "__builtin_exit", &void_ctype, 0, { &int_ctype }}, > + { "__builtin_expect", &long_ctype, 0, { &long_ctype ,&long_ctype }}, > + { "__builtin_extract_return_addr", &ptr_ctype, 0, { &ptr_ctype }}, > + { "__builtin_fabs", &double_ctype, 0, { &double_ctype }}, > + { "__builtin_ffs", &int_ctype, 0, { &int_ctype }}, > + { "__builtin_ffsl", &int_ctype, 0, { &long_ctype }}, > + { "__builtin_ffsll", &int_ctype, 0, { &llong_ctype }}, > + { "__builtin_frame_address", &ptr_ctype, 0, { &uint_ctype }}, > + { "__builtin_free", &void_ctype, 0, { &ptr_ctype }}, > + { "__builtin_huge_val", &double_ctype, 0 }, > + { "__builtin_huge_valf", &float_ctype, 0 }, > + { "__builtin_huge_vall", &ldouble_ctype, 0 }, > + { "__builtin_index", &string_ctype, 0, { &const_string_ctype, &int_ctype }}, > + { "__builtin_inf", &double_ctype, 0 }, > + { "__builtin_inff", &float_ctype, 0 }, > + { "__builtin_infl", &ldouble_ctype, 0 }, > + { "__builtin_isfinite", &int_ctype, 1 }, > + { "__builtin_isgreater", &int_ctype, 0, { &float_ctype, &float_ctype }}, > + { "__builtin_isgreaterequal", &int_ctype, 0, { &float_ctype, &float_ctype }}, > + { "__builtin_isinf", &int_ctype, 1 }, > + { "__builtin_isinf_sign", &int_ctype, 1 }, > + { "__builtin_isless", &int_ctype, 0, { &float_ctype, &float_ctype }}, > + { "__builtin_islessequal", &int_ctype, 0, { &float_ctype, &float_ctype }}, > + { "__builtin_islessgreater", &int_ctype, 0, { &float_ctype, &float_ctype }}, > + { "__builtin_isnan", &int_ctype, 1 }, > + { "__builtin_isnormal", &int_ctype, 1 }, > + { "__builtin_isunordered", &int_ctype, 0, { &float_ctype, &float_ctype }}, > + { "__builtin_labs", &long_ctype, 0, { &long_ctype }}, > + { "__builtin_llabs", &llong_ctype, 0, { &llong_ctype }}, > + { "__builtin_malloc", &ptr_ctype, 0, { size_t_ctype }}, > + { "__builtin_memchr", &ptr_ctype, 0, { &const_ptr_ctype, &int_ctype, size_t_ctype }}, > + { "__builtin_memcmp", &int_ctype, 0, { &const_ptr_ctype, &const_ptr_ctype, size_t_ctype }}, > + { "__builtin_memcpy", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype }}, > + { "__builtin_memmove", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype }}, > + { "__builtin_mempcpy", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype }}, > + { "__builtin_memset", &ptr_ctype, 0, { &ptr_ctype, &int_ctype, size_t_ctype }}, > + { "__builtin_nan", &double_ctype, 0, { &const_string_ctype }}, > + { "__builtin_nanf", &float_ctype, 0, { &const_string_ctype }}, > + { "__builtin_nanl", &ldouble_ctype, 0, { &const_string_ctype }}, > + { "__builtin_object_size", size_t_ctype, 0, { &const_ptr_ctype, &int_ctype }}, > + { "__builtin_parity", &int_ctype, 0, { &uint_ctype }}, > + { "__builtin_parityl", &int_ctype, 0, { &ulong_ctype }}, > + { "__builtin_parityll", &int_ctype, 0, { &ullong_ctype }}, > + { "__builtin_popcount", &int_ctype, 0, { &uint_ctype }}, > + { "__builtin_popcountl", &int_ctype, 0, { &ulong_ctype }}, > + { "__builtin_popcountll", &int_ctype, 0, { &ullong_ctype }}, > + { "__builtin_prefetch", &void_ctype, 1, { &const_ptr_ctype }}, > + { "__builtin_printf", &int_ctype, 1, { &const_string_ctype }}, > + { "__builtin_puts", &int_ctype, 0, { &const_string_ctype }}, > + { "__builtin_realloc", &ptr_ctype, 0, { &ptr_ctype, size_t_ctype }}, > + { "__builtin_return_address", &ptr_ctype, 0, { &uint_ctype }}, > + { "__builtin_rindex", &string_ctype, 0, { &const_string_ctype, &int_ctype }}, > + { "__builtin_sadd_overflow", &bool_ctype, 0, { &int_ctype, &int_ctype, &int_ptr_ctype }}, > + { "__builtin_saddl_overflow", &bool_ctype, 0, { &long_ctype, &long_ctype, &long_ptr_ctype }}, > + { "__builtin_saddll_overflow", &bool_ctype, 0, { &llong_ctype, &llong_ctype, &llong_ptr_ctype }}, > + { "__builtin_signbit", &int_ctype, 1 }, > + { "__builtin_smul_overflow", &bool_ctype, 0, { &int_ctype, &int_ctype, &int_ptr_ctype }}, > + { "__builtin_smull_overflow", &bool_ctype, 0, { &long_ctype, &long_ctype, &long_ptr_ctype }}, > + { "__builtin_smulll_overflow", &bool_ctype, 0, { &llong_ctype, &llong_ctype, &llong_ptr_ctype }}, > + { "__builtin_snprintf", &int_ctype, 1, { &string_ctype, size_t_ctype, &const_string_ctype }}, > + { "__builtin_sprintf", &int_ctype, 1, { &string_ctype, &const_string_ctype }}, > + { "__builtin_ssub_overflow", &bool_ctype, 0, { &int_ctype, &int_ctype, &int_ptr_ctype }}, > + { "__builtin_ssubl_overflow", &bool_ctype, 0, { &long_ctype, &long_ctype, &long_ptr_ctype }}, > + { "__builtin_ssubll_overflow", &bool_ctype, 0, { &llong_ctype, &llong_ctype, &llong_ptr_ctype }}, > + { "__builtin_stpcpy", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }}, > + { "__builtin_stpncpy", &string_ctype, 0, { &const_string_ctype, &const_string_ctype, size_t_ctype }}, > + { "__builtin_strcasecmp", &int_ctype, 0, { &const_string_ctype, &const_string_ctype }}, > + { "__builtin_strcasestr", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }}, > + { "__builtin_strcat", &string_ctype, 0, { &string_ctype, &const_string_ctype }}, > + { "__builtin_strchr", &string_ctype, 0, { &const_string_ctype, &int_ctype }}, > + { "__builtin_strcmp", &int_ctype, 0, { &const_string_ctype, &const_string_ctype }}, > + { "__builtin_strcpy", &string_ctype, 0, { &string_ctype, &const_string_ctype }}, > + { "__builtin_strcspn", size_t_ctype, 0, { &const_string_ctype, &const_string_ctype }}, > + { "__builtin_strdup", &string_ctype, 0, { &const_string_ctype }}, > + { "__builtin_strlen", size_t_ctype, 0, { &const_string_ctype }}, > + { "__builtin_strncasecmp", &int_ctype, 0, { &const_string_ctype, &const_string_ctype, size_t_ctype }}, > + { "__builtin_strncat", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }}, > + { "__builtin_strncmp", &int_ctype, 0, { &const_string_ctype, &const_string_ctype, size_t_ctype }}, > + { "__builtin_strncpy", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }}, > + { "__builtin_strndup", &string_ctype, 0, { &const_string_ctype, size_t_ctype }}, > + { "__builtin_strnstr", &string_ctype, 0, { &const_string_ctype, &const_string_ctype, size_t_ctype }}, > + { "__builtin_strpbrk", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }}, > + { "__builtin_strrchr", &string_ctype, 0, { &const_string_ctype, &int_ctype }}, > + { "__builtin_strspn", size_t_ctype, 0, { &const_string_ctype, &const_string_ctype }}, > + { "__builtin_strstr", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }}, > + { "__builtin_trap", &void_ctype, 0 }, > + { "__builtin_uadd_overflow", &bool_ctype, 0, { &uint_ctype, &uint_ctype, &uint_ptr_ctype }}, > + { "__builtin_uaddl_overflow", &bool_ctype, 0, { &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype }}, > + { "__builtin_uaddll_overflow", &bool_ctype, 0, { &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype }}, > + { "__builtin_umul_overflow", &bool_ctype, 0, { &uint_ctype, &uint_ctype, &uint_ptr_ctype }}, > + { "__builtin_umull_overflow", &bool_ctype, 0, { &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype }}, > + { "__builtin_umulll_overflow", &bool_ctype, 0, { &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype }}, > + { "__builtin_unreachable", &void_ctype, 0 }, > + { "__builtin_usub_overflow", &bool_ctype, 0, { &uint_ctype, &uint_ctype, &uint_ptr_ctype }}, > + { "__builtin_usubl_overflow", &bool_ctype, 0, { &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype }}, > + { "__builtin_usubll_overflow", &bool_ctype, 0, { &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype }}, > + { "__builtin_va_arg_pack_len", size_t_ctype, 0 }, > + { "__builtin_vprintf", &int_ctype, 0, { &const_string_ctype, va_list_ctype }}, > + { "__builtin_vsnprintf", &int_ctype, 0, { &string_ctype, size_t_ctype, &const_string_ctype, va_list_ctype }}, > + { "__builtin_vsprintf", &int_ctype, 0, { &string_ctype, &const_string_ctype, va_list_ctype }}, > + > + { "__builtin___memcpy_chk", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype }}, > + { "__builtin___memmove_chk", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype }}, > + { "__builtin___mempcpy_chk", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype }}, > + { "__builtin___memset_chk", &ptr_ctype, 0, { &ptr_ctype, &int_ctype, size_t_ctype, size_t_ctype }}, > + { "__builtin___snprintf_chk", &int_ctype, 1, { &string_ctype, size_t_ctype, &int_ctype , size_t_ctype, &const_string_ctype }}, > + { "__builtin___sprintf_chk", &int_ctype, 1, { &string_ctype, &int_ctype, size_t_ctype, &const_string_ctype }}, > + { "__builtin___stpcpy_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }}, > + { "__builtin___strcat_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }}, > + { "__builtin___strcpy_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }}, > + { "__builtin___strncat_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype, size_t_ctype }}, > + { "__builtin___strncpy_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype, size_t_ctype }}, > + { "__builtin___vsnprintf_chk", &int_ctype, 0, { &string_ctype, size_t_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype }}, > + { "__builtin___vsprintf_chk", &int_ctype, 0, { &string_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype }}, > + > + { "__sync_add_and_fetch", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_and_and_fetch", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_bool_compare_and_swap", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_fetch_and_add", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_fetch_and_and", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_fetch_and_nand", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_fetch_and_or", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_fetch_and_sub", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_fetch_and_xor", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_lock_release", &void_ctype, 1, { &ptr_ctype }}, > + { "__sync_lock_test_and_set", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_nand_and_fetch", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_or_and_fetch", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_sub_and_fetch", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_synchronize", &void_ctype, 0 }, > + { "__sync_val_compare_and_swap", &int_ctype, 1, { &ptr_ctype }}, > + { "__sync_xor_and_fetch", &int_ctype, 1, { &ptr_ctype }}, > + > + // Blackfin-specific stuff > + { "__builtin_bfin_csync", &void_ctype, 0 }, > + { "__builtin_bfin_ssync", &void_ctype, 0 }, > + { "__builtin_bfin_norm_fr1x32", &int_ctype, 0, { &int_ctype }}, > + > + // Nios-II-specific > + { "__builtin_rdctl", &int_ctype, 0, { &int_ctype }}, > + { "__builtin_wrctl", &void_ctype, 0, { &int_ctype, &int_ctype }}, > + { "__builtin_custom_ini", &int_ctype, 0, { &int_ctype }}, > + > + { } > +}; > + > static struct symbol builtin_fn_type = { .type = SYM_FN /* , .variadic =1 */ }; > static struct sym_init { > const char *name; > @@ -420,202 +632,5 @@ void init_builtins(int stream) > } > > init_linearized_builtins(stream); > -} > - > -static void declare_builtin(const char *name, struct symbol *rtype, int variadic, ...) > -{ > - int stream = 0; // FIXME ... and, yes, here is the FIXME (so my memory is not as bad as I thought!). This all looks good. ATB, Ramsay Jones > - struct symbol *sym = create_symbol(stream, name, SYM_NODE, NS_SYMBOL); > - struct symbol *fun = alloc_symbol(sym->pos, SYM_FN); > - struct symbol *arg; > - va_list args; > - > - sym->ctype.base_type = fun; > - sym->ctype.modifiers = MOD_TOPLEVEL; > - sym->builtin = 1; > - > - fun->ctype.base_type = rtype; > - fun->variadic = variadic; > - > - va_start(args, variadic); > - while ((arg = va_arg(args, struct symbol *))) { > - struct symbol *anode = alloc_symbol(sym->pos, SYM_NODE); > - anode->ctype.base_type = arg; > - add_symbol(&fun->arguments, anode); > - } > - va_end(args); > -} > - > -void declare_builtins(void) > -{ > - struct symbol *va_list_ctype = &ptr_ctype; > - > - declare_builtin("__builtin_abort", &void_ctype, 0, NULL); > - declare_builtin("__builtin_abs", &int_ctype , 0, &int_ctype, NULL); > - declare_builtin("__builtin_alloca", &ptr_ctype, 0, size_t_ctype, NULL); > - declare_builtin("__builtin_alpha_cmpbge", &long_ctype, 0, &long_ctype, &long_ctype, NULL); > - declare_builtin("__builtin_alpha_extbl", &long_ctype, 0, &long_ctype, &long_ctype, NULL); > - declare_builtin("__builtin_alpha_extwl", &long_ctype, 0, &long_ctype, &long_ctype, NULL); > - declare_builtin("__builtin_alpha_insbl", &long_ctype, 0, &long_ctype, &long_ctype, NULL); > - declare_builtin("__builtin_alpha_inslh", &long_ctype, 0, &long_ctype, &long_ctype, NULL); > - declare_builtin("__builtin_alpha_insql", &long_ctype, 0, &long_ctype, &long_ctype, NULL); > - declare_builtin("__builtin_alpha_inswl", &long_ctype, 0, &long_ctype, &long_ctype, NULL); > - declare_builtin("__builtin_bcmp", &int_ctype , 0, &const_ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_bcopy", &void_ctype, 0, &const_ptr_ctype, &ptr_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_bswap16", &ushort_ctype, 0, &ushort_ctype, NULL); > - declare_builtin("__builtin_bswap32", &uint_ctype, 0, &uint_ctype, NULL); > - declare_builtin("__builtin_bswap64", &ullong_ctype, 0, &ullong_ctype, NULL); > - declare_builtin("__builtin_bzero", &void_ctype, 0, &ptr_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_calloc", &ptr_ctype, 0, size_t_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_clrsb", &int_ctype, 0, &int_ctype, NULL); > - declare_builtin("__builtin_clrsbl", &int_ctype, 0, &long_ctype, NULL); > - declare_builtin("__builtin_clrsbll", &int_ctype, 0, &llong_ctype, NULL); > - declare_builtin("__builtin_clz", &int_ctype, 0, &int_ctype, NULL); > - declare_builtin("__builtin_clzl", &int_ctype, 0, &long_ctype, NULL); > - declare_builtin("__builtin_clzll", &int_ctype, 0, &llong_ctype, NULL); > - declare_builtin("__builtin_ctz", &int_ctype, 0, &int_ctype, NULL); > - declare_builtin("__builtin_ctzl", &int_ctype, 0, &long_ctype, NULL); > - declare_builtin("__builtin_ctzll", &int_ctype, 0, &llong_ctype, NULL); > - declare_builtin("__builtin_exit", &void_ctype, 0, &int_ctype, NULL); > - declare_builtin("__builtin_expect", &long_ctype, 0, &long_ctype ,&long_ctype, NULL); > - declare_builtin("__builtin_extract_return_addr", &ptr_ctype, 0, &ptr_ctype, NULL); > - declare_builtin("__builtin_fabs", &double_ctype, 0, &double_ctype, NULL); > - declare_builtin("__builtin_ffs", &int_ctype, 0, &int_ctype, NULL); > - declare_builtin("__builtin_ffsl", &int_ctype, 0, &long_ctype, NULL); > - declare_builtin("__builtin_ffsll", &int_ctype, 0, &llong_ctype, NULL); > - declare_builtin("__builtin_frame_address", &ptr_ctype, 0, &uint_ctype, NULL); > - declare_builtin("__builtin_free", &void_ctype, 0, &ptr_ctype, NULL); > - declare_builtin("__builtin_huge_val", &double_ctype, 0, NULL); > - declare_builtin("__builtin_huge_valf", &float_ctype, 0, NULL); > - declare_builtin("__builtin_huge_vall", &ldouble_ctype, 0, NULL); > - declare_builtin("__builtin_index", &string_ctype, 0, &const_string_ctype, &int_ctype, NULL); > - declare_builtin("__builtin_inf", &double_ctype, 0, NULL); > - declare_builtin("__builtin_inff", &float_ctype, 0, NULL); > - declare_builtin("__builtin_infl", &ldouble_ctype, 0, NULL); > - declare_builtin("__builtin_isfinite", &int_ctype, 1, NULL); > - declare_builtin("__builtin_isgreater", &int_ctype, 0, &float_ctype, &float_ctype, NULL); > - declare_builtin("__builtin_isgreaterequal", &int_ctype, 0, &float_ctype, &float_ctype, NULL); > - declare_builtin("__builtin_isinf", &int_ctype, 1, NULL); > - declare_builtin("__builtin_isinf_sign", &int_ctype, 1, NULL); > - declare_builtin("__builtin_isless", &int_ctype, 0, &float_ctype, &float_ctype, NULL); > - declare_builtin("__builtin_islessequal", &int_ctype, 0, &float_ctype, &float_ctype, NULL); > - declare_builtin("__builtin_islessgreater", &int_ctype, 0, &float_ctype, &float_ctype, NULL); > - declare_builtin("__builtin_isnan", &int_ctype, 1, NULL); > - declare_builtin("__builtin_isnormal", &int_ctype, 1, NULL); > - declare_builtin("__builtin_isunordered", &int_ctype, 0, &float_ctype, &float_ctype, NULL); > - declare_builtin("__builtin_labs", &long_ctype, 0, &long_ctype, NULL); > - declare_builtin("__builtin_llabs", &llong_ctype, 0, &llong_ctype, NULL); > - declare_builtin("__builtin_malloc", &ptr_ctype, 0, size_t_ctype, NULL); > - declare_builtin("__builtin_memchr", &ptr_ctype, 0, &const_ptr_ctype, &int_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_memcmp", &int_ctype, 0, &const_ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_memcpy", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_memmove", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_mempcpy", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_memset", &ptr_ctype, 0, &ptr_ctype, &int_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_nan", &double_ctype, 0, &const_string_ctype, NULL); > - declare_builtin("__builtin_nanf", &float_ctype, 0, &const_string_ctype, NULL); > - declare_builtin("__builtin_nanl", &ldouble_ctype, 0, &const_string_ctype, NULL); > - declare_builtin("__builtin_object_size", size_t_ctype, 0, &const_ptr_ctype, &int_ctype, NULL); > - declare_builtin("__builtin_parity", &int_ctype, 0, &uint_ctype, NULL); > - declare_builtin("__builtin_parityl", &int_ctype, 0, &ulong_ctype, NULL); > - declare_builtin("__builtin_parityll", &int_ctype, 0, &ullong_ctype, NULL); > - declare_builtin("__builtin_popcount", &int_ctype, 0, &uint_ctype, NULL); > - declare_builtin("__builtin_popcountl", &int_ctype, 0, &ulong_ctype, NULL); > - declare_builtin("__builtin_popcountll", &int_ctype, 0, &ullong_ctype, NULL); > - declare_builtin("__builtin_prefetch", &void_ctype, 1, &const_ptr_ctype, NULL); > - declare_builtin("__builtin_printf", &int_ctype, 1, &const_string_ctype, NULL); > - declare_builtin("__builtin_puts", &int_ctype, 0, &const_string_ctype, NULL); > - declare_builtin("__builtin_realloc", &ptr_ctype, 0, &ptr_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_return_address", &ptr_ctype, 0, &uint_ctype, NULL); > - declare_builtin("__builtin_rindex", &string_ctype, 0, &const_string_ctype, &int_ctype, NULL); > - declare_builtin("__builtin_sadd_overflow", &bool_ctype, 0, &int_ctype, &int_ctype, &int_ptr_ctype, NULL); > - declare_builtin("__builtin_saddl_overflow", &bool_ctype, 0, &long_ctype, &long_ctype, &long_ptr_ctype, NULL); > - declare_builtin("__builtin_saddll_overflow", &bool_ctype, 0, &llong_ctype, &llong_ctype, &llong_ptr_ctype, NULL); > - declare_builtin("__builtin_signbit", &int_ctype, 1, NULL); > - declare_builtin("__builtin_smul_overflow", &bool_ctype, 0, &int_ctype, &int_ctype, &int_ptr_ctype, NULL); > - declare_builtin("__builtin_smull_overflow", &bool_ctype, 0, &long_ctype, &long_ctype, &long_ptr_ctype, NULL); > - declare_builtin("__builtin_smulll_overflow", &bool_ctype, 0, &llong_ctype, &llong_ctype, &llong_ptr_ctype, NULL); > - declare_builtin("__builtin_snprintf", &int_ctype, 1, &string_ctype, size_t_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin_sprintf", &int_ctype, 1, &string_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin_ssub_overflow", &bool_ctype, 0, &int_ctype, &int_ctype, &int_ptr_ctype, NULL); > - declare_builtin("__builtin_ssubl_overflow", &bool_ctype, 0, &long_ctype, &long_ctype, &long_ptr_ctype, NULL); > - declare_builtin("__builtin_ssubll_overflow", &bool_ctype, 0, &llong_ctype, &llong_ctype, &llong_ptr_ctype, NULL); > - declare_builtin("__builtin_stpcpy", &string_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin_stpncpy", &string_ctype, 0, &const_string_ctype, &const_string_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_strcasecmp", &int_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin_strcasestr", &string_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin_strcat", &string_ctype, 0, &string_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin_strchr", &string_ctype, 0, &const_string_ctype, &int_ctype, NULL); > - declare_builtin("__builtin_strcmp", &int_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin_strcpy", &string_ctype, 0, &string_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin_strcspn", size_t_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin_strdup", &string_ctype, 0, &const_string_ctype, NULL); > - declare_builtin("__builtin_strlen", size_t_ctype, 0, &const_string_ctype, NULL); > - declare_builtin("__builtin_strncasecmp", &int_ctype, 0, &const_string_ctype, &const_string_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_strncat", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_strncmp", &int_ctype, 0, &const_string_ctype, &const_string_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_strncpy", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_strndup", &string_ctype, 0, &const_string_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_strnstr", &string_ctype, 0, &const_string_ctype, &const_string_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin_strpbrk", &string_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin_strrchr", &string_ctype, 0, &const_string_ctype, &int_ctype, NULL); > - declare_builtin("__builtin_strspn", size_t_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin_strstr", &string_ctype, 0, &const_string_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin_trap", &void_ctype, 0, NULL); > - declare_builtin("__builtin_uadd_overflow", &bool_ctype, 0, &uint_ctype, &uint_ctype, &uint_ptr_ctype, NULL); > - declare_builtin("__builtin_uaddl_overflow", &bool_ctype, 0, &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype, NULL); > - declare_builtin("__builtin_uaddll_overflow", &bool_ctype, 0, &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype, NULL); > - declare_builtin("__builtin_umul_overflow", &bool_ctype, 0, &uint_ctype, &uint_ctype, &uint_ptr_ctype, NULL); > - declare_builtin("__builtin_umull_overflow", &bool_ctype, 0, &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype, NULL); > - declare_builtin("__builtin_umulll_overflow", &bool_ctype, 0, &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype, NULL); > - declare_builtin("__builtin_unreachable", &void_ctype, 0, NULL); > - declare_builtin("__builtin_usub_overflow", &bool_ctype, 0, &uint_ctype, &uint_ctype, &uint_ptr_ctype, NULL); > - declare_builtin("__builtin_usubl_overflow", &bool_ctype, 0, &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype, NULL); > - declare_builtin("__builtin_usubll_overflow", &bool_ctype, 0, &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype, NULL); > - declare_builtin("__builtin_va_arg_pack_len", size_t_ctype, 0, NULL); > - declare_builtin("__builtin_vprintf", &int_ctype, 0, &const_string_ctype, va_list_ctype, NULL); > - declare_builtin("__builtin_vsnprintf", &int_ctype, 0, &string_ctype, size_t_ctype, &const_string_ctype, va_list_ctype, NULL); > - declare_builtin("__builtin_vsprintf", &int_ctype, 0, &string_ctype, &const_string_ctype, va_list_ctype, NULL); > - > - declare_builtin("__builtin___memcpy_chk", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin___memmove_chk", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin___mempcpy_chk", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin___memset_chk", &ptr_ctype, 0, &ptr_ctype, &int_ctype, size_t_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin___snprintf_chk", &int_ctype, 1, &string_ctype, size_t_ctype, &int_ctype , size_t_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin___sprintf_chk", &int_ctype, 1, &string_ctype, &int_ctype, size_t_ctype, &const_string_ctype, NULL); > - declare_builtin("__builtin___stpcpy_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin___strcat_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin___strcpy_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin___strncat_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin___strncpy_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, size_t_ctype, NULL); > - declare_builtin("__builtin___vsnprintf_chk", &int_ctype, 0, &string_ctype, size_t_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype, NULL); > - declare_builtin("__builtin___vsprintf_chk", &int_ctype, 0, &string_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype, NULL); > - > - declare_builtin("__sync_add_and_fetch", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_and_and_fetch", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_bool_compare_and_swap", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_fetch_and_add", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_fetch_and_and", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_fetch_and_nand", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_fetch_and_or", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_fetch_and_sub", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_fetch_and_xor", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_lock_release", &void_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_lock_test_and_set", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_nand_and_fetch", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_or_and_fetch", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_sub_and_fetch", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_synchronize", &void_ctype, 0, NULL); > - declare_builtin("__sync_val_compare_and_swap", &int_ctype, 1, &ptr_ctype, NULL); > - declare_builtin("__sync_xor_and_fetch", &int_ctype, 1, &ptr_ctype, NULL); > - > - // Blackfin-specific stuff > - declare_builtin("__builtin_bfin_csync", &void_ctype, 0, NULL); > - declare_builtin("__builtin_bfin_ssync", &void_ctype, 0, NULL); > - declare_builtin("__builtin_bfin_norm_fr1x32", &int_ctype, 0, &int_ctype, NULL); > - > - // Nios-II-specific > - declare_builtin("__builtin_rdctl", &int_ctype, 0, &int_ctype, NULL); > - declare_builtin("__builtin_wrctl", &void_ctype, 0, &int_ctype, &int_ctype, NULL); > - declare_builtin("__builtin_custom_ini", &int_ctype, 0, &int_ctype, NULL); > + declare_builtins(builtins_common); > } > diff --git a/builtin.h b/builtin.h > new file mode 100644 > index 000000000000..233cf2806760 > --- /dev/null > +++ b/builtin.h > @@ -0,0 +1,14 @@ > +#ifndef _BUILTIN_H_ > +#define _BUILTIN_H_ > + > +#include "symbol.h" > + > +struct builtin_fn { > + const char *name; > + struct symbol *ret_type; > + unsigned int variadic:1; > + struct symbol *args[6]; > + struct symbol *_args_null_tail; > +}; > + > +#endif > diff --git a/lib.c b/lib.c > index aa1c1d656b9d..951d400ea2fa 100644 > --- a/lib.c > +++ b/lib.c > @@ -1596,7 +1596,6 @@ struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list > predefined_macros(); > create_builtin_stream(); > init_builtins(0); > - declare_builtins(); > > list = sparse_initial(); > > diff --git a/symbol.h b/symbol.h > index a16a27c24afe..13e1d90ac76d 100644 > --- a/symbol.h > +++ b/symbol.h > @@ -325,7 +325,6 @@ extern struct symbol *create_symbol(int stream, const char *name, int type, int > extern void init_symbols(void); > extern void init_builtins(int stream); > extern void init_linearized_builtins(int stream); > -extern void declare_builtins(void); > extern void init_ctype(void); > extern struct symbol *alloc_symbol(struct position, int type); > extern void show_type(struct symbol *); > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/7] builtin: use a table for the builtins 2020-06-12 0:56 ` Ramsay Jones @ 2020-06-12 16:48 ` Luc Van Oostenryck 0 siblings, 0 replies; 14+ messages in thread From: Luc Van Oostenryck @ 2020-06-12 16:48 UTC (permalink / raw) To: Ramsay Jones; +Cc: linux-sparse On Fri, Jun 12, 2020 at 01:56:20AM +0100, Ramsay Jones wrote: > On 10/06/2020 21:27, Luc Van Oostenryck wrote: > > > > A table is table is preferable but a complication for doing this > > s/table is table is/table is/ Thanks for noticing this typo (and the ones in the other patches). > > +static void declare_one_builtin(const struct builtin_fn *entry) > > +{ > > + struct symbol *sym = create_symbol(0, entry->name, SYM_NODE, NS_SYMBOL); > > So, assuming stream 0 here as well ... > > > -static void declare_builtin(const char *name, struct symbol *rtype, int variadic, ...) > > -{ > > - int stream = 0; // FIXME > > ... and, yes, here is the FIXME (so my memory is not as bad > as I thought!). > > This all looks good. Well yes ... I don't really like the situation, though. I probably should do something like adding a #define builtin_stream 0 and use this. Thnaks to bring my attention to this. -- Luc ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 3/7] builtin: unify the 2 tables of builtins 2020-06-10 20:27 [PATCH 0/7] move arch-specific builtins to their own table Luc Van Oostenryck 2020-06-10 20:27 ` [PATCH 1/7] builtin: can be initialized later Luc Van Oostenryck 2020-06-10 20:27 ` [PATCH 2/7] builtin: use a table for the builtins Luc Van Oostenryck @ 2020-06-10 20:27 ` Luc Van Oostenryck 2020-06-12 1:01 ` Ramsay Jones 2020-06-10 20:27 ` [PATCH 4/7] builtin: add support for arch-specific builtins Luc Van Oostenryck ` (3 subsequent siblings) 6 siblings, 1 reply; 14+ messages in thread From: Luc Van Oostenryck @ 2020-06-10 20:27 UTC (permalink / raw) To: linux-sparse; +Cc: Luc Van Oostenryck Till now, 2 tables are used to initialize builtin functions: * an older, small one, without type information, used to set a symbol_op to evaluate and/or expand the ones that have effectively an effect. * a newer and bigger one which only contains what is effectively the prototype for these builtins in order to avoid warnings about undeclared functions. It's kinda annoying to have 2 tables for this, even more so because most entries in the first table also need to be in the second one (for arguments type & number checking). Fix this by: * adding a field in the second table for the symbol_op * merging or moving the entries in the first table into the second one. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- builtin.c | 145 +++++++++++++++++++----------------------------------- builtin.h | 1 + 2 files changed, 51 insertions(+), 95 deletions(-) diff --git a/builtin.c b/builtin.c index aa9ce09c0f40..bb9ec65b2d20 100644 --- a/builtin.c +++ b/builtin.c @@ -377,6 +377,7 @@ static void declare_one_builtin(const struct builtin_fn *entry) sym->ctype.base_type = fun; sym->ctype.modifiers = MOD_TOPLEVEL; sym->builtin = 1; + sym->op = entry->op; fun->ctype.base_type = get_ctype(entry->ret_type); fun->variadic = entry->variadic; @@ -397,39 +398,39 @@ static void declare_builtins(const struct builtin_fn tbl[]) static const struct builtin_fn builtins_common[] = { #define size_t_ctype &size_t_alias #define va_list_ctype &ptr_ctype + { "__builtin_choose_expr", NULL, 1, .op = &choose_op }, + { "__builtin_constant_p", NULL, 1, .op = &constant_p_op }, + { "__builtin_expect", &long_ctype, 0, { &long_ctype ,&long_ctype }, .op = &expect_op }, + { "__builtin_safe_p", NULL, 1, .op = &safe_p_op }, + { "__builtin_warning", NULL, 1, .op = &warning_op }, + { "__builtin_abort", &void_ctype, 0 }, { "__builtin_abs", &int_ctype , 0, { &int_ctype }}, + { "__builtin_add_overflow", &bool_ctype, 1, .op = &overflow_op }, + { "__builtin_add_overflow_p", &bool_ctype, 1, .op = &overflow_p_op }, { "__builtin_alloca", &ptr_ctype, 0, { size_t_ctype }}, - { "__builtin_alpha_cmpbge", &long_ctype, 0, { &long_ctype, &long_ctype }}, - { "__builtin_alpha_extbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, - { "__builtin_alpha_extwl", &long_ctype, 0, { &long_ctype, &long_ctype }}, - { "__builtin_alpha_insbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, - { "__builtin_alpha_inslh", &long_ctype, 0, { &long_ctype, &long_ctype }}, - { "__builtin_alpha_insql", &long_ctype, 0, { &long_ctype, &long_ctype }}, - { "__builtin_alpha_inswl", &long_ctype, 0, { &long_ctype, &long_ctype }}, { "__builtin_bcmp", &int_ctype , 0, { &const_ptr_ctype, &const_ptr_ctype, size_t_ctype }}, { "__builtin_bcopy", &void_ctype, 0, { &const_ptr_ctype, &ptr_ctype, size_t_ctype }}, - { "__builtin_bswap16", &ushort_ctype, 0, { &ushort_ctype }}, - { "__builtin_bswap32", &uint_ctype, 0, { &uint_ctype }}, - { "__builtin_bswap64", &ullong_ctype, 0, { &ullong_ctype }}, + { "__builtin_bswap16", &ushort_ctype, 0, { &ushort_ctype }, .op = &bswap_op }, + { "__builtin_bswap32", &uint_ctype, 0, { &uint_ctype }, .op = &bswap_op }, + { "__builtin_bswap64", &ullong_ctype, 0, { &ullong_ctype }, .op = &bswap_op }, { "__builtin_bzero", &void_ctype, 0, { &ptr_ctype, size_t_ctype }}, { "__builtin_calloc", &ptr_ctype, 0, { size_t_ctype, size_t_ctype }}, - { "__builtin_clrsb", &int_ctype, 0, { &int_ctype }}, - { "__builtin_clrsbl", &int_ctype, 0, { &long_ctype }}, - { "__builtin_clrsbll", &int_ctype, 0, { &llong_ctype }}, - { "__builtin_clz", &int_ctype, 0, { &int_ctype }}, - { "__builtin_clzl", &int_ctype, 0, { &long_ctype }}, - { "__builtin_clzll", &int_ctype, 0, { &llong_ctype }}, - { "__builtin_ctz", &int_ctype, 0, { &int_ctype }}, - { "__builtin_ctzl", &int_ctype, 0, { &long_ctype }}, - { "__builtin_ctzll", &int_ctype, 0, { &llong_ctype }}, + { "__builtin_clrsb", &int_ctype, 0, { &int_ctype }, .op = &clrsb_op }, + { "__builtin_clrsbl", &int_ctype, 0, { &long_ctype }, .op = &clrsb_op }, + { "__builtin_clrsbll", &int_ctype, 0, { &llong_ctype }, .op = &clrsb_op }, + { "__builtin_clz", &int_ctype, 0, { &int_ctype }, .op = &clz_op }, + { "__builtin_clzl", &int_ctype, 0, { &long_ctype }, .op = &clz_op }, + { "__builtin_clzll", &int_ctype, 0, { &llong_ctype }, .op = &clz_op }, + { "__builtin_ctz", &int_ctype, 0, { &int_ctype }, .op = &ctz_op }, + { "__builtin_ctzl", &int_ctype, 0, { &long_ctype }, .op = &ctz_op }, + { "__builtin_ctzll", &int_ctype, 0, { &llong_ctype }, .op = &ctz_op }, { "__builtin_exit", &void_ctype, 0, { &int_ctype }}, - { "__builtin_expect", &long_ctype, 0, { &long_ctype ,&long_ctype }}, { "__builtin_extract_return_addr", &ptr_ctype, 0, { &ptr_ctype }}, { "__builtin_fabs", &double_ctype, 0, { &double_ctype }}, - { "__builtin_ffs", &int_ctype, 0, { &int_ctype }}, - { "__builtin_ffsl", &int_ctype, 0, { &long_ctype }}, - { "__builtin_ffsll", &int_ctype, 0, { &llong_ctype }}, + { "__builtin_ffs", &int_ctype, 0, { &int_ctype }, .op = &ffs_op }, + { "__builtin_ffsl", &int_ctype, 0, { &long_ctype }, .op = &ffs_op }, + { "__builtin_ffsll", &int_ctype, 0, { &llong_ctype }, .op = &ffs_op }, { "__builtin_frame_address", &ptr_ctype, 0, { &uint_ctype }}, { "__builtin_free", &void_ctype, 0, { &ptr_ctype }}, { "__builtin_huge_val", &double_ctype, 0 }, @@ -439,16 +440,16 @@ static const struct builtin_fn builtins_common[] = { { "__builtin_inf", &double_ctype, 0 }, { "__builtin_inff", &float_ctype, 0 }, { "__builtin_infl", &ldouble_ctype, 0 }, - { "__builtin_isfinite", &int_ctype, 1 }, + { "__builtin_isfinite", &int_ctype, 1, .op = &fp_unop_op }, { "__builtin_isgreater", &int_ctype, 0, { &float_ctype, &float_ctype }}, { "__builtin_isgreaterequal", &int_ctype, 0, { &float_ctype, &float_ctype }}, - { "__builtin_isinf", &int_ctype, 1 }, - { "__builtin_isinf_sign", &int_ctype, 1 }, + { "__builtin_isinf", &int_ctype, 1, .op = &fp_unop_op }, + { "__builtin_isinf_sign", &int_ctype, 1, .op = &fp_unop_op }, { "__builtin_isless", &int_ctype, 0, { &float_ctype, &float_ctype }}, { "__builtin_islessequal", &int_ctype, 0, { &float_ctype, &float_ctype }}, { "__builtin_islessgreater", &int_ctype, 0, { &float_ctype, &float_ctype }}, - { "__builtin_isnan", &int_ctype, 1 }, - { "__builtin_isnormal", &int_ctype, 1 }, + { "__builtin_isnan", &int_ctype, 1, .op = &fp_unop_op }, + { "__builtin_isnormal", &int_ctype, 1, .op = &fp_unop_op }, { "__builtin_isunordered", &int_ctype, 0, { &float_ctype, &float_ctype }}, { "__builtin_labs", &long_ctype, 0, { &long_ctype }}, { "__builtin_llabs", &llong_ctype, 0, { &llong_ctype }}, @@ -459,16 +460,18 @@ static const struct builtin_fn builtins_common[] = { { "__builtin_memmove", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype }}, { "__builtin_mempcpy", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype }}, { "__builtin_memset", &ptr_ctype, 0, { &ptr_ctype, &int_ctype, size_t_ctype }}, + { "__builtin_mul_overflow", &bool_ctype, 1, .op = &overflow_op }, + { "__builtin_mul_overflow_p", &bool_ctype, 1, .op = &overflow_p_op }, { "__builtin_nan", &double_ctype, 0, { &const_string_ctype }}, { "__builtin_nanf", &float_ctype, 0, { &const_string_ctype }}, { "__builtin_nanl", &ldouble_ctype, 0, { &const_string_ctype }}, { "__builtin_object_size", size_t_ctype, 0, { &const_ptr_ctype, &int_ctype }}, - { "__builtin_parity", &int_ctype, 0, { &uint_ctype }}, - { "__builtin_parityl", &int_ctype, 0, { &ulong_ctype }}, - { "__builtin_parityll", &int_ctype, 0, { &ullong_ctype }}, - { "__builtin_popcount", &int_ctype, 0, { &uint_ctype }}, - { "__builtin_popcountl", &int_ctype, 0, { &ulong_ctype }}, - { "__builtin_popcountll", &int_ctype, 0, { &ullong_ctype }}, + { "__builtin_parity", &int_ctype, 0, { &uint_ctype }, .op = &parity_op }, + { "__builtin_parityl", &int_ctype, 0, { &ulong_ctype }, .op = &parity_op }, + { "__builtin_parityll", &int_ctype, 0, { &ullong_ctype }, .op = &parity_op }, + { "__builtin_popcount", &int_ctype, 0, { &uint_ctype }, .op = &popcount_op }, + { "__builtin_popcountl", &int_ctype, 0, { &ulong_ctype }, .op = &popcount_op }, + { "__builtin_popcountll", &int_ctype, 0, { &ullong_ctype }, .op = &popcount_op }, { "__builtin_prefetch", &void_ctype, 1, { &const_ptr_ctype }}, { "__builtin_printf", &int_ctype, 1, { &const_string_ctype }}, { "__builtin_puts", &int_ctype, 0, { &const_string_ctype }}, @@ -478,7 +481,7 @@ static const struct builtin_fn builtins_common[] = { { "__builtin_sadd_overflow", &bool_ctype, 0, { &int_ctype, &int_ctype, &int_ptr_ctype }}, { "__builtin_saddl_overflow", &bool_ctype, 0, { &long_ctype, &long_ctype, &long_ptr_ctype }}, { "__builtin_saddll_overflow", &bool_ctype, 0, { &llong_ctype, &llong_ctype, &llong_ptr_ctype }}, - { "__builtin_signbit", &int_ctype, 1 }, + { "__builtin_signbit", &int_ctype, 1 , .op = &fp_unop_op }, { "__builtin_smul_overflow", &bool_ctype, 0, { &int_ctype, &int_ctype, &int_ptr_ctype }}, { "__builtin_smull_overflow", &bool_ctype, 0, { &long_ctype, &long_ctype, &long_ptr_ctype }}, { "__builtin_smulll_overflow", &bool_ctype, 0, { &llong_ctype, &llong_ctype, &llong_ptr_ctype }}, @@ -508,6 +511,8 @@ static const struct builtin_fn builtins_common[] = { { "__builtin_strrchr", &string_ctype, 0, { &const_string_ctype, &int_ctype }}, { "__builtin_strspn", size_t_ctype, 0, { &const_string_ctype, &const_string_ctype }}, { "__builtin_strstr", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }}, + { "__builtin_sub_overflow", &bool_ctype, 1, .op = &overflow_op }, + { "__builtin_sub_overflow_p", &bool_ctype, 1, .op = &overflow_p_op }, { "__builtin_trap", &void_ctype, 0 }, { "__builtin_uadd_overflow", &bool_ctype, 0, { &uint_ctype, &uint_ctype, &uint_ptr_ctype }}, { "__builtin_uaddl_overflow", &bool_ctype, 0, { &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype }}, @@ -556,6 +561,15 @@ static const struct builtin_fn builtins_common[] = { { "__sync_val_compare_and_swap", &int_ctype, 1, { &ptr_ctype }}, { "__sync_xor_and_fetch", &int_ctype, 1, { &ptr_ctype }}, + // Alpha-specific + { "__builtin_alpha_cmpbge", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_extbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_extwl", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_insbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_inslh", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_insql", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_inswl", &long_ctype, 0, { &long_ctype, &long_ctype }}, + // Blackfin-specific stuff { "__builtin_bfin_csync", &void_ctype, 0 }, { "__builtin_bfin_ssync", &void_ctype, 0 }, @@ -569,68 +583,9 @@ static const struct builtin_fn builtins_common[] = { { } }; -static struct symbol builtin_fn_type = { .type = SYM_FN /* , .variadic =1 */ }; -static struct sym_init { - const char *name; - struct symbol *base_type; - unsigned int modifiers; - struct symbol_op *op; -} builtins_table[] = { - { "__builtin_constant_p", &builtin_fn_type, MOD_TOPLEVEL, &constant_p_op }, - { "__builtin_safe_p", &builtin_fn_type, MOD_TOPLEVEL, &safe_p_op }, - { "__builtin_warning", &builtin_fn_type, MOD_TOPLEVEL, &warning_op }, - { "__builtin_expect", &builtin_fn_type, MOD_TOPLEVEL, &expect_op }, - { "__builtin_choose_expr", &builtin_fn_type, MOD_TOPLEVEL, &choose_op }, - { "__builtin_bswap16", &builtin_fn_type, MOD_TOPLEVEL, &bswap_op }, - { "__builtin_bswap32", &builtin_fn_type, MOD_TOPLEVEL, &bswap_op }, - { "__builtin_bswap64", &builtin_fn_type, MOD_TOPLEVEL, &bswap_op }, - { "__builtin_clrsb", &builtin_fn_type, MOD_TOPLEVEL, &clrsb_op }, - { "__builtin_clrsbl", &builtin_fn_type, MOD_TOPLEVEL, &clrsb_op }, - { "__builtin_clrsbll", &builtin_fn_type, MOD_TOPLEVEL, &clrsb_op }, - { "__builtin_clz", &builtin_fn_type, MOD_TOPLEVEL, &clz_op }, - { "__builtin_clzl", &builtin_fn_type, MOD_TOPLEVEL, &clz_op }, - { "__builtin_clzll", &builtin_fn_type, MOD_TOPLEVEL, &clz_op }, - { "__builtin_ctz", &builtin_fn_type, MOD_TOPLEVEL, &ctz_op }, - { "__builtin_ctzl", &builtin_fn_type, MOD_TOPLEVEL, &ctz_op }, - { "__builtin_ctzll", &builtin_fn_type, MOD_TOPLEVEL, &ctz_op }, - { "__builtin_ffs", &builtin_fn_type, MOD_TOPLEVEL, &ffs_op }, - { "__builtin_ffsl", &builtin_fn_type, MOD_TOPLEVEL, &ffs_op }, - { "__builtin_ffsll", &builtin_fn_type, MOD_TOPLEVEL, &ffs_op }, - { "__builtin_isfinite", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op }, - { "__builtin_isinf", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op }, - { "__builtin_isinf_sign", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op }, - { "__builtin_isnan", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op }, - { "__builtin_isnormal", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op }, - { "__builtin_parity", &builtin_fn_type, MOD_TOPLEVEL, &parity_op }, - { "__builtin_parityl", &builtin_fn_type, MOD_TOPLEVEL, &parity_op }, - { "__builtin_parityll", &builtin_fn_type, MOD_TOPLEVEL, &parity_op }, - { "__builtin_popcount", &builtin_fn_type, MOD_TOPLEVEL, &popcount_op }, - { "__builtin_popcountl", &builtin_fn_type, MOD_TOPLEVEL, &popcount_op }, - { "__builtin_popcountll", &builtin_fn_type, MOD_TOPLEVEL, &popcount_op }, - { "__builtin_signbit", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op }, - { "__builtin_add_overflow", &builtin_fn_type, MOD_TOPLEVEL, &overflow_op }, - { "__builtin_sub_overflow", &builtin_fn_type, MOD_TOPLEVEL, &overflow_op }, - { "__builtin_mul_overflow", &builtin_fn_type, MOD_TOPLEVEL, &overflow_op }, - { "__builtin_add_overflow_p", &builtin_fn_type, MOD_TOPLEVEL, &overflow_p_op }, - { "__builtin_sub_overflow_p", &builtin_fn_type, MOD_TOPLEVEL, &overflow_p_op }, - { "__builtin_mul_overflow_p", &builtin_fn_type, MOD_TOPLEVEL, &overflow_p_op }, - { NULL, NULL, 0 } -}; - void init_builtins(int stream) { - struct sym_init *ptr; - - builtin_fn_type.variadic = 1; - for (ptr = builtins_table; ptr->name; ptr++) { - struct symbol *sym; - sym = create_symbol(stream, ptr->name, SYM_NODE, NS_SYMBOL); - sym->ctype.base_type = ptr->base_type; - sym->ctype.modifiers = ptr->modifiers; - sym->op = ptr->op; - sym->builtin = 1; - } - init_linearized_builtins(stream); declare_builtins(builtins_common); + init_linearized_builtins(stream); } diff --git a/builtin.h b/builtin.h index 233cf2806760..d0d3fd2ccf87 100644 --- a/builtin.h +++ b/builtin.h @@ -9,6 +9,7 @@ struct builtin_fn { unsigned int variadic:1; struct symbol *args[6]; struct symbol *_args_null_tail; + struct symbol_op *op; }; #endif -- 2.27.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 3/7] builtin: unify the 2 tables of builtins 2020-06-10 20:27 ` [PATCH 3/7] builtin: unify the 2 tables of builtins Luc Van Oostenryck @ 2020-06-12 1:01 ` Ramsay Jones 0 siblings, 0 replies; 14+ messages in thread From: Ramsay Jones @ 2020-06-12 1:01 UTC (permalink / raw) To: Luc Van Oostenryck, linux-sparse On 10/06/2020 21:27, Luc Van Oostenryck wrote: > Till now, 2 tables are used to initialize builtin functions: > * an older, small one, without type information, used to set > a symbol_op to evaluate and/or expand the ones that have > effectively an effect. Hmm, s/effectively an effect/some associated behaviour/? > * a newer and bigger one which only contains what is effectively > the prototype for these builtins in order to avoid warnings > about undeclared functions. > > It's kinda annoying to have 2 tables for this, even more so > because most entries in the first table also need to be in the > second one (for arguments type & number checking). s/type & number/type and number/ > > Fix this by: > * adding a field in the second table for the symbol_op > * merging or moving the entries in the first table into > the second one. I didn't check every entry below, but I didn't see any obvious mistakes either! ATB, Ramsay Jones > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> > --- > builtin.c | 145 +++++++++++++++++++----------------------------------- > builtin.h | 1 + > 2 files changed, 51 insertions(+), 95 deletions(-) > > diff --git a/builtin.c b/builtin.c > index aa9ce09c0f40..bb9ec65b2d20 100644 > --- a/builtin.c > +++ b/builtin.c > @@ -377,6 +377,7 @@ static void declare_one_builtin(const struct builtin_fn *entry) > sym->ctype.base_type = fun; > sym->ctype.modifiers = MOD_TOPLEVEL; > sym->builtin = 1; > + sym->op = entry->op; > > fun->ctype.base_type = get_ctype(entry->ret_type); > fun->variadic = entry->variadic; > @@ -397,39 +398,39 @@ static void declare_builtins(const struct builtin_fn tbl[]) > static const struct builtin_fn builtins_common[] = { > #define size_t_ctype &size_t_alias > #define va_list_ctype &ptr_ctype > + { "__builtin_choose_expr", NULL, 1, .op = &choose_op }, > + { "__builtin_constant_p", NULL, 1, .op = &constant_p_op }, > + { "__builtin_expect", &long_ctype, 0, { &long_ctype ,&long_ctype }, .op = &expect_op }, > + { "__builtin_safe_p", NULL, 1, .op = &safe_p_op }, > + { "__builtin_warning", NULL, 1, .op = &warning_op }, > + > { "__builtin_abort", &void_ctype, 0 }, > { "__builtin_abs", &int_ctype , 0, { &int_ctype }}, > + { "__builtin_add_overflow", &bool_ctype, 1, .op = &overflow_op }, > + { "__builtin_add_overflow_p", &bool_ctype, 1, .op = &overflow_p_op }, > { "__builtin_alloca", &ptr_ctype, 0, { size_t_ctype }}, > - { "__builtin_alpha_cmpbge", &long_ctype, 0, { &long_ctype, &long_ctype }}, > - { "__builtin_alpha_extbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, > - { "__builtin_alpha_extwl", &long_ctype, 0, { &long_ctype, &long_ctype }}, > - { "__builtin_alpha_insbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, > - { "__builtin_alpha_inslh", &long_ctype, 0, { &long_ctype, &long_ctype }}, > - { "__builtin_alpha_insql", &long_ctype, 0, { &long_ctype, &long_ctype }}, > - { "__builtin_alpha_inswl", &long_ctype, 0, { &long_ctype, &long_ctype }}, > { "__builtin_bcmp", &int_ctype , 0, { &const_ptr_ctype, &const_ptr_ctype, size_t_ctype }}, > { "__builtin_bcopy", &void_ctype, 0, { &const_ptr_ctype, &ptr_ctype, size_t_ctype }}, > - { "__builtin_bswap16", &ushort_ctype, 0, { &ushort_ctype }}, > - { "__builtin_bswap32", &uint_ctype, 0, { &uint_ctype }}, > - { "__builtin_bswap64", &ullong_ctype, 0, { &ullong_ctype }}, > + { "__builtin_bswap16", &ushort_ctype, 0, { &ushort_ctype }, .op = &bswap_op }, > + { "__builtin_bswap32", &uint_ctype, 0, { &uint_ctype }, .op = &bswap_op }, > + { "__builtin_bswap64", &ullong_ctype, 0, { &ullong_ctype }, .op = &bswap_op }, > { "__builtin_bzero", &void_ctype, 0, { &ptr_ctype, size_t_ctype }}, > { "__builtin_calloc", &ptr_ctype, 0, { size_t_ctype, size_t_ctype }}, > - { "__builtin_clrsb", &int_ctype, 0, { &int_ctype }}, > - { "__builtin_clrsbl", &int_ctype, 0, { &long_ctype }}, > - { "__builtin_clrsbll", &int_ctype, 0, { &llong_ctype }}, > - { "__builtin_clz", &int_ctype, 0, { &int_ctype }}, > - { "__builtin_clzl", &int_ctype, 0, { &long_ctype }}, > - { "__builtin_clzll", &int_ctype, 0, { &llong_ctype }}, > - { "__builtin_ctz", &int_ctype, 0, { &int_ctype }}, > - { "__builtin_ctzl", &int_ctype, 0, { &long_ctype }}, > - { "__builtin_ctzll", &int_ctype, 0, { &llong_ctype }}, > + { "__builtin_clrsb", &int_ctype, 0, { &int_ctype }, .op = &clrsb_op }, > + { "__builtin_clrsbl", &int_ctype, 0, { &long_ctype }, .op = &clrsb_op }, > + { "__builtin_clrsbll", &int_ctype, 0, { &llong_ctype }, .op = &clrsb_op }, > + { "__builtin_clz", &int_ctype, 0, { &int_ctype }, .op = &clz_op }, > + { "__builtin_clzl", &int_ctype, 0, { &long_ctype }, .op = &clz_op }, > + { "__builtin_clzll", &int_ctype, 0, { &llong_ctype }, .op = &clz_op }, > + { "__builtin_ctz", &int_ctype, 0, { &int_ctype }, .op = &ctz_op }, > + { "__builtin_ctzl", &int_ctype, 0, { &long_ctype }, .op = &ctz_op }, > + { "__builtin_ctzll", &int_ctype, 0, { &llong_ctype }, .op = &ctz_op }, > { "__builtin_exit", &void_ctype, 0, { &int_ctype }}, > - { "__builtin_expect", &long_ctype, 0, { &long_ctype ,&long_ctype }}, > { "__builtin_extract_return_addr", &ptr_ctype, 0, { &ptr_ctype }}, > { "__builtin_fabs", &double_ctype, 0, { &double_ctype }}, > - { "__builtin_ffs", &int_ctype, 0, { &int_ctype }}, > - { "__builtin_ffsl", &int_ctype, 0, { &long_ctype }}, > - { "__builtin_ffsll", &int_ctype, 0, { &llong_ctype }}, > + { "__builtin_ffs", &int_ctype, 0, { &int_ctype }, .op = &ffs_op }, > + { "__builtin_ffsl", &int_ctype, 0, { &long_ctype }, .op = &ffs_op }, > + { "__builtin_ffsll", &int_ctype, 0, { &llong_ctype }, .op = &ffs_op }, > { "__builtin_frame_address", &ptr_ctype, 0, { &uint_ctype }}, > { "__builtin_free", &void_ctype, 0, { &ptr_ctype }}, > { "__builtin_huge_val", &double_ctype, 0 }, > @@ -439,16 +440,16 @@ static const struct builtin_fn builtins_common[] = { > { "__builtin_inf", &double_ctype, 0 }, > { "__builtin_inff", &float_ctype, 0 }, > { "__builtin_infl", &ldouble_ctype, 0 }, > - { "__builtin_isfinite", &int_ctype, 1 }, > + { "__builtin_isfinite", &int_ctype, 1, .op = &fp_unop_op }, > { "__builtin_isgreater", &int_ctype, 0, { &float_ctype, &float_ctype }}, > { "__builtin_isgreaterequal", &int_ctype, 0, { &float_ctype, &float_ctype }}, > - { "__builtin_isinf", &int_ctype, 1 }, > - { "__builtin_isinf_sign", &int_ctype, 1 }, > + { "__builtin_isinf", &int_ctype, 1, .op = &fp_unop_op }, > + { "__builtin_isinf_sign", &int_ctype, 1, .op = &fp_unop_op }, > { "__builtin_isless", &int_ctype, 0, { &float_ctype, &float_ctype }}, > { "__builtin_islessequal", &int_ctype, 0, { &float_ctype, &float_ctype }}, > { "__builtin_islessgreater", &int_ctype, 0, { &float_ctype, &float_ctype }}, > - { "__builtin_isnan", &int_ctype, 1 }, > - { "__builtin_isnormal", &int_ctype, 1 }, > + { "__builtin_isnan", &int_ctype, 1, .op = &fp_unop_op }, > + { "__builtin_isnormal", &int_ctype, 1, .op = &fp_unop_op }, > { "__builtin_isunordered", &int_ctype, 0, { &float_ctype, &float_ctype }}, > { "__builtin_labs", &long_ctype, 0, { &long_ctype }}, > { "__builtin_llabs", &llong_ctype, 0, { &llong_ctype }}, > @@ -459,16 +460,18 @@ static const struct builtin_fn builtins_common[] = { > { "__builtin_memmove", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype }}, > { "__builtin_mempcpy", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype }}, > { "__builtin_memset", &ptr_ctype, 0, { &ptr_ctype, &int_ctype, size_t_ctype }}, > + { "__builtin_mul_overflow", &bool_ctype, 1, .op = &overflow_op }, > + { "__builtin_mul_overflow_p", &bool_ctype, 1, .op = &overflow_p_op }, > { "__builtin_nan", &double_ctype, 0, { &const_string_ctype }}, > { "__builtin_nanf", &float_ctype, 0, { &const_string_ctype }}, > { "__builtin_nanl", &ldouble_ctype, 0, { &const_string_ctype }}, > { "__builtin_object_size", size_t_ctype, 0, { &const_ptr_ctype, &int_ctype }}, > - { "__builtin_parity", &int_ctype, 0, { &uint_ctype }}, > - { "__builtin_parityl", &int_ctype, 0, { &ulong_ctype }}, > - { "__builtin_parityll", &int_ctype, 0, { &ullong_ctype }}, > - { "__builtin_popcount", &int_ctype, 0, { &uint_ctype }}, > - { "__builtin_popcountl", &int_ctype, 0, { &ulong_ctype }}, > - { "__builtin_popcountll", &int_ctype, 0, { &ullong_ctype }}, > + { "__builtin_parity", &int_ctype, 0, { &uint_ctype }, .op = &parity_op }, > + { "__builtin_parityl", &int_ctype, 0, { &ulong_ctype }, .op = &parity_op }, > + { "__builtin_parityll", &int_ctype, 0, { &ullong_ctype }, .op = &parity_op }, > + { "__builtin_popcount", &int_ctype, 0, { &uint_ctype }, .op = &popcount_op }, > + { "__builtin_popcountl", &int_ctype, 0, { &ulong_ctype }, .op = &popcount_op }, > + { "__builtin_popcountll", &int_ctype, 0, { &ullong_ctype }, .op = &popcount_op }, > { "__builtin_prefetch", &void_ctype, 1, { &const_ptr_ctype }}, > { "__builtin_printf", &int_ctype, 1, { &const_string_ctype }}, > { "__builtin_puts", &int_ctype, 0, { &const_string_ctype }}, > @@ -478,7 +481,7 @@ static const struct builtin_fn builtins_common[] = { > { "__builtin_sadd_overflow", &bool_ctype, 0, { &int_ctype, &int_ctype, &int_ptr_ctype }}, > { "__builtin_saddl_overflow", &bool_ctype, 0, { &long_ctype, &long_ctype, &long_ptr_ctype }}, > { "__builtin_saddll_overflow", &bool_ctype, 0, { &llong_ctype, &llong_ctype, &llong_ptr_ctype }}, > - { "__builtin_signbit", &int_ctype, 1 }, > + { "__builtin_signbit", &int_ctype, 1 , .op = &fp_unop_op }, > { "__builtin_smul_overflow", &bool_ctype, 0, { &int_ctype, &int_ctype, &int_ptr_ctype }}, > { "__builtin_smull_overflow", &bool_ctype, 0, { &long_ctype, &long_ctype, &long_ptr_ctype }}, > { "__builtin_smulll_overflow", &bool_ctype, 0, { &llong_ctype, &llong_ctype, &llong_ptr_ctype }}, > @@ -508,6 +511,8 @@ static const struct builtin_fn builtins_common[] = { > { "__builtin_strrchr", &string_ctype, 0, { &const_string_ctype, &int_ctype }}, > { "__builtin_strspn", size_t_ctype, 0, { &const_string_ctype, &const_string_ctype }}, > { "__builtin_strstr", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }}, > + { "__builtin_sub_overflow", &bool_ctype, 1, .op = &overflow_op }, > + { "__builtin_sub_overflow_p", &bool_ctype, 1, .op = &overflow_p_op }, > { "__builtin_trap", &void_ctype, 0 }, > { "__builtin_uadd_overflow", &bool_ctype, 0, { &uint_ctype, &uint_ctype, &uint_ptr_ctype }}, > { "__builtin_uaddl_overflow", &bool_ctype, 0, { &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype }}, > @@ -556,6 +561,15 @@ static const struct builtin_fn builtins_common[] = { > { "__sync_val_compare_and_swap", &int_ctype, 1, { &ptr_ctype }}, > { "__sync_xor_and_fetch", &int_ctype, 1, { &ptr_ctype }}, > > + // Alpha-specific > + { "__builtin_alpha_cmpbge", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + { "__builtin_alpha_extbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + { "__builtin_alpha_extwl", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + { "__builtin_alpha_insbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + { "__builtin_alpha_inslh", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + { "__builtin_alpha_insql", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + { "__builtin_alpha_inswl", &long_ctype, 0, { &long_ctype, &long_ctype }}, > + > // Blackfin-specific stuff > { "__builtin_bfin_csync", &void_ctype, 0 }, > { "__builtin_bfin_ssync", &void_ctype, 0 }, > @@ -569,68 +583,9 @@ static const struct builtin_fn builtins_common[] = { > { } > }; > > -static struct symbol builtin_fn_type = { .type = SYM_FN /* , .variadic =1 */ }; > -static struct sym_init { > - const char *name; > - struct symbol *base_type; > - unsigned int modifiers; > - struct symbol_op *op; > -} builtins_table[] = { > - { "__builtin_constant_p", &builtin_fn_type, MOD_TOPLEVEL, &constant_p_op }, > - { "__builtin_safe_p", &builtin_fn_type, MOD_TOPLEVEL, &safe_p_op }, > - { "__builtin_warning", &builtin_fn_type, MOD_TOPLEVEL, &warning_op }, > - { "__builtin_expect", &builtin_fn_type, MOD_TOPLEVEL, &expect_op }, > - { "__builtin_choose_expr", &builtin_fn_type, MOD_TOPLEVEL, &choose_op }, > - { "__builtin_bswap16", &builtin_fn_type, MOD_TOPLEVEL, &bswap_op }, > - { "__builtin_bswap32", &builtin_fn_type, MOD_TOPLEVEL, &bswap_op }, > - { "__builtin_bswap64", &builtin_fn_type, MOD_TOPLEVEL, &bswap_op }, > - { "__builtin_clrsb", &builtin_fn_type, MOD_TOPLEVEL, &clrsb_op }, > - { "__builtin_clrsbl", &builtin_fn_type, MOD_TOPLEVEL, &clrsb_op }, > - { "__builtin_clrsbll", &builtin_fn_type, MOD_TOPLEVEL, &clrsb_op }, > - { "__builtin_clz", &builtin_fn_type, MOD_TOPLEVEL, &clz_op }, > - { "__builtin_clzl", &builtin_fn_type, MOD_TOPLEVEL, &clz_op }, > - { "__builtin_clzll", &builtin_fn_type, MOD_TOPLEVEL, &clz_op }, > - { "__builtin_ctz", &builtin_fn_type, MOD_TOPLEVEL, &ctz_op }, > - { "__builtin_ctzl", &builtin_fn_type, MOD_TOPLEVEL, &ctz_op }, > - { "__builtin_ctzll", &builtin_fn_type, MOD_TOPLEVEL, &ctz_op }, > - { "__builtin_ffs", &builtin_fn_type, MOD_TOPLEVEL, &ffs_op }, > - { "__builtin_ffsl", &builtin_fn_type, MOD_TOPLEVEL, &ffs_op }, > - { "__builtin_ffsll", &builtin_fn_type, MOD_TOPLEVEL, &ffs_op }, > - { "__builtin_isfinite", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op }, > - { "__builtin_isinf", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op }, > - { "__builtin_isinf_sign", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op }, > - { "__builtin_isnan", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op }, > - { "__builtin_isnormal", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op }, > - { "__builtin_parity", &builtin_fn_type, MOD_TOPLEVEL, &parity_op }, > - { "__builtin_parityl", &builtin_fn_type, MOD_TOPLEVEL, &parity_op }, > - { "__builtin_parityll", &builtin_fn_type, MOD_TOPLEVEL, &parity_op }, > - { "__builtin_popcount", &builtin_fn_type, MOD_TOPLEVEL, &popcount_op }, > - { "__builtin_popcountl", &builtin_fn_type, MOD_TOPLEVEL, &popcount_op }, > - { "__builtin_popcountll", &builtin_fn_type, MOD_TOPLEVEL, &popcount_op }, > - { "__builtin_signbit", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op }, > - { "__builtin_add_overflow", &builtin_fn_type, MOD_TOPLEVEL, &overflow_op }, > - { "__builtin_sub_overflow", &builtin_fn_type, MOD_TOPLEVEL, &overflow_op }, > - { "__builtin_mul_overflow", &builtin_fn_type, MOD_TOPLEVEL, &overflow_op }, > - { "__builtin_add_overflow_p", &builtin_fn_type, MOD_TOPLEVEL, &overflow_p_op }, > - { "__builtin_sub_overflow_p", &builtin_fn_type, MOD_TOPLEVEL, &overflow_p_op }, > - { "__builtin_mul_overflow_p", &builtin_fn_type, MOD_TOPLEVEL, &overflow_p_op }, > - { NULL, NULL, 0 } > -}; > - > void init_builtins(int stream) > { > - struct sym_init *ptr; > - > - builtin_fn_type.variadic = 1; > - for (ptr = builtins_table; ptr->name; ptr++) { > - struct symbol *sym; > - sym = create_symbol(stream, ptr->name, SYM_NODE, NS_SYMBOL); > - sym->ctype.base_type = ptr->base_type; > - sym->ctype.modifiers = ptr->modifiers; > - sym->op = ptr->op; > - sym->builtin = 1; > - } > > - init_linearized_builtins(stream); > declare_builtins(builtins_common); > + init_linearized_builtins(stream); > } > diff --git a/builtin.h b/builtin.h > index 233cf2806760..d0d3fd2ccf87 100644 > --- a/builtin.h > +++ b/builtin.h > @@ -9,6 +9,7 @@ struct builtin_fn { > unsigned int variadic:1; > struct symbol *args[6]; > struct symbol *_args_null_tail; > + struct symbol_op *op; > }; > > #endif > ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 4/7] builtin: add support for arch-specific builtins 2020-06-10 20:27 [PATCH 0/7] move arch-specific builtins to their own table Luc Van Oostenryck ` (2 preceding siblings ...) 2020-06-10 20:27 ` [PATCH 3/7] builtin: unify the 2 tables of builtins Luc Van Oostenryck @ 2020-06-10 20:27 ` Luc Van Oostenryck 2020-06-10 20:27 ` [PATCH 5/7] arch: add specificities for Nios2 Luc Van Oostenryck ` (2 subsequent siblings) 6 siblings, 0 replies; 14+ messages in thread From: Luc Van Oostenryck @ 2020-06-10 20:27 UTC (permalink / raw) To: linux-sparse; +Cc: Luc Van Oostenryck Now that a table is used for the declaration of builtin functions it's easy to support arch-specific builtins. The main objective is to not 'pollute' the main table with arch-specfic entries for uncommon architectures. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- builtin.c | 4 ++++ target.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/builtin.c b/builtin.c index bb9ec65b2d20..dcf8200ec002 100644 --- a/builtin.c +++ b/builtin.c @@ -391,6 +391,9 @@ static void declare_one_builtin(const struct builtin_fn *entry) static void declare_builtins(const struct builtin_fn tbl[]) { + if (!tbl) + return; + while (tbl->name) declare_one_builtin(tbl++); } @@ -587,5 +590,6 @@ void init_builtins(int stream) { declare_builtins(builtins_common); + declare_builtins(arch_target->builtins); init_linearized_builtins(stream); } diff --git a/target.h b/target.h index a89e21b63563..1202c0be1ac9 100644 --- a/target.h +++ b/target.h @@ -54,6 +54,8 @@ extern int bits_in_enum; extern int enum_alignment; +struct builtin_fn; + struct target { enum machine mach; enum bitness bitness; @@ -71,6 +73,8 @@ struct target { const struct target *target_32bit; const struct target *target_64bit; + const struct builtin_fn *builtins; + void (*init)(const struct target *self); void (*predefine)(const struct target *self); }; -- 2.27.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 5/7] arch: add specificities for Nios2 2020-06-10 20:27 [PATCH 0/7] move arch-specific builtins to their own table Luc Van Oostenryck ` (3 preceding siblings ...) 2020-06-10 20:27 ` [PATCH 4/7] builtin: add support for arch-specific builtins Luc Van Oostenryck @ 2020-06-10 20:27 ` Luc Van Oostenryck 2020-06-12 1:04 ` Ramsay Jones 2020-06-10 20:27 ` [PATCH 6/7] arch: add specificities for Blackfin Luc Van Oostenryck 2020-06-10 20:27 ` [PATCH 7/7] arch: add specificities for Alpha Luc Van Oostenryck 6 siblings, 1 reply; 14+ messages in thread From: Luc Van Oostenryck @ 2020-06-10 20:27 UTC (permalink / raw) To: linux-sparse; +Cc: Luc Van Oostenryck The real goal here is in fact to move the nios2-specfic builtins out of the main builtins table. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- Makefile | 1 + builtin.c | 5 ----- machine.h | 1 + target-nios2.c | 31 +++++++++++++++++++++++++++++++ target.c | 2 ++ target.h | 1 + 6 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 target-nios2.c diff --git a/Makefile b/Makefile index e93cfd66d0c9..69fae4828e62 100644 --- a/Makefile +++ b/Makefile @@ -70,6 +70,7 @@ LIB_OBJS += target-arm64.o LIB_OBJS += target-default.o LIB_OBJS += target-m68k.o LIB_OBJS += target-mips.o +LIB_OBJS += target-nios2.o LIB_OBJS += target-ppc.o LIB_OBJS += target-riscv.o LIB_OBJS += target-s390.o diff --git a/builtin.c b/builtin.c index dcf8200ec002..9442fb5b89ef 100644 --- a/builtin.c +++ b/builtin.c @@ -578,11 +578,6 @@ static const struct builtin_fn builtins_common[] = { { "__builtin_bfin_ssync", &void_ctype, 0 }, { "__builtin_bfin_norm_fr1x32", &int_ctype, 0, { &int_ctype }}, - // Nios-II-specific - { "__builtin_rdctl", &int_ctype, 0, { &int_ctype }}, - { "__builtin_wrctl", &void_ctype, 0, { &int_ctype, &int_ctype }}, - { "__builtin_custom_ini", &int_ctype, 0, { &int_ctype }}, - { } }; diff --git a/machine.h b/machine.h index 9c17dd6aa620..a211345c80ce 100644 --- a/machine.h +++ b/machine.h @@ -33,6 +33,7 @@ enum machine { MACH_SPARC32, MACH_SPARC64, MACH_S390, MACH_S390X, MACH_M68K, + MACH_NIOS2, MACH_UNKNOWN }; diff --git a/target-nios2.c b/target-nios2.c new file mode 100644 index 000000000000..05f0926e2df9 --- /dev/null +++ b/target-nios2.c @@ -0,0 +1,31 @@ +#include "symbol.h" +#include "target.h" +#include "machine.h" +#include "builtin.h" + + +static void predefine_nios2(const struct target *self) +{ + predefine("__NIOS2__", 1, "1"); + predefine("__nios2__", 1, "1"); + + if (arch_big_endian) + predefine("__nios2_big_endian__", 1, "1"); + else + predefine("__nios2_little_endian__", 1, "1"); +} + +static const struct builtin_fn builtins_nios2[] = { + { "__builtin_rdctl", &int_ctype, 0, { &int_ctype }}, + { "__builtin_wrctl", &void_ctype, 0, { &int_ctype, &int_ctype }}, + { "__builtin_custom_ini", &int_ctype, 0, { &int_ctype }}, + { } +}; + +const struct target target_nios2 = { + .mach = MACH_NIOS2, + .bitness = ARCH_LP32, + + .predefine = predefine_nios2, + .builtins = builtins_nios2, +}; diff --git a/target.c b/target.c index abfa975672b1..0ef0eb5a14ae 100644 --- a/target.c +++ b/target.c @@ -63,6 +63,7 @@ static const struct target *targets[] = { [MACH_X86_64] = &target_x86_64, [MACH_MIPS32] = &target_mips32, [MACH_MIPS64] = &target_mips64, + [MACH_NIOS2] = &target_nios2, [MACH_PPC32] = &target_ppc32, [MACH_PPC64] = &target_ppc64, [MACH_RISCV32] = &target_riscv32, @@ -89,6 +90,7 @@ enum machine target_parse(const char *name) { "i386", MACH_I386, 32, }, { "m68k", MACH_M68K, 32, }, { "mips", MACH_MIPS32, 0, }, + { "nios2", MACH_NIOS2, 32, }, { "powerpc", MACH_PPC32, 0, }, { "ppc", MACH_PPC32, 0, }, { "riscv", MACH_RISCV32, 0, }, diff --git a/target.h b/target.h index 1202c0be1ac9..4c184d8f2fbe 100644 --- a/target.h +++ b/target.h @@ -85,6 +85,7 @@ extern const struct target target_arm64; extern const struct target target_m68k; extern const struct target target_mips32; extern const struct target target_mips64; +extern const struct target target_nios2; extern const struct target target_ppc32; extern const struct target target_ppc64; extern const struct target target_riscv32; -- 2.27.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 5/7] arch: add specificities for Nios2 2020-06-10 20:27 ` [PATCH 5/7] arch: add specificities for Nios2 Luc Van Oostenryck @ 2020-06-12 1:04 ` Ramsay Jones 2020-06-12 17:04 ` Luc Van Oostenryck 0 siblings, 1 reply; 14+ messages in thread From: Ramsay Jones @ 2020-06-12 1:04 UTC (permalink / raw) To: Luc Van Oostenryck, linux-sparse On 10/06/2020 21:27, Luc Van Oostenryck wrote: > The real goal here is in fact to move the nios2-specfic > builtins out of the main builtins table. I had to do a search for Nois II - do people actually run Linux on these? :-P This and all remaining patches look good. Thanks. ATB, Ramsay Jones > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> > --- > Makefile | 1 + > builtin.c | 5 ----- > machine.h | 1 + > target-nios2.c | 31 +++++++++++++++++++++++++++++++ > target.c | 2 ++ > target.h | 1 + > 6 files changed, 36 insertions(+), 5 deletions(-) > create mode 100644 target-nios2.c > > diff --git a/Makefile b/Makefile > index e93cfd66d0c9..69fae4828e62 100644 > --- a/Makefile > +++ b/Makefile > @@ -70,6 +70,7 @@ LIB_OBJS += target-arm64.o > LIB_OBJS += target-default.o > LIB_OBJS += target-m68k.o > LIB_OBJS += target-mips.o > +LIB_OBJS += target-nios2.o > LIB_OBJS += target-ppc.o > LIB_OBJS += target-riscv.o > LIB_OBJS += target-s390.o > diff --git a/builtin.c b/builtin.c > index dcf8200ec002..9442fb5b89ef 100644 > --- a/builtin.c > +++ b/builtin.c > @@ -578,11 +578,6 @@ static const struct builtin_fn builtins_common[] = { > { "__builtin_bfin_ssync", &void_ctype, 0 }, > { "__builtin_bfin_norm_fr1x32", &int_ctype, 0, { &int_ctype }}, > > - // Nios-II-specific > - { "__builtin_rdctl", &int_ctype, 0, { &int_ctype }}, > - { "__builtin_wrctl", &void_ctype, 0, { &int_ctype, &int_ctype }}, > - { "__builtin_custom_ini", &int_ctype, 0, { &int_ctype }}, > - > { } > }; > > diff --git a/machine.h b/machine.h > index 9c17dd6aa620..a211345c80ce 100644 > --- a/machine.h > +++ b/machine.h > @@ -33,6 +33,7 @@ enum machine { > MACH_SPARC32, MACH_SPARC64, > MACH_S390, MACH_S390X, > MACH_M68K, > + MACH_NIOS2, > MACH_UNKNOWN > }; > > diff --git a/target-nios2.c b/target-nios2.c > new file mode 100644 > index 000000000000..05f0926e2df9 > --- /dev/null > +++ b/target-nios2.c > @@ -0,0 +1,31 @@ > +#include "symbol.h" > +#include "target.h" > +#include "machine.h" > +#include "builtin.h" > + > + > +static void predefine_nios2(const struct target *self) > +{ > + predefine("__NIOS2__", 1, "1"); > + predefine("__nios2__", 1, "1"); > + > + if (arch_big_endian) > + predefine("__nios2_big_endian__", 1, "1"); > + else > + predefine("__nios2_little_endian__", 1, "1"); > +} > + > +static const struct builtin_fn builtins_nios2[] = { > + { "__builtin_rdctl", &int_ctype, 0, { &int_ctype }}, > + { "__builtin_wrctl", &void_ctype, 0, { &int_ctype, &int_ctype }}, > + { "__builtin_custom_ini", &int_ctype, 0, { &int_ctype }}, > + { } > +}; > + > +const struct target target_nios2 = { > + .mach = MACH_NIOS2, > + .bitness = ARCH_LP32, > + > + .predefine = predefine_nios2, > + .builtins = builtins_nios2, > +}; > diff --git a/target.c b/target.c > index abfa975672b1..0ef0eb5a14ae 100644 > --- a/target.c > +++ b/target.c > @@ -63,6 +63,7 @@ static const struct target *targets[] = { > [MACH_X86_64] = &target_x86_64, > [MACH_MIPS32] = &target_mips32, > [MACH_MIPS64] = &target_mips64, > + [MACH_NIOS2] = &target_nios2, > [MACH_PPC32] = &target_ppc32, > [MACH_PPC64] = &target_ppc64, > [MACH_RISCV32] = &target_riscv32, > @@ -89,6 +90,7 @@ enum machine target_parse(const char *name) > { "i386", MACH_I386, 32, }, > { "m68k", MACH_M68K, 32, }, > { "mips", MACH_MIPS32, 0, }, > + { "nios2", MACH_NIOS2, 32, }, > { "powerpc", MACH_PPC32, 0, }, > { "ppc", MACH_PPC32, 0, }, > { "riscv", MACH_RISCV32, 0, }, > diff --git a/target.h b/target.h > index 1202c0be1ac9..4c184d8f2fbe 100644 > --- a/target.h > +++ b/target.h > @@ -85,6 +85,7 @@ extern const struct target target_arm64; > extern const struct target target_m68k; > extern const struct target target_mips32; > extern const struct target target_mips64; > +extern const struct target target_nios2; > extern const struct target target_ppc32; > extern const struct target target_ppc64; > extern const struct target target_riscv32; > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 5/7] arch: add specificities for Nios2 2020-06-12 1:04 ` Ramsay Jones @ 2020-06-12 17:04 ` Luc Van Oostenryck 0 siblings, 0 replies; 14+ messages in thread From: Luc Van Oostenryck @ 2020-06-12 17:04 UTC (permalink / raw) To: Ramsay Jones; +Cc: linux-sparse On Fri, Jun 12, 2020 at 02:04:50AM +0100, Ramsay Jones wrote: > On 10/06/2020 21:27, Luc Van Oostenryck wrote: > > The real goal here is in fact to move the nios2-specfic > > builtins out of the main builtins table. > > I had to do a search for Nois II - do people actually run Linux > on these? :-P Yes, quite exotic! I also had to look about it. > This and all remaining patches look good. Thanks, -- Luc ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 6/7] arch: add specificities for Blackfin 2020-06-10 20:27 [PATCH 0/7] move arch-specific builtins to their own table Luc Van Oostenryck ` (4 preceding siblings ...) 2020-06-10 20:27 ` [PATCH 5/7] arch: add specificities for Nios2 Luc Van Oostenryck @ 2020-06-10 20:27 ` Luc Van Oostenryck 2020-06-10 20:27 ` [PATCH 7/7] arch: add specificities for Alpha Luc Van Oostenryck 6 siblings, 0 replies; 14+ messages in thread From: Luc Van Oostenryck @ 2020-06-10 20:27 UTC (permalink / raw) To: linux-sparse; +Cc: Luc Van Oostenryck The real goal here is in fact to move the bfin-specfic builtins out of the main builtins table. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- Makefile | 1 + builtin.c | 5 ----- machine.h | 1 + target-bfin.c | 26 ++++++++++++++++++++++++++ target.c | 2 ++ target.h | 1 + 6 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 target-bfin.c diff --git a/Makefile b/Makefile index 69fae4828e62..bee6a324b1c7 100644 --- a/Makefile +++ b/Makefile @@ -67,6 +67,7 @@ LIB_OBJS += symbol.o LIB_OBJS += target.o LIB_OBJS += target-arm.o LIB_OBJS += target-arm64.o +LIB_OBJS += target-bfin.o LIB_OBJS += target-default.o LIB_OBJS += target-m68k.o LIB_OBJS += target-mips.o diff --git a/builtin.c b/builtin.c index 9442fb5b89ef..dd467db425df 100644 --- a/builtin.c +++ b/builtin.c @@ -573,11 +573,6 @@ static const struct builtin_fn builtins_common[] = { { "__builtin_alpha_insql", &long_ctype, 0, { &long_ctype, &long_ctype }}, { "__builtin_alpha_inswl", &long_ctype, 0, { &long_ctype, &long_ctype }}, - // Blackfin-specific stuff - { "__builtin_bfin_csync", &void_ctype, 0 }, - { "__builtin_bfin_ssync", &void_ctype, 0 }, - { "__builtin_bfin_norm_fr1x32", &int_ctype, 0, { &int_ctype }}, - { } }; diff --git a/machine.h b/machine.h index a211345c80ce..b9f22850b9db 100644 --- a/machine.h +++ b/machine.h @@ -32,6 +32,7 @@ enum machine { MACH_RISCV32, MACH_RISCV64, MACH_SPARC32, MACH_SPARC64, MACH_S390, MACH_S390X, + MACH_BFIN, MACH_M68K, MACH_NIOS2, MACH_UNKNOWN diff --git a/target-bfin.c b/target-bfin.c new file mode 100644 index 000000000000..b84cd5de8d54 --- /dev/null +++ b/target-bfin.c @@ -0,0 +1,26 @@ +#include "symbol.h" +#include "target.h" +#include "machine.h" +#include "builtin.h" + + +static void predefine_bfin(const struct target *self) +{ + predefine("__BFIN__", 1, "1"); + predefine("__bfin__", 1, "1"); +} + +static const struct builtin_fn builtins_bfin[] = { + { "__builtin_bfin_csync", &void_ctype, 0 }, + { "__builtin_bfin_ssync", &void_ctype, 0 }, + { "__builtin_bfin_norm_fr1x32", &int_ctype, 0, { &int_ctype }}, + { } +}; + +const struct target target_bfin = { + .mach = MACH_BFIN, + .bitness = ARCH_LP32, + + .predefine = predefine_bfin, + .builtins = builtins_bfin, +}; diff --git a/target.c b/target.c index 0ef0eb5a14ae..1fd066da8639 100644 --- a/target.c +++ b/target.c @@ -60,6 +60,7 @@ static const struct target *targets[] = { [MACH_ARM] = &target_arm, [MACH_ARM64] = &target_arm64, [MACH_I386] = &target_i386, + [MACH_BFIN] = &target_bfin, [MACH_X86_64] = &target_x86_64, [MACH_MIPS32] = &target_mips32, [MACH_MIPS64] = &target_mips64, @@ -88,6 +89,7 @@ enum machine target_parse(const char *name) { "arm64", MACH_ARM64, 64, }, { "arm", MACH_ARM, 32, }, { "i386", MACH_I386, 32, }, + { "bfin", MACH_BFIN, 32, }, { "m68k", MACH_M68K, 32, }, { "mips", MACH_MIPS32, 0, }, { "nios2", MACH_NIOS2, 32, }, diff --git a/target.h b/target.h index 4c184d8f2fbe..9674d0995fd5 100644 --- a/target.h +++ b/target.h @@ -82,6 +82,7 @@ struct target { extern const struct target target_default; extern const struct target target_arm; extern const struct target target_arm64; +extern const struct target target_bfin; extern const struct target target_m68k; extern const struct target target_mips32; extern const struct target target_mips64; -- 2.27.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 7/7] arch: add specificities for Alpha 2020-06-10 20:27 [PATCH 0/7] move arch-specific builtins to their own table Luc Van Oostenryck ` (5 preceding siblings ...) 2020-06-10 20:27 ` [PATCH 6/7] arch: add specificities for Blackfin Luc Van Oostenryck @ 2020-06-10 20:27 ` Luc Van Oostenryck 6 siblings, 0 replies; 14+ messages in thread From: Luc Van Oostenryck @ 2020-06-10 20:27 UTC (permalink / raw) To: linux-sparse; +Cc: Luc Van Oostenryck The real goal here is in fact to move the alpha-specfic builtins out of the main builtins table. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- Makefile | 1 + builtin.c | 9 --------- machine.h | 3 +++ target-alpha.c | 30 ++++++++++++++++++++++++++++++ target.c | 2 ++ target.h | 1 + 6 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 target-alpha.c diff --git a/Makefile b/Makefile index bee6a324b1c7..e1831a1d259b 100644 --- a/Makefile +++ b/Makefile @@ -65,6 +65,7 @@ LIB_OBJS += stats.o LIB_OBJS += storage.o LIB_OBJS += symbol.o LIB_OBJS += target.o +LIB_OBJS += target-alpha.o LIB_OBJS += target-arm.o LIB_OBJS += target-arm64.o LIB_OBJS += target-bfin.o diff --git a/builtin.c b/builtin.c index dd467db425df..2038de5730e3 100644 --- a/builtin.c +++ b/builtin.c @@ -564,15 +564,6 @@ static const struct builtin_fn builtins_common[] = { { "__sync_val_compare_and_swap", &int_ctype, 1, { &ptr_ctype }}, { "__sync_xor_and_fetch", &int_ctype, 1, { &ptr_ctype }}, - // Alpha-specific - { "__builtin_alpha_cmpbge", &long_ctype, 0, { &long_ctype, &long_ctype }}, - { "__builtin_alpha_extbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, - { "__builtin_alpha_extwl", &long_ctype, 0, { &long_ctype, &long_ctype }}, - { "__builtin_alpha_insbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, - { "__builtin_alpha_inslh", &long_ctype, 0, { &long_ctype, &long_ctype }}, - { "__builtin_alpha_insql", &long_ctype, 0, { &long_ctype, &long_ctype }}, - { "__builtin_alpha_inswl", &long_ctype, 0, { &long_ctype, &long_ctype }}, - { } }; diff --git a/machine.h b/machine.h index b9f22850b9db..02a7f90e5362 100644 --- a/machine.h +++ b/machine.h @@ -32,6 +32,7 @@ enum machine { MACH_RISCV32, MACH_RISCV64, MACH_SPARC32, MACH_SPARC64, MACH_S390, MACH_S390X, + MACH_ALPHA, MACH_BFIN, MACH_M68K, MACH_NIOS2, @@ -40,6 +41,8 @@ enum machine { #if defined(__aarch64__) #define MACH_NATIVE MACH_ARM64 +#elif defined(__alpha__) || defined(__alpha) +#define MACH_NATIVE MACH_ALPHA #elif defined(__arm__) #define MACH_NATIVE MACH_ARM #elif defined(__x86_64__) || defined(__x86_64) diff --git a/target-alpha.c b/target-alpha.c new file mode 100644 index 000000000000..3f582997eb96 --- /dev/null +++ b/target-alpha.c @@ -0,0 +1,30 @@ +#include "symbol.h" +#include "target.h" +#include "machine.h" +#include "builtin.h" + + +static void predefine_alpha(const struct target *self) +{ + predefine("__alpha__", 1, "1"); + predefine("__alpha", 1, "1"); +} + +static const struct builtin_fn builtins_alpha[] = { + { "__builtin_alpha_cmpbge", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_extbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_extwl", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_insbl", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_inslh", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_insql", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { "__builtin_alpha_inswl", &long_ctype, 0, { &long_ctype, &long_ctype }}, + { } +}; + +const struct target target_alpha = { + .mach = MACH_ALPHA, + .bitness = ARCH_LP64, + + .predefine = predefine_alpha, + .builtins = builtins_alpha, +}; diff --git a/target.c b/target.c index 1fd066da8639..07c298128da4 100644 --- a/target.c +++ b/target.c @@ -57,6 +57,7 @@ int enum_alignment = 4; static const struct target *targets[] = { + [MACH_ALPHA] = &target_alpha, [MACH_ARM] = &target_arm, [MACH_ARM64] = &target_arm64, [MACH_I386] = &target_i386, @@ -85,6 +86,7 @@ enum machine target_parse(const char *name) enum machine mach; char bits; } archs[] = { + { "alpha", MACH_ALPHA, 64, }, { "aarch64", MACH_ARM64, 64, }, { "arm64", MACH_ARM64, 64, }, { "arm", MACH_ARM, 32, }, diff --git a/target.h b/target.h index 9674d0995fd5..8640026cc6d4 100644 --- a/target.h +++ b/target.h @@ -80,6 +80,7 @@ struct target { }; extern const struct target target_default; +extern const struct target target_alpha; extern const struct target target_arm; extern const struct target target_arm64; extern const struct target target_bfin; -- 2.27.0 ^ permalink raw reply related [flat|nested] 14+ messages in thread
end of thread, other threads:[~2020-06-12 17:04 UTC | newest] Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-06-10 20:27 [PATCH 0/7] move arch-specific builtins to their own table Luc Van Oostenryck 2020-06-10 20:27 ` [PATCH 1/7] builtin: can be initialized later Luc Van Oostenryck 2020-06-12 0:50 ` Ramsay Jones 2020-06-10 20:27 ` [PATCH 2/7] builtin: use a table for the builtins Luc Van Oostenryck 2020-06-12 0:56 ` Ramsay Jones 2020-06-12 16:48 ` Luc Van Oostenryck 2020-06-10 20:27 ` [PATCH 3/7] builtin: unify the 2 tables of builtins Luc Van Oostenryck 2020-06-12 1:01 ` Ramsay Jones 2020-06-10 20:27 ` [PATCH 4/7] builtin: add support for arch-specific builtins Luc Van Oostenryck 2020-06-10 20:27 ` [PATCH 5/7] arch: add specificities for Nios2 Luc Van Oostenryck 2020-06-12 1:04 ` Ramsay Jones 2020-06-12 17:04 ` Luc Van Oostenryck 2020-06-10 20:27 ` [PATCH 6/7] arch: add specificities for Blackfin Luc Van Oostenryck 2020-06-10 20:27 ` [PATCH 7/7] arch: add specificities for Alpha Luc Van Oostenryck
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 NNTP newsgroup(s).