On 18/4/25 18:23, Pierrick Bouvier wrote:
On 4/18/25 07:02, Philippe Mathieu-Daudé wrote:
On 18/4/25 05:01, Pierrick Bouvier wrote:
On 4/17/25 17:50, Philippe Mathieu-Daudé wrote:
Have target_name() be a target-agnostic method, dispatching
to a per-target TargetInfo singleton structure.
By default a stub singleton is used. No logical change
expected.

Inspired-by: Pierrick Bouvier <pierrick.bouv...@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouv...@linaro.org>
---
   meson.build                     |  3 +++
   include/hw/core/cpu.h           |  2 --
   include/qemu/target_info-impl.h | 23 +++++++++++++++++++++++
   include/qemu/target_info.h      | 19 +++++++++++++++++++
   cpu-target.c                    |  5 -----
   hw/core/machine-qmp-cmds.c      |  1 +
   plugins/loader.c                |  2 +-
   system/vl.c                     |  2 +-
   target_info-stub.c              | 19 +++++++++++++++++++
   target_info.c                   | 16 ++++++++++++++++
   10 files changed, 83 insertions(+), 9 deletions(-)
   create mode 100644 include/qemu/target_info-impl.h
   create mode 100644 include/qemu/target_info.h
   create mode 100644 target_info-stub.c
   create mode 100644 target_info.c


diff --git a/target_info-stub.c b/target_info-stub.c
new file mode 100644
index 00000000000..1e44bb6f6fb
--- /dev/null
+++ b/target_info-stub.c
@@ -0,0 +1,19 @@
+/*
+ * QEMU target info stubs
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/target_info-impl.h"
+
+static const TargetInfo target_info_stub = {
+    .name = TARGET_NAME,
+};
+
+const TargetInfo *target_info(void)
+{
+    return &target_info_stub;
+}
diff --git a/target_info.c b/target_info.c
new file mode 100644
index 00000000000..877a6a15014
--- /dev/null
+++ b/target_info.c
@@ -0,0 +1,16 @@
+/*
+ * QEMU binary/target helpers
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/target_info-impl.h"
+#include "qemu/target_info.h"
+
+const char *target_name(void)
+{
+    return target_info()->name;
+}

What is the benefit to have two different files (common and specific)?
target_name() can be inline in the same header, returning the matching
field in existing target_info, which does not need any specialization
per target.

common interface exposed target-agnostic, dispatching to target-specific
implementation (providing a stub we'll remove once all targets converted).

What would you suggest?

To remove target_info.c and target_info-impl.h, and implement target_name() as a static inline in target_info.h.

This way, target_info.h can still be included from common code, the structure is directly accessed, and we have a single header where we can add new sugar functions and associated fields later.

OK. As I'm about to post a good-enough v3, I'll not implement this
now, but will consider for v4.

Reply via email to