Skip to content

Commit 4044303

Browse files
committed
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.
1 parent 607a052 commit 4044303

2 files changed

Lines changed: 45 additions & 31 deletions

File tree

src/emu/device.h

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ class device_registrar
177177
};
178178

179179

180-
template <class DeviceClass, char const *ShortName, char const *FullName, char const *Source>
180+
template <class DeviceClass, typename Traits>
181181
struct device_tag_struct { typedef DeviceClass type; };
182-
template <class DriverClass, char const *ShortName, char const *FullName, char const *Source, device_flags::type Flags, device_feature::type Unemulated, device_feature::type Imperfect>
182+
template <class DriverClass, typename Traits, device_flags::type Flags, device_feature::type Unemulated, device_feature::type Imperfect>
183183
struct driver_tag_struct { typedef DriverClass type; };
184184

185185
class device_type_impl_base
@@ -238,13 +238,13 @@ class device_type_impl_base
238238
{
239239
}
240240

241-
template <class DeviceClass, char const *ShortName, char const *FullName, char const *Source>
242-
device_type_impl_base(device_tag_struct<DeviceClass, ShortName, FullName, Source>)
241+
template <class DeviceClass, typename Traits>
242+
device_type_impl_base(device_tag_struct<DeviceClass, Traits>)
243243
: m_creator(&create_device<DeviceClass>)
244244
, m_type(typeid(DeviceClass))
245-
, m_shortname(ShortName)
246-
, m_fullname(FullName)
247-
, m_source(Source)
245+
, m_shortname(Traits::shortname)
246+
, m_fullname(Traits::fullname)
247+
, m_source(Traits::source)
248248
, m_emulation_flags(DeviceClass::emulation_flags())
249249
, m_unemulated_features(DeviceClass::unemulated_features())
250250
, m_imperfect_features(DeviceClass::imperfect_features())
@@ -253,13 +253,13 @@ class device_type_impl_base
253253
{
254254
}
255255

256-
template <class DriverClass, char const *ShortName, char const *FullName, char const *Source, device_flags::type Flags, device_feature::type Unemulated, device_feature::type Imperfect>
257-
device_type_impl_base(driver_tag_struct<DriverClass, ShortName, FullName, Source, Flags, Unemulated, Imperfect>)
256+
template <class DriverClass, typename Traits, device_flags::type Flags, device_feature::type Unemulated, device_feature::type Imperfect>
257+
device_type_impl_base(driver_tag_struct<DriverClass, Traits, Flags, Unemulated, Imperfect>)
258258
: m_creator(&create_driver<DriverClass>)
259259
, m_type(typeid(DriverClass))
260-
, m_shortname(ShortName)
261-
, m_fullname(FullName)
262-
, m_source(Source)
260+
, m_shortname(Traits::shortname)
261+
, m_fullname(Traits::fullname)
262+
, m_source(Traits::source)
263263
, m_emulation_flags(DriverClass::emulation_flags() | Flags)
264264
, m_unemulated_features(DriverClass::unemulated_features() | Unemulated)
265265
, m_imperfect_features((DriverClass::imperfect_features() & ~Unemulated) | Imperfect)
@@ -400,10 +400,15 @@ extern emu::detail::device_registrar const registered_device_types;
400400
/// DEFINE_DEVICE_TYPE_PRIVATE
401401
#define DEFINE_DEVICE_TYPE(Type, Class, ShortName, FullName) \
402402
namespace { \
403-
struct Type##_device_traits { static constexpr char const shortname[] = ShortName, fullname[] = FullName, source[] = __FILE__; }; \
404-
constexpr char const Type##_device_traits::shortname[], Type##_device_traits::fullname[], Type##_device_traits::source[]; \
403+
struct Type##_device_traits \
404+
{ \
405+
static inline constexpr char const *const shortname = (ShortName); \
406+
static inline constexpr char const *const source = __FILE__; \
407+
static constexpr char const fullname[] = (FullName); \
408+
}; \
409+
constexpr decltype(Type##_device_traits::fullname) Type##_device_traits::fullname; \
405410
} \
406-
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)>{ }; \
411+
emu::detail::device_type_impl<Class> const Type = emu::detail::device_tag_struct<Class, Type##_device_traits>{ }; \
407412
template class device_finder<Class, false>; \
408413
template class device_finder<Class, true>;
409414

@@ -437,10 +442,15 @@ extern emu::detail::device_registrar const registered_device_types;
437442
#define DEFINE_DEVICE_TYPE_PRIVATE(Type, Base, Class, ShortName, FullName) \
438443
namespace { \
439444
static_assert(std::is_convertible_v<Class &, Base &>, "Device implementation class must be convertible to exposed class."); \
440-
struct Type##_device_traits { static constexpr char const shortname[] = ShortName, fullname[] = FullName, source[] = __FILE__; }; \
441-
constexpr char const Type##_device_traits::shortname[], Type##_device_traits::fullname[], Type##_device_traits::source[]; \
445+
struct Type##_device_traits \
446+
{ \
447+
static inline constexpr char const *const shortname = (ShortName); \
448+
static inline constexpr char const *const source = __FILE__; \
449+
static constexpr char const fullname[] = (FullName); \
450+
}; \
451+
constexpr decltype(Type##_device_traits::fullname) Type##_device_traits::fullname; \
442452
} \
443-
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)>{ };
453+
emu::detail::device_type_impl<Base> const Type = emu::detail::device_tag_struct<Class, Type##_device_traits>{ };
444454

445455
/// \}
446456

src/emu/gamedrv.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,25 @@ class game_driver
176176

177177
// wrappers for declaring and defining game drivers
178178
#define GAME_NAME(name) driver_##name
179-
#define GAME_TRAITS_NAME(name) driver_##name##traits
179+
#define GAME_TRAITS_NAME(name) driver_##name##_traits
180180
#define GAME_EXTERN(name) extern game_driver const GAME_NAME(name)
181181

182182
// static game traits
183-
#define GAME_DRIVER_TRAITS(NAME, FULLNAME) \
183+
#define GAME_DRIVER_TRAITS(NAME, FULLNAME, COMPANY) \
184184
namespace { \
185-
struct GAME_TRAITS_NAME(NAME) { static constexpr char const shortname[] = #NAME, fullname[] = FULLNAME, source[] = __FILE__; }; \
186-
constexpr char const GAME_TRAITS_NAME(NAME)::shortname[], GAME_TRAITS_NAME(NAME)::fullname[], GAME_TRAITS_NAME(NAME)::source[]; \
185+
struct GAME_TRAITS_NAME(NAME) \
186+
{ \
187+
static inline constexpr char const *const shortname = #NAME; \
188+
static inline constexpr char const *const source = __FILE__; \
189+
static inline constexpr char const *manufacturer = (COMPANY); \
190+
static constexpr char const fullname[] = (FULLNAME); \
191+
}; \
192+
constexpr decltype(GAME_TRAITS_NAME(NAME)::fullname) GAME_TRAITS_NAME(NAME)::fullname; \
187193
}
188194
#define GAME_DRIVER_TYPE(NAME, CLASS, FLAGS) \
189195
emu::detail::driver_tag_struct< \
190196
CLASS, \
191-
(GAME_TRAITS_NAME(NAME)::shortname), \
192-
(GAME_TRAITS_NAME(NAME)::fullname), \
193-
(GAME_TRAITS_NAME(NAME)::source), \
197+
GAME_TRAITS_NAME(NAME), \
194198
game_driver::emulation_flags(FLAGS), \
195199
game_driver::unemulated_features(FLAGS), \
196200
game_driver::imperfect_features(FLAGS)>{ }
@@ -247,13 +251,13 @@ class game_driver
247251
/// avoid repetition.
248252
/// \sa GAMEL SYST
249253
#define GAME(YEAR, NAME, PARENT, MACHINE, INPUT, CLASS, INIT, MONITOR, COMPANY, FULLNAME, FLAGS) \
250-
GAME_DRIVER_TRAITS(NAME, FULLNAME) \
254+
GAME_DRIVER_TRAITS(NAME, FULLNAME, COMPANY) \
251255
extern game_driver const GAME_NAME(NAME) \
252256
{ \
253257
GAME_DRIVER_TYPE(NAME, CLASS, FLAGS), \
254258
#PARENT, \
255259
#YEAR, \
256-
COMPANY, \
260+
GAME_TRAITS_NAME(NAME)::manufacturer, \
257261
[] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \
258262
INPUT_PORTS_NAME(INPUT), \
259263
[] (device_t &owner) { downcast<CLASS &>(owner).INIT(); }, \
@@ -319,13 +323,13 @@ extern game_driver const GAME_NAME(NAME) \
319323
/// internal artwork for the system.
320324
/// \sa GAME SYST
321325
#define GAMEL(YEAR, NAME, PARENT, MACHINE, INPUT, CLASS, INIT, MONITOR, COMPANY, FULLNAME, FLAGS, LAYOUT) \
322-
GAME_DRIVER_TRAITS(NAME, FULLNAME) \
326+
GAME_DRIVER_TRAITS(NAME, FULLNAME, COMPANY) \
323327
extern game_driver const GAME_NAME(NAME) \
324328
{ \
325329
GAME_DRIVER_TYPE(NAME, CLASS, FLAGS), \
326330
#PARENT, \
327331
#YEAR, \
328-
COMPANY, \
332+
GAME_TRAITS_NAME(NAME)::manufacturer, \
329333
[] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \
330334
INPUT_PORTS_NAME(INPUT), \
331335
[] (device_t &owner) { downcast<CLASS &>(owner).INIT(); }, \
@@ -385,13 +389,13 @@ extern game_driver const GAME_NAME(NAME) \
385389
/// avoid repetition. Screen orientation flags may be included here.
386390
/// \sa GAME GAMEL
387391
#define SYST(YEAR, NAME, PARENT, COMPAT, MACHINE, INPUT, CLASS, INIT, COMPANY, FULLNAME, FLAGS) \
388-
GAME_DRIVER_TRAITS(NAME, FULLNAME) \
392+
GAME_DRIVER_TRAITS(NAME, FULLNAME, COMPANY) \
389393
extern game_driver const GAME_NAME(NAME) \
390394
{ \
391395
GAME_DRIVER_TYPE(NAME, CLASS, FLAGS), \
392396
#PARENT, \
393397
#YEAR, \
394-
COMPANY, \
398+
GAME_TRAITS_NAME(NAME)::manufacturer, \
395399
[] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \
396400
INPUT_PORTS_NAME(INPUT), \
397401
[] (device_t &owner) { downcast<CLASS &>(owner).INIT(); }, \

0 commit comments

Comments
 (0)