SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
device.h
Go to the documentation of this file.
1/*
2 © 2015 Intel Corporation
3
4 This software and the related documents are Intel copyrighted materials, and
5 your use of them is governed by the express license under which they were
6 provided to you ("License"). Unless the License provides otherwise, you may
7 not use, modify, copy, publish, distribute, disclose or transmit this software
8 or the related documents without Intel's prior written permission.
9
10 This software and the related documents are provided as is, with no express or
11 implied warranties, other than those that are expressly stated in the License.
12*/
13
14#ifndef SIMICS_SYSTEMC_DEVICE_H
15#define SIMICS_SYSTEMC_DEVICE_H
16
17
18#include <systemc>
19
23
24#include <string>
25#include <utility>
26
27namespace simics {
28namespace systemc {
29
35template <typename T>
36class Device {
37 public:
41 };
42
47 Device() : simulation_(NULL), device_(NULL), is_device_owner_(false) {}
48
61 Device(Device &other)
62 : simulation_(NULL), device_(NULL), is_device_owner_(false) {
63 *this = other;
64 }
65
73 explicit Device(iface::SimulationInterface *simulation)
74 : simulation_(simulation), device_(new T), is_device_owner_(true) {
75 }
76
87 const std::string &device_name)
88 : simulation_(simulation), device_(new T(device_name.c_str())),
89 is_device_owner_(true) {
90 }
91
105 Device(iface::SimulationInterface *simulation, T *device_model,
106 ownership_t ownership = TAKE_OWNERSHIP)
107 : simulation_(simulation), device_(device_model),
108 is_device_owner_(ownership == TAKE_OWNERSHIP) {
109 }
110
111
126 Device& operator=(Device &other) { // NOLINT(runtime/references)
127 FATAL_ERROR_IF(device_, "Changing the device is not allowed");
128 FATAL_ERROR_IF(simulation_, "Changing the simulation is not allowed");
129
130 std::swap(device_, other.device_);
131 std::swap(simulation_, other.simulation_);
132 std::swap(is_device_owner_, other.is_device_owner_);
133 return *this;
134 }
135
138 return DeviceAccess<T>(simulation_, device_);
139 }
140
143 return DeviceAccess<T>(simulation_, device_);
144 }
145
147 T *pointer() {
148 return device_;
149 }
150
152 const T *pointer() const {
153 return device_;
154 }
155
156 virtual ~Device() {
157 if (is_device_owner_) {
158 simics::systemc::Context c(simulation_);
159 delete device_;
160 }
161 }
162
163 private:
164 iface::SimulationInterface *simulation_;
165 T *device_;
166 bool is_device_owner_;
167};
168
169} // namespace systemc
170} // namespace simics
171
172#endif
Utility class that handles the context switching, using RAII methodology.
Definition: context.h:31
Definition: device_access.h:26
Utility class for handling direct access to the SystemC top module (i.e.
Definition: device.h:36
const T * pointer() const
pointer to underlying device object
Definition: device.h:152
Device & operator=(Device &other)
Assume ownership of the underlying simulation and device model.
Definition: device.h:126
Device(iface::SimulationInterface *simulation, const std::string &device_name)
This constructor automatically allocates an object of type T with device_name passed as the only argu...
Definition: device.h:86
const DeviceAccess< T > operator->() const
Access the underlying device object with the proper simulation context.
Definition: device.h:142
ownership_t
Definition: device.h:38
@ TAKE_OWNERSHIP
Definition: device.h:40
@ DONT_TAKE_OWNERSHIP
Definition: device.h:39
T * pointer()
pointer to underlying device object
Definition: device.h:147
Device()
Default constructor.
Definition: device.h:47
Device(Device &other)
Assume ownership of the underlying simulation and device model.
Definition: device.h:61
Device(iface::SimulationInterface *simulation, T *device_model, ownership_t ownership=TAKE_OWNERSHIP)
Wrap an existing model in this Device.
Definition: device.h:105
virtual ~Device()
Definition: device.h:156
Device(iface::SimulationInterface *simulation)
This constructor automatically allocates an object of type T with default arguments.
Definition: device.h:73
DeviceAccess< T > operator->()
Access the underlying device object with the proper simulation context.
Definition: device.h:137
Interface to the SystemC simulation.
Definition: simulation_interface.h:25
Definition: adapter.h:79