mirror of
https://github.com/holub/mame
synced 2025-04-20 15:32:45 +03:00
netlist: simplify factory call structure. (nw)
This change will make it a lot easier to add enhanced functionality to the factory infrastructure. Using integral constants also improves linking stability.
This commit is contained in:
parent
daadbfe6b7
commit
40628bc269
@ -1363,7 +1363,8 @@ void netlist_mame_cpu_device::device_start()
|
||||
|
||||
void netlist_mame_cpu_device::nl_register_devices(netlist::nlparse_t &parser) const
|
||||
{
|
||||
parser.factory().add<nld_analog_callback>( "NETDEV_CALLBACK", "-", std::move(PSOURCELOC()));
|
||||
parser.factory().add<nld_analog_callback>( "NETDEV_CALLBACK",
|
||||
netlist::factory::properties("-", std::move(PSOURCELOC())));
|
||||
}
|
||||
|
||||
uint64_t netlist_mame_cpu_device::execute_clocks_to_cycles(uint64_t clocks) const noexcept
|
||||
@ -1522,8 +1523,10 @@ void netlist_mame_sound_device::device_start()
|
||||
|
||||
void netlist_mame_sound_device::nl_register_devices(netlist::nlparse_t &parser) const
|
||||
{
|
||||
parser.factory().add<nld_sound_out>("NETDEV_SOUND_OUT", "+CHAN", std::move(PSOURCELOC()));
|
||||
parser.factory().add<nld_sound_in>("NETDEV_SOUND_IN", "-", std::move(PSOURCELOC()));
|
||||
parser.factory().add<nld_sound_out>("NETDEV_SOUND_OUT",
|
||||
netlist::factory::properties("+CHAN", std::move(PSOURCELOC())));
|
||||
parser.factory().add<nld_sound_in>("NETDEV_SOUND_IN",
|
||||
netlist::factory::properties("-", std::move(PSOURCELOC())));
|
||||
}
|
||||
|
||||
void netlist_mame_sound_device::device_clock_changed()
|
||||
|
@ -241,8 +241,8 @@ namespace devices
|
||||
{
|
||||
public:
|
||||
netlist_factory_truthtable_t(const pstring &name,
|
||||
const pstring &def_param, plib::source_location &&sourceloc)
|
||||
: truthtable_base_element_t(name, def_param, std::move(sourceloc))
|
||||
factory::properties &&props)
|
||||
: truthtable_base_element_t(name, std::move(props))
|
||||
{ }
|
||||
|
||||
unique_pool_ptr<core_device_t> make_device(nlmempool &pool, netlist_state_t &anetlist, const pstring &name) override
|
||||
@ -472,8 +472,8 @@ namespace factory
|
||||
{
|
||||
|
||||
truthtable_base_element_t::truthtable_base_element_t(const pstring &name,
|
||||
const pstring &def_param, plib::source_location &&sourceloc)
|
||||
: factory::element_t(name, def_param, std::move(sourceloc))
|
||||
properties &&props)
|
||||
: factory::element_t(name, std::move(props))
|
||||
, m_family_name(NETLIST_DEFAULT_LOGIC_FAMILY)
|
||||
{
|
||||
}
|
||||
@ -481,31 +481,31 @@ namespace factory
|
||||
#define ENTRYY(n, m, s) case (n * 100 + m): \
|
||||
{ using xtype = devices::netlist_factory_truthtable_t<n, m>; \
|
||||
auto cs=s; \
|
||||
ret = plib::make_unique<xtype>(desc.name, desc.def_param, std::move(cs)); } \
|
||||
ret = plib::make_unique<xtype>(desc.name, std::move(cs)); } \
|
||||
break
|
||||
|
||||
#define ENTRY(n, s) ENTRYY(n, 1, s); ENTRYY(n, 2, s); ENTRYY(n, 3, s); \
|
||||
ENTRYY(n, 4, s); ENTRYY(n, 5, s); ENTRYY(n, 6, s); \
|
||||
ENTRYY(n, 7, s); ENTRYY(n, 8, s)
|
||||
|
||||
plib::unique_ptr<truthtable_base_element_t> truthtable_create(tt_desc &desc, plib::source_location &&sourceloc)
|
||||
plib::unique_ptr<truthtable_base_element_t> truthtable_create(tt_desc &desc, properties &&props)
|
||||
{
|
||||
plib::unique_ptr<truthtable_base_element_t> ret;
|
||||
|
||||
switch (desc.ni * 100 + desc.no)
|
||||
{
|
||||
ENTRY(1, sourceloc);
|
||||
ENTRY(2, sourceloc);
|
||||
ENTRY(3, sourceloc);
|
||||
ENTRY(4, sourceloc);
|
||||
ENTRY(5, sourceloc);
|
||||
ENTRY(6, sourceloc);
|
||||
ENTRY(7, sourceloc);
|
||||
ENTRY(8, sourceloc);
|
||||
ENTRY(9, sourceloc);
|
||||
ENTRY(10, sourceloc);
|
||||
ENTRY(11, sourceloc);
|
||||
ENTRY(12, sourceloc);
|
||||
ENTRY(1, props);
|
||||
ENTRY(2, props);
|
||||
ENTRY(3, props);
|
||||
ENTRY(4, props);
|
||||
ENTRY(5, props);
|
||||
ENTRY(6, props);
|
||||
ENTRY(7, props);
|
||||
ENTRY(8, props);
|
||||
ENTRY(9, props);
|
||||
ENTRY(10, props);
|
||||
ENTRY(11, props);
|
||||
ENTRY(12, props);
|
||||
default:
|
||||
pstring msg = plib::pfmt("unable to create truthtable<{1},{2}>")(desc.ni)(desc.no);
|
||||
nl_assert_always(false, msg.c_str());
|
||||
|
@ -200,15 +200,14 @@ namespace factory
|
||||
class truthtable_base_element_t : public factory::element_t
|
||||
{
|
||||
public:
|
||||
truthtable_base_element_t(const pstring &name,
|
||||
const pstring &def_param, plib::source_location &&sourceloc);
|
||||
truthtable_base_element_t(const pstring &name,properties &&props);
|
||||
|
||||
std::vector<pstring> m_desc;
|
||||
pstring m_family_name;
|
||||
};
|
||||
|
||||
plib::unique_ptr<truthtable_base_element_t> truthtable_create(tt_desc &desc,
|
||||
plib::source_location &&sourceloc);
|
||||
properties &&props);
|
||||
|
||||
} // namespace factory
|
||||
} // namespace netlist
|
||||
|
@ -27,16 +27,9 @@ namespace factory {
|
||||
NETLIB_UPDATEI() { }
|
||||
};
|
||||
|
||||
element_t::element_t(const pstring &name, const pstring &def_param,
|
||||
plib::source_location &&sourceloc)
|
||||
: m_name(name), m_def_param(def_param),
|
||||
m_sourceloc(sourceloc)
|
||||
{
|
||||
}
|
||||
|
||||
element_t::element_t(const pstring &name, const pstring &def_param)
|
||||
: m_name(name), m_def_param(def_param),
|
||||
m_sourceloc("<unknown>", 1)
|
||||
element_t::element_t(const pstring &name, properties &&props)
|
||||
: m_name(name)
|
||||
, m_properties(props)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,8 @@
|
||||
() \
|
||||
{ \
|
||||
using devtype = factory::device_element_t<ns :: NETLIB_NAME(chip)>; \
|
||||
auto sl(PSOURCELOC()); \
|
||||
return devtype::create(p_name, p_def_param, std::move(sl)); \
|
||||
auto sl(factory::properties(p_def_param, PSOURCELOC())); \
|
||||
return devtype::create(p_name, std::move(sl)); \
|
||||
} \
|
||||
\
|
||||
factory::constructor_ptr_t decl_ ## p_alias = NETLIB_NAME(p_alias ## _c);
|
||||
@ -42,6 +42,30 @@ namespace netlist {
|
||||
class netlist_state_t;
|
||||
|
||||
namespace factory {
|
||||
|
||||
struct properties
|
||||
{
|
||||
properties(const pstring &defparam, plib::source_location &&sourceloc)
|
||||
: m_defparam(defparam)
|
||||
, m_sourceloc(std::move(sourceloc))
|
||||
{ }
|
||||
|
||||
PCOPYASSIGNMOVE(properties, default)
|
||||
|
||||
const pstring &defparam() const noexcept
|
||||
{
|
||||
return m_defparam;
|
||||
}
|
||||
|
||||
const plib::source_location &source() const noexcept
|
||||
{
|
||||
return m_sourceloc;
|
||||
}
|
||||
private:
|
||||
pstring m_defparam;
|
||||
plib::source_location m_sourceloc;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// net_dev class factory
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -49,9 +73,7 @@ namespace factory {
|
||||
class element_t
|
||||
{
|
||||
public:
|
||||
element_t(const pstring &name, const pstring &def_param);
|
||||
element_t(const pstring &name, const pstring &def_param,
|
||||
plib::source_location &&sourceloc);
|
||||
element_t(const pstring &name, properties &&props);
|
||||
virtual ~element_t() = default;
|
||||
|
||||
PCOPYASSIGNMOVE(element_t, default)
|
||||
@ -67,13 +89,12 @@ namespace factory {
|
||||
}
|
||||
|
||||
const pstring &name() const noexcept { return m_name; }
|
||||
const pstring ¶m_desc() const noexcept { return m_def_param; }
|
||||
const plib::source_location &source() const noexcept { return m_sourceloc; }
|
||||
const pstring ¶m_desc() const noexcept { return m_properties.defparam(); }
|
||||
const plib::source_location &source() const noexcept { return m_properties.source(); }
|
||||
|
||||
private:
|
||||
pstring m_name; ///< device name
|
||||
pstring m_def_param; ///< default parameter
|
||||
plib::source_location m_sourceloc; ///< source file
|
||||
properties m_properties; ///< source file and other information and settings
|
||||
};
|
||||
|
||||
template <class C>
|
||||
@ -84,11 +105,8 @@ namespace factory {
|
||||
using device_ptr = unique_pool_ptr<core_device_t>;
|
||||
using element_ptr = plib::unique_ptr<device_element_t<C>>;
|
||||
|
||||
device_element_t(const pstring &name, const pstring &def_param)
|
||||
: element_t(name, def_param) { }
|
||||
device_element_t(const pstring &name, const pstring &def_param,
|
||||
plib::source_location &&sourceloc)
|
||||
: element_t(name, def_param, std::move(sourceloc)) { }
|
||||
device_element_t(const pstring &name, properties &&props)
|
||||
: element_t(name, std::move(props)) { }
|
||||
|
||||
device_ptr make_device(nlmempool &pool,
|
||||
netlist_state_t &anetlist,
|
||||
@ -97,10 +115,9 @@ namespace factory {
|
||||
return pool.make_unique<C>(anetlist, name);
|
||||
}
|
||||
|
||||
static element_ptr create(const pstring &name,
|
||||
const pstring &def_param, plib::source_location &&sourceloc)
|
||||
static element_ptr create(const pstring &name, properties &&props)
|
||||
{
|
||||
return plib::make_unique<device_element_t<C>>(name, def_param, std::move(sourceloc));
|
||||
return plib::make_unique<device_element_t<C>>(name, std::move(props));
|
||||
}
|
||||
};
|
||||
|
||||
@ -113,10 +130,9 @@ namespace factory {
|
||||
PCOPYASSIGNMOVE(list_t, delete)
|
||||
|
||||
template<class device_class>
|
||||
void add(const pstring &name, const pstring &def_param,
|
||||
plib::source_location &&sourceloc)
|
||||
void add(const pstring &name, properties &&props)
|
||||
{
|
||||
add(device_element_t<device_class>::create(name, def_param, std::move(sourceloc)));
|
||||
add(device_element_t<device_class>::create(name, std::move(props)));
|
||||
}
|
||||
|
||||
void add(plib::unique_ptr<element_t> &&factory) noexcept(false);
|
||||
@ -140,9 +156,9 @@ namespace factory {
|
||||
using constructor_ptr_t = plib::unique_ptr<element_t> (*)();
|
||||
|
||||
template <typename T>
|
||||
plib::unique_ptr<element_t> constructor_t(const pstring &name, const pstring &def_param)
|
||||
plib::unique_ptr<element_t> constructor_t(const pstring &name, properties &&props)
|
||||
{
|
||||
return plib::make_unique<device_element_t<T>>(name, def_param);
|
||||
return plib::make_unique<device_element_t<T>>(name, std::move(props));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -153,9 +169,8 @@ namespace factory {
|
||||
{
|
||||
public:
|
||||
|
||||
library_element_t(const pstring &name, const pstring &def_param,
|
||||
plib::source_location &&sourceloc)
|
||||
: element_t(name, def_param, std::move(sourceloc))
|
||||
library_element_t(const pstring &name, properties &&props)
|
||||
: element_t(name, std::move(props))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ void parser_t::parse_netlist(const pstring &nlname)
|
||||
{
|
||||
require_token(m_tok_paren_left);
|
||||
// FIXME: Need to pass in parameter definition FIXME: get line number right
|
||||
m_setup.register_lib_entry(get_identifier(), "", plib::source_location("parser: " + nlname, 1));
|
||||
m_setup.register_lib_entry(get_identifier(), factory::properties("", plib::source_location("parser: " + nlname, 1)));
|
||||
require_token(m_tok_paren_right);
|
||||
}
|
||||
else if (token.is(m_tok_NETLIST_END))
|
||||
@ -166,7 +166,6 @@ void parser_t::net_truthtable_start(const pstring &nlname)
|
||||
desc.name = name;
|
||||
desc.ni = static_cast<unsigned long>(ni);
|
||||
desc.no = static_cast<unsigned long>(no);
|
||||
desc.def_param = "+" + def_param;
|
||||
desc.family = "";
|
||||
|
||||
while (true)
|
||||
@ -200,7 +199,7 @@ void parser_t::net_truthtable_start(const pstring &nlname)
|
||||
require_token(m_tok_paren_left);
|
||||
require_token(m_tok_paren_right);
|
||||
// FIXME: proper location
|
||||
m_setup.truthtable_create(desc, plib::source_location(nlname, 1));
|
||||
m_setup.truthtable_create(desc, factory::properties("+" + def_param, plib::source_location(nlname, 1)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -170,7 +170,6 @@ namespace netlist
|
||||
throw nl_exception(MF_NOT_FOUND_IN_SOURCE_COLLECTION(netlist_name));
|
||||
}
|
||||
|
||||
|
||||
void nlparse_t::namespace_push(const pstring &aname)
|
||||
{
|
||||
if (m_namespace_stack.empty())
|
||||
@ -234,10 +233,9 @@ namespace netlist
|
||||
m_abstract.m_defparams.emplace_back(namespace_prefix() + name, def);
|
||||
}
|
||||
|
||||
void nlparse_t::register_lib_entry(const pstring &name, const
|
||||
pstring ¶mdef, plib::source_location &&sourceloc)
|
||||
void nlparse_t::register_lib_entry(const pstring &name, factory::properties &&props)
|
||||
{
|
||||
m_factory.add(plib::make_unique<factory::library_element_t>(name, paramdef, std::move(sourceloc)));
|
||||
m_factory.add(plib::make_unique<factory::library_element_t>(name, std::move(props)));
|
||||
}
|
||||
|
||||
void nlparse_t::register_frontier(const pstring &attach, const pstring &r_IN,
|
||||
@ -273,9 +271,9 @@ namespace netlist
|
||||
register_link(attach, frontier_name + ".Q");
|
||||
}
|
||||
|
||||
void nlparse_t::truthtable_create(tt_desc &desc, plib::source_location &&sourceloc)
|
||||
void nlparse_t::truthtable_create(tt_desc &desc, factory::properties &&props)
|
||||
{
|
||||
auto fac = factory::truthtable_create(desc, std::move(sourceloc));
|
||||
auto fac = factory::truthtable_create(desc, std::move(props));
|
||||
m_factory.add(std::move(fac));
|
||||
}
|
||||
|
||||
|
@ -84,11 +84,13 @@ void NETLIST_NAME(name)(netlist::nlparse_t &setup) \
|
||||
// FIXME: Need to pass in parameter definition
|
||||
#define LOCAL_LIB_ENTRY_1(name) \
|
||||
LOCAL_SOURCE(name) \
|
||||
setup.register_lib_entry(# name, "", PSOURCELOC());
|
||||
setup.register_lib_entry(# name, \
|
||||
netlist::factory::properties("", PSOURCELOC()));
|
||||
|
||||
#define LOCAL_LIB_ENTRY_2(name, param_spec) \
|
||||
LOCAL_SOURCE(name) \
|
||||
setup.register_lib_entry(# name, param_spec, PSOURCELOC());
|
||||
setup.register_lib_entry(# name, \
|
||||
netlist::factory::properties(param_spec, PSOURCELOC()));
|
||||
|
||||
#define LOCAL_LIB_ENTRY(...) PCALLVARARG(LOCAL_LIB_ENTRY_, __VA_ARGS__)
|
||||
|
||||
@ -107,14 +109,14 @@ void NETLIST_NAME(name)(netlist::nlparse_t &setup) \
|
||||
// truthtable defines
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define TRUTHTABLE_START(cname, in, out, def_params) \
|
||||
#define TRUTHTABLE_START(cname, in, out, def_params) \
|
||||
{ \
|
||||
netlist::tt_desc desc; \
|
||||
desc.name = #cname ; \
|
||||
desc.ni = in; \
|
||||
desc.no = out; \
|
||||
desc.def_param = def_params; \
|
||||
desc.family = "";
|
||||
netlist::tt_desc desc; \
|
||||
desc.name = #cname ; \
|
||||
desc.ni = in; \
|
||||
desc.no = out; \
|
||||
desc.family = ""; \
|
||||
auto props(netlist::factory::properties(def_params, PSOURCELOC()));
|
||||
|
||||
#define TT_HEAD(x) \
|
||||
desc.desc.emplace_back(x);
|
||||
@ -126,7 +128,7 @@ void NETLIST_NAME(name)(netlist::nlparse_t &setup) \
|
||||
desc.family = x;
|
||||
|
||||
#define TRUTHTABLE_END() \
|
||||
setup.truthtable_create(desc, PSOURCELOC()); \
|
||||
setup.truthtable_create(desc, std::move(props)); \
|
||||
}
|
||||
|
||||
namespace netlist
|
||||
@ -160,7 +162,6 @@ namespace netlist
|
||||
pstring name;
|
||||
unsigned long ni;
|
||||
unsigned long no;
|
||||
pstring def_param;
|
||||
std::vector<pstring> desc;
|
||||
pstring family;
|
||||
};
|
||||
@ -309,7 +310,7 @@ namespace netlist
|
||||
register_param(param, static_cast<nl_fptype>(value));
|
||||
}
|
||||
|
||||
void register_lib_entry(const pstring &name, const pstring ¶mdef, plib::source_location &&sourceloc);
|
||||
void register_lib_entry(const pstring &name, factory::properties &&props);
|
||||
|
||||
void register_frontier(const pstring &attach, const pstring &r_IN, const pstring &r_OUT);
|
||||
|
||||
@ -323,7 +324,7 @@ namespace netlist
|
||||
m_sources.add_source(std::move(src));
|
||||
}
|
||||
|
||||
void truthtable_create(tt_desc &desc, plib::source_location &&sourceloc);
|
||||
void truthtable_create(tt_desc &desc, factory::properties &&props);
|
||||
|
||||
// handle namespace
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user