Deleted Added
sdiff udiff text old ( 4859:97c7749896a6 ) new ( 5033:2a48ab2b86d5 )
full compact
1# Copyright (c) 2004-2006 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 32 unchanged lines hidden (view full) ---

41# Note that the default values are loaded into the class's attribute
42# space when the parameter dictionary is initialized (in
43# MetaSimObject._new_param()); after that point they aren't used.
44#
45#####################################################################
46
47import copy
48import datetime
49import inspect
50import re
51import sys
52import time
53
54import convert
55import proxy
56import ticks
57from util import *

--- 4 unchanged lines hidden (view full) ---

62 return SimObject.isSimObject(*args, **kwargs)
63
64def isSimObjectSequence(*args, **kwargs):
65 return SimObject.isSimObjectSequence(*args, **kwargs)
66
67def isSimObjectClass(*args, **kwargs):
68 return SimObject.isSimObjectClass(*args, **kwargs)
69
70# Dummy base class to identify types that are legitimate for SimObject
71# parameters.
72class ParamValue(object):
73
74 cxx_predecls = []
75 swig_predecls = []
76
77 # default for printing to .ini file is regular string conversion.
78 # will be overridden in some cases
79 def ini_str(self):
80 return str(self)

--- 33 unchanged lines hidden (view full) ---

114 if kwargs:
115 raise TypeError, 'extra unknown kwargs %s' % kwargs
116
117 if not hasattr(self, 'desc'):
118 raise TypeError, 'desc attribute missing'
119
120 def __getattr__(self, attr):
121 if attr == 'ptype':
122 try:
123 ptype = SimObject.allClasses[self.ptype_str]
124 if not isinstance(ptype, type):
125 raise NameError
126 self.ptype = ptype
127 return ptype
128 except NameError:
129 raise
130 #raise TypeError, \
131 # "Param qualifier '%s' is not a type" % self.ptype_str
132 raise AttributeError, "'%s' object has no attribute '%s'" % \
133 (type(self).__name__, attr)
134
135 def convert(self, value):
136 if isinstance(value, proxy.BaseProxy):
137 value.set_param_desc(self)
138 return value
139 if not hasattr(self, 'ptype') and isNullPointer(value):

--- 15 unchanged lines hidden (view full) ---

155 def cxx_decl(self):
156 return '%s %s;' % (self.ptype.cxx_type, self.name)
157
158# Vector-valued parameter description. Just like ParamDesc, except
159# that the value is a vector (list) of the specified type instead of a
160# single value.
161
162class VectorParamValue(list):
163 def ini_str(self):
164 return ' '.join([v.ini_str() for v in self])
165
166 def getValue(self):
167 return [ v.getValue() for v in self ]
168
169 def unproxy(self, base):
170 return [v.unproxy(base) for v in self]

--- 41 unchanged lines hidden (view full) ---

212
213 def __getattr__(self, attr):
214 if self.ptype_str:
215 attr = self.ptype_str + '.' + attr
216 return ParamFactory(self.param_desc_class, attr)
217
218 # E.g., Param.Int(5, "number of widgets")
219 def __call__(self, *args, **kwargs):
220 caller_frame = inspect.currentframe().f_back
221 ptype = None
222 try:
223 ptype = eval(self.ptype_str,
224 caller_frame.f_globals, caller_frame.f_locals)
225 if not isinstance(ptype, type):
226 raise TypeError, \
227 "Param qualifier is not a type: %s" % ptype
228 except NameError:
229 # if name isn't defined yet, assume it's a SimObject, and
230 # try to resolve it later
231 pass
232 return self.param_desc_class(self.ptype_str, ptype, *args, **kwargs)
233
234Param = ParamFactory(ParamDesc)
235VectorParam = ParamFactory(VectorParamDesc)
236

--- 58 unchanged lines hidden (view full) ---

295
296 def __sub__(self, other):
297 newobj = self.__class__(self)
298 newobj.value -= other
299 newobj._check()
300 return newobj
301
302# Metaclass for bounds-checked integer parameters. See CheckedInt.
303class CheckedIntType(type):
304 def __init__(cls, name, bases, dict):
305 super(CheckedIntType, cls).__init__(name, bases, dict)
306
307 # CheckedInt is an abstract base class, so we actually don't
308 # want to do any processing on it... the rest of this code is
309 # just for classes that derive from CheckedInt.
310 if name == 'CheckedInt':
311 return

--- 107 unchanged lines hidden (view full) ---

419 self._check()
420 def __add__(self, other):
421 if isinstance(other, Addr):
422 return self.value + other.value
423 else:
424 return self.value + other
425
426
427class MetaRange(type):
428 def __init__(cls, name, bases, dict):
429 super(MetaRange, cls).__init__(name, bases, dict)
430 if name == 'Range':
431 return
432 cls.cxx_type = 'Range< %s >' % cls.type.cxx_type
433 cls.cxx_predecls = \
434 ['#include "base/range.hh"'] + cls.type.cxx_predecls
435

--- 224 unchanged lines hidden (view full) ---

660# What Enum() must do is generate a new type encapsulating the
661# provided list/dictionary so that specific values of the parameter
662# can be instances of that type. We define two hidden internal
663# classes (_ListEnum and _DictEnum) to serve as base classes, then
664# derive the new type from the appropriate base class on the fly.
665
666allEnums = {}
667# Metaclass for Enum types
668class MetaEnum(type):
669 def __new__(mcls, name, bases, dict):
670 assert name not in allEnums
671
672 cls = super(MetaEnum, mcls).__new__(mcls, name, bases, dict)
673 allEnums[name] = cls
674 return cls
675
676 def __init__(cls, name, bases, init_dict):

--- 491 unchanged lines hidden ---