Linux-Sparse Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/2] add helper predefine_{strong,weak}()
@ 2020-07-05 13:16 Luc Van Oostenryck
  2020-07-05 13:16 ` [PATCH 1/2] predefine: " Luc Van Oostenryck
  2020-07-05 13:16 ` [PATCH 2/2] predefine: avoid add_pre_buffer() for targets Luc Van Oostenryck
  0 siblings, 2 replies; 3+ messages in thread
From: Luc Van Oostenryck @ 2020-07-05 13:16 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

A lot of predefined macros are just set to the value '1'.
So, create a pair of helper for this and use it to limit
the use of add_pre_buffer() in target-specific files.


Luc Van Oostenryck (2):
  predefine: add helper predefine_{strong,weak}()
  predefine: avoid add_pre_buffer() for targets

 lib.h          |  2 ++
 pre-process.c  | 26 ++++++++++++++++++++++++++
 target-arm64.c |  2 +-
 target-riscv.c |  2 +-
 4 files changed, 30 insertions(+), 2 deletions(-)


base-commit: 88c90bb192663bfc2dc54782c316e39e6fe26e1d
-- 
2.27.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] predefine: add helper predefine_{strong,weak}()
  2020-07-05 13:16 [PATCH 0/2] add helper predefine_{strong,weak}() Luc Van Oostenryck
@ 2020-07-05 13:16 ` Luc Van Oostenryck
  2020-07-05 13:16 ` [PATCH 2/2] predefine: avoid add_pre_buffer() for targets Luc Van Oostenryck
  1 sibling, 0 replies; 3+ messages in thread
From: Luc Van Oostenryck @ 2020-07-05 13:16 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

A lot of predefined macros are just set to the value '1' and
of them have a name that is not statically known. OTOH, the
function predefine() is designed for a statically known name
but a variable value.

Add a set of helpers to cover the first case: predefine_strong()
and predefine_weak().

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.h         |  2 ++
 pre-process.c | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/lib.h b/lib.h
index 46483f2bed5c..a3288a3abf4e 100644
--- a/lib.h
+++ b/lib.h
@@ -127,6 +127,8 @@ enum phase {
 
 extern void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1);
 extern void predefine(const char *name, int weak, const char *fmt, ...) FORMAT_ATTR(3);
+extern void predefine_strong(const char *name, ...) FORMAT_ATTR(1);
+extern void predefine_weak(const char *name, ...) FORMAT_ATTR(1);
 extern void predefine_nostd(const char *name);
 extern void predefined_macros(void);
 
diff --git a/pre-process.c b/pre-process.c
index 38167802f465..403e3507611c 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -1439,6 +1439,32 @@ void predefine_nostd(const char *name)
 		predefine(name, 1, "1");
 }
 
+static void predefine_fmt(const char *fmt, int weak, va_list ap)
+{
+	static char buf[256];
+
+	vsnprintf(buf, sizeof(buf), fmt, ap);
+	predefine(buf, weak, "1");
+}
+
+void predefine_strong(const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	predefine_fmt(fmt, 0, ap);
+	va_end(ap);
+}
+
+void predefine_weak(const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	predefine_fmt(fmt, 1, ap);
+	va_end(ap);
+}
+
 static int do_handle_define(struct stream *stream, struct token **line, struct token *token, int attr)
 {
 	struct token *arglist, *expansion;
-- 
2.27.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] predefine: avoid add_pre_buffer() for targets
  2020-07-05 13:16 [PATCH 0/2] add helper predefine_{strong,weak}() Luc Van Oostenryck
  2020-07-05 13:16 ` [PATCH 1/2] predefine: " Luc Van Oostenryck
@ 2020-07-05 13:16 ` Luc Van Oostenryck
  1 sibling, 0 replies; 3+ messages in thread
From: Luc Van Oostenryck @ 2020-07-05 13:16 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Avoid add_pre_buffer() and use one of the predefine...()
variant instead.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 target-arm64.c | 2 +-
 target-riscv.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-arm64.c b/target-arm64.c
index d491b65e5154..8619bd842f9b 100644
--- a/target-arm64.c
+++ b/target-arm64.c
@@ -21,7 +21,7 @@ static void predefine_arm64(const struct target *self)
 	predefine("__aarch64__", 1, "1");
 
 	if (cmodel)
-		add_pre_buffer("#define __AARCH64_CMODEL_%s__ 1\n", cmodel);
+		predefine_strong("__AARCH64_CMODEL_%s__", cmodel);
 }
 
 const struct target target_arm64 = {
diff --git a/target-riscv.c b/target-riscv.c
index 08d036ca04b7..d68fb585c254 100644
--- a/target-riscv.c
+++ b/target-riscv.c
@@ -24,7 +24,7 @@ static void predefine_riscv(const struct target *self)
 	predefine("__riscv_xlen", 1, "%d", ptr_ctype.bit_size);
 
 	if (cmodel)
-		add_pre_buffer("#define __riscv_cmodel_%s 1\n", cmodel);
+		predefine_strong("__riscv_cmodel_%s", cmodel);
 }
 
 const struct target target_riscv32 = {
-- 
2.27.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-05 13:16 [PATCH 0/2] add helper predefine_{strong,weak}() Luc Van Oostenryck
2020-07-05 13:16 ` [PATCH 1/2] predefine: " Luc Van Oostenryck
2020-07-05 13:16 ` [PATCH 2/2] predefine: avoid add_pre_buffer() for targets Luc Van Oostenryck

Linux-Sparse Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sparse/0 linux-sparse/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sparse linux-sparse/ https://lore.kernel.org/linux-sparse \
		linux-sparse@vger.kernel.org
	public-inbox-index linux-sparse

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sparse


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git