2 * Copyright (c) 2014 ARM Limited
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.
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.
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.
41 * C++-only configuration and instantiation support. This allows a
42 * config to be read back from a .ini and instantiated without
43 * Python. Useful if you want to embed gem5 within a larger system
44 * without carrying the integration cost of the fully-featured
45 * configuration system.
47 * This file contains definitions needed to store summaries of a
48 * SimObject's parameter structure
51 #ifndef __SIM_CXX_CONFIG_HH__
52 #define __SIM_CXX_CONFIG_HH__
58 #include "sim/sim_object.hh"
60 class CxxConfigParams;
62 /** Config details entry for a SimObject. Instances of this class contain
63 * enough configuration layout information to popular a ...Param structure
64 * and build a SimObject from it with the help of the 'set' functions in
65 * each ...Param class */
66 class CxxConfigDirectoryEntry
69 /* Class to represent parameters and SimObject references within
74 const std::string name;
76 /* Is this a vector or singleton parameters/SimObject */
79 /** Is this a SimObject, and so is to be set with setSimObject...
80 * or another from-string parameter set with setParam... */
81 const bool isSimObject;
83 ParamDesc(const std::string &name_,
84 bool isVector_, bool isSimObject_) :
85 name(name_), isVector(isVector_), isSimObject(isSimObject_)
89 /** Similar to ParamDesc to describe ports */
93 const std::string name;
95 /* Is this a vector or singleton parameters/SimObject */
98 /** Is this a request or response port */
99 const bool isRequestor;
101 PortDesc(const std::string &name_,
102 bool isVector_, bool isRequestor_) :
103 name(name_), isVector(isVector_), isRequestor(isRequestor_)
107 /** All parameters (including SimObjects) in order */
108 std::map<std::string, ParamDesc *> parameters;
111 std::map<std::string, PortDesc *> ports;
113 /** Make a ...Param structure for the SimObject class of this entry */
114 virtual CxxConfigParams *makeParamsObject() const { return NULL; }
116 virtual ~CxxConfigDirectoryEntry() { }
119 /** Base for peer classes of SimObjectParams derived classes with parameter
120 * modifying member functions. C++ configuration will offer objects of
121 * these classes to SimObjects as params rather than SimObjectParams
123 class CxxConfigParams
126 static const std::string invalidName;
129 /** Flags passable to setParam... to smooth over any parsing difference
130 * between different config files */
131 typedef uint32_t FlagsType;
132 typedef ::Flags<FlagsType> Flags;
135 /* static const FlagsType MY_NEW_FLAG = 0x00000001; */
138 /** Set future object's full path name */
139 virtual void setName(const std::string &name_) { }
141 /** Get full path name string */
142 virtual const std::string &getName() { return invalidName; }
144 /** Set a SimObject valued parameter with a reference to the given
145 * SimObject. This will return false if the parameter name is not
146 * valid or the object is of the wrong type */
147 virtual bool setSimObject(const std::string &name,
148 SimObject *simObject)
151 /** As setSimObjectVector but set a whole vector of references */
152 virtual bool setSimObjectVector(const std::string &name,
153 const std::vector<SimObject *> &simObjects)
156 /** Set a parameter with a value parsed from the given string. The
157 * parsing regime matches the format of .ini config files. Returns
158 * false if the parameter name is not valid or the string cannot be
159 * parsed as the type of the parameter */
160 virtual bool setParam(const std::string &name,
161 const std::string &value, const Flags flags)
164 /** As setParamVector but for parameters given as vectors pre-separated
166 virtual bool setParamVector(const std::string &name,
167 const std::vector<std::string> &values, const Flags flags)
170 /** Set the number of connections expected for the named port. Returns
171 * false if the port name is not valid */
172 virtual bool setPortConnectionCount(const std::string &name,
176 /** Create the associated SimObject */
177 virtual SimObject *simObjectCreate() { return NULL; }
179 CxxConfigParams() { }
181 virtual ~CxxConfigParams() { }
184 /** Config file wrapper providing a common interface to CxxConfigManager */
185 class CxxConfigFileBase
188 CxxConfigFileBase() { }
189 virtual ~CxxConfigFileBase() { }
191 /** Get a single parameter value as a string returned in value.
192 * For booleans, the function expects "true" or "false" in value.
193 * For NULL SimObjects, it expects "Null" */
194 virtual bool getParam(const std::string &object_name,
195 const std::string ¶m_name,
196 std::string &value) const = 0;
198 /** Get a list/vector parameter */
199 virtual bool getParamVector(const std::string &object_name,
200 const std::string ¶m_name,
201 std::vector<std::string> &values) const = 0;
203 /** Get the peer (connected) ports of the named ports */
204 virtual bool getPortPeers(const std::string &object_name,
205 const std::string &port_name,
206 std::vector<std::string> &peers) const = 0;
208 /** Does an object with this path exist? */
209 virtual bool objectExists(const std::string &object_name) const = 0;
211 /** Get all SimObjects in the config */
212 virtual void getAllObjectNames(std::vector<std::string> &list) const = 0;
214 /** Get the names or paths of all the children SimObjects of this
215 * SimObject. If return_paths is true then full paths are returned.
216 * If false, only the last name component for each object is returned */
217 virtual void getObjectChildren(const std::string &object_name,
218 std::vector<std::string> &children,
219 bool return_paths = false) const = 0;
221 /** Load config file */
222 virtual bool load(const std::string &filename) = 0;
224 /** Get the flags which should be used to modify parameter parsing
226 virtual CxxConfigParams::Flags getFlags() const { return 0; }
229 /** Directory of all SimObject classes config details */
230 extern std::map<std::string, CxxConfigDirectoryEntry *>
231 cxx_config_directory;
233 /** Initialise cxx_config_directory. This is defined in the
234 * auto-generated .../cxx_config/init.cc */
235 void cxxConfigInit();
237 #endif // __SIM_CXX_CONFIG_HH__