144c144,147
< keywords = { 'check' : types.FunctionType }
---
> keywords = { 'check' : types.FunctionType,
> 'cxx_type' : types.StringType,
> 'cxx_predecls' : types.ListType,
> 'swig_predecls' : types.ListType }
226a230,235
> cls.cxx_type = cls.type + '*'
> # A forward class declaration is sufficient since we are just
> # declaring a pointer.
> cls.cxx_predecls = ['class %s;' % cls.type]
> cls.swig_predecls = cls.cxx_predecls
>
235,238c244,250
< def _new_param(cls, name, value):
< cls._params[name] = value
< if hasattr(value, 'default'):
< setattr(cls, name, value.default)
---
> def _new_param(cls, name, pdesc):
> # each param desc should be uniquely assigned to one variable
> assert(not hasattr(pdesc, 'name'))
> pdesc.name = name
> cls._params[name] = pdesc
> if hasattr(pdesc, 'default'):
> setattr(cls, name, pdesc.default)
285a298,395
> def __str__(cls):
> return cls.__name__
>
> def cxx_decl(cls):
> code = "#ifndef __PARAMS__%s\n#define __PARAMS__%s\n\n" % (cls, cls)
>
> if str(cls) != 'SimObject':
> base = cls.__bases__[0].type
> else:
> base = None
>
> # The 'dict' attribute restricts us to the params declared in
> # the object itself, not including inherited params (which
> # will also be inherited from the base class's param struct
> # here).
> params = cls._params.dict.values()
> try:
> ptypes = [p.ptype for p in params]
> except:
> print cls, p, p.ptype_str
> print params
> raise
>
> # get a list of lists of predeclaration lines
> predecls = [p.cxx_predecls() for p in params]
> # flatten
> predecls = reduce(lambda x,y:x+y, predecls, [])
> # remove redundant lines
> predecls2 = []
> for pd in predecls:
> if pd not in predecls2:
> predecls2.append(pd)
> predecls2.sort()
> code += "\n".join(predecls2)
> code += "\n\n";
>
> if base:
> code += '#include "params/%s.hh"\n\n' % base
>
> # Generate declarations for locally defined enumerations.
> enum_ptypes = [t for t in ptypes if issubclass(t, Enum)]
> if enum_ptypes:
> code += "\n".join([t.cxx_decl() for t in enum_ptypes])
> code += "\n\n"
>
> # now generate the actual param struct
> code += "struct %sParams" % cls
> if base:
> code += " : public %sParams" % base
> code += " {\n"
> decls = [p.cxx_decl() for p in params]
> decls.sort()
> code += "".join([" %s\n" % d for d in decls])
> code += "};\n"
>
> # close #ifndef __PARAMS__* guard
> code += "\n#endif\n"
> return code
>
> def swig_decl(cls):
>
> code = '%%module %sParams\n' % cls
>
> if str(cls) != 'SimObject':
> base = cls.__bases__[0].type
> else:
> base = None
>
> # The 'dict' attribute restricts us to the params declared in
> # the object itself, not including inherited params (which
> # will also be inherited from the base class's param struct
> # here).
> params = cls._params.dict.values()
> ptypes = [p.ptype for p in params]
>
> # get a list of lists of predeclaration lines
> predecls = [p.swig_predecls() for p in params]
> # flatten
> predecls = reduce(lambda x,y:x+y, predecls, [])
> # remove redundant lines
> predecls2 = []
> for pd in predecls:
> if pd not in predecls2:
> predecls2.append(pd)
> predecls2.sort()
> code += "\n".join(predecls2)
> code += "\n\n";
>
> if base:
> code += '%%import "python/m5/swig/%sParams.i"\n\n' % base
>
> code += '%{\n'
> code += '#include "params/%s.hh"\n' % cls
> code += '%}\n\n'
> code += '%%include "params/%s.hh"\n\n' % cls
>
> return code
>
292a403
> type = 'SimObject'
293a405,406
> name = Param.String("Object name")
>
797a911,913
> cxx_predecls = []
> swig_predecls = []
>
867a984,992
> def cxx_predecls(self):
> return self.ptype.cxx_predecls
>
> def swig_predecls(self):
> return self.ptype.swig_predecls
>
> def cxx_decl(self):
> return '%s %s;' % (self.ptype.cxx_type, self.name)
>
899a1025,1026
> def cxx_predecls(self):
> return ['#include <vector>'] + self.ptype.cxx_predecls
900a1028,1033
> def swig_predecls(self):
> return ['%include "std_vector.i"'] + self.ptype.swig_predecls
>
> def cxx_decl(self):
> return 'std::vector< %s > %s;' % (self.ptype.cxx_type, self.name)
>
929a1063,1071
> # String-valued parameter. Just mixin the ParamValue class
> # with the built-in str class.
> class String(ParamValue,str):
> cxx_type = 'std::string'
> cxx_predecls = ['#include <string>']
> swig_predecls = ['%include "std_string.i"\n' +
> '%apply const std::string& {std::string *};']
> pass
>
978,1016d1119
< class Range(ParamValue):
< type = int # default; can be overridden in subclasses
< def __init__(self, *args, **kwargs):
<
< def handle_kwargs(self, kwargs):
< if 'end' in kwargs:
< self.second = self.type(kwargs.pop('end'))
< elif 'size' in kwargs:
< self.second = self.first + self.type(kwargs.pop('size')) - 1
< else:
< raise TypeError, "Either end or size must be specified"
<
< if len(args) == 0:
< self.first = self.type(kwargs.pop('start'))
< handle_kwargs(self, kwargs)
<
< elif len(args) == 1:
< if kwargs:
< self.first = self.type(args[0])
< handle_kwargs(self, kwargs)
< elif isinstance(args[0], Range):
< self.first = self.type(args[0].first)
< self.second = self.type(args[0].second)
< else:
< self.first = self.type(0)
< self.second = self.type(args[0]) - 1
<
< elif len(args) == 2:
< self.first = self.type(args[0])
< self.second = self.type(args[1])
< else:
< raise TypeError, "Too many arguments specified"
<
< if kwargs:
< raise TypeError, "too many keywords: %s" % kwargs.keys()
<
< def __str__(self):
< return '%s:%s' % (self.first, self.second)
<
1027a1131,1139
> if not cls.cxx_predecls:
> # most derived types require this, so we just do it here once
> cls.cxx_predecls = ['#include "sim/host.hh"']
>
> if not cls.swig_predecls:
> # most derived types require this, so we just do it here once
> cls.swig_predecls = ['%import "python/m5/swig/stdint.i"\n' +
> '%import "sim/host.hh"']
>
1059,1060c1171,1172
< class Int(CheckedInt): size = 32; unsigned = False
< class Unsigned(CheckedInt): size = 32; unsigned = True
---
> class Int(CheckedInt): cxx_type = 'int'; size = 32; unsigned = False
> class Unsigned(CheckedInt): cxx_type = 'unsigned'; size = 32; unsigned = True
1062,1069c1174,1181
< class Int8(CheckedInt): size = 8; unsigned = False
< class UInt8(CheckedInt): size = 8; unsigned = True
< class Int16(CheckedInt): size = 16; unsigned = False
< class UInt16(CheckedInt): size = 16; unsigned = True
< class Int32(CheckedInt): size = 32; unsigned = False
< class UInt32(CheckedInt): size = 32; unsigned = True
< class Int64(CheckedInt): size = 64; unsigned = False
< class UInt64(CheckedInt): size = 64; unsigned = True
---
> class Int8(CheckedInt): cxx_type = 'int8_t'; size = 8; unsigned = False
> class UInt8(CheckedInt): cxx_type = 'uint8_t'; size = 8; unsigned = True
> class Int16(CheckedInt): cxx_type = 'int16_t'; size = 16; unsigned = False
> class UInt16(CheckedInt): cxx_type = 'uint16_t'; size = 16; unsigned = True
> class Int32(CheckedInt): cxx_type = 'int32_t'; size = 32; unsigned = False
> class UInt32(CheckedInt): cxx_type = 'uint32_t'; size = 32; unsigned = True
> class Int64(CheckedInt): cxx_type = 'int64_t'; size = 64; unsigned = False
> class UInt64(CheckedInt): cxx_type = 'uint64_t'; size = 64; unsigned = True
1071,1074c1183,1186
< class Counter(CheckedInt): size = 64; unsigned = True
< class Tick(CheckedInt): size = 64; unsigned = True
< class TcpPort(CheckedInt): size = 16; unsigned = True
< class UdpPort(CheckedInt): size = 16; unsigned = True
---
> class Counter(CheckedInt): cxx_type = 'Counter'; size = 64; unsigned = True
> class Tick(CheckedInt): cxx_type = 'Tick'; size = 64; unsigned = True
> class TcpPort(CheckedInt): cxx_type = 'uint16_t'; size = 16; unsigned = True
> class UdpPort(CheckedInt): cxx_type = 'uint16_t'; size = 16; unsigned = True
1076c1188
< class Percent(CheckedInt): min = 0; max = 100
---
> class Percent(CheckedInt): cxx_type = 'int'; min = 0; max = 100
1081a1194
> cxx_type = 'uint64_t'
1101a1215,1216
> cxx_type = 'Addr'
> cxx_predecls = ['#include "targetarch/isa_traits.hh"']
1113a1229,1277
>
> class MetaRange(type):
> def __init__(cls, name, bases, dict):
> super(MetaRange, cls).__init__(name, bases, dict)
> if name == 'Range':
> return
> cls.cxx_type = 'Range< %s >' % cls.type.cxx_type
> cls.cxx_predecls = \
> ['#include "base/range.hh"'] + cls.type.cxx_predecls
>
> class Range(ParamValue):
> __metaclass__ = MetaRange
> type = Int # default; can be overridden in subclasses
> def __init__(self, *args, **kwargs):
> def handle_kwargs(self, kwargs):
> if 'end' in kwargs:
> self.second = self.type(kwargs.pop('end'))
> elif 'size' in kwargs:
> self.second = self.first + self.type(kwargs.pop('size')) - 1
> else:
> raise TypeError, "Either end or size must be specified"
>
> if len(args) == 0:
> self.first = self.type(kwargs.pop('start'))
> handle_kwargs(self, kwargs)
>
> elif len(args) == 1:
> if kwargs:
> self.first = self.type(args[0])
> handle_kwargs(self, kwargs)
> elif isinstance(args[0], Range):
> self.first = self.type(args[0].first)
> self.second = self.type(args[0].second)
> else:
> self.first = self.type(0)
> self.second = self.type(args[0]) - 1
>
> elif len(args) == 2:
> self.first = self.type(args[0])
> self.second = self.type(args[1])
> else:
> raise TypeError, "Too many arguments specified"
>
> if kwargs:
> raise TypeError, "too many keywords: %s" % kwargs.keys()
>
> def __str__(self):
> return '%s:%s' % (self.first, self.second)
>
1117,1120c1281,1282
< # String-valued parameter. Just mixin the ParamValue class
< # with the built-in str class.
< class String(ParamValue,str):
< pass
---
> class TickRange(Range):
> type = Tick
1125a1288
> cxx_type = 'bool'
1159a1323,1325
> cxx_type = 'Net::EthAddr'
> cxx_predecls = ['#include "base/inet.hh"']
> swig_predecls = ['class Net::EthAddr;']
1255a1422,1423
> cls.cxx_type = name + '::Enum'
>
1258,1259c1426,1430
< def cpp_declare(cls):
< s = 'enum %s {\n ' % cls.__name__
---
> # Generate C++ class declaration for this enum type.
> # Note that we wrap the enum in a class/struct to act as a namespace,
> # so that the enum strings can be brief w/o worrying about collisions.
> def cxx_decl(cls):
> s = 'struct %s {\n enum Enum {\n ' % cls.__name__
1261c1432
< s += '\n};\n'
---
> s += '\n };\n};\n'
1312a1484,1487
> cxx_type = 'Tick'
> cxx_predecls = ['#include "sim/host.hh"']
> swig_predecls = ['%import "python/m5/swig/stdint.i"\n' +
> '%import "sim/host.hh"']
1327a1503,1506
> cxx_type = 'Tick'
> cxx_predecls = ['#include "sim/host.hh"']
> swig_predecls = ['%import "python/m5/swig/stdint.i"\n' +
> '%import "sim/host.hh"']
1345a1525,1528
> cxx_type = 'Tick'
> cxx_predecls = ['#include "sim/host.hh"']
> swig_predecls = ['%import "python/m5/swig/stdint.i"\n' +
> '%import "sim/host.hh"']
1362a1546,1549
> cxx_type = 'Tick'
> cxx_predecls = ['#include "sim/host.hh"']
> swig_predecls = ['%import "python/m5/swig/stdint.i"\n' +
> '%import "sim/host.hh"']
1376a1564
> cxx_type = 'float'
1387a1576
> cxx_type = 'float'
1523c1712,1713
< 'Range', 'AddrRange', 'MaxAddr', 'MaxTick', 'AllMemory',
---
> 'Range', 'AddrRange', 'TickRange',
> 'MaxAddr', 'MaxTick', 'AllMemory',