Deleted Added
sdiff udiff text old ( 4762:c94e103c83ad ) new ( 4859:97c7749896a6 )
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

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

123# class are instantiated, and provides inherited instance behavior).
124class MetaSimObject(type):
125 # Attributes that can be set only at initialization time
126 init_keywords = { 'abstract' : types.BooleanType,
127 'cxx_namespace' : types.StringType,
128 'cxx_class' : types.StringType,
129 'cxx_type' : types.StringType,
130 'cxx_predecls' : types.ListType,
131 'swig_predecls' : types.ListType,
132 'type' : types.StringType }
133 # Attributes that can be set any time
134 keywords = { 'check' : types.FunctionType }
135
136 # __new__ is called before __init__, and is where the statements
137 # in the body of the class definition get loaded into the class's
138 # __dict__. We intercept this to filter out parameter & port assignments

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

220 cls._value_dict['cxx_predecls'] = [decl]
221
222 if 'swig_predecls' not in cls._value_dict:
223 # A forward class declaration is sufficient since we are
224 # just declaring a pointer.
225 cls._value_dict['swig_predecls'] = \
226 cls._value_dict['cxx_predecls']
227
228 # Now process the _value_dict items. They could be defining
229 # new (or overriding existing) parameters or ports, setting
230 # class keywords (e.g., 'abstract'), or setting parameter
231 # values or port bindings. The first 3 can only be set when
232 # the class is defined, so we handle them here. The others
233 # can be set later too, so just emulate that by calling
234 # setattr().
235 for key,val in cls._value_dict.items():

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

340 return cls._values[attr]
341
342 raise AttributeError, \
343 "object '%s' has no attribute '%s'" % (cls.__name__, attr)
344
345 def __str__(cls):
346 return cls.__name__
347
348 def cxx_decl(cls):
349 if str(cls) != 'SimObject':
350 base = cls.__bases__[0].type
351 else:
352 base = None
353
354 code = "#ifndef __PARAMS__%s\n" % cls
355 code += "#define __PARAMS__%s\n\n" % cls
356
357 # The 'dict' attribute restricts us to the params declared in
358 # the object itself, not including inherited params (which
359 # will also be inherited from the base class's param struct
360 # here).
361 params = cls._params.local.values()

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

375 predecls2 = []
376 for pd in predecls:
377 if pd not in predecls2:
378 predecls2.append(pd)
379 predecls2.sort()
380 code += "\n".join(predecls2)
381 code += "\n\n";
382
383 if base:
384 code += '#include "params/%s.hh"\n\n' % base
385
386 for ptype in ptypes:
387 if issubclass(ptype, Enum):
388 code += '#include "enums/%s.hh"\n' % ptype.__name__
389 code += "\n\n"
390

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

403 code += "".join([" %s\n" % d for d in decls])
404 code += "};\n"
405
406 # close #ifndef __PARAMS__* guard
407 code += "\n#endif\n"
408 return code
409
410 def cxx_type_decl(cls):
411 if str(cls) != 'SimObject':
412 base = cls.__bases__[0]
413 else:
414 base = None
415
416 code = ''
417
418 if base:
419 code += '#include "%s_type.h"\n' % base
420
421 # now generate dummy code for inheritance
422 code += "struct %s" % cls.cxx_class
423 if base:
424 code += " : public %s" % base.cxx_class
425 code += "\n{};\n"
426
427 return code
428
429 def swig_decl(cls):
430 code = '%%module %s\n' % cls
431
432 code += '%{\n'
433 code += '#include "params/%s.hh"\n' % cls
434 code += '%}\n\n'
435
436 if str(cls) != 'SimObject':
437 base = cls.__bases__[0]
438 else:
439 base = None
440
441 # The 'dict' attribute restricts us to the params declared in
442 # the object itself, not including inherited params (which
443 # will also be inherited from the base class's param struct
444 # here).
445 params = cls._params.local.values()
446 ptypes = [p.ptype for p in params]
447
448 # get a list of lists of predeclaration lines

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

478class SimObject(object):
479 # Specify metaclass. Any class inheriting from SimObject will
480 # get this metaclass.
481 __metaclass__ = MetaSimObject
482 type = 'SimObject'
483 abstract = True
484
485 name = Param.String("Object name")
486
487 # Initialize new instance. For objects with SimObject-valued
488 # children, we need to recursively clone the classes represented
489 # by those param values as well in a consistent "deep copy"-style
490 # fashion. That is, we want to make sure that each instance is
491 # cloned only once, and that if there are multiple references to
492 # the same original object, we end up with the corresponding
493 # cloned references all pointing to the same cloned instance.

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

787 setattr(cc_params, port_name, port)
788 self._ccParams = cc_params
789 return self._ccParams
790
791 # Get C++ object corresponding to this object, calling C++ if
792 # necessary to construct it. Does *not* recursively create
793 # children.
794 def getCCObject(self):
795 import internal
796 params = self.getCCParams()
797 if not self._ccObject:
798 self._ccObject = -1 # flag to catch cycles in recursion
799 self._ccObject = params.create()
800 elif self._ccObject == -1:
801 raise RuntimeError, "%s: recursive call to getCCObject()" \
802 % self.path()
803 return self._ccObject

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

835 self._ccObject.resume()
836 for child in self._children.itervalues():
837 child.resume()
838
839 def getMemoryMode(self):
840 if not isinstance(self, m5.objects.System):
841 return None
842
843 system_ptr = internal.sim_object.convertToSystemPtr(self._ccObject)
844 return system_ptr.getMemoryMode()
845
846 def changeTiming(self, mode):
847 import internal
848 if isinstance(self, m5.objects.System):
849 # i don't know if there's a better way to do this - calling
850 # setMemoryMode directly from self._ccObject results in calling
851 # SimObject::setMemoryMode, not the System::setMemoryMode
852 system_ptr = internal.sim_object.convertToSystemPtr(self._ccObject)
853 system_ptr.setMemoryMode(mode)
854 for child in self._children.itervalues():
855 child.changeTiming(mode)
856
857 def takeOverFrom(self, old_cpu):
858 import internal
859 cpu_ptr = internal.sim_object.convertToBaseCPUPtr(old_cpu._ccObject)
860 self._ccObject.takeOverFrom(cpu_ptr)
861
862 # generate output file for 'dot' to display as a pretty graph.
863 # this code is currently broken.
864 def outputDot(self, dot):
865 label = "{%s|" % self.path
866 if isSimObject(self.realtype):
867 label += '%s|' % self.type
868

--- 45 unchanged lines hidden ---