system: Convert qemu_arch_available() to TargetInfo API
PATCH 1/1 system: Convert qemu_arch_available() to TargetInfo API
Get the base arch_mask from the current SysEmuTarget, making qemu_arch_available() target-agnostic.
We don't need the per-target QEMU_ARCH definition anymore, remove it.
--- meson.build | 2 -- system/arch_init.c | 30 ------------------------------ target-info.c | 41 +++++++++++++++++++++++++++++++++++++++++ system/meson.build | 1 - 4 files changed, 41 insertions(+), 33 deletions(-) delete mode 100644 system/arch_init.c
meson.build +0 -2
@@ -3419,8 +3419,6 @@ foreach target : target_dirs config_target_data.set(k, v) endif endforeach - config_target_data.set('QEMU_ARCH', - 'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper()) config_target_h += {target: configure_file(output: target + '-config-target.h', configuration: config_target_data)}
system/arch_init.c deleted +0 -30
@@ -1,30 +0,0 @@ -/* -* QEMU System Emulator -* -* Copyright (c) 2003-2008 Fabrice Bellard -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ -#include "qemu/osdep.h" -#include "system/arch_init.h" - -bool qemu_arch_available (unsigned qemu_arch_mask) -{ -return qemu_arch_mask &QEMU_ARCH ; -}
target-info.c +41 -0
53 lines not on this page · raw message
system/meson.build +0 -1
@@ -1,5 +1,4 @@ specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files( - 'arch_init.c', 'globals-target.c', )])
Signature · 1 line
2.52.0
Quoted 107 lines · Philippe Mathieu-Daudé
Get the base
arch_maskfrom the current SysEmuTarget, makingqemu_arch_available()target-agnostic.We don't need the per-target
QEMU_ARCHdefinition anymore, remove it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- meson.build | 2 -- system/arch_init.c | 30 ------------------------------ target-info.c | 41 +++++++++++++++++++++++++++++++++++++++++ system/meson.build | 1 - 4 files changed, 41 insertions(+), 33 deletions(-)delete mode 100644
system/arch_init.cmeson.build +0
-2@@ -3419,8 +3419,6 @@ foreach target : target_dirs config_target_data.set(k, v) endif endforeach - config_target_data.set('QEMU_ARCH', - 'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper()) config_target_h += {target: configure_file(output: target + '-config-target.h', configuration: config_target_data)}system/arch_init.c deleted +0
-30@@ -1,30 +0,0 @@ -/* -* QEMU System Emulator -* -* Copyright (c) 2003-2008 Fabrice Bellard -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ -#include "qemu/osdep.h" -#include "system/arch_init.h" - -bool qemu_arch_available (unsigned qemu_arch_mask) -{ -return qemu_arch_mask &QEMU_ARCH ; -}target-info.c +28
-0@@ -11,6 +11,7 @@#include "qemu/target-info-qapi.h" #include "qemu/target-info-impl.h" #include "qapi/error.h" +#include "system/arch_init.h" const char *target_name (void ) {@@ -33,6 +34,46 @@ SysEmuTarget target_arch(void)return arch; } +bool qemu_arch_available (unsigned qemu_arch_mask) +{ +static const unsigned base_arch_mask[SYS_EMU_TARGET__MAX ] = { + [SYS_EMU_TARGET_AARCH64 ] =QEMU_ARCH_ARM , + [SYS_EMU_TARGET_ALPHA ] =QEMU_ARCH_ALPHA , + [SYS_EMU_TARGET_ARM ] =QEMU_ARCH_ARM , + [SYS_EMU_TARGET_AVR ] =QEMU_ARCH_AVR , +/* +[SYS_EMU_TARGET_HEXAGON] = QEMU_ARCH_HEXAGON, +*/ + [SYS_EMU_TARGET_HPPA ] =QEMU_ARCH_HPPA , + [SYS_EMU_TARGET_I386 ] =QEMU_ARCH_I386 , + [SYS_EMU_TARGET_LOONGARCH64 ] =QEMU_ARCH_LOONGARCH , + [SYS_EMU_TARGET_M68K ] =QEMU_ARCH_M68K , + [SYS_EMU_TARGET_MICROBLAZE ] =QEMU_ARCH_MICROBLAZE , + [SYS_EMU_TARGET_MICROBLAZEEL ] =QEMU_ARCH_MICROBLAZE , + [SYS_EMU_TARGET_MIPS ] =QEMU_ARCH_MIPS , + [SYS_EMU_TARGET_MIPS64 ] =QEMU_ARCH_MIPS , + [SYS_EMU_TARGET_MIPS64EL ] =QEMU_ARCH_MIPS , + [SYS_EMU_TARGET_MIPSEL ] =QEMU_ARCH_MIPS , + [SYS_EMU_TARGET_OR1K ] =QEMU_ARCH_OPENRISC , + [SYS_EMU_TARGET_PPC ] =QEMU_ARCH_PPC , + [SYS_EMU_TARGET_PPC64 ] =QEMU_ARCH_PPC , + [SYS_EMU_TARGET_RISCV32 ] =QEMU_ARCH_RISCV , + [SYS_EMU_TARGET_RISCV64 ] =QEMU_ARCH_RISCV , + [SYS_EMU_TARGET_RX ] =QEMU_ARCH_RX , + [SYS_EMU_TARGET_S390X ] =QEMU_ARCH_S390X ,
target-info.c SysEmuTarget target_arch(void) · line 73
Quoted 10 lines
target-info.c +10
-0+ [SYS_EMU_TARGET_SH4] = QEMU_ARCH_SH4, + [SYS_EMU_TARGET_SH4EB] = QEMU_ARCH_SH4, + [SYS_EMU_TARGET_SPARC] = QEMU_ARCH_SPARC, + [SYS_EMU_TARGET_SPARC64] = QEMU_ARCH_SPARC, + [SYS_EMU_TARGET_TRICORE] = QEMU_ARCH_TRICORE, + [SYS_EMU_TARGET_X86_64] = QEMU_ARCH_I386, + [SYS_EMU_TARGET_XTENSA] = QEMU_ARCH_XTENSA, + [SYS_EMU_TARGET_XTENSAEB] = QEMU_ARCH_XTENSA, + }; +
Just a remark: is that worth having the "static const" array approach when we could have a proper switch than can be checked for exhaustiveness with compiler warnings instead?
Beyond that,
Quoted 121 lines · Pierrick Bouvier
Quoted 120 lines · Philippe Mathieu-Daudé
Get the base
arch_maskfrom the current SysEmuTarget, makingqemu_arch_available()target-agnostic.We don't need the per-target
QEMU_ARCHdefinition anymore, remove it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
meson.build | 2 --
system/arch_init.c| 30 ------------------------------ target-info.c | 41 +++++++++++++++++++++++++++++++++++++++++ system/meson.build | 1 -4 files changed, 41 insertions(+), 33 deletions(-)delete mode 100644
system/arch_init.cmeson.build +0
-0@@ -3419,8 +3419,6 @@ foreach target : target_dirs config_target_data.set(k, v)endif
endforeach
- config_target_data.set('QEMU_ARCH',
- 'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper())
config_target_h+= {target: configure_file(output: target + '-config-target.h',
configuration:config_target_data)}system/arch_init.c deleted +0
-6@@ -1,30 +0,0 @@ -/* -* QEMU System Emulator -* -* Copyright (c) 2003-2008 Fabrice Bellard -* -* Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/ or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */system/arch_init.c deleted +0
-7-#include "qemu/osdep.h" -#include "system/arch_init.h" - -bool qemu_arch_available (unsigned qemu_arch_mask) -{ - return qemu_arch_mask & QEMU_ARCH; -}target-info.c +32
-0@@ -11,6 +11,7 @@ #include "qemu/target-info-qapi.h" #include "qemu/target-info-impl.h" #include "qapi/error.h" +#include "system/arch_init.h" const char *target_name(void) {@@ -33,6 +34,46 @@ SysEmuTarget target_arch(void) return arch; } +bool qemu_arch_available (unsigned qemu_arch_mask) +{ + static const unsigned base_arch_mask[SYS_EMU_TARGET__MAX] = { + [SYS_EMU_TARGET_AARCH64] = QEMU_ARCH_ARM, + [SYS_EMU_TARGET_ALPHA] = QEMU_ARCH_ALPHA, + [SYS_EMU_TARGET_ARM] = QEMU_ARCH_ARM, + [SYS_EMU_TARGET_AVR] = QEMU_ARCH_AVR, + /* + [SYS_EMU_TARGET_HEXAGON] = QEMU_ARCH_HEXAGON, + */ + [SYS_EMU_TARGET_HPPA] = QEMU_ARCH_HPPA, + [SYS_EMU_TARGET_I386] = QEMU_ARCH_I386, + [SYS_EMU_TARGET_LOONGARCH64] = QEMU_ARCH_LOONGARCH, + [SYS_EMU_TARGET_M68K] = QEMU_ARCH_M68K, + [SYS_EMU_TARGET_MICROBLAZE] = QEMU_ARCH_MICROBLAZE, + [SYS_EMU_TARGET_MICROBLAZEEL] = QEMU_ARCH_MICROBLAZE, + [SYS_EMU_TARGET_MIPS] = QEMU_ARCH_MIPS, + [SYS_EMU_TARGET_MIPS64] = QEMU_ARCH_MIPS, + [SYS_EMU_TARGET_MIPS64EL] = QEMU_ARCH_MIPS, + [SYS_EMU_TARGET_MIPSEL] = QEMU_ARCH_MIPS, + [SYS_EMU_TARGET_OR1K] = QEMU_ARCH_OPENRISC, + [SYS_EMU_TARGET_PPC] = QEMU_ARCH_PPC, + [SYS_EMU_TARGET_PPC64] = QEMU_ARCH_PPC, + [SYS_EMU_TARGET_RISCV32] = QEMU_ARCH_RISCV, + [SYS_EMU_TARGET_RISCV64] = QEMU_ARCH_RISCV, + [SYS_EMU_TARGET_RX] = QEMU_ARCH_RX, + [SYS_EMU_TARGET_S390X] = QEMU_ARCH_S390X, + [SYS_EMU_TARGET_SH4] = QEMU_ARCH_SH4, + [SYS_EMU_TARGET_SH4EB] = QEMU_ARCH_SH4, + [SYS_EMU_TARGET_SPARC] = QEMU_ARCH_SPARC, + [SYS_EMU_TARGET_SPARC64] = QEMU_ARCH_SPARC,
Quoted 8 lines
target-info.c SysEmuTarget target_arch(void) · line 73
Quoted 6 lines
target-info.c +6
-0+ [SYS_EMU_TARGET_TRICORE] = QEMU_ARCH_TRICORE, + [SYS_EMU_TARGET_X86_64] = QEMU_ARCH_I386, + [SYS_EMU_TARGET_XTENSA] = QEMU_ARCH_XTENSA, + [SYS_EMU_TARGET_XTENSAEB] = QEMU_ARCH_XTENSA, + }; +Just a remark: is that worth having the "static const" array approach when we could have a proper switch than can be checked for exhaustiveness with compiler warnings instead?
I thought 40 LoC would be simpler to review than 80, and it was simpler to generate the template in bash.
Besides, we don't use compiler warnings for enum (such -Wswitch) due to QAPI:
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 3 lines
Beyond that,
Reviewed-by Pierrick Bouvier <[email protected]>
Quoted 135 lines · Philippe Mathieu-Daudé
Quoted 125 lines · Pierrick Bouvier
Quoted 124 lines · Philippe Mathieu-Daudé
Get the base
arch_maskfrom the current SysEmuTarget, makingqemu_arch_available()target-agnostic.We don't need the per-target
QEMU_ARCHdefinition anymore, remove it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- meson.build | 2 -- system/arch_init.c | 30 ------------------------------ target-info.c | 41 +++++++++++++++++++++++++++++++++++++++++ system/meson.build | 1 - 4 files changed, 41 insertions(+), 33 deletions(-)delete mode 100644
system/arch_init.cmeson.build +0
-2@@ -3419,8 +3419,6 @@ foreach target : target_dirs config_target_data.set(k, v) endif endforeach - config_target_data.set('QEMU_ARCH', - 'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper()) config_target_h += {target: configure_file(output: target + '- config-target.h',configuration:
config_target_data)}system/arch_init.c deleted +0
-6@@ -1,30 +0,0 @@ -/* -* QEMU System Emulator -* -* Copyright (c) 2003-2008 Fabrice Bellard -* -* Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/ or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */system/arch_init.c deleted +0
-7-#include "qemu/osdep.h" -#include "system/arch_init.h" - -bool qemu_arch_available (unsigned qemu_arch_mask) -{ - return qemu_arch_mask & QEMU_ARCH; -}target-info.c +34
-0@@ -11,6 +11,7 @@ #include "qemu/target-info-qapi.h" #include "qemu/target-info-impl.h" #include "qapi/error.h" +#include "system/arch_init.h" const char *target_name(void) {@@ -33,6 +34,46 @@ SysEmuTarget target_arch(void) return arch; } +bool qemu_arch_available (unsigned qemu_arch_mask) +{ + static const unsigned base_arch_mask[SYS_EMU_TARGET__MAX] = { + [SYS_EMU_TARGET_AARCH64] = QEMU_ARCH_ARM, + [SYS_EMU_TARGET_ALPHA] = QEMU_ARCH_ALPHA, + [SYS_EMU_TARGET_ARM] = QEMU_ARCH_ARM, + [SYS_EMU_TARGET_AVR] = QEMU_ARCH_AVR, + /* + [SYS_EMU_TARGET_HEXAGON] = QEMU_ARCH_HEXAGON, + */ + [SYS_EMU_TARGET_HPPA] = QEMU_ARCH_HPPA, + [SYS_EMU_TARGET_I386] = QEMU_ARCH_I386, + [SYS_EMU_TARGET_LOONGARCH64] = QEMU_ARCH_LOONGARCH, + [SYS_EMU_TARGET_M68K] = QEMU_ARCH_M68K, + [SYS_EMU_TARGET_MICROBLAZE] = QEMU_ARCH_MICROBLAZE, + [SYS_EMU_TARGET_MICROBLAZEEL] = QEMU_ARCH_MICROBLAZE, + [SYS_EMU_TARGET_MIPS] = QEMU_ARCH_MIPS, + [SYS_EMU_TARGET_MIPS64] = QEMU_ARCH_MIPS, + [SYS_EMU_TARGET_MIPS64EL] = QEMU_ARCH_MIPS, + [SYS_EMU_TARGET_MIPSEL] = QEMU_ARCH_MIPS, + [SYS_EMU_TARGET_OR1K] = QEMU_ARCH_OPENRISC, + [SYS_EMU_TARGET_PPC] = QEMU_ARCH_PPC, + [SYS_EMU_TARGET_PPC64] = QEMU_ARCH_PPC, + [SYS_EMU_TARGET_RISCV32] = QEMU_ARCH_RISCV, + [SYS_EMU_TARGET_RISCV64] = QEMU_ARCH_RISCV, + [SYS_EMU_TARGET_RX] = QEMU_ARCH_RX, + [SYS_EMU_TARGET_S390X] = QEMU_ARCH_S390X, + [SYS_EMU_TARGET_SH4] = QEMU_ARCH_SH4, + [SYS_EMU_TARGET_SH4EB] = QEMU_ARCH_SH4, + [SYS_EMU_TARGET_SPARC] = QEMU_ARCH_SPARC, + [SYS_EMU_TARGET_SPARC64] = QEMU_ARCH_SPARC, + [SYS_EMU_TARGET_TRICORE] = QEMU_ARCH_TRICORE, + [SYS_EMU_TARGET_X86_64] = QEMU_ARCH_I386,Quoted 8 lines
target-info.c SysEmuTarget target_arch(void) · line 73
Quoted 4 lines
target-info.c +4
-0+ [SYS_EMU_TARGET_XTENSA] = QEMU_ARCH_XTENSA, + [SYS_EMU_TARGET_XTENSAEB] = QEMU_ARCH_XTENSA, + }; +Just a remark: is that worth having the "static const" array approach when we could have a proper switch than can be checked for exhaustiveness with compiler warnings instead?
Quoted 7 lines
I thought 40 LoC would be simpler to review than 80, and it was simpler to generate the template in bash.
Besides, we don't use compiler warnings for enum (such -Wswitch) due to QAPI:
https://lore.kernel.org/qemu-devel/[email protected]/
Reading the thread above, the only mention I find is the 3rd commit that precisely change definition because -Wswitch is enabled with clang. And it's not only a clang thing, gcc has it in Wall also [1].
I don't mind the array approach, but maybe just add a *static* assert making sure (SYS_EMU_TARGET__MAX-1 == SYS_EMU_TARGET_XTENSAEB) so this file will break as soon as there is a new target added. It's simple and the next developer who won't have to debug this will thank you.
[1] https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html
Quoted 4 lines
Quoted 3 lines
Beyond that,
Reviewed-by Pierrick Bouvier <[email protected]>
Quoted 10 lines · Pierrick Bouvier
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Pierrick Bouvier
Quoted 7 lines · Philippe Mathieu-Daudé
Get the base
arch_maskfrom the current SysEmuTarget, makingqemu_arch_available()target-agnostic.We don't need the per-target
QEMU_ARCHdefinition anymore, remove it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
[...]
Quoted 45 lines
Quoted 45 lines
Quoted 44 lines
Quoted 30 lines
target-info.c +27
-0@@ -33,6 +34,46 @@ SysEmuTarget target_arch(void) return arch; } +bool qemu_arch_available (unsigned qemu_arch_mask) +{ + static const unsigned base_arch_mask[SYS_EMU_TARGET__MAX] = { + [SYS_EMU_TARGET_AARCH64] = QEMU_ARCH_ARM, + [SYS_EMU_TARGET_ALPHA] = QEMU_ARCH_ALPHA, + [SYS_EMU_TARGET_ARM] = QEMU_ARCH_ARM, + [SYS_EMU_TARGET_AVR] = QEMU_ARCH_AVR, + /* + [SYS_EMU_TARGET_HEXAGON] = QEMU_ARCH_HEXAGON, + */ + [SYS_EMU_TARGET_HPPA] = QEMU_ARCH_HPPA, + [SYS_EMU_TARGET_I386] = QEMU_ARCH_I386, + [SYS_EMU_TARGET_LOONGARCH64] = QEMU_ARCH_LOONGARCH, + [SYS_EMU_TARGET_M68K] = QEMU_ARCH_M68K, + [SYS_EMU_TARGET_MICROBLAZE] = QEMU_ARCH_MICROBLAZE, + [SYS_EMU_TARGET_MICROBLAZEEL] = QEMU_ARCH_MICROBLAZE, + [SYS_EMU_TARGET_MIPS] = QEMU_ARCH_MIPS, + [SYS_EMU_TARGET_MIPS64] = QEMU_ARCH_MIPS, + [SYS_EMU_TARGET_MIPS64EL] = QEMU_ARCH_MIPS, + [SYS_EMU_TARGET_MIPSEL] = QEMU_ARCH_MIPS, + [SYS_EMU_TARGET_OR1K] = QEMU_ARCH_OPENRISC, + [SYS_EMU_TARGET_PPC] = QEMU_ARCH_PPC, + [SYS_EMU_TARGET_PPC64] = QEMU_ARCH_PPC, + [SYS_EMU_TARGET_RISCV32] = QEMU_ARCH_RISCV, + [SYS_EMU_TARGET_RISCV64] = QEMU_ARCH_RISCV, + [SYS_EMU_TARGET_RX] = QEMU_ARCH_RX, + [SYS_EMU_TARGET_S390X] = QEMU_ARCH_S390X,target-info.c SysEmuTarget target_arch(void) · line 72
Quoted 10 lines
target-info.c +10
-0+ [SYS_EMU_TARGET_SH4] = QEMU_ARCH_SH4, + [SYS_EMU_TARGET_SH4EB] = QEMU_ARCH_SH4, + [SYS_EMU_TARGET_SPARC] = QEMU_ARCH_SPARC, + [SYS_EMU_TARGET_SPARC64] = QEMU_ARCH_SPARC, + [SYS_EMU_TARGET_TRICORE] = QEMU_ARCH_TRICORE, + [SYS_EMU_TARGET_X86_64] = QEMU_ARCH_I386, + [SYS_EMU_TARGET_XTENSA] = QEMU_ARCH_XTENSA, + [SYS_EMU_TARGET_XTENSAEB] = QEMU_ARCH_XTENSA, + }; +Just a remark: is that worth having the "static const" array approach when we could have a proper switch than can be checked for exhaustiveness with compiler warnings instead?
Quoted 2 lines
Quoted 2 lines
I thought 40 LoC would be simpler to review than 80, and it was simpler to generate the template in bash.
I find the array solution much easier to grasp at a glance. The initializer shows the mapping concisely. With a switch, there's noise around the mapping, and the fact that all all switch cases do nothing but assign a constant to the same variable is not obvious at a glance.
Quoted 10 lines
Quoted 4 lines
Besides, we don't use compiler warnings for enum (such -Wswitch) due to QAPI:
https://lore.kernel.org/qemu-devel/[email protected]/Reading the thread above, the only mention I find is the 3rd commit that precisely change definition because -Wswitch is enabled with clang.
And it's not only a clang thing, gcc has it in Wall also [1].
I don't mind the array approach, but maybe just add a *static* assert making sure (SYS_EMU_TARGET__MAX-1 ==
SYS_EMU_TARGET_XTENSAEB) so this file will break as soon as there is a new target added. It's simple and the next developer who won't have to debug this will thank you.
Won't help when new enum values are added in the middle. We keep them alphabetically sorted...
We could use a simple run-time assertion:
arch_mask = qemu_arch_mask & base_arch_mask[target_arch()];
assert(arch_mask);
return arch_mask;Works because the QEMU_ARCH_FOO are all non-zero.
Pick your poison.
Quoted 5 lines
[1] https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html
Quoted 3 lines
Quoted 3 lines
Beyond that,
Reviewed-by Pierrick Bouvier <[email protected]>