diff options
author | Ali Saidi <saidi@eecs.umich.edu> | 2005-11-02 14:56:18 -0500 |
---|---|---|
committer | Ali Saidi <saidi@eecs.umich.edu> | 2005-11-02 14:56:18 -0500 |
commit | 3b66cb49ecf29e762f4659ed174ca76b8f553a1e (patch) | |
tree | b8f29795c7abf7c93882881252aff716fb33ee02 /python/m5/config.py | |
parent | 0523736b96b2779f8a33c2315c94be55d0a4d9c7 (diff) | |
parent | a0829a7780b110a912ffc250d424b6dfe3586e62 (diff) | |
download | gem5-3b66cb49ecf29e762f4659ed174ca76b8f553a1e.tar.xz |
Merge zizzer:/bk/m5
into zeep.eecs.umich.edu:/z/saidi/work/m5
--HG--
extra : convert_revision : 3cc23080d19cc464a8ba7c1c93b6e5d45af7d463
Diffstat (limited to 'python/m5/config.py')
-rw-r--r-- | python/m5/config.py | 103 |
1 files changed, 61 insertions, 42 deletions
diff --git a/python/m5/config.py b/python/m5/config.py index 3c49421d3..e1970e672 100644 --- a/python/m5/config.py +++ b/python/m5/config.py @@ -755,7 +755,7 @@ class ParamDesc(object): class VectorParamValue(list): def ini_str(self): - return ' '.join([str(v) for v in self]) + return ' '.join([v.ini_str() for v in self]) def unproxy(self, base): return [v.unproxy(base) for v in self] @@ -825,6 +825,40 @@ VectorParam = ParamFactory(VectorParamDesc) # ##################################################################### +# superclass for "numeric" parameter values, to emulate math +# operations in a type-safe way. e.g., a Latency times an int returns +# a new Latency object. +class NumericParamValue(ParamValue): + def __str__(self): + return str(self.value) + + def __float__(self): + return float(self.value) + + # hook for bounds checking + def _check(self): + return + + def __mul__(self, other): + newobj = self.__class__(self) + newobj.value *= other + newobj._check() + return newobj + + __rmul__ = __mul__ + + def __div__(self, other): + newobj = self.__class__(self) + newobj.value /= other + newobj._check() + return newobj + + def __sub__(self, other): + newobj = self.__class__(self) + newobj.value -= other + newobj._check() + return newobj + class Range(ParamValue): type = int # default; can be overridden in subclasses def __init__(self, *args, **kwargs): @@ -891,19 +925,20 @@ class CheckedIntType(type): # class is subclassed to generate parameter classes with specific # bounds. Initialization of the min and max bounds is done in the # metaclass CheckedIntType.__init__. -class CheckedInt(long,ParamValue): +class CheckedInt(NumericParamValue): __metaclass__ = CheckedIntType - def __new__(cls, value): - if isinstance(value, str): - value = toInteger(value) - - self = long.__new__(cls, value) - - if not cls.min <= self <= cls.max: + def _check(self): + if not self.min <= self.value <= self.max: raise TypeError, 'Integer param out of bounds %d < %d < %d' % \ - (cls.min, self, cls.max) - return self + (self.min, self.value, self.max) + + def __init__(self, value): + if isinstance(value, str): + self.value = toInteger(value) + elif isinstance(value, (int, long)): + self.value = long(value) + self._check() class Int(CheckedInt): size = 32; unsigned = False class Unsigned(CheckedInt): size = 32; unsigned = True @@ -930,19 +965,26 @@ class Float(ParamValue, float): class MemorySize(CheckedInt): size = 64 unsigned = True - def __new__(cls, value): - return super(MemorySize, cls).__new__(cls, toMemorySize(value)) + def __init__(self, value): + if isinstance(value, MemorySize): + self.value = value.value + else: + self.value = toMemorySize(value) + self._check() class Addr(CheckedInt): size = 64 unsigned = True - def __new__(cls, value): - try: - value = long(toMemorySize(value)) - except TypeError: - value = long(value) - return super(Addr, cls).__new__(cls, value) + def __init__(self, value): + if isinstance(value, Addr): + self.value = value.value + else: + try: + self.value = toMemorySize(value) + except TypeError: + self.value = long(value) + self._check() class AddrRange(Range): type = Addr @@ -1123,29 +1165,6 @@ def tick_check(float_ticks): #raise ValueError return int_ticks -# superclass for "numeric" parameter values, to emulate math -# operations in a type-safe way. e.g., a Latency times an int returns -# a new Latency object. -class NumericParamValue(ParamValue): - def __str__(self): - return str(self.value) - - def __float__(self): - return float(self.value) - - def __mul__(self, other): - newobj = self.__class__(self) - newobj.value *= other - return newobj - - __rmul__ = __mul__ - - def __div__(self, other): - newobj = self.__class__(self) - newobj.value /= other - return newobj - - def getLatency(value): if isinstance(value, Latency) or isinstance(value, Clock): return value.value |