diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-03-18 15:40:40 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-03-20 00:52:39 +0100 |
| commit | c88f0098ff20f8f64cd4f57c4b63363da88b8ee0 (patch) | |
| tree | b4f8685fee65af4310f193d7628c3281e7d350b2 /linearize.c | |
| parent | e737cc332ccb8f48fb0f1ddefd4a4fba20140c9d (diff) | |
| download | sparse-dev-c88f0098ff20f8f64cd4f57c4b63363da88b8ee0.tar.gz | |
add support for linearization of builtins
Sparse ignores most builtins. A few of them are directly
interpreted at parsing time (types_compatible_p, offsetof).
Some others are expanded if their argument(s) are constant
but that's all.
However, some of the builtins are significant at the IR
level and shouldn't thus be ignored.
This patch add the support needed for the linearization of
these builtins.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'linearize.c')
| -rw-r--r-- | linearize.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/linearize.c b/linearize.c index a8395bff..bda831ce 100644 --- a/linearize.c +++ b/linearize.c @@ -1509,6 +1509,11 @@ static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expressi fn = expr->fn; fntype = fn->ctype; + + // handle builtins + if (fntype->op && fntype->op->linearize) + return fntype->op->linearize(ep, expr); + ctype = &fntype->ctype; if (fntype->type == SYM_NODE) fntype = fntype->ctype.base_type; @@ -2526,3 +2531,30 @@ struct entrypoint *linearize_symbol(struct symbol *sym) return linearize_fn(sym, base_type); return NULL; } + +/* + * Builtin functions + */ + +static struct sym_init { + const char *name; + pseudo_t (*linearize)(struct entrypoint *, struct expression*); + struct symbol_op op; +} builtins_table[] = { + // must be declared in builtin.c:declare_builtins[] + { } +}; + +void init_linearized_builtins(int stream) +{ + struct sym_init *ptr; + + for (ptr = builtins_table; ptr->name; ptr++) { + struct symbol *sym; + sym = create_symbol(stream, ptr->name, SYM_NODE, NS_SYMBOL); + if (!sym->op) + sym->op = &ptr->op; + sym->op->type |= KW_BUILTIN; + ptr->op.linearize = ptr->linearize; + } +} |
