Deleted Added
sdiff udiff text old ( 2667:fe64b8353b1c ) new ( 2711:2cbc3999ec58 )
full compact
1# Copyright (c) 2004-2005 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

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

22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Steve Reinhardt
28# Nathan Binkert
29
30from __future__ import generators
31import os, re, sys, types, inspect
32
33import m5
34panic = m5.panic
35from convert import *
36from multidict import multidict
37
38noDot = False
39try:
40 import pydot
41except:
42 noDot = True

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

132# metaclass to define most of the SimObject parameter behavior for
133# this class hierarchy.
134#
135#####################################################################
136
137def isSimObject(value):
138 return isinstance(value, SimObject)
139
140def isSimObjSequence(value):
141 if not isinstance(value, (list, tuple)):
142 return False
143
144 for val in value:
145 if not isNullPointer(val) and not isSimObject(val):
146 return False
147
148 return True
149
150def isNullPointer(value):
151 return isinstance(value, NullSimObject)
152
153# The metaclass for ConfigNode (and thus for everything that derives
154# from ConfigNode, including SimObject). This class controls how new
155# classes that derive from ConfigNode are instantiated, and provides
156# inherited class behavior (just like a class controls how instances
157# of that class are instantiated, and provides inherited instance

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

165 'children' : types.ListType }
166
167 # __new__ is called before __init__, and is where the statements
168 # in the body of the class definition get loaded into the class's
169 # __dict__. We intercept this to filter out parameter assignments
170 # and only allow "private" attributes to be passed to the base
171 # __new__ (starting with underscore).
172 def __new__(mcls, name, bases, dict):
173 # Copy "private" attributes (including special methods such as __new__)
174 # to the official dict. Everything else goes in _init_dict to be
175 # filtered in __init__.
176 cls_dict = {}
177 for key,val in dict.items():
178 if key.startswith('_'):
179 cls_dict[key] = val
180 del dict[key]
181 cls_dict['_init_dict'] = dict
182 return super(MetaSimObject, mcls).__new__(mcls, name, bases, cls_dict)
183
184 # initialization
185 def __init__(cls, name, bases, dict):
186 super(MetaSimObject, cls).__init__(name, bases, dict)
187
188 # initialize required attributes
189 cls._params = multidict()
190 cls._values = multidict()
191 cls._anon_subclass_counter = 0
192
193 # We don't support multiple inheritance. If you want to, you
194 # must fix multidict to deal with it properly.
195 if len(bases) > 1:
196 raise TypeError, "SimObjects do not support multiple inheritance"
197
198 base = bases[0]
199
200 if isinstance(base, MetaSimObject):
201 cls._params.parent = base._params
202 cls._values.parent = base._values
203
204 # If your parent has a value in it that's a config node, clone
205 # it. Do this now so if we update any of the values'
206 # attributes we are updating the clone and not the original.
207 for key,val in base._values.iteritems():
208
209 # don't clone if (1) we're about to overwrite it with
210 # a local setting or (2) we've already cloned a copy
211 # from an earlier (more derived) base
212 if cls._init_dict.has_key(key) or cls._values.has_key(key):
213 continue
214
215 if isSimObject(val):
216 cls._values[key] = val()
217 elif isSimObjSequence(val) and len(val):
218 cls._values[key] = [ v() for v in val ]
219
220 # now process remaining _init_dict items
221 for key,val in cls._init_dict.items():
222 if isinstance(val, (types.FunctionType, types.TypeType)):
223 type.__setattr__(cls, key, val)
224
225 # param descriptions
226 elif isinstance(val, ParamDesc):
227 cls._new_param(key, val)
228
229 # init-time-only keywords
230 elif cls.init_keywords.has_key(key):
231 cls._set_keyword(key, val, cls.init_keywords[key])
232
233 # default: use normal path (ends up in __setattr__)
234 else:
235 setattr(cls, key, val)
236
237 def _set_keyword(cls, keyword, val, kwtype):
238 if not isinstance(val, kwtype):
239 raise TypeError, 'keyword %s has bad type %s (expecting %s)' % \
240 (keyword, type(val), kwtype)
241 if isinstance(val, types.FunctionType):
242 val = classmethod(val)
243 type.__setattr__(cls, keyword, val)
244

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

279
280 def __getattr__(cls, attr):
281 if cls._values.has_key(attr):
282 return cls._values[attr]
283
284 raise AttributeError, \
285 "object '%s' has no attribute '%s'" % (cls.__name__, attr)
286
287# The ConfigNode class is the root of the special hierarchy. Most of
288# the code in this class deals with the configuration hierarchy itself
289# (parent/child node relationships).
290class SimObject(object):
291 # Specify metaclass. Any class inheriting from SimObject will
292 # get this metaclass.
293 __metaclass__ = MetaSimObject
294
295 def __init__(self, _value_parent = None, **kwargs):
296 self._children = {}
297 if _value_parent and type(_value_parent) != type(self):
298 # this was called as a type conversion rather than a clone
299 raise TypeError, "Cannot convert %s to %s" % \
300 (_value_parent.__class__.__name__, self.__class__.__name__)
301 if not _value_parent:
302 _value_parent = self.__class__
303 # clone values
304 self._values = multidict(_value_parent._values)
305 for key,val in _value_parent._values.iteritems():
306 if isSimObject(val):
307 setattr(self, key, val())
308 elif isSimObjSequence(val) and len(val):
309 setattr(self, key, [ v() for v in val ])
310 # apply attribute assignments from keyword args, if any
311 for key,val in kwargs.iteritems():
312 setattr(self, key, val)
313
314 def __call__(self, **kwargs):
315 return self.__class__(_value_parent = self, **kwargs)
316
317 def __getattr__(self, attr):
318 if self._values.has_key(attr):
319 return self._values[attr]
320
321 raise AttributeError, "object '%s' has no attribute '%s'" \
322 % (self.__class__.__name__, attr)
323

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

1064
1065 def unproxy(self, base):
1066 if self.value == NextEthernetAddr:
1067 self.addr = self.value().value
1068 return self
1069
1070 def __str__(self):
1071 if self.value == NextEthernetAddr:
1072 return self.addr
1073 else:
1074 return self.value
1075
1076# Special class for NULL pointers. Note the special check in
1077# make_param_value() above that lets these be assigned where a
1078# SimObject is required.
1079# only one copy of a particular node
1080class NullSimObject(object):

--- 229 unchanged lines hidden ---