cxx_config.hh (10458:64809024b924) cxx_config.hh (11800:54436a1784dc)
1/*
2 * Copyright (c) 2014 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 * Authors: Andrew Bardsley
38 */
39
40/**
41 * @file
42 *
43 * C++-only configuration and instantiation support. This allows a
44 * config to be read back from a .ini and instantiated without
45 * Python. Useful if you want to embed gem5 within a larger system
46 * without carrying the integration cost of the fully-featured
47 * configuration system.
48 *
49 * This file contains definitions needed to store summaries of a
50 * SimObject's parameter structure
51 */
52
53#ifndef __SIM_CXX_CONFIG_HH__
54#define __SIM_CXX_CONFIG_HH__
55
56#include <map>
57#include <string>
58#include <vector>
59
1/*
2 * Copyright (c) 2014 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 * Authors: Andrew Bardsley
38 */
39
40/**
41 * @file
42 *
43 * C++-only configuration and instantiation support. This allows a
44 * config to be read back from a .ini and instantiated without
45 * Python. Useful if you want to embed gem5 within a larger system
46 * without carrying the integration cost of the fully-featured
47 * configuration system.
48 *
49 * This file contains definitions needed to store summaries of a
50 * SimObject's parameter structure
51 */
52
53#ifndef __SIM_CXX_CONFIG_HH__
54#define __SIM_CXX_CONFIG_HH__
55
56#include <map>
57#include <string>
58#include <vector>
59
60#include "mem/port.hh"
61#include "params/SimObject.hh"
62#include "sim/sim_object.hh"
63
64class CxxConfigParams;
65
66/** Config details entry for a SimObject. Instances of this class contain
67 * enough configuration layout information to popular a ...Param structure
68 * and build a SimObject from it with the help of the 'set' functions in
69 * each ...Param class */
70class CxxConfigDirectoryEntry
71{
72 public:
73 /* Class to represent parameters and SimObject references within
74 * SimObjects */
75 class ParamDesc
76 {
77 public:
78 const std::string name;
79
80 /* Is this a vector or singleton parameters/SimObject */
81 const bool isVector;
82
83 /** Is this a SimObject, and so is to be set with setSimObject...
84 * or another from-string parameter set with setParam... */
85 const bool isSimObject;
86
87 ParamDesc(const std::string &name_,
88 bool isVector_, bool isSimObject_) :
89 name(name_), isVector(isVector_), isSimObject(isSimObject_)
90 { }
91 };
92
93 /** Similar to ParamDesc to describe ports */
94 class PortDesc
95 {
96 public:
97 const std::string name;
98
99 /* Is this a vector or singleton parameters/SimObject */
100 const bool isVector;
101
102 /** Is this a master or slave port */
103 const bool isMaster;
104
105 PortDesc(const std::string &name_,
106 bool isVector_, bool isMaster_) :
107 name(name_), isVector(isVector_), isMaster(isMaster_)
108 { }
109 };
110
111 /** All parameters (including SimObjects) in order */
112 std::map<std::string, ParamDesc *> parameters;
113
114 /** Ports */
115 std::map<std::string, PortDesc *> ports;
116
117 /** Make a ...Param structure for the SimObject class of this entry */
118 virtual CxxConfigParams *makeParamsObject() const { return NULL; }
119
120 virtual ~CxxConfigDirectoryEntry() { }
121};
122
123/** Base for peer classes of SimObjectParams derived classes with parameter
124 * modifying member functions. C++ configuration will offer objects of
125 * these classes to SimObjects as params rather than SimObjectParams
126 * objects */
127class CxxConfigParams
128{
129 private:
130 static const std::string invalidName;
131
132 public:
133 /** Flags passable to setParam... to smooth over any parsing difference
134 * between different config files */
135 typedef uint32_t FlagsType;
136 typedef ::Flags<FlagsType> Flags;
137
138 /** Example flag */
139 /* static const FlagsType MY_NEW_FLAG = 0x00000001; */
140
141 public:
142 /** Set future object's full path name */
143 virtual void setName(const std::string &name_) { }
144
145 /** Get full path name string */
146 virtual const std::string &getName() { return invalidName; }
147
148 /** Set a SimObject valued parameter with a reference to the given
149 * SimObject. This will return false if the parameter name is not
150 * valid or the object is of the wrong type */
151 virtual bool setSimObject(const std::string &name,
152 SimObject *simObject)
153 { return false; }
154
155 /** As setSimObjectVector but set a whole vector of references */
156 virtual bool setSimObjectVector(const std::string &name,
157 const std::vector<SimObject *> &simObjects)
158 { return false; }
159
160 /** Set a parameter with a value parsed from the given string. The
161 * parsing regime matches the format of .ini config files. Returns
162 * false if the parameter name is not valid or the string cannot be
163 * parsed as the type of the parameter */
164 virtual bool setParam(const std::string &name,
165 const std::string &value, const Flags flags)
166 { return false; }
167
168 /** As setParamVector but for parameters given as vectors pre-separated
169 * into elements */
170 virtual bool setParamVector(const std::string &name,
171 const std::vector<std::string> &values, const Flags flags)
172 { return false; }
173
174 /** Set the number of connections expected for the named port. Returns
175 * false if the port name is not valid */
176 virtual bool setPortConnectionCount(const std::string &name,
177 unsigned int count)
178 { return false; }
179
180 /** Create the associated SimObject */
181 virtual SimObject *simObjectCreate() { return NULL; }
182
183 CxxConfigParams() { }
184
185 virtual ~CxxConfigParams() { }
186};
187
188/** Config file wrapper providing a common interface to CxxConfigManager */
189class CxxConfigFileBase
190{
191 public:
192 CxxConfigFileBase() { }
193 virtual ~CxxConfigFileBase() { }
194
195 /** Get a single parameter value as a string returned in value.
196 * For booleans, the function expects "true" or "false" in value.
197 * For NULL SimObjects, it expects "Null" */
198 virtual bool getParam(const std::string &object_name,
199 const std::string &param_name,
200 std::string &value) const = 0;
201
202 /** Get a list/vector parameter */
203 virtual bool getParamVector(const std::string &object_name,
204 const std::string &param_name,
205 std::vector<std::string> &values) const = 0;
206
207 /** Get the peer (connected) ports of the named ports */
208 virtual bool getPortPeers(const std::string &object_name,
209 const std::string &port_name,
210 std::vector<std::string> &peers) const = 0;
211
212 /** Does an object with this path exist? */
213 virtual bool objectExists(const std::string &object_name) const = 0;
214
215 /** Get all SimObjects in the config */
216 virtual void getAllObjectNames(std::vector<std::string> &list) const = 0;
217
218 /** Get the names or paths of all the children SimObjects of this
219 * SimObject. If return_paths is true then full paths are returned.
220 * If false, only the last name component for each object is returned */
221 virtual void getObjectChildren(const std::string &object_name,
222 std::vector<std::string> &children,
223 bool return_paths = false) const = 0;
224
225 /** Load config file */
226 virtual bool load(const std::string &filename) = 0;
227
228 /** Get the flags which should be used to modify parameter parsing
229 * behaviour */
230 virtual CxxConfigParams::Flags getFlags() const { return 0; }
231};
232
233/** Directory of all SimObject classes config details */
234extern std::map<std::string, CxxConfigDirectoryEntry *>
235 cxx_config_directory;
236
237/** Initialise cxx_config_directory. This is defined in the
238 * auto-generated .../cxx_config/init.cc */
239void cxxConfigInit();
240
241#endif // __SIM_CXX_CONFIG_HH__
60#include "sim/sim_object.hh"
61
62class CxxConfigParams;
63
64/** Config details entry for a SimObject. Instances of this class contain
65 * enough configuration layout information to popular a ...Param structure
66 * and build a SimObject from it with the help of the 'set' functions in
67 * each ...Param class */
68class CxxConfigDirectoryEntry
69{
70 public:
71 /* Class to represent parameters and SimObject references within
72 * SimObjects */
73 class ParamDesc
74 {
75 public:
76 const std::string name;
77
78 /* Is this a vector or singleton parameters/SimObject */
79 const bool isVector;
80
81 /** Is this a SimObject, and so is to be set with setSimObject...
82 * or another from-string parameter set with setParam... */
83 const bool isSimObject;
84
85 ParamDesc(const std::string &name_,
86 bool isVector_, bool isSimObject_) :
87 name(name_), isVector(isVector_), isSimObject(isSimObject_)
88 { }
89 };
90
91 /** Similar to ParamDesc to describe ports */
92 class PortDesc
93 {
94 public:
95 const std::string name;
96
97 /* Is this a vector or singleton parameters/SimObject */
98 const bool isVector;
99
100 /** Is this a master or slave port */
101 const bool isMaster;
102
103 PortDesc(const std::string &name_,
104 bool isVector_, bool isMaster_) :
105 name(name_), isVector(isVector_), isMaster(isMaster_)
106 { }
107 };
108
109 /** All parameters (including SimObjects) in order */
110 std::map<std::string, ParamDesc *> parameters;
111
112 /** Ports */
113 std::map<std::string, PortDesc *> ports;
114
115 /** Make a ...Param structure for the SimObject class of this entry */
116 virtual CxxConfigParams *makeParamsObject() const { return NULL; }
117
118 virtual ~CxxConfigDirectoryEntry() { }
119};
120
121/** Base for peer classes of SimObjectParams derived classes with parameter
122 * modifying member functions. C++ configuration will offer objects of
123 * these classes to SimObjects as params rather than SimObjectParams
124 * objects */
125class CxxConfigParams
126{
127 private:
128 static const std::string invalidName;
129
130 public:
131 /** Flags passable to setParam... to smooth over any parsing difference
132 * between different config files */
133 typedef uint32_t FlagsType;
134 typedef ::Flags<FlagsType> Flags;
135
136 /** Example flag */
137 /* static const FlagsType MY_NEW_FLAG = 0x00000001; */
138
139 public:
140 /** Set future object's full path name */
141 virtual void setName(const std::string &name_) { }
142
143 /** Get full path name string */
144 virtual const std::string &getName() { return invalidName; }
145
146 /** Set a SimObject valued parameter with a reference to the given
147 * SimObject. This will return false if the parameter name is not
148 * valid or the object is of the wrong type */
149 virtual bool setSimObject(const std::string &name,
150 SimObject *simObject)
151 { return false; }
152
153 /** As setSimObjectVector but set a whole vector of references */
154 virtual bool setSimObjectVector(const std::string &name,
155 const std::vector<SimObject *> &simObjects)
156 { return false; }
157
158 /** Set a parameter with a value parsed from the given string. The
159 * parsing regime matches the format of .ini config files. Returns
160 * false if the parameter name is not valid or the string cannot be
161 * parsed as the type of the parameter */
162 virtual bool setParam(const std::string &name,
163 const std::string &value, const Flags flags)
164 { return false; }
165
166 /** As setParamVector but for parameters given as vectors pre-separated
167 * into elements */
168 virtual bool setParamVector(const std::string &name,
169 const std::vector<std::string> &values, const Flags flags)
170 { return false; }
171
172 /** Set the number of connections expected for the named port. Returns
173 * false if the port name is not valid */
174 virtual bool setPortConnectionCount(const std::string &name,
175 unsigned int count)
176 { return false; }
177
178 /** Create the associated SimObject */
179 virtual SimObject *simObjectCreate() { return NULL; }
180
181 CxxConfigParams() { }
182
183 virtual ~CxxConfigParams() { }
184};
185
186/** Config file wrapper providing a common interface to CxxConfigManager */
187class CxxConfigFileBase
188{
189 public:
190 CxxConfigFileBase() { }
191 virtual ~CxxConfigFileBase() { }
192
193 /** Get a single parameter value as a string returned in value.
194 * For booleans, the function expects "true" or "false" in value.
195 * For NULL SimObjects, it expects "Null" */
196 virtual bool getParam(const std::string &object_name,
197 const std::string &param_name,
198 std::string &value) const = 0;
199
200 /** Get a list/vector parameter */
201 virtual bool getParamVector(const std::string &object_name,
202 const std::string &param_name,
203 std::vector<std::string> &values) const = 0;
204
205 /** Get the peer (connected) ports of the named ports */
206 virtual bool getPortPeers(const std::string &object_name,
207 const std::string &port_name,
208 std::vector<std::string> &peers) const = 0;
209
210 /** Does an object with this path exist? */
211 virtual bool objectExists(const std::string &object_name) const = 0;
212
213 /** Get all SimObjects in the config */
214 virtual void getAllObjectNames(std::vector<std::string> &list) const = 0;
215
216 /** Get the names or paths of all the children SimObjects of this
217 * SimObject. If return_paths is true then full paths are returned.
218 * If false, only the last name component for each object is returned */
219 virtual void getObjectChildren(const std::string &object_name,
220 std::vector<std::string> &children,
221 bool return_paths = false) const = 0;
222
223 /** Load config file */
224 virtual bool load(const std::string &filename) = 0;
225
226 /** Get the flags which should be used to modify parameter parsing
227 * behaviour */
228 virtual CxxConfigParams::Flags getFlags() const { return 0; }
229};
230
231/** Directory of all SimObject classes config details */
232extern std::map<std::string, CxxConfigDirectoryEntry *>
233 cxx_config_directory;
234
235/** Initialise cxx_config_directory. This is defined in the
236 * auto-generated .../cxx_config/init.cc */
237void cxxConfigInit();
238
239#endif // __SIM_CXX_CONFIG_HH__