summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/core/device.h
blob: 12f3f7d174e2abf6831e59b873f2864991dc156b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// license:BSD-3-Clause
// copyright-holders:Couriersud

///
/// \file device.h
///

#ifndef NL_DEVICE_H_
#define NL_DEVICE_H_

#include "core_device.h"
#include "logic_family.h"
#include "param.h"

namespace netlist
{

	// -------------------------------------------------------------------------
	// device_t construction parameters
	// -------------------------------------------------------------------------

	using device_data_t = base_device_data_t;
	// The type use to pass data on
	using device_param_t = const device_data_t &;

	// -------------------------------------------------------------------------
	// device_t
	// -------------------------------------------------------------------------

	class device_t : public base_device_t, public logic_family_t
	{
	public:
		using constructor_data_t = device_data_t;
		using constructor_param_t = device_param_t;

		device_t(device_param_t data);

		device_t(device_param_t data, const pstring &model);
		// only needed by proxies
		device_t(device_param_t data, const logic_family_desc_t *desc);

		device_t(const device_t &) = delete;
		device_t &operator=(const device_t &) = delete;
		device_t(device_t &&) noexcept = delete;
		device_t &operator=(device_t &&) noexcept = delete;

		~device_t() noexcept override = default;

	protected:
		template <typename T1, typename T2>
		void push_two(T1 &term1, netlist_sig_t newQ1,
			const netlist_time &delay1, T2 &term2, netlist_sig_t newQ2,
			const netlist_time &delay2) noexcept
		{
			if (delay2 < delay1)
			{
				term1.push(newQ1, delay1);
				term2.push(newQ2, delay2);
			}
			else
			{
				term2.push(newQ2, delay2);
				term1.push(newQ1, delay1);
			}
		}

		// NETLIB_UPDATE_TERMINALSI() { }
	private:
		param_model_t m_model;
	};

	// -------------------------------------------------------------------------
	// FIXME: Rename
	// -------------------------------------------------------------------------

	template <typename DEVICE>
	struct sub_device_wrapper
	{
		using constructor_data_t = typename DEVICE::constructor_data_t;
		using constructor_param_t = typename DEVICE::constructor_param_t;

		template <typename... Args>
		sub_device_wrapper(base_device_t &owner, const pstring &name,
						   Args &&...args)
		{
			// m_dev = owner.state().make_pool_object<DEVICE>(owner, name,
			// std::forward<Args>(args)...);
			m_dev = owner.state().make_pool_object<DEVICE>(
				constructor_data_t{owner.state(), owner.name() + "." + name},
				std::forward<Args>(args)...);
			owner.state().register_device(
				m_dev->name(),
				device_arena::owned_ptr<core_device_t>(m_dev.get(), false));
		}
		template <typename... Args>
		sub_device_wrapper(device_t &owner, const pstring &name, Args &&...args)
		{
			// m_dev = owner.state().make_pool_object<DEVICE>(owner, name,
			// std::forward<Args>(args)...);
			m_dev = owner.state().make_pool_object<DEVICE>(
				constructor_data_t{owner.state(), owner.name() + "." + name},
				std::forward<Args>(args)...);
			owner.state().register_device(
				m_dev->name(),
				device_arena::owned_ptr<core_device_t>(m_dev.get(), false));
		}
		DEVICE &      operator()() { return *m_dev; }
		const DEVICE &operator()() const { return *m_dev; }

	private:
		device_arena::unique_ptr<DEVICE> m_dev;
	};

} // namespace netlist

#endif // NL_DEVICE_H_