2f316082e4
arch/alpha/alpha_linux_process.cc: arch/alpha/alpha_linux_process.hh: arch/alpha/alpha_memory.cc: arch/alpha/alpha_memory.hh: arch/alpha/alpha_tru64_process.cc: arch/alpha/alpha_tru64_process.hh: arch/alpha/aout_machdep.h: arch/alpha/arguments.cc: arch/alpha/arguments.hh: arch/alpha/faults.cc: arch/alpha/faults.hh: arch/alpha/isa_traits.hh: arch/alpha/osfpal.cc: arch/alpha/osfpal.hh: arch/alpha/pseudo_inst.cc: arch/alpha/pseudo_inst.hh: arch/alpha/vptr.hh: arch/alpha/vtophys.cc: arch/alpha/vtophys.hh: base/bitfield.hh: base/callback.hh: base/circlebuf.cc: base/circlebuf.hh: base/compression/lzss_compression.cc: base/compression/lzss_compression.hh: base/compression/null_compression.hh: base/cprintf.cc: base/cprintf.hh: base/cprintf_formats.hh: base/date.cc: base/dbl_list.hh: base/endian.hh: base/fast_alloc.cc: base/fast_alloc.hh: base/fifo_buffer.cc: base/fifo_buffer.hh: base/hashmap.hh: base/hostinfo.cc: base/hostinfo.hh: base/hybrid_pred.cc: base/hybrid_pred.hh: base/inet.cc: base/inet.hh: base/inifile.cc: base/inifile.hh: base/intmath.cc: base/intmath.hh: base/loader/aout_object.cc: base/loader/aout_object.hh: base/loader/ecoff_object.cc: base/loader/ecoff_object.hh: base/loader/elf_object.cc: base/loader/elf_object.hh: base/loader/object_file.cc: base/loader/object_file.hh: base/loader/symtab.cc: base/loader/symtab.hh: base/misc.cc: base/misc.hh: base/mod_num.hh: base/mysql.cc: base/mysql.hh: base/pollevent.cc: base/pollevent.hh: base/predictor.hh: base/random.cc: base/random.hh: base/range.cc: base/range.hh: base/refcnt.hh: base/remote_gdb.cc: base/remote_gdb.hh: base/res_list.hh: base/sat_counter.cc: base/sat_counter.hh: base/sched_list.hh: base/socket.cc: base/socket.hh: base/statistics.cc: base/statistics.hh: base/stats/events.cc: base/stats/events.hh: base/stats/flags.hh: base/stats/mysql.cc: base/stats/mysql.hh: base/stats/mysql_run.hh: base/stats/output.hh: base/stats/statdb.cc: base/stats/statdb.hh: base/stats/text.cc: base/stats/text.hh: base/stats/types.hh: base/stats/visit.cc: base/stats/visit.hh: base/str.cc: base/str.hh: base/time.cc: base/time.hh: base/trace.cc: base/trace.hh: base/userinfo.cc: base/userinfo.hh: cpu/base_cpu.cc: cpu/base_cpu.hh: cpu/exec_context.cc: cpu/exec_context.hh: cpu/exetrace.cc: cpu/exetrace.hh: cpu/full_cpu/op_class.hh: cpu/full_cpu/smt.hh: cpu/inst_seq.hh: cpu/intr_control.cc: cpu/intr_control.hh: cpu/memtest/memtest.cc: cpu/memtest/memtest.hh: cpu/pc_event.cc: cpu/pc_event.hh: cpu/simple_cpu/simple_cpu.cc: cpu/simple_cpu/simple_cpu.hh: cpu/static_inst.cc: cpu/static_inst.hh: dev/alpha_console.cc: dev/alpha_console.hh: dev/baddev.cc: dev/baddev.hh: dev/disk_image.cc: dev/disk_image.hh: dev/etherbus.cc: dev/etherbus.hh: dev/etherdump.cc: dev/etherdump.hh: dev/etherint.cc: dev/etherint.hh: dev/etherlink.cc: dev/etherlink.hh: dev/etherpkt.cc: dev/etherpkt.hh: dev/ethertap.cc: dev/ethertap.hh: dev/ide_ctrl.cc: dev/ide_ctrl.hh: dev/ide_disk.cc: dev/ide_disk.hh: dev/io_device.cc: dev/io_device.hh: dev/ns_gige.cc: dev/ns_gige.hh: dev/ns_gige_reg.h: dev/pciconfigall.cc: dev/pciconfigall.hh: dev/pcidev.cc: dev/pcidev.hh: dev/pcireg.h: dev/platform.cc: dev/platform.hh: dev/simple_disk.cc: dev/simple_disk.hh: dev/tsunami.cc: dev/tsunami.hh: dev/tsunami_cchip.cc: dev/tsunami_cchip.hh: dev/tsunami_io.cc: dev/tsunami_io.hh: dev/tsunami_pchip.cc: dev/tsunami_pchip.hh: dev/tsunami_uart.hh: dev/tsunamireg.h: docs/stl.hh: kern/linux/linux.hh: kern/linux/linux_syscalls.cc: kern/linux/linux_syscalls.hh: kern/linux/linux_system.cc: kern/linux/linux_system.hh: kern/system_events.cc: kern/system_events.hh: kern/tru64/dump_mbuf.cc: kern/tru64/dump_mbuf.hh: kern/tru64/mbuf.hh: kern/tru64/printf.cc: kern/tru64/printf.hh: kern/tru64/tru64.hh: kern/tru64/tru64_events.cc: kern/tru64/tru64_events.hh: kern/tru64/tru64_syscalls.cc: kern/tru64/tru64_syscalls.hh: kern/tru64/tru64_system.cc: kern/tru64/tru64_system.hh: sim/async.hh: sim/builder.cc: sim/builder.hh: sim/debug.cc: sim/debug.hh: sim/eventq.cc: sim/eventq.hh: sim/host.hh: sim/main.cc: sim/param.cc: sim/param.hh: sim/process.cc: sim/process.hh: sim/serialize.cc: sim/serialize.hh: sim/sim_events.cc: sim/sim_events.hh: sim/sim_exit.hh: sim/sim_object.cc: sim/sim_object.hh: sim/stat_control.cc: sim/stat_control.hh: sim/stats.hh: sim/syscall_emul.cc: sim/syscall_emul.hh: sim/system.cc: sim/system.hh: sim/universe.cc: test/bitvectest.cc: test/circletest.cc: test/cprintftest.cc: test/initest.cc: test/lru_test.cc: test/nmtest.cc: test/offtest.cc: test/paramtest.cc: test/rangetest.cc: test/sized_test.cc: test/stattest.cc: test/strnumtest.cc: test/symtest.cc: test/tokentest.cc: test/tracetest.cc: util/m5/m5.c: util/m5/m5op.h: util/tap/tap.cc: Updated Copyright dev/console.cc: dev/console.hh: This code isn't ours, and shouldn't have our copyright --HG-- extra : convert_revision : 598f2e5eab5d5d3de2c1e862b389086e3212f7c4
765 lines
22 KiB
C++
765 lines
22 KiB
C++
/*
|
|
* Copyright (c) 2002-2003 The Regents of The University of Michigan
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are
|
|
* met: redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer;
|
|
* redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution;
|
|
* neither the name of the copyright holders nor the names of its
|
|
* contributors may be used to endorse or promote products derived from
|
|
* this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#ifndef __PARAM_HH__
|
|
#define __PARAM_HH__
|
|
|
|
#include <list>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "sim/configfile.hh"
|
|
|
|
// forward decls
|
|
class BaseParam;
|
|
class SimObject;
|
|
|
|
//
|
|
// The context of a parameter definition... usually a subclass of
|
|
// SimObjectBuilder (which derives from ParamContext), but abstracted
|
|
// here to support more global simulator control parameters as well.
|
|
//
|
|
class ParamContext
|
|
{
|
|
private:
|
|
|
|
// static list of all ParamContext objects, built as a side effect
|
|
// of the ParamContext constructor
|
|
static std::list<ParamContext *> *ctxList;
|
|
|
|
protected:
|
|
|
|
// .ini file (database) for parameter lookup... initialized on call
|
|
// to parseParams()
|
|
IniFile *iniFilePtr;
|
|
|
|
// .ini file section for parameter lookup
|
|
const std::string iniSection;
|
|
|
|
typedef std::vector<BaseParam *> ParamList;
|
|
|
|
// list of parameters defined in this context
|
|
ParamList *paramList;
|
|
|
|
ParamList *getParamList() {
|
|
if (!paramList)
|
|
paramList = new ParamList;
|
|
return paramList;
|
|
}
|
|
|
|
public:
|
|
|
|
// Second arg, if set to true, says don't put on paramContextList
|
|
// (i.e. don't automatically parse params). Used by derived
|
|
// SimObjectBuilder class, where parsing is done in
|
|
// SimObject::create()
|
|
ParamContext(const std::string &_iniSection, bool noAutoParse = false);
|
|
|
|
virtual ~ParamContext() {}
|
|
|
|
// add a parameter to the context... called from the parameter
|
|
// object's constructor (see BaseParam::BaseParam())
|
|
void addParam(BaseParam *);
|
|
|
|
// call parse() on all params in this context to convert string
|
|
// representations to parameter values
|
|
virtual void parseParams(IniFile &iniFile);
|
|
|
|
// Check parameter values for validity & consistency. Default
|
|
// implementation is no-op; derive subclass & override to add
|
|
// actual functionality here
|
|
virtual void checkParams();
|
|
|
|
// Clean up at end of execution: close file descriptors, etc.
|
|
// Default implementation is no-op; derive subclass & override to
|
|
// add actual functionality here
|
|
virtual void cleanup();
|
|
|
|
// dump parameter descriptions
|
|
void describeParams(std::ostream &);
|
|
|
|
// Display the parameters & values used
|
|
void showParams(std::ostream &);
|
|
|
|
// print context information for parameter error
|
|
virtual void printErrorProlog(std::ostream &);
|
|
|
|
// resolve a SimObject name in this context to an object pointer.
|
|
virtual SimObject *resolveSimObject(const std::string &name);
|
|
|
|
// generate the name for this instance of this context (used as a
|
|
// prefix to create unique names in resolveSimObject()
|
|
virtual const std::string &getInstanceName() { return iniSection; }
|
|
|
|
// return the configuration hierarchy node for this context. Bare
|
|
// ParamContext objects have no corresponding node, so the default
|
|
// implementation returns NULL.
|
|
virtual ConfigNode *getConfigNode() { return NULL; }
|
|
|
|
// Parse all parameters registered with all ParamContext objects.
|
|
static void parseAllContexts(IniFile &iniFile);
|
|
|
|
// Check all parameters registered with all ParamContext objects.
|
|
// (calls checkParams() on each)
|
|
static void checkAllContexts();
|
|
|
|
// Print all parameter values on indicated ostream.
|
|
static void showAllContexts(std::ostream &os);
|
|
|
|
// Clean up all registered ParamContext objects. (calls cleanup()
|
|
// on each)
|
|
static void cleanupAllContexts();
|
|
|
|
// print descriptions of all parameters registered with all
|
|
// ParamContext objects
|
|
static void describeAllContexts(std::ostream &os);
|
|
};
|
|
|
|
|
|
//
|
|
// Base class for all parameter objects
|
|
//
|
|
class BaseParam
|
|
{
|
|
public:
|
|
|
|
ParamContext *context;
|
|
std::string name;
|
|
std::string description; // text description for help message
|
|
bool wasSet; // true if parameter was set by user
|
|
bool hasDefault; // true if parameter has default value
|
|
|
|
BaseParam(ParamContext *_context, const std::string &_name,
|
|
const std::string &_description, bool _hasDefault)
|
|
: context(_context), name(_name), description(_description),
|
|
wasSet(false), hasDefault(_hasDefault)
|
|
{
|
|
context->addParam(this);
|
|
}
|
|
|
|
virtual ~BaseParam() {}
|
|
|
|
// a parameter is valid only if its value was set by the user or
|
|
// it has a default value
|
|
bool isValid() const
|
|
{
|
|
return (wasSet || hasDefault);
|
|
}
|
|
|
|
// set value by parsing string
|
|
virtual void parse(const std::string &s) = 0;
|
|
|
|
// display value to stream
|
|
virtual void showValue(std::ostream &) const = 0;
|
|
|
|
// display type to stream
|
|
virtual void showType(std::ostream &) const = 0;
|
|
|
|
// signal parse or usage error
|
|
virtual void die(const std::string &err) const;
|
|
};
|
|
|
|
//
|
|
// Template classes to specialize parameters to specific types.
|
|
//
|
|
// Param<T> is for single-valued (scalar) parameters of type T.
|
|
// VectorParam<T> is for multi-valued (vector) parameters of type T.
|
|
// These are specified in the .ini file as a space-delimited list of
|
|
// arguments.
|
|
//
|
|
template <class T>
|
|
class Param : public BaseParam
|
|
{
|
|
protected:
|
|
|
|
T value;
|
|
|
|
public:
|
|
|
|
// Param with default value: set value to default
|
|
Param(ParamContext *context,
|
|
const std::string &name, const std::string &description, T dfltValue)
|
|
: BaseParam(context, name, description, true),
|
|
value(dfltValue)
|
|
{
|
|
}
|
|
|
|
// Param with no default value: leave value uninitialized
|
|
Param(ParamContext *context,
|
|
const std::string &name, const std::string &description)
|
|
: BaseParam(context, name, description, false)
|
|
{
|
|
}
|
|
|
|
virtual ~Param() {}
|
|
|
|
operator T&()
|
|
{
|
|
// if we attempt to reference an invalid parameter (i.e., one
|
|
// with no default value that was not set by the user), die.
|
|
if (!isValid())
|
|
die("not found");
|
|
return value;
|
|
}
|
|
|
|
// display value to stream
|
|
virtual void showValue(std::ostream &os) const;
|
|
|
|
// display type to stream
|
|
virtual void showType(std::ostream &) const;
|
|
|
|
// set value by parsing string
|
|
virtual void parse(const std::string &s);
|
|
};
|
|
|
|
|
|
//
|
|
// Template class for vector-valued parameters (lists)
|
|
//
|
|
template <class T>
|
|
class VectorParam : public BaseParam
|
|
{
|
|
protected:
|
|
|
|
std::vector<T> value;
|
|
|
|
public:
|
|
|
|
typedef typename std::vector<T>::size_type size_type;
|
|
|
|
// Param with default value: set value to default
|
|
VectorParam(ParamContext *context, const std::string &name,
|
|
const std::string &description,
|
|
const std::vector<T> &dfltValue)
|
|
: BaseParam(context, name, description, true),
|
|
value(dfltValue)
|
|
{
|
|
}
|
|
|
|
// Param with no default value: leave value uninitialized
|
|
VectorParam(ParamContext *context,
|
|
const std::string &name, const std::string &description)
|
|
: BaseParam(context, name, description, false)
|
|
{
|
|
}
|
|
|
|
virtual ~VectorParam() {}
|
|
|
|
// basic vector access methods
|
|
size_type size() const
|
|
{
|
|
if (!isValid())
|
|
die("not found");
|
|
return value.size();
|
|
}
|
|
|
|
const T &operator[](size_type n) const
|
|
{
|
|
if (!isValid())
|
|
die("not found");
|
|
return value[n];
|
|
}
|
|
|
|
// return reference to value vector
|
|
operator std::vector<T>&()
|
|
{
|
|
if (!isValid())
|
|
die("not found");
|
|
return value;
|
|
}
|
|
|
|
// display value to stream
|
|
virtual void showValue(std::ostream &os) const;
|
|
|
|
// display type to stream
|
|
virtual void showType(std::ostream &) const;
|
|
|
|
// set value by parsing string
|
|
virtual void parse(const std::string &s);
|
|
};
|
|
|
|
//
|
|
// Specialization of Param<int> and VectorParam<int> to handle
|
|
// enumerated types is done in two ways, using SimpleEnumParam and
|
|
// MappedEnumParam (and their vector counterparts,
|
|
// SimpleEnumVectorParam and MappedEnumVectorParam). SimpleEnumParam
|
|
// takes an array of strings and maps them to integers based on array
|
|
// index. MappedEnumParam takes an array of string-to-int mappings,
|
|
// allowing for mapping strings to non-contiguous integer values, or
|
|
// mapping multiple strings to the same integer value.
|
|
//
|
|
// Both SimpleEnumParam and MappedEnumParam are implemented using a
|
|
// single template class, EnumParam<Map>, which takes the type of the map
|
|
// as a parameter (const char * or EnumParamMap). Similarly,
|
|
// SimpleEnumVectorParam and MappedEnumVectorParam are both
|
|
// implemented using EnumVectorParam<Map>.
|
|
//
|
|
template <class Map>
|
|
class EnumParam : public Param<int>
|
|
{
|
|
const int num_values;
|
|
const Map *map;
|
|
|
|
public:
|
|
|
|
// Param with default value: set value to default
|
|
EnumParam(ParamContext *context,
|
|
const std::string &name, const std::string &description,
|
|
const Map *_map, int _num_values,
|
|
int dfltValue)
|
|
: Param<int>(context, name, description, dfltValue),
|
|
num_values(_num_values), map(_map)
|
|
{
|
|
}
|
|
|
|
// Param with no default value: leave value uninitialized
|
|
EnumParam(ParamContext *context,
|
|
const std::string &name, const std::string &description,
|
|
const Map *_map, int _num_values)
|
|
: Param<int>(context, name, description),
|
|
num_values(_num_values), map(_map)
|
|
{
|
|
}
|
|
|
|
virtual ~EnumParam() {}
|
|
|
|
// display value to stream
|
|
virtual void showValue(std::ostream &os) const;
|
|
|
|
// display type to stream
|
|
virtual void showType(std::ostream &) const;
|
|
|
|
// set value by parsing string
|
|
virtual void parse(const std::string &s);
|
|
};
|
|
|
|
//
|
|
// Vector counterpart to SimpleEnumParam
|
|
//
|
|
template <class Map>
|
|
class EnumVectorParam : public VectorParam<int>
|
|
{
|
|
const int num_values;
|
|
const Map *map;
|
|
|
|
public:
|
|
|
|
// Param with default value: set value to default
|
|
EnumVectorParam(ParamContext *context,
|
|
const std::string &name, const std::string &description,
|
|
const Map *_map, int _num_values,
|
|
std::vector<int> &dfltValue)
|
|
: VectorParam<int>(context, name, description, dfltValue),
|
|
num_values(_num_values), map(_map)
|
|
{
|
|
}
|
|
|
|
// Param with no default value: leave value uninitialized
|
|
EnumVectorParam(ParamContext *context,
|
|
const std::string &name, const std::string &description,
|
|
const Map *_map, int _num_values)
|
|
: VectorParam<int>(context, name, description),
|
|
num_values(_num_values), map(_map)
|
|
{
|
|
}
|
|
|
|
virtual ~EnumVectorParam() {}
|
|
|
|
// display value to stream
|
|
virtual void showValue(std::ostream &os) const;
|
|
|
|
// display type to stream
|
|
virtual void showType(std::ostream &) const;
|
|
|
|
// set value by parsing string
|
|
virtual void parse(const std::string &s);
|
|
};
|
|
|
|
// Specialize EnumParam for a particular enumeration type ENUM
|
|
// (automates casting to get value of enum type)
|
|
|
|
template <class ENUM>
|
|
class SimpleEnumParam : public EnumParam<const char *>
|
|
{
|
|
public:
|
|
|
|
SimpleEnumParam(ParamContext *context,
|
|
const std::string &name, const std::string &description,
|
|
const char **_map, int _num_values,
|
|
ENUM dfltValue)
|
|
: EnumParam<const char *>(context, name, description,
|
|
_map, _num_values, (int)dfltValue)
|
|
{
|
|
}
|
|
|
|
SimpleEnumParam(ParamContext *context,
|
|
const std::string &name, const std::string &description,
|
|
const char **_map, int _num_values)
|
|
: EnumParam<const char *>(context, name, description,
|
|
_map, _num_values)
|
|
{
|
|
}
|
|
|
|
operator ENUM() const
|
|
{
|
|
if (!isValid())
|
|
die("not found");
|
|
return (ENUM)value;
|
|
}
|
|
};
|
|
|
|
|
|
// Specialize EnumParam for a particular enumeration type ENUM
|
|
// (automates casting to get value of enum type)
|
|
|
|
template <class ENUM>
|
|
class SimpleEnumVectorParam : public EnumVectorParam<const char *>
|
|
{
|
|
public:
|
|
|
|
// skip default value constructor: too much pain to convert
|
|
// vector<ENUM> initializer to vector<int>
|
|
|
|
|
|
SimpleEnumVectorParam(ParamContext *context,
|
|
const std::string &name,
|
|
const std::string &description,
|
|
const char **_map, int _num_values)
|
|
: EnumVectorParam<const char *>(context, name, description,
|
|
_map, _num_values)
|
|
{
|
|
}
|
|
|
|
ENUM operator[](size_type n)
|
|
{
|
|
if (!isValid())
|
|
die("not found");
|
|
return (ENUM)value[n];
|
|
}
|
|
};
|
|
|
|
|
|
//
|
|
// Handle enums via string-to-int map (see comment above).
|
|
//
|
|
|
|
// An array of string-to-int mappings must be supplied using the
|
|
// following type.
|
|
typedef struct {
|
|
const char *name;
|
|
int value;
|
|
} EnumParamMap;
|
|
|
|
// Specialize EnumParam for a particular enumeration type ENUM
|
|
// (automates casting to get value of enum type)
|
|
|
|
template <class ENUM>
|
|
class MappedEnumParam : public EnumParam<EnumParamMap>
|
|
{
|
|
public:
|
|
|
|
MappedEnumParam(ParamContext *context,
|
|
const std::string &name, const std::string &description,
|
|
const EnumParamMap *_map, int _num_values,
|
|
ENUM dfltValue)
|
|
: EnumParam<EnumParamMap>(context, name, description,
|
|
_map, _num_values, (int)dfltValue)
|
|
{
|
|
}
|
|
|
|
MappedEnumParam(ParamContext *context,
|
|
const std::string &name, const std::string &description,
|
|
const EnumParamMap *_map, int _num_values)
|
|
: EnumParam<EnumParamMap>(context, name, description,
|
|
_map, _num_values)
|
|
{
|
|
}
|
|
|
|
operator ENUM()
|
|
{
|
|
if (!isValid())
|
|
die("not found");
|
|
return (ENUM)value[n];
|
|
}
|
|
};
|
|
|
|
|
|
// Specialize EnumParam for a particular enumeration type ENUM
|
|
// (automates casting to get value of enum type)
|
|
|
|
template <class ENUM>
|
|
class MappedEnumVectorParam : public EnumVectorParam<EnumParamMap>
|
|
{
|
|
public:
|
|
|
|
// skip default value constructor: too much pain to convert
|
|
// vector<ENUM> initializer to vector<int>
|
|
|
|
|
|
MappedEnumVectorParam(ParamContext *context,
|
|
const std::string &name,
|
|
const std::string &description,
|
|
const EnumParamMap *_map, int _num_values)
|
|
: EnumVectorParam<EnumParamMap>(context, name, description,
|
|
_map, _num_values)
|
|
{
|
|
}
|
|
|
|
ENUM operator[](size_type n)
|
|
{
|
|
if (!isValid())
|
|
die("not found");
|
|
return (ENUM)value[n];
|
|
}
|
|
};
|
|
|
|
|
|
//
|
|
// Parameters that point to other simulation objects (e.g. caches,
|
|
// busses, etc.) are handled by specializing SimObjectBaseParam to the
|
|
// specific subtype. The main purpose of SimObjectBaseParam is to
|
|
// provide a place to stick several helper functions common to all
|
|
// SimObject-derived parameters.
|
|
//
|
|
class SimObjectBaseParam : public BaseParam
|
|
{
|
|
public:
|
|
|
|
SimObjectBaseParam(ParamContext *context, const std::string &name,
|
|
const std::string &description, bool hasDefault)
|
|
: BaseParam(context, name, description, hasDefault)
|
|
{
|
|
}
|
|
|
|
virtual ~SimObjectBaseParam() {}
|
|
|
|
// helper function for SimObjectParam<T>::showValue()
|
|
void showValue(std::ostream &os, SimObject *obj) const;
|
|
|
|
// helper function for SimObjectParam<T>::parse()
|
|
void parse(const std::string &s, SimObject *&value);
|
|
|
|
// helper function for SimObjectParam<T>::parse()
|
|
void parse(const std::string &s, std::vector<SimObject *>&value_vec);
|
|
};
|
|
|
|
|
|
//
|
|
// Parameter to a specific type of SimObject. Note that T must be a
|
|
// pointer to a class derived from SimObject (e.g., <CPU *>).
|
|
//
|
|
|
|
template <class T> class SimObjectParam;
|
|
|
|
template <class T>
|
|
class SimObjectParam<T *> : public SimObjectBaseParam
|
|
{
|
|
protected:
|
|
|
|
T *value;
|
|
|
|
public:
|
|
|
|
// initialization w/o default
|
|
SimObjectParam(ParamContext *context,
|
|
const std::string &name, const std::string &description)
|
|
: SimObjectBaseParam(context, name, description, false)
|
|
{
|
|
}
|
|
|
|
// initialization wit=h default
|
|
SimObjectParam(ParamContext *context,
|
|
const std::string &name, const std::string &description,
|
|
T *dfltValue)
|
|
: SimObjectBaseParam(context, name, description, true),
|
|
value(dfltValue)
|
|
{
|
|
}
|
|
|
|
virtual ~SimObjectParam() {}
|
|
|
|
// convert to pointer
|
|
operator T*()
|
|
{
|
|
if (!isValid())
|
|
die("not found");
|
|
return value;
|
|
}
|
|
|
|
T *operator->() const
|
|
{
|
|
if (!isValid())
|
|
die("not found");
|
|
return value;
|
|
}
|
|
|
|
// display value to stream
|
|
virtual void showValue(std::ostream &os) const
|
|
{
|
|
SimObjectBaseParam::showValue(os, value);
|
|
}
|
|
|
|
// display type to stream: see REGISTER_SIM_OBJECT macro in
|
|
// sim_object.hh for declaration
|
|
virtual void showType(std::ostream &os) const;
|
|
|
|
// set value by parsing string
|
|
virtual void parse(const std::string &s)
|
|
{
|
|
SimObject *so_ptr;
|
|
// first parse to generic SimObject *
|
|
SimObjectBaseParam::parse(s, so_ptr);
|
|
// now dynamic_cast to specific derived type
|
|
value = dynamic_cast<T *>(so_ptr);
|
|
// check for failure of dynamic_cast
|
|
if (value == NULL && so_ptr != NULL)
|
|
die("not of appropriate type");
|
|
}
|
|
};
|
|
|
|
|
|
//
|
|
// Vector counterpart to SimObjectParam<T>
|
|
//
|
|
|
|
template <class T> class SimObjectVectorParam;
|
|
|
|
template <class T>
|
|
class SimObjectVectorParam<T *> : public SimObjectBaseParam
|
|
{
|
|
protected:
|
|
|
|
std::vector<T *> value;
|
|
|
|
public:
|
|
|
|
typedef typename std::vector<T *>::size_type size_type;
|
|
|
|
SimObjectVectorParam(ParamContext *context,
|
|
const std::string &name,
|
|
const std::string &description)
|
|
: SimObjectBaseParam(context, name, description, false)
|
|
{
|
|
}
|
|
|
|
SimObjectVectorParam(ParamContext *context,
|
|
const std::string &name,
|
|
const std::string &description,
|
|
std::vector<T *> dfltValue)
|
|
: SimObjectBaseParam(context, name, description, true),
|
|
value(dfltValue)
|
|
{
|
|
}
|
|
|
|
virtual ~SimObjectVectorParam() {}
|
|
|
|
// basic vector access methods
|
|
size_type size() const
|
|
{
|
|
if (!isValid())
|
|
die("not found");
|
|
return value.size();
|
|
}
|
|
|
|
T *&operator[](size_type n)
|
|
{
|
|
if (!isValid())
|
|
die("not found");
|
|
return value[n];
|
|
}
|
|
|
|
// return reference to value vector
|
|
operator std::vector<T *>&()
|
|
{
|
|
if (!isValid())
|
|
die("not found");
|
|
return value;
|
|
}
|
|
|
|
// display value to stream
|
|
virtual void showValue(std::ostream &os) const
|
|
{
|
|
for (int i = 0; i < value.size(); i++) {
|
|
if (i != 0)
|
|
os << " ";
|
|
SimObjectBaseParam::showValue(os, value[i]);
|
|
}
|
|
}
|
|
|
|
// display type to stream: see
|
|
virtual void showType(std::ostream &os) const;
|
|
|
|
// set value by parsing string
|
|
virtual void parse(const std::string &s)
|
|
{
|
|
std::vector<SimObject *> so_ptr_vec;
|
|
// first parse to generic SimObject * vector (from SimObjectBaseParam)
|
|
SimObjectBaseParam::parse(s, so_ptr_vec);
|
|
|
|
value.resize(so_ptr_vec.size());
|
|
|
|
for (int i = 0; i < so_ptr_vec.size(); ++i) {
|
|
// now dynamic_cast to specific derived type
|
|
value[i] = dynamic_cast<T *>(so_ptr_vec[i]);
|
|
// check for failure of dynamic_cast
|
|
if (value[i] == NULL && so_ptr_vec[i] != NULL)
|
|
die("not of appropriate type");
|
|
}
|
|
}
|
|
};
|
|
|
|
//
|
|
// Macro to define showType() methods for SimObjectParam &
|
|
// SimObjectVectorParam. Can't do this automatically as it requires a
|
|
// string name for the type, which you can't get from a template
|
|
// argument. For concrete derived SimObject types, this macro is
|
|
// automatically invoked by REGISTER_SIM_OBJECT() (see sim_object.hh).
|
|
//
|
|
#define DEFINE_SIM_OBJECT_CLASS_NAME(CLASS_NAME, OBJ_CLASS) \
|
|
void \
|
|
SimObjectParam<OBJ_CLASS *>::showType(std::ostream &os) const \
|
|
{ \
|
|
os << CLASS_NAME; \
|
|
} \
|
|
\
|
|
void \
|
|
SimObjectVectorParam<OBJ_CLASS *>::showType(std::ostream &os) const \
|
|
{ \
|
|
os << "vector of " << CLASS_NAME; \
|
|
}
|
|
|
|
|
|
//
|
|
// Declarations for low-level parsing & displaying functions. These
|
|
// are used internally, but should not be used directly by clients of
|
|
// the parameter mechanism, but are declared here so they can be
|
|
// shared with the serialization code (see sim/serialize.cc).
|
|
template <class T> bool parseParam(const std::string &str, T &data);
|
|
template <class T> void showParam(std::ostream &os, const T &data);
|
|
|
|
#endif // _PARAM_HH
|