ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CVirtualStruct.cpp
Go to the documentation of this file.
1/*
2
3 @copyright
4
5 <pre>
6
7 Copyright 2018 Infineon Technologies AG
8
9 This file is part of ETISS tool, see <https://github.com/tum-ei-eda/etiss>.
10
11 The initial version of this software has been created with the funding support by the German Federal
12 Ministry of Education and Research (BMBF) in the project EffektiV under grant 01IS13022.
13
14 Redistribution and use in source and binary forms, with or without modification, are permitted
15 provided that the following conditions are met:
16
17 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
18 the following disclaimer.
19
20 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
21 and the following disclaimer in the documentation and/or other materials provided with the distribution.
22
23 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
24 or promote products derived from this software without specific prior written permission.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
27 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
28 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
29 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 POSSIBILITY OF SUCH DAMAGE.
34
35 </pre>
36
37 @author Chair of Electronic Design Automation, TUM
38
39 @version 0.1
40
41*/
42
43#include "etiss/VirtualStruct.h"
44
45namespace etiss
46{
47
48static void parseName(const char *cname, const int baseflags, unsigned &flags, std::string &name_)
49{
50 flags = 0;
51
52 if (!cname)
53 etiss::log(etiss::FATALERROR, "fix VirtualStruct::allocateFromC", ETISS_SRCLOC);
54
55 std::string name(cname);
56 size_t ppos = name.find('.');
57 if (ppos == std::string::npos)
58 {
60 "etiss::VirtualStruct::allocateFromC encountered an invalid field name. flags cannot be parsed and "
61 "will be set to private. check the documentation of VirtualStruct_names for the propper syntax",
62 name);
64 name_ = name;
65 return;
66 }
67}
68
69std::shared_ptr<VirtualStruct> VirtualStruct::allocateFromC(
70 void *handle, VirtualStruct_names names, VirtualStruct_prettyNames prettyNames_optional,
71 VirtualStruct_read read_recommended, VirtualStruct_write write_optional,
72 VirtualStruct_setListenerCallback setListenerCallback_optional, std::function<void(void *handle)> cleanup)
73{
74 const int baseflags = (read_recommended ? etiss::VirtualStruct::Field::R : 0) |
75 (write_optional ? etiss::VirtualStruct::Field::W : 0) |
76 (setListenerCallback_optional ? etiss::VirtualStruct::Field::L : 0) |
78
79 if (!names)
80 {
81 etiss::log(etiss::ERROR, "VirtualStruct::allocateFromC: names cannot be 0");
82 return std::shared_ptr<VirtualStruct>();
83 }
84
85 bool handle_deleted = false;
86 std::shared_ptr<VirtualStruct> ret = allocate(handle, [handle_deleted, handle, cleanup](Field *f) mutable {
87 if (!handle_deleted)
88 {
89 handle_deleted = true;
90 cleanup(handle);
91 }
92 delete f;
93 });
94
95 size_t apos = 0;
96 const char *const *name_array = names(handle);
97 // const char * const * pname_array = names(handle);
98
99 while (name_array[apos] != 0)
100 {
101 unsigned flags;
102 std::string name;
103 parseName(name_array[apos], baseflags, flags, name);
105 }
106
107 return ret;
108}
109
110} // namespace etiss
#define ETISS_SRCLOC
Definition Misc.h:239
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_)
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition Benchmark.h:53
static void parseName(const char *cname, const int baseflags, unsigned &flags, std::string &name_)
@ WARNING
Definition Misc.h:128
@ ERROR
Definition Misc.h:127
@ FATALERROR
Definition Misc.h:126
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:125