gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
cxx_config.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014, 2025 Arm Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
50
51#ifndef __SIM_CXX_CONFIG_HH__
52#define __SIM_CXX_CONFIG_HH__
53
54#include <map>
55#include <string>
56#include <vector>
57
58#include "sim/sim_object.hh"
59
60namespace gem5
61{
62
63class CxxConfigParams;
64
70{
71 public:
72 /* Class to represent parameters and SimObject references within
73 * SimObjects */
75 {
76 public:
77 const std::string name;
78
79 /* Is this a vector or singleton parameters/SimObject */
80 const bool isVector;
81
82 /* Is this a dictionary */
83 const bool isDict;
84
87 const bool isSimObject;
88
89 ParamDesc(const std::string &name_,
90 bool is_vector, bool is_dict, bool is_simobj)
91 : name(name_), isVector(is_vector),
92 isDict(is_dict), isSimObject(is_simobj)
93 { }
94 };
95
98 {
99 public:
100 const std::string name;
101
102 /* Is this a vector or singleton parameters/SimObject */
103 const bool isVector;
104
106 const bool isRequestor;
107
108 PortDesc(const std::string &name_,
109 bool isVector_, bool isRequestor_) :
110 name(name_), isVector(isVector_), isRequestor(isRequestor_)
111 { }
112 };
113
115 std::map<std::string, ParamDesc *> parameters;
116
118 std::map<std::string, PortDesc *> ports;
119
121 virtual CxxConfigParams *makeParamsObject() const { return NULL; }
122
124};
125
127std::map<std::string, CxxConfigDirectoryEntry *> &cxxConfigDirectory();
128
134{
135 private:
136 static const std::string invalidName;
137
138 protected:
140 {
141 AddToConfigDir(const std::string &name, CxxConfigDirectoryEntry *entry)
142 {
143 auto it_success = cxxConfigDirectory().insert({name, entry});
144 panic_if(!it_success.second,
145 "Failed to insert config directory entry %s (duplicate?).",
146 name);
147 }
148 };
149
150 public:
153 typedef uint32_t FlagsType;
155
157 /* static const FlagsType MY_NEW_FLAG = 0x00000001; */
158
159 public:
161 virtual void setName(const std::string &name_) { }
162
164 virtual const std::string &getName() { return invalidName; }
165
169 virtual bool setSimObject(const std::string &name,
170 SimObject *simObject)
171 { return false; }
172
174 virtual bool setSimObjectVector(const std::string &name,
175 const std::vector<SimObject *> &simObjects)
176 { return false; }
177
182 virtual bool setParam(const std::string &name,
183 const std::string &value, const Flags flags)
184 { return false; }
185
188 virtual bool setParamVector(const std::string &name,
189 const std::vector<std::string> &values, const Flags flags)
190 { return false; }
191
194 virtual bool setParamDict(const std::string &name,
195 const std::unordered_map<std::string, std::string> &values,
196 const Flags flags)
197 { return false; }
198
201 virtual bool setPortConnectionCount(const std::string &name,
202 unsigned int count)
203 { return false; }
204
206 virtual SimObject *simObjectCreate() { return NULL; }
207
209
210 virtual ~CxxConfigParams() { }
211};
212
215{
216 public:
218 virtual ~CxxConfigFileBase() { }
219
223 virtual bool getParam(const std::string &object_name,
224 const std::string &param_name,
225 std::string &value) const = 0;
226
228 virtual bool getParamVector(const std::string &object_name,
229 const std::string &param_name,
230 std::vector<std::string> &values) const = 0;
231
233 virtual bool getParamDict(const std::string &object_name,
234 const std::string &param_name,
235 std::unordered_map<std::string, std::string> &values) const = 0;
236
238 virtual bool getPortPeers(const std::string &object_name,
239 const std::string &port_name,
240 std::vector<std::string> &peers) const = 0;
241
243 virtual bool objectExists(const std::string &object_name) const = 0;
244
247
251 virtual void getObjectChildren(const std::string &object_name,
252 std::vector<std::string> &children,
253 bool return_paths = false) const = 0;
254
256 virtual bool load(const std::string &filename) = 0;
257
260 virtual CxxConfigParams::Flags getFlags() const { return 0; }
261};
262
263} // namespace gem5
264
265#endif // __SIM_CXX_CONFIG_HH__
ParamDesc(const std::string &name_, bool is_vector, bool is_dict, bool is_simobj)
Definition cxx_config.hh:89
const bool isSimObject
Is this a SimObject, and so is to be set with setSimObject... or another from-string parameter set wi...
Definition cxx_config.hh:87
const bool isRequestor
Is this a request or response port.
PortDesc(const std::string &name_, bool isVector_, bool isRequestor_)
Config details entry for a SimObject.
Definition cxx_config.hh:70
std::map< std::string, ParamDesc * > parameters
All parameters (including SimObjects) in order.
virtual CxxConfigParams * makeParamsObject() const
Make a ...Param structure for the SimObject class of this entry.
std::map< std::string, PortDesc * > ports
Ports.
virtual void getAllObjectNames(std::vector< std::string > &list) const =0
Get all SimObjects in the config.
virtual bool getParamDict(const std::string &object_name, const std::string &param_name, std::unordered_map< std::string, std::string > &values) const =0
Get a dictionary parameter.
virtual bool getParamVector(const std::string &object_name, const std::string &param_name, std::vector< std::string > &values) const =0
Get a list/vector parameter.
virtual void getObjectChildren(const std::string &object_name, std::vector< std::string > &children, bool return_paths=false) const =0
Get the names or paths of all the children SimObjects of this SimObject.
virtual bool getPortPeers(const std::string &object_name, const std::string &port_name, std::vector< std::string > &peers) const =0
Get the peer (connected) ports of the named ports.
virtual bool getParam(const std::string &object_name, const std::string &param_name, std::string &value) const =0
Get a single parameter value as a string returned in value.
virtual bool load(const std::string &filename)=0
Load config file.
virtual CxxConfigParams::Flags getFlags() const
Get the flags which should be used to modify parameter parsing behaviour.
virtual bool objectExists(const std::string &object_name) const =0
Does an object with this path exist?
Base for peer classes of SimObjectParams derived classes with parameter modifying member functions.
virtual bool setParam(const std::string &name, const std::string &value, const Flags flags)
Set a parameter with a value parsed from the given string.
virtual bool setPortConnectionCount(const std::string &name, unsigned int count)
Set the number of connections expected for the named port.
virtual const std::string & getName()
Get full path name string.
gem5::Flags< FlagsType > Flags
virtual bool setParamDict(const std::string &name, const std::unordered_map< std::string, std::string > &values, const Flags flags)
As setParamVector but for parameters given as dictionaries pre-separated into elements.
virtual bool setSimObjectVector(const std::string &name, const std::vector< SimObject * > &simObjects)
As setSimObjectVector but set a whole vector of references.
virtual SimObject * simObjectCreate()
Create the associated SimObject.
virtual void setName(const std::string &name_)
Example flag.
virtual bool setSimObject(const std::string &name, SimObject *simObject)
Set a SimObject valued parameter with a reference to the given SimObject.
uint32_t FlagsType
Flags passable to setParam... to smooth over any parsing difference between different config files.
static const std::string invalidName
virtual bool setParamVector(const std::string &name, const std::vector< std::string > &values, const Flags flags)
As setParam but for parameters given as vectors pre-separated into elements.
Wrapper that groups a few flag bits under the same undelying container.
Definition flags.hh:45
Abstract superclass for simulation objects.
STL list class.
Definition stl.hh:51
STL vector class.
Definition stl.hh:37
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:246
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::map< std::string, CxxConfigDirectoryEntry * > & cxxConfigDirectory()
Directory of all SimObject classes config details.
Definition cxx_config.cc:47
AddToConfigDir(const std::string &name, CxxConfigDirectoryEntry *entry)
const std::string & name()
Definition trace.cc:48

Generated on Mon May 26 2025 09:19:13 for gem5 by doxygen 1.13.2