SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
proxy_factory.h
Go to the documentation of this file.
1/*
2 © 2014 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_AWARENESS_PROXY_FACTORY_H
15#define SIMICS_SYSTEMC_AWARENESS_PROXY_FACTORY_H
16
17#include <simics/base/types.h>
18#include <simics/base/sim-exception.h>
19#include <simics/simulator/sim-get-class.h>
20
31
32#include <vector>
33#include <string>
34#include <set>
35#include <utility> // move, ignore
36
37namespace simics {
38namespace systemc {
39namespace awareness {
40
41template <typename TProxy = Proxy>
43 public:
44 bool mapToProxy(sc_core::sc_object *object) const override {
45 if (suppress_proxy_build_.find(object) != suppress_proxy_build_.end())
46 return false;
47 return true;
48 }
49 bool canManufacture(sc_core::sc_object *object) const override {
50 return true;
51 }
52 bool needUniqueConfClassName(sc_core::sc_object *object) const override {
53#if INTC_EXT && USE_SIMICS_CCI
55 return cfg.getParameters(object).size() > 0;
56#else
57 return false;
58#endif
59 }
61 sc_core::sc_object *object) const override {
62 return &sc_class_attributes;
63 }
65 sc_core::sc_object *object) const override {
66 return &sc_instance_attributes;
67 }
68 conf_class_t *createConfClass(sc_core::sc_object *object,
69 std::string name,
70 std::string description,
71 std::string documentation) const override {
72 return *make_class<TProxy>(name, description, documentation,
73 Sim_Class_Kind_Pseudo).get();
74 }
75 void registerAttributes(sc_core::sc_object *object,
76 conf_class_t *cls) const override {
77 if (!object)
78 return;
79
80#if INTC_EXT && USE_SIMICS_CCI
82 for (const auto &parameter : cfg.getParameters(object)) {
83 const char *type = cfg.simicsType(parameter);
84 if (!type)
85 continue;
86
87 int key = CciAttribute::define(parameter.name());
88 ProxyAttributeName attribute_name(cfg.simicsName(parameter));
89 if (attribute_name.transformed()) {
90 SIM_LOG_INFO(4, log_object_, Log_Awareness,
91 "CCI Attribute %s is now %s.",
92 parameter.name(),
93 attribute_name.c_str());
94 }
95
96 char *key_arg = NULL;
97 key_arg += key;
98 SIM_register_typed_attribute(
99 cls, attribute_name.c_str(),
100 Proxy::getAttribute, key_arg,
101 Proxy::setAttribute, key_arg,
102 Sim_Attr_Pseudo, cfg.simicsType(parameter), 0,
103 parameter.get_description().c_str());
104 if (SIM_clear_exception() != SimExc_No_Exception) {
105 SIM_LOG_ERROR(log_object_, Log_Awareness,
106 "Failed to register CCI attribute: '%s'",
107 attribute_name.c_str());
108 }
109 }
110#endif
111 }
112 void registerInterfaces(sc_core::sc_object *object,
113 conf_class_t *cls) const override {
114 registerInterface<iface::ScObjectSimicsAdapter<TProxy> >(cls);
115 if (dynamic_cast<sc_core::sc_module *>(object)) {
116 // TODO(ah): replace this with a proper SimicsAdapter class and a
117 // working implementation once the interface is used for something
118 // more than just type-info.
119 static sc_module_interface_t iface = {};
120 iface._not_valid = NULL;
121 SIM_register_interface(cls, SC_MODULE_INTERFACE, &iface);
122 }
123 }
124 void registerLogGroups(sc_core::sc_object *object,
125 conf_class_t *cls) const override {
126 }
127 void registerFeatures(sc_core::sc_object *object,
128 ProxyInterface *proxy) const override {
129 }
130 bool registerClass(std::string sc_kind,
131 const char *class_name) const override {
132 std::string name = sc_class_attributes.name(class_name);
133 conf_class_t *cls = SIM_get_class(name.c_str());
134 if (SIM_clear_exception() != SimExc_No_Exception) {
135 std::string description = std::string("SystemC ") + sc_kind;
136 std::string documentation = std::string("The <class>") +
137 name + "</class> class corresponds to the generic " +
138 description + " class.";
139 cls = createConfClass(NULL, std::move(name), std::move(description),
140 std::move(documentation));
141 if (cls == NULL) {
142 std::ignore = SIM_clear_exception();
143 return false;
144 }
145
146 registerAttributes(NULL, cls);
147 registerInterfaces(NULL, cls);
148 registerLogGroups(NULL, cls);
149
150 // TODO(ah): hack! should be handled by registerInterfaces(), but
151 // since we invoke it with NULL the dynamic cast to sc_module* will
152 // always fail and the sc_module interface will never be
153 // registered. Not sure why we need to call registerClass(...,
154 // "sc_module") from ProxyBuilder::registerProxyClasses(), but we
155 // must handle this more gracefully.
156 {
157 static sc_module_interface_t iface = {};
158 iface._not_valid = NULL;
159 SIM_register_interface(cls, SC_MODULE_INTERFACE, &iface);
160 }
161 }
162
163 return true;
164 }
165 bool isClassRegistered(std::string sc_kind) const override {
166 std::string name = sc_class_attributes.name(sc_kind.c_str());
167 SIM_get_class(name.c_str());
168 return SIM_clear_exception() == SimExc_No_Exception;
169 }
170 void addSuppressProxyBuild(sc_core::sc_object* obj) {
171 suppress_proxy_build_.insert(obj);
172 }
173 template <class A>
174 void registerInterface(conf_class_t *cls) const {
175 static A adapter;
176 SIM_register_interface(cls, adapter.name().c_str(),
177 adapter.cstruct());
178 }
179
180 private:
181 ClassAttributes sc_class_attributes;
182 InstanceAttributes sc_instance_attributes;
183 std::set<sc_core::sc_object *> suppress_proxy_build_;
184};
185
186} // namespace awareness
187} // namespace systemc
188} // namespace simics
189
190#endif
Definition: cci_configuration.h:35
static int define(std::string parameter_name)
Definition: class_attributes_interface.h:24
Definition: class_attributes.h:25
std::string name(std::string class_name) const override
Definition: instance_attributes_interface.h:24
Definition: instance_attributes.h:25
Definition: proxy_attribute_name.h:30
Definition: proxy_factory_base.h:23
static ConfObjectRef log_object_
Definition: proxy_factory_base.h:28
Definition: proxy_factory_interface.h:29
Definition: proxy_factory.h:42
const InstanceAttributesInterface * instanceAttributes(sc_core::sc_object *object) const override
Definition: proxy_factory.h:64
bool needUniqueConfClassName(sc_core::sc_object *object) const override
Definition: proxy_factory.h:52
bool mapToProxy(sc_core::sc_object *object) const override
Definition: proxy_factory.h:44
bool isClassRegistered(std::string sc_kind) const override
Definition: proxy_factory.h:165
const ClassAttributesInterface * classAttributes(sc_core::sc_object *object) const override
Definition: proxy_factory.h:60
void registerInterface(conf_class_t *cls) const
Definition: proxy_factory.h:174
void registerLogGroups(sc_core::sc_object *object, conf_class_t *cls) const override
Definition: proxy_factory.h:124
bool registerClass(std::string sc_kind, const char *class_name) const override
Definition: proxy_factory.h:130
void registerInterfaces(sc_core::sc_object *object, conf_class_t *cls) const override
Definition: proxy_factory.h:112
void registerAttributes(sc_core::sc_object *object, conf_class_t *cls) const override
Definition: proxy_factory.h:75
conf_class_t * createConfClass(sc_core::sc_object *object, std::string name, std::string description, std::string documentation) const override
Definition: proxy_factory.h:68
void addSuppressProxyBuild(sc_core::sc_object *obj)
Definition: proxy_factory.h:170
bool canManufacture(sc_core::sc_object *object) const override
Definition: proxy_factory.h:49
void registerFeatures(sc_core::sc_object *object, ProxyInterface *proxy) const override
Definition: proxy_factory.h:127
Definition: proxy_interface.h:27
static set_error_t setAttribute(lang_void *ptr, conf_object_t *obj, attr_value_t *val, attr_value_t *idx)
static attr_value_t getAttribute(lang_void *ptr, conf_object_t *obj, attr_value_t *idx)
conf_class_t * SIM_get_class(const char *NOTNULL name)
@ Log_Awareness
Definition: adapter_log_groups.h:24
Definition: adapter.h:79