More netlist code reschuffle to separate setup from run. (nw)

This commit is contained in:
couriersud 2015-01-18 20:37:11 +01:00
parent e517f7ed2d
commit cf7e7e8361
10 changed files with 72 additions and 51 deletions

View File

@ -48,6 +48,7 @@
#include "netlist.h"
#include "netlist/nl_base.h"
#include "netlist/nl_setup.h"
#include "netlist/nl_factory.h"
#include "netlist/devices/net_lib.h"
#include "debugger.h"
@ -134,9 +135,8 @@ void netlist_mame_analog_output_t::custom_netlist_additions(netlist_setup_t &set
pstring dname = "OUT_" + m_in;
m_delegate.bind_relative_to(owner()->machine().root_device());
NETLIB_NAME(analog_callback) *dev = downcast<NETLIB_NAME(analog_callback) *>(
setup.factory().new_device_by_classname("nld_analog_callback", setup));
setup.register_dev("nld_analog_callback", dname));
setup.register_dev(dev, dname);
dev->register_callback(m_delegate);
setup.register_link(dname + ".IN", m_in);
}
@ -208,10 +208,7 @@ void netlist_mame_stream_input_t::custom_netlist_additions(netlist_setup_t &setu
{
NETLIB_NAME(sound_in) *snd_in = setup.netlist().get_first_device<NETLIB_NAME(sound_in)>();
if (snd_in == NULL)
{
snd_in = dynamic_cast<NETLIB_NAME(sound_in) *>(setup.factory().new_device_by_classname("nld_sound_in", setup));
setup.register_dev(snd_in, "STREAM_INPUT");
}
snd_in = dynamic_cast<NETLIB_NAME(sound_in) *>(setup.register_dev("nld_sound_in", "STREAM_INPUT"));
pstring sparam = pstring::sprintf("STREAM_INPUT.CHAN%d", m_channel);
setup.register_param(sparam, m_param_name);
@ -247,11 +244,11 @@ void netlist_mame_stream_output_t::device_start()
void netlist_mame_stream_output_t::custom_netlist_additions(netlist_setup_t &setup)
{
NETLIB_NAME(sound_out) *snd_out;
//NETLIB_NAME(sound_out) *snd_out;
pstring sname = pstring::sprintf("STREAM_OUT_%d", m_channel);
snd_out = dynamic_cast<NETLIB_NAME(sound_out) *>(setup.factory().new_device_by_classname("nld_sound_out", setup));
setup.register_dev(snd_out, sname);
//snd_out = dynamic_cast<NETLIB_NAME(sound_out) *>(setup.register_dev("nld_sound_out", sname));
setup.register_dev("nld_sound_out", sname);
setup.register_param(sname + ".CHAN" , m_channel);
setup.register_param(sname + ".MULT", m_mult);

View File

@ -1002,22 +1002,3 @@ NETLIB_UPDATE(mainclock)
net.set_time(netlist().time() + m_inc);
}
// ----------------------------------------------------------------------------------------
// net_device_t_base_factory
// ----------------------------------------------------------------------------------------
ATTR_COLD const nl_util::pstring_list net_device_t_base_factory::term_param_list()
{
if (m_def_param.startsWith("+"))
return nl_util::split(m_def_param.substr(1), ",");
else
return nl_util::pstring_list();
}
ATTR_COLD const nl_util::pstring_list net_device_t_base_factory::def_params()
{
if (m_def_param.startsWith("+") || m_def_param.equals("-"))
return nl_util::pstring_list();
else
return nl_util::split(m_def_param, ",");
}

View File

@ -159,7 +159,7 @@ public:
#else
#define nl_assert(x) do { } while (0)
//#define assert_always(x, msg) do { if (!(x)) throw emu_fatalerror("Fatal error: %s (%s:%d)", msg, __FILE__, __LINE__); } while (0)
#define nl_assert_always(x, msg) do { } while (0)
#define nl_assert_always(x, msg) do { if (!(x)) throw nl_fatalerror("Fatal error: %s\nCaused by assert: %s:%d: %s", msg, __FILE__, __LINE__, #x); } while (0)
#endif
//============================================================

View File

@ -8,12 +8,23 @@
#ifndef NL_DICE_COMPAT_H_
#define NL_DICE_COMPAT_H_
#include "netlist/devices/net_lib.h"
/* --------------------------------------------------------------------
* Compatibility macros for DICE netlists ...
* -------------------------------------------------------------------- */
//#define CHIP(_n, _t) netlist.register_dev(NET_NEW(_t ## _dip), _n);
/*
* define NETLIST_DEVELOPMENT in IDEs before including this header file
* to get compile time errors on unknown devices. This should only be
* a temporary support and not be used in commits.
*/
#ifdef NETLIST_DEVELOPMENT
#define CHIP(_n, _t) setup.register_dev( nl_alloc(nld_ ## _t ## _dip), _n);
#else
#define CHIP(_n, _t) setup.register_dev(NETLIB_NAME_STR(_t ## _dip), _n);
#endif
#define CONNECTION( ... ) CONNECTIONY( CONNECTIONX( __VA_ARGS__ ) )
#define CONNECTIONY(_a) _a

View File

@ -50,6 +50,27 @@
#include "nl_factory.h"
#include "nl_setup.h"
// ----------------------------------------------------------------------------------------
// net_device_t_base_factory
// ----------------------------------------------------------------------------------------
ATTR_COLD const nl_util::pstring_list net_device_t_base_factory::term_param_list()
{
if (m_def_param.startsWith("+"))
return nl_util::split(m_def_param.substr(1), ",");
else
return nl_util::pstring_list();
}
ATTR_COLD const nl_util::pstring_list net_device_t_base_factory::def_params()
{
if (m_def_param.startsWith("+") || m_def_param.equals("-"))
return nl_util::pstring_list();
else
return nl_util::split(m_def_param, ",");
}
netlist_factory_t::netlist_factory_t()
{
}
@ -64,7 +85,7 @@ netlist_factory_t::~netlist_factory_t()
m_list.clear();
}
netlist_device_t *netlist_factory_t::new_device_by_classname(const pstring &classname, netlist_setup_t &setup) const
netlist_device_t *netlist_factory_t::new_device_by_classname(const pstring &classname) const
{
for (net_device_t_base_factory * const *e = m_list.first(); e != NULL; e = m_list.next(e))
{
@ -76,7 +97,6 @@ netlist_device_t *netlist_factory_t::new_device_by_classname(const pstring &clas
}
p++;
}
setup.netlist().error("Class %s not found!\n", classname.cstr());
return NULL; // appease code analysis
}

View File

@ -80,7 +80,7 @@ public:
m_list.add(nl_alloc(net_device_t_factory< _C >, name, classname, def_param));
}
ATTR_COLD netlist_device_t *new_device_by_classname(const pstring &classname, netlist_setup_t &setup) const;
ATTR_COLD netlist_device_t *new_device_by_classname(const pstring &classname) const;
ATTR_COLD netlist_device_t *new_device_by_name(const pstring &name, netlist_setup_t &setup) const;
ATTR_COLD net_device_t_base_factory * factory_by_name(const pstring &name, netlist_setup_t &setup) const;

View File

@ -6,6 +6,7 @@
*/
#include "nl_parser.h"
#include "nl_factory.h"
//#undef NL_VERBOSE_OUT
//#define NL_VERBOSE_OUT(x) printf x

View File

@ -9,6 +9,7 @@
#include "nl_setup.h"
#include "nl_parser.h"
#include "nl_util.h"
#include "nl_factory.h"
#include "devices/net_lib.h"
#include "devices/nld_system.h"
#include "analog/nld_solver.h"
@ -37,6 +38,7 @@ netlist_setup_t::netlist_setup_t(netlist_base_t &netlist)
, m_proxy_cnt(0)
{
netlist.set_setup(this);
m_factory = nl_alloc(netlist_factory_t);
}
void netlist_setup_t::init()
@ -55,6 +57,7 @@ netlist_setup_t::~netlist_setup_t()
m_params_temp.clear();
netlist().set_setup(NULL);
nl_free(m_factory);
pstring::resetmem();
}
@ -92,6 +95,14 @@ netlist_device_t *netlist_setup_t::register_dev(netlist_device_t *dev, const pst
return dev;
}
netlist_device_t *netlist_setup_t::register_dev(const pstring &classname, const pstring &name)
{
netlist_device_t *dev = factory().new_device_by_classname(classname);
if (dev == NULL)
netlist().error("Class %s not found!\n", classname.cstr());
return register_dev(dev, name);
}
template <class T>
static void remove_start_with(T &hm, pstring &sw)
{
@ -695,7 +706,7 @@ void netlist_setup_t::start_devices()
{
NL_VERBOSE_OUT(("%d: <%s>\n",i, ll[i].cstr()));
NL_VERBOSE_OUT(("%d: <%s>\n",i, ll[i].cstr()));
netlist_device_t *nc = factory().new_device_by_classname("nld_log", *this);
netlist_device_t *nc = factory().new_device_by_classname("nld_log");
pstring name = "log_" + ll[i];
register_dev(nc, name);
register_link(name + ".I", ll[i]);

View File

@ -3,15 +3,13 @@
/*
* nlsetup.h
*
* Created on: 3 Nov 2013
* Author: andre
*/
#ifndef NLSETUP_H_
#define NLSETUP_H_
#include "nl_base.h"
#include "nl_factory.h"
//#include "nl_factory.h"
//============================================================
// MACROS / inline netlist definitions
@ -25,10 +23,10 @@
#define ALIAS(_alias, _name) \
setup.register_alias(# _alias, # _name);
#define NET_NEW(_type) setup.factory().new_device_by_classname(NETLIB_NAME_STR(_type), setup)
//#define NET_NEW(_type) setup.factory().new_device_by_classname(NETLIB_NAME_STR(_type), setup)
#define NET_REGISTER_DEV(_type, _name) \
setup.register_dev(NET_NEW(_type), # _name);
setup.register_dev(NETLIB_NAME_STR(_type), # _name);
#define NET_REMOVE_DEV(_name) \
setup.remove_dev(# _name);
@ -66,16 +64,13 @@ ATTR_COLD void NETLIST_NAME(_name)(netlist_setup_t &setup)
NETLIST_NAME(_model)(setup); \
setup.namespace_pop();
// ----------------------------------------------------------------------------------------
// FIXME: Clean this up
// ----------------------------------------------------------------------------------------
//class NETLIB_NAME(analog_callback);
// ----------------------------------------------------------------------------------------
// netlist_setup_t
// ----------------------------------------------------------------------------------------
// Forward definition so we keep nl_factory.h out of the public
class netlist_factory_t;
class netlist_setup_t
{
NETLIST_PREVENT_COPYING(netlist_setup_t)
@ -118,12 +113,11 @@ public:
netlist_base_t &netlist() { return m_netlist; }
const netlist_base_t &netlist() const { return m_netlist; }
netlist_factory_t &factory() { return m_factory; }
const netlist_factory_t &factory() const { return m_factory; }
pstring build_fqn(const pstring &obj_name) const;
netlist_device_t *register_dev(netlist_device_t *dev, const pstring &name);
netlist_device_t *register_dev(const pstring &classname, const pstring &name);
void remove_dev(const pstring &name);
void register_model(const pstring &model);
@ -152,10 +146,13 @@ public:
void namespace_push(const pstring &aname);
void namespace_pop();
/* not ideal, but needed for save_state */
tagmap_terminal_t m_terminals;
netlist_factory_t &factory() { return *m_factory; }
const netlist_factory_t &factory() const { return *m_factory; }
void print_stats() const;
/* not ideal, but needed for save_state */
tagmap_terminal_t m_terminals;
void print_stats() const;
protected:
@ -168,7 +165,7 @@ private:
tagmap_link_t m_links;
tagmap_nstring_t m_params_temp;
netlist_factory_t m_factory;
netlist_factory_t *m_factory;
plinearlist_t<pstring> m_models;

View File

@ -65,6 +65,9 @@
*
*/
// identify unknown devices in IDE
//#define NETLIST_DEVELOPMENT 1
#include "netlist/nl_dice_compat.h"
#include "netlist/devices/net_lib.h"