Re: [PATCH 2/2] builtin: make builtins more builtin

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Nov 7, 2017 at 4:16 AM, Luc Van Oostenryck
<luc.vanoostenryck@xxxxxxxxx> wrote:
> Currently, (most) builtin functions are declared like
> a normal function prototype. Furthermore, these declarations
> is done via the pre-buffer mechanism and thus need to be
> tokenized & parsed like normal code.
> This is far from being 'builtin'.
>
> Change this by skipping this pre-buffer phase and directly creating
> the appropriate symbol for them.
>
> Note: the correct mechanism to be used to make them really builtin
>       is via init_builtins(), used when we have a real semantic
>       action for the builtin.
>
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
> ---
>  builtin.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  lib.c     | 157 ++---------------------------------------------------------
>  symbol.h  |   1 +
>  3 files changed, 171 insertions(+), 152 deletions(-)
>
> diff --git a/builtin.c b/builtin.c
> index 9f90926cb..987ca9b3a 100644
> --- a/builtin.c
> +++ b/builtin.c
> @@ -27,6 +27,7 @@
>  #include "expand.h"
>  #include "symbol.h"
>  #include "compat/bswap.h"
> +#include <stdarg.h>
>
>  static int evaluate_to_int_const_expr(struct expression *expr)
>  {
> @@ -259,3 +260,167 @@ void init_builtins(int stream)
>                 sym->op = ptr->op;
>         }
>  }
> +
> +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->ident->reserved = 1;
> +       sym->ctype.base_type = fun;
> +       sym->ctype.modifiers = MOD_TOPLEVEL;
> +
> +       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);

Hi Luc,

I like the direction this patch is heading.

I think you can change the  declare_builtin to be driven by table (C
structure array).
Rather than explicit function call. That will both save code do you
don't need to deal with
the variance part.

Thanks

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux