From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Johannes Berg <johannes@sipsolutions.net>,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 2/3] allow builtins to have prototype and evaluate/expand methods
Date: Mon, 23 Jan 2017 22:37:27 +0100 [thread overview]
Message-ID: <20170123213728.89900-3-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170123213728.89900-1-luc.vanoostenryck@gmail.com>
So far, builtin functions which had some evaluate/expand method
couldn't also have a prototype because each would have its own symbol
and only the one for the prototype will be seen.
This also meant that the evaluate/expand functions had to take care
to set the correct types for they argumenst & results, which is fine
for some generic builtins like __builtin_constant_p() it's much less
practical for the ones like __builtin_bswap{16,32,64}().
Fix this by marking the idents for the builtins we declare some
evaluate/expand methods has being the ident of a builtin function
and later at evaluation time, to share the methods between all the symbols
corresponding to an identifier so marked.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
builtin.c | 1 +
evaluate.c | 6 ++++++
token.h | 1 +
3 files changed, 8 insertions(+)
diff --git a/builtin.c b/builtin.c
index c6c97ed85..ddc71f785 100644
--- a/builtin.c
+++ b/builtin.c
@@ -205,6 +205,7 @@ void init_builtins(int stream)
sym = create_symbol(stream, ptr->name, SYM_NODE, NS_SYMBOL);
sym->ctype.base_type = ptr->base_type;
sym->ctype.modifiers = ptr->modifiers;
+ sym->ident->builtin = 1;
sym->op = ptr->op;
}
}
diff --git a/evaluate.c b/evaluate.c
index 6d44e0d9c..f89e44b75 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -2829,6 +2829,12 @@ static int evaluate_symbol_call(struct expression *expr)
if (fn->type != EXPR_PREOP)
return 0;
+ if (ctype->ident->builtin) {
+ struct symbol *next = ctype->next_id;
+ if (!ctype->op && next)
+ ctype->op = next->op;
+ }
+
if (ctype->op && ctype->op->evaluate)
return ctype->op->evaluate(expr);
diff --git a/token.h b/token.h
index f7d88eb45..7b9c7ab74 100644
--- a/token.h
+++ b/token.h
@@ -73,6 +73,7 @@ struct ident {
unsigned char len; /* Length of identifier name */
unsigned char tainted:1,
reserved:1,
+ builtin:1,
keyword:1;
char name[]; /* Actual identifier */
};
--
2.11.0
next prev parent reply other threads:[~2017-01-23 21:37 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-23 21:37 [PATCH 0/3] builtins expansion Luc Van Oostenryck
2017-01-23 21:37 ` [PATCH 1/3] move evaluation & expansion of builtins in a separate file Luc Van Oostenryck
2017-01-23 21:37 ` Luc Van Oostenryck [this message]
2017-02-07 19:49 ` [PATCH 2/3] allow builtins to have prototype and evaluate/expand methods Chris Li
2017-02-07 20:12 ` Luc Van Oostenryck
2017-02-07 20:26 ` Chris Li
2017-02-07 20:32 ` Christopher Li
2017-02-07 21:34 ` Luc Van Oostenryck
2017-02-07 22:19 ` Christopher Li
2017-02-12 15:03 ` Luc Van Oostenryck
2017-02-12 15:10 ` [PATCH v2 0/3] builtins expansion Luc Van Oostenryck
2017-02-12 15:10 ` [PATCH v2 1/3] move evaluation & expansion of builtins in a separate file Luc Van Oostenryck
2017-02-12 15:10 ` [PATCH v2 2/3] let identical symbols share their evaluate/expand methods Luc Van Oostenryck
2017-02-12 15:11 ` [PATCH v2 3/3] expand __builtin_bswap*() with constant args Luc Van Oostenryck
2017-02-13 1:54 ` [PATCH v2 0/3] builtins expansion Christopher Li
2017-02-12 23:35 ` [PATCH 2/3] allow builtins to have prototype and evaluate/expand methods Chris Li
2017-01-23 21:37 ` [PATCH 3/3] expand __builtin_bswap*() with constant args Luc Van Oostenryck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170123213728.89900-3-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=johannes@sipsolutions.net \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).