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// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2014 Intel Corporation
5
6 This software and the related documents are Intel copyrighted materials, and
7 your use of them is governed by the express license under which they were
8 provided to you ("License"). Unless the License provides otherwise, you may
9 not use, modify, copy, publish, distribute, disclose or transmit this software
10 or the related documents without Intel's prior written permission.
11
12 This software and the related documents are provided as is, with no express or
13 implied warranties, other than those that are expressly stated in the License.
14*/
15
16#ifndef SIMICS_SYSTEMC_AWARENESS_PROXY_FACTORY_H
17#define SIMICS_SYSTEMC_AWARENESS_PROXY_FACTORY_H
18
19#include <simics/base/types.h>
20#include <simics/base/sim-exception.h>
21#include <simics/simulator/sim-get-class.h>
22
33
34#include <vector>
35#include <string>
36#include <set>
37#include <utility> // move, ignore
38
39namespace simics {
40namespace systemc {
41namespace awareness {
42
43template <typename TProxy = Proxy>
45 public:
46 bool mapToProxy(sc_core::sc_object *object) const override {
47 if (suppress_proxy_build_.find(object) != suppress_proxy_build_.end())
48 return false;
49 return true;
50 }
51 bool canManufacture(sc_core::sc_object *object) const override {
52 return true;
53 }
54 bool needUniqueConfClassName(sc_core::sc_object *object) const override {
55#if INTC_EXT && USE_SIMICS_CCI
57 return cfg.getParameters(object).size() > 0;
58#else
59 return false;
60#endif
61 }
63 sc_core::sc_object *object) const override {
64 return &sc_class_attributes;
65 }
67 sc_core::sc_object *object) const override {
68 return &sc_instance_attributes;
69 }
70 conf_class_t *createConfClass(sc_core::sc_object *object,
71 std::string name,
72 std::string description,
73 std::string documentation) const override {
74 return *make_class<TProxy>(name, description, documentation,
75 Sim_Class_Kind_Pseudo).get();
76 }
77 void registerAttributes(sc_core::sc_object *object,
78 conf_class_t *cls) const override {
79 if (!object)
80 return;
81
82#if INTC_EXT && USE_SIMICS_CCI
84 std::vector <cci::cci_param_handle> parameters =
85 cfg.getParameters(object);
86 std::vector <cci::cci_param_handle>::iterator i;
87 for (i = parameters.begin(); i != parameters.end(); ++i) {
88 const char *type = cfg.simicsType(*i);
89 if (!type)
90 continue;
91
92 int key = CciAttribute::define(i->name());
93 ProxyAttributeName attribute_name(cfg.simicsName(*i));
94 if (attribute_name.transformed()) {
95 SIM_LOG_INFO(4, log_object_, Log_Awareness,
96 "CCI Attribute %s is now %s.",
97 i->name(),
98 attribute_name.c_str());
99 }
100
101 char *key_arg = NULL;
102 key_arg += key;
103 SIM_register_typed_attribute(
104 cls, attribute_name.c_str(),
105 Proxy::getAttribute, key_arg,
106 Proxy::setAttribute, key_arg,
107 Sim_Attr_Pseudo, cfg.simicsType(*i), 0,
108 i->get_description().c_str());
109 if (SIM_clear_exception() != SimExc_No_Exception) {
110 SIM_LOG_ERROR(log_object_, Log_Awareness,
111 "Failed to register CCI attribute: '%s'",
112 attribute_name.c_str());
113 }
114 }
115#endif
116 }
117 void registerInterfaces(sc_core::sc_object *object,
118 conf_class_t *cls) const override {
119 registerInterface<iface::ScObjectSimicsAdapter<TProxy> >(cls);
120 if (dynamic_cast<sc_core::sc_module *>(object)) {
121 // TODO(ah): replace this with a proper SimicsAdapter class and a
122 // working implementation once the interface is used for something
123 // more than just type-info.
124 static sc_module_interface_t iface = {};
125 iface._not_valid = NULL;
126 SIM_register_interface(cls, SC_MODULE_INTERFACE, &iface);
127 }
128 }
129 void registerLogGroups(sc_core::sc_object *object,
130 conf_class_t *cls) const override {
131 }
132 void registerFeatures(sc_core::sc_object *object,
133 ProxyInterface *proxy) const override {
134 }
135 bool registerClass(std::string sc_kind,
136 const char *class_name) const override {
137 std::string name = sc_class_attributes.name(class_name);
138 conf_class_t *cls = SIM_get_class(name.c_str());
139 if (SIM_clear_exception() != SimExc_No_Exception) {
140 std::string description = std::string("SystemC ") + sc_kind;
141 std::string documentation = std::string("The <class>") +
142 name + "</class> class corresponds to the generic " +
143 description + " class.";
144 cls = createConfClass(NULL, std::move(name), std::move(description),
145 std::move(documentation));
146 if (cls == NULL) {
147 std::ignore = SIM_clear_exception();
148 return false;
149 }
150
151 registerAttributes(NULL, cls);
152 registerInterfaces(NULL, cls);
153 registerLogGroups(NULL, cls);
154
155 // TODO(ah): hack! should be handled by registerInterfaces(), but
156 // since we invoke it with NULL the dynamic cast to sc_module* will
157 // always fail and the sc_module interface will never be
158 // registered. Not sure why we need to call registerClass(...,
159 // "sc_module") from ProxyBuilder::registerProxyClasses(), but we
160 // must handle this more gracefully.
161 {
162 static sc_module_interface_t iface = {};
163 iface._not_valid = NULL;
164 SIM_register_interface(cls, SC_MODULE_INTERFACE, &iface);
165 }
166 }
167
168 return true;
169 }
170 bool isClassRegistered(std::string sc_kind) const override {
171 std::string name = sc_class_attributes.name(sc_kind.c_str());
172 SIM_get_class(name.c_str());
173 return SIM_clear_exception() == SimExc_No_Exception;
174 }
175 void addSuppressProxyBuild(sc_core::sc_object* obj) {
176 suppress_proxy_build_.insert(obj);
177 }
178 template <class A>
179 void registerInterface(conf_class_t *cls) const {
180 static A adapter;
181 SIM_register_interface(cls, adapter.name().c_str(),
182 adapter.cstruct());
183 }
184
185 private:
186 ClassAttributes sc_class_attributes;
187 InstanceAttributes sc_instance_attributes;
188 std::set<sc_core::sc_object *> suppress_proxy_build_;
189};
190
191} // namespace awareness
192} // namespace systemc
193} // namespace simics
194
195#endif
Definition: cci_configuration.h:37
static int define(std::string parameter_name)
Definition: class_attributes_interface.h:26
Definition: class_attributes.h:27
std::string name(std::string class_name) const override
Definition: instance_attributes_interface.h:26
Definition: instance_attributes.h:27
Definition: proxy_attribute_name.h:32
Definition: proxy_factory_base.h:25
static ConfObjectRef log_object_
Definition: proxy_factory_base.h:30
Definition: proxy_factory_interface.h:31
Definition: proxy_factory.h:44
const InstanceAttributesInterface * instanceAttributes(sc_core::sc_object *object) const override
Definition: proxy_factory.h:66
bool needUniqueConfClassName(sc_core::sc_object *object) const override
Definition: proxy_factory.h:54
bool mapToProxy(sc_core::sc_object *object) const override
Definition: proxy_factory.h:46
bool isClassRegistered(std::string sc_kind) const override
Definition: proxy_factory.h:170
const ClassAttributesInterface * classAttributes(sc_core::sc_object *object) const override
Definition: proxy_factory.h:62
void registerInterface(conf_class_t *cls) const
Definition: proxy_factory.h:179
void registerLogGroups(sc_core::sc_object *object, conf_class_t *cls) const override
Definition: proxy_factory.h:129
bool registerClass(std::string sc_kind, const char *class_name) const override
Definition: proxy_factory.h:135
void registerInterfaces(sc_core::sc_object *object, conf_class_t *cls) const override
Definition: proxy_factory.h:117
void registerAttributes(sc_core::sc_object *object, conf_class_t *cls) const override
Definition: proxy_factory.h:77
conf_class_t * createConfClass(sc_core::sc_object *object, std::string name, std::string description, std::string documentation) const override
Definition: proxy_factory.h:70
void addSuppressProxyBuild(sc_core::sc_object *obj)
Definition: proxy_factory.h:175
bool canManufacture(sc_core::sc_object *object) const override
Definition: proxy_factory.h:51
void registerFeatures(sc_core::sc_object *object, ProxyInterface *proxy) const override
Definition: proxy_factory.h:132
Definition: proxy_interface.h:29
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:26
Definition: adapter.h:81