diff options
| author | 2026-03-29 07:45:41 +1100 | |
|---|---|---|
| committer | 2026-03-29 07:45:41 +1100 | |
| commit | 4044303cd767b13f5490d69974cae6e8d0cd6f04 (patch) | |
| tree | 68e99e47119596e9b43265ba5213e3d989caa954 | |
| parent | 607a052f9a12beca3ca252b5e6aa2af81c1c32cc (diff) | |
emu/gamedrv.h, emu/device.h: Allow source and manufacturer strings to be deduplicated.
This increases coupling between the "traits" classes generated for
driver/device definitions and the device type implementation class, but
it noticeably reduces static data size for MAME as a whole.
| -rw-r--r-- | src/emu/device.h | 46 | ||||
| -rw-r--r-- | src/emu/gamedrv.h | 30 |
2 files changed, 45 insertions, 31 deletions
diff --git a/src/emu/device.h b/src/emu/device.h index 52db91ace40..54d5a7e9b01 100644 --- a/src/emu/device.h +++ b/src/emu/device.h @@ -177,9 +177,9 @@ private: }; -template <class DeviceClass, char const *ShortName, char const *FullName, char const *Source> +template <class DeviceClass, typename Traits> struct device_tag_struct { typedef DeviceClass type; }; -template <class DriverClass, char const *ShortName, char const *FullName, char const *Source, device_flags::type Flags, device_feature::type Unemulated, device_feature::type Imperfect> +template <class DriverClass, typename Traits, device_flags::type Flags, device_feature::type Unemulated, device_feature::type Imperfect> struct driver_tag_struct { typedef DriverClass type; }; class device_type_impl_base @@ -238,13 +238,13 @@ public: { } - template <class DeviceClass, char const *ShortName, char const *FullName, char const *Source> - device_type_impl_base(device_tag_struct<DeviceClass, ShortName, FullName, Source>) + template <class DeviceClass, typename Traits> + device_type_impl_base(device_tag_struct<DeviceClass, Traits>) : m_creator(&create_device<DeviceClass>) , m_type(typeid(DeviceClass)) - , m_shortname(ShortName) - , m_fullname(FullName) - , m_source(Source) + , m_shortname(Traits::shortname) + , m_fullname(Traits::fullname) + , m_source(Traits::source) , m_emulation_flags(DeviceClass::emulation_flags()) , m_unemulated_features(DeviceClass::unemulated_features()) , m_imperfect_features(DeviceClass::imperfect_features()) @@ -253,13 +253,13 @@ public: { } - template <class DriverClass, char const *ShortName, char const *FullName, char const *Source, device_flags::type Flags, device_feature::type Unemulated, device_feature::type Imperfect> - device_type_impl_base(driver_tag_struct<DriverClass, ShortName, FullName, Source, Flags, Unemulated, Imperfect>) + template <class DriverClass, typename Traits, device_flags::type Flags, device_feature::type Unemulated, device_feature::type Imperfect> + device_type_impl_base(driver_tag_struct<DriverClass, Traits, Flags, Unemulated, Imperfect>) : m_creator(&create_driver<DriverClass>) , m_type(typeid(DriverClass)) - , m_shortname(ShortName) - , m_fullname(FullName) - , m_source(Source) + , m_shortname(Traits::shortname) + , m_fullname(Traits::fullname) + , m_source(Traits::source) , m_emulation_flags(DriverClass::emulation_flags() | Flags) , m_unemulated_features(DriverClass::unemulated_features() | Unemulated) , m_imperfect_features((DriverClass::imperfect_features() & ~Unemulated) | Imperfect) @@ -400,10 +400,15 @@ extern emu::detail::device_registrar const registered_device_types; /// DEFINE_DEVICE_TYPE_PRIVATE #define DEFINE_DEVICE_TYPE(Type, Class, ShortName, FullName) \ namespace { \ - struct Type##_device_traits { static constexpr char const shortname[] = ShortName, fullname[] = FullName, source[] = __FILE__; }; \ - constexpr char const Type##_device_traits::shortname[], Type##_device_traits::fullname[], Type##_device_traits::source[]; \ + struct Type##_device_traits \ + { \ + static inline constexpr char const *const shortname = (ShortName); \ + static inline constexpr char const *const source = __FILE__; \ + static constexpr char const fullname[] = (FullName); \ + }; \ + constexpr decltype(Type##_device_traits::fullname) Type##_device_traits::fullname; \ } \ - emu::detail::device_type_impl<Class> const Type = emu::detail::device_tag_struct<Class, (Type##_device_traits::shortname), (Type##_device_traits::fullname), (Type##_device_traits::source)>{ }; \ + emu::detail::device_type_impl<Class> const Type = emu::detail::device_tag_struct<Class, Type##_device_traits>{ }; \ template class device_finder<Class, false>; \ template class device_finder<Class, true>; @@ -437,10 +442,15 @@ extern emu::detail::device_registrar const registered_device_types; #define DEFINE_DEVICE_TYPE_PRIVATE(Type, Base, Class, ShortName, FullName) \ namespace { \ static_assert(std::is_convertible_v<Class &, Base &>, "Device implementation class must be convertible to exposed class."); \ - struct Type##_device_traits { static constexpr char const shortname[] = ShortName, fullname[] = FullName, source[] = __FILE__; }; \ - constexpr char const Type##_device_traits::shortname[], Type##_device_traits::fullname[], Type##_device_traits::source[]; \ + struct Type##_device_traits \ + { \ + static inline constexpr char const *const shortname = (ShortName); \ + static inline constexpr char const *const source = __FILE__; \ + static constexpr char const fullname[] = (FullName); \ + }; \ + constexpr decltype(Type##_device_traits::fullname) Type##_device_traits::fullname; \ } \ - emu::detail::device_type_impl<Base> const Type = emu::detail::device_tag_struct<Class, (Type##_device_traits::shortname), (Type##_device_traits::fullname), (Type##_device_traits::source)>{ }; + emu::detail::device_type_impl<Base> const Type = emu::detail::device_tag_struct<Class, Type##_device_traits>{ }; /// \} diff --git a/src/emu/gamedrv.h b/src/emu/gamedrv.h index b3a1087a66a..d4eeed25699 100644 --- a/src/emu/gamedrv.h +++ b/src/emu/gamedrv.h @@ -176,21 +176,25 @@ public: // wrappers for declaring and defining game drivers #define GAME_NAME(name) driver_##name -#define GAME_TRAITS_NAME(name) driver_##name##traits +#define GAME_TRAITS_NAME(name) driver_##name##_traits #define GAME_EXTERN(name) extern game_driver const GAME_NAME(name) // static game traits -#define GAME_DRIVER_TRAITS(NAME, FULLNAME) \ +#define GAME_DRIVER_TRAITS(NAME, FULLNAME, COMPANY) \ namespace { \ - struct GAME_TRAITS_NAME(NAME) { static constexpr char const shortname[] = #NAME, fullname[] = FULLNAME, source[] = __FILE__; }; \ - constexpr char const GAME_TRAITS_NAME(NAME)::shortname[], GAME_TRAITS_NAME(NAME)::fullname[], GAME_TRAITS_NAME(NAME)::source[]; \ + struct GAME_TRAITS_NAME(NAME) \ + { \ + static inline constexpr char const *const shortname = #NAME; \ + static inline constexpr char const *const source = __FILE__; \ + static inline constexpr char const *manufacturer = (COMPANY); \ + static constexpr char const fullname[] = (FULLNAME); \ + }; \ + constexpr decltype(GAME_TRAITS_NAME(NAME)::fullname) GAME_TRAITS_NAME(NAME)::fullname; \ } #define GAME_DRIVER_TYPE(NAME, CLASS, FLAGS) \ emu::detail::driver_tag_struct< \ CLASS, \ - (GAME_TRAITS_NAME(NAME)::shortname), \ - (GAME_TRAITS_NAME(NAME)::fullname), \ - (GAME_TRAITS_NAME(NAME)::source), \ + GAME_TRAITS_NAME(NAME), \ game_driver::emulation_flags(FLAGS), \ game_driver::unemulated_features(FLAGS), \ game_driver::imperfect_features(FLAGS)>{ } @@ -247,13 +251,13 @@ public: /// avoid repetition. /// \sa GAMEL SYST #define GAME(YEAR, NAME, PARENT, MACHINE, INPUT, CLASS, INIT, MONITOR, COMPANY, FULLNAME, FLAGS) \ -GAME_DRIVER_TRAITS(NAME, FULLNAME) \ +GAME_DRIVER_TRAITS(NAME, FULLNAME, COMPANY) \ extern game_driver const GAME_NAME(NAME) \ { \ GAME_DRIVER_TYPE(NAME, CLASS, FLAGS), \ #PARENT, \ #YEAR, \ - COMPANY, \ + GAME_TRAITS_NAME(NAME)::manufacturer, \ [] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \ INPUT_PORTS_NAME(INPUT), \ [] (device_t &owner) { downcast<CLASS &>(owner).INIT(); }, \ @@ -319,13 +323,13 @@ extern game_driver const GAME_NAME(NAME) \ /// internal artwork for the system. /// \sa GAME SYST #define GAMEL(YEAR, NAME, PARENT, MACHINE, INPUT, CLASS, INIT, MONITOR, COMPANY, FULLNAME, FLAGS, LAYOUT) \ -GAME_DRIVER_TRAITS(NAME, FULLNAME) \ +GAME_DRIVER_TRAITS(NAME, FULLNAME, COMPANY) \ extern game_driver const GAME_NAME(NAME) \ { \ GAME_DRIVER_TYPE(NAME, CLASS, FLAGS), \ #PARENT, \ #YEAR, \ - COMPANY, \ + GAME_TRAITS_NAME(NAME)::manufacturer, \ [] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \ INPUT_PORTS_NAME(INPUT), \ [] (device_t &owner) { downcast<CLASS &>(owner).INIT(); }, \ @@ -385,13 +389,13 @@ extern game_driver const GAME_NAME(NAME) \ /// avoid repetition. Screen orientation flags may be included here. /// \sa GAME GAMEL #define SYST(YEAR, NAME, PARENT, COMPAT, MACHINE, INPUT, CLASS, INIT, COMPANY, FULLNAME, FLAGS) \ - GAME_DRIVER_TRAITS(NAME, FULLNAME) \ + GAME_DRIVER_TRAITS(NAME, FULLNAME, COMPANY) \ extern game_driver const GAME_NAME(NAME) \ { \ GAME_DRIVER_TYPE(NAME, CLASS, FLAGS), \ #PARENT, \ #YEAR, \ - COMPANY, \ + GAME_TRAITS_NAME(NAME)::manufacturer, \ [] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \ INPUT_PORTS_NAME(INPUT), \ [] (device_t &owner) { downcast<CLASS &>(owner).INIT(); }, \ |
