summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/nl_factory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/netlist/nl_factory.cpp')
-rw-r--r--src/lib/netlist/nl_factory.cpp98
1 files changed, 52 insertions, 46 deletions
diff --git a/src/lib/netlist/nl_factory.cpp b/src/lib/netlist/nl_factory.cpp
index f8fc40d27db..6ab9e84cafd 100644
--- a/src/lib/netlist/nl_factory.cpp
+++ b/src/lib/netlist/nl_factory.cpp
@@ -1,93 +1,99 @@
-// license:GPL-2.0+
+// license:BSD-3-Clause
// copyright-holders:Couriersud
-/***************************************************************************
- nl_factory.c
-
- Discrete netlist implementation.
-
-****************************************************************************/
+///
+/// \file nl_factory.cpp
+///
#include "nl_factory.h"
-#include "nl_base.h"
+
#include "nl_errstr.h"
#include "nl_setup.h"
+
+#include "core/core_device.h"
+
#include "plib/putil.h"
-namespace netlist { namespace factory
+namespace netlist::factory
{
- class NETLIB_NAME(wrapper) : public device_t
+ // FIXME: this doesn't do anything, check how to remove
+ class NETLIB_NAME(wrapper)
+ : public base_device_t
{
public:
- NETLIB_NAME(wrapper)(netlist_state_t &anetlist, const pstring &name)
- : device_t(anetlist, name)
+ NETLIB_NAME(wrapper)(base_device_param_t data)
+ : base_device_t(data)
{
}
+
protected:
- NETLIB_RESETI() { }
- NETLIB_UPDATEI() { }
+ // NETLIB_RESETI() {}
};
- element_t::element_t(const pstring &name, const pstring &classname,
- const pstring &def_param, const pstring &sourcefile)
- : m_name(name), m_classname(classname), m_def_param(def_param),
- m_sourcefile(sourcefile)
- {
- }
-
- element_t::element_t(const pstring &name, const pstring &classname,
- const pstring &def_param)
- : m_name(name), m_classname(classname), m_def_param(def_param),
- m_sourcefile("<unknown>")
+ element_t::element_t(const pstring &name, properties &&props)
+ : m_name(name)
+ , m_properties(props)
{
}
- // ----------------------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
// net_device_t_base_factory
- // ----------------------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
list_t::list_t(log_type &alog)
: m_log(alog)
{
}
- void list_t::register_device(plib::unique_ptr<element_t> &&factory)
+ bool exists(const pstring &name);
+
+ bool list_t::exists(const pstring &name) const noexcept
+ {
+ for (const auto &e : *this)
+ if (e->name() == name)
+ return true;
+ return false;
+ }
+
+ void list_t::add(host_arena::unique_ptr<element_t> &&factory)
{
- for (auto & e : *this)
- if (e->name() == factory->name())
- m_log.fatal(MF_FACTORY_ALREADY_CONTAINS_1(factory->name()));
+ if (exists(factory->name()))
+ {
+ m_log.fatal(MF_FACTORY_ALREADY_CONTAINS_1(factory->name()));
+ throw nl_exception(MF_FACTORY_ALREADY_CONTAINS_1(factory->name()));
+ }
push_back(std::move(factory));
}
- factory::element_t * list_t::factory_by_name(const pstring &devname)
+ factory::element_t *list_t::factory_by_name(const pstring &devname)
{
- for (auto & e : *this)
+ for (auto &e : *this)
{
if (e->name() == devname)
return e.get();
}
m_log.fatal(MF_CLASS_1_NOT_FOUND(devname));
- return nullptr; // appease code analysis
+ throw nl_exception(MF_CLASS_1_NOT_FOUND(devname));
}
- // -----------------------------------------------------------------------------
- // factory_lib_entry_t: factory class to wrap macro based chips/elements
- // -----------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
+ // library_element_t: factory class to wrap macro based chips/elements
+ // -------------------------------------------------------------------------
- pool_owned_ptr<device_t> library_element_t::Create(netlist_state_t &anetlist, const pstring &name)
+ library_element_t::library_element_t(const pstring &name,
+ properties && props)
+ : element_t(name,
+ std::move(properties(props).set_type(element_type::MACRO)))
{
- return pool().make_poolptr<NETLIB_NAME(wrapper)>(anetlist, name);
}
- void library_element_t::macro_actions(nlparse_t &nparser, const pstring &name)
+ device_arena::unique_ptr<core_device_t> library_element_t::make_device(
+ device_arena &pool, netlist_state_t &anetlist, const pstring &name)
{
- nparser.namespace_push(name);
- nparser.include(this->name());
- nparser.namespace_pop();
+ return plib::make_unique<NETLIB_NAME(wrapper)>(pool,
+ base_device_data_t{anetlist, name});
}
-
-} // namespace factory
- } // namespace netlist
+} // namespace netlist::factory