ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
CVirtualStruct.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
6
8
9namespace etiss
10{
11
12static void parseName(const char *cname, const int baseflags, unsigned &flags, std::string &name_)
13{
14 flags = 0;
15
16 if (!cname)
17 etiss::log(etiss::FATALERROR, "fix VirtualStruct::allocateFromC", ETISS_SRCLOC);
18
19 std::string name(cname);
20 size_t ppos = name.find('.');
21 if (ppos == std::string::npos)
22 {
24 "etiss::VirtualStruct::allocateFromC encountered an invalid field name. flags cannot be parsed and "
25 "will be set to private. check the documentation of VirtualStruct_names for the propper syntax",
26 name);
28 name_ = name;
29 return;
30 }
31}
32
33std::shared_ptr<VirtualStruct> VirtualStruct::allocateFromC(
34 void *handle, VirtualStruct_names names, VirtualStruct_prettyNames prettyNames_optional,
35 VirtualStruct_read read_recommended, VirtualStruct_write write_optional,
36 VirtualStruct_setListenerCallback setListenerCallback_optional, std::function<void(void *handle)> cleanup)
37{
38 const int baseflags = (read_recommended ? etiss::VirtualStruct::Field::R : 0) |
39 (write_optional ? etiss::VirtualStruct::Field::W : 0) |
40 (setListenerCallback_optional ? etiss::VirtualStruct::Field::L : 0) |
42
43 if (!names)
44 {
45 etiss::log(etiss::ERROR, "VirtualStruct::allocateFromC: names cannot be 0");
46 return std::shared_ptr<VirtualStruct>();
47 }
48
49 bool handle_deleted = false;
50 std::shared_ptr<VirtualStruct> ret = allocate(handle,
51 [handle_deleted, handle, cleanup](Field *f) mutable
52 {
53 if (!handle_deleted)
54 {
55 handle_deleted = true;
56 cleanup(handle);
57 }
58 delete f;
59 });
60
61 size_t apos = 0;
62 const char *const *name_array = names(handle);
63 // const char * const * pname_array = names(handle);
64
65 while (name_array[apos] != 0)
66 {
67 unsigned flags;
68 std::string name;
69 parseName(name_array[apos], baseflags, flags, name);
71 }
72
73 return ret;
74}
75
76} // namespace etiss
#define ETISS_SRCLOC
Definition Misc.h:202
uint64_t(* VirtualStruct_read)(void *handle, uint32_t index)
read the value of the field at the given index
void(* VirtualStruct_setListenerCallback)(void *handle, void *callbackHandle, void(*callback)(void *handle, void *callbackHandle, uint32_t index))
setter function to register the callback handle for listener supported fields.
void(* VirtualStruct_write)(void *handle, uint32_t index)
write the value of the field at the given index
const char *const *(* VirtualStruct_names)(void *handle)
must return an array of zero terminated strings.
const char *const *(* VirtualStruct_prettyNames)(void *handle)
similar to above array but with human readable/alternative field names (see etiss::VirtualStruct)
a Field instance represents e.g.
static const int W
write flag
static const int L
supports listener plugins; used for etiss::RegisterDevicePlugins to determine access to a variable/fi...
static const int P
private field: this flag indicates that this field is an implementation specific field that e....
static const int R
read flag
static std::shared_ptr< VirtualStruct > allocateFromC(void *handle, VirtualStruct_names names, VirtualStruct_prettyNames prettyNames_optional, VirtualStruct_read read_recommended, VirtualStruct_write write_optional, VirtualStruct_setListenerCallback setListenerCallback_optional, std::function< void(void *handle)> cleanup)
implemented in CVirtualStruct.cpp
static std::shared_ptr< VirtualStruct > allocate(void *structure, std::function< void(Field *)> delete_)
forwards: include/jit/*
Definition Benchmark.h:17
static void parseName(const char *cname, const int baseflags, unsigned &flags, std::string &name_)
@ WARNING
Definition Misc.h:86
@ ERROR
Definition Misc.h:85
@ FATALERROR
Definition Misc.h:84
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:94