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_objdecls' : types.ListType, |
132 'swig_predecls' : types.ListType, 133 'type' : types.StringType } 134 # Attributes that can be set any time 135 keywords = { 'check' : types.FunctionType } 136 137 # __new__ is called before __init__, and is where the statements 138 # in the body of the class definition get loaded into the class's 139 # __dict__. We intercept this to filter out parameter & port assignments --- 81 unchanged lines hidden (view full) --- 221 cls._value_dict['cxx_predecls'] = [decl] 222 223 if 'swig_predecls' not in cls._value_dict: 224 # A forward class declaration is sufficient since we are 225 # just declaring a pointer. 226 cls._value_dict['swig_predecls'] = \ 227 cls._value_dict['cxx_predecls'] 228 |
229 if 'swig_objdecls' not in cls._value_dict: 230 cls._value_dict['swig_objdecls'] = [] 231 |
232 # Now process the _value_dict items. They could be defining 233 # new (or overriding existing) parameters or ports, setting 234 # class keywords (e.g., 'abstract'), or setting parameter 235 # values or port bindings. The first 3 can only be set when 236 # the class is defined, so we handle them here. The others 237 # can be set later too, so just emulate that by calling 238 # setattr(). 239 for key,val in cls._value_dict.items(): --- 104 unchanged lines hidden (view full) --- 344 return cls._values[attr] 345 346 raise AttributeError, \ 347 "object '%s' has no attribute '%s'" % (cls.__name__, attr) 348 349 def __str__(cls): 350 return cls.__name__ 351 |
352 def get_base(cls): 353 if str(cls) == 'SimObject': 354 return None |
355 |
356 return cls.__bases__[0].type 357 358 def cxx_decl(cls): |
359 code = "#ifndef __PARAMS__%s\n" % cls 360 code += "#define __PARAMS__%s\n\n" % cls 361 362 # The 'dict' attribute restricts us to the params declared in 363 # the object itself, not including inherited params (which 364 # will also be inherited from the base class's param struct 365 # here). 366 params = cls._params.local.values() --- 13 unchanged lines hidden (view full) --- 380 predecls2 = [] 381 for pd in predecls: 382 if pd not in predecls2: 383 predecls2.append(pd) 384 predecls2.sort() 385 code += "\n".join(predecls2) 386 code += "\n\n"; 387 |
388 base = cls.get_base() |
389 if base: 390 code += '#include "params/%s.hh"\n\n' % base 391 392 for ptype in ptypes: 393 if issubclass(ptype, Enum): 394 code += '#include "enums/%s.hh"\n' % ptype.__name__ 395 code += "\n\n" 396 --- 12 unchanged lines hidden (view full) --- 409 code += "".join([" %s\n" % d for d in decls]) 410 code += "};\n" 411 412 # close #ifndef __PARAMS__* guard 413 code += "\n#endif\n" 414 return code 415 416 def cxx_type_decl(cls): |
417 base = cls.get_base() |
418 code = '' 419 420 if base: 421 code += '#include "%s_type.h"\n' % base 422 423 # now generate dummy code for inheritance 424 code += "struct %s" % cls.cxx_class 425 if base: 426 code += " : public %s" % base.cxx_class 427 code += "\n{};\n" 428 429 return code 430 431 def swig_decl(cls): |
432 base = cls.get_base() 433 |
434 code = '%%module %s\n' % cls 435 436 code += '%{\n' 437 code += '#include "params/%s.hh"\n' % cls 438 code += '%}\n\n' 439 |
440 # The 'dict' attribute restricts us to the params declared in 441 # the object itself, not including inherited params (which 442 # will also be inherited from the base class's param struct 443 # here). 444 params = cls._params.local.values() 445 ptypes = [p.ptype for p in params] 446 447 # get a list of lists of predeclaration lines --- 29 unchanged lines hidden (view full) --- 477class SimObject(object): 478 # Specify metaclass. Any class inheriting from SimObject will 479 # get this metaclass. 480 __metaclass__ = MetaSimObject 481 type = 'SimObject' 482 abstract = True 483 484 name = Param.String("Object name") |
485 swig_objdecls = [ '%include "python/swig/sim_object.i"' ] |
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 params = self.getCCParams() 796 if not self._ccObject: 797 self._ccObject = -1 # flag to catch cycles in recursion 798 self._ccObject = params.create() 799 elif self._ccObject == -1: 800 raise RuntimeError, "%s: recursive call to getCCObject()" \ 801 % self.path() 802 return self._ccObject --- 31 unchanged lines hidden (view full) --- 834 self._ccObject.resume() 835 for child in self._children.itervalues(): 836 child.resume() 837 838 def getMemoryMode(self): 839 if not isinstance(self, m5.objects.System): 840 return None 841 |
842 return self._ccObject.getMemoryMode() |
843 844 def changeTiming(self, mode): |
845 if isinstance(self, m5.objects.System): 846 # i don't know if there's a better way to do this - calling 847 # setMemoryMode directly from self._ccObject results in calling 848 # SimObject::setMemoryMode, not the System::setMemoryMode |
849 self._ccObject.setMemoryMode(mode) |
850 for child in self._children.itervalues(): 851 child.changeTiming(mode) 852 853 def takeOverFrom(self, old_cpu): |
854 self._ccObject.takeOverFrom(old_cpu._ccObject) |
855 856 # generate output file for 'dot' to display as a pretty graph. 857 # this code is currently broken. 858 def outputDot(self, dot): 859 label = "{%s|" % self.path 860 if isSimObject(self.realtype): 861 label += '%s|' % self.type 862 --- 45 unchanged lines hidden --- |