SimObject.py (4762:c94e103c83ad) | SimObject.py (4859:97c7749896a6) |
---|---|
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, | 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, |
|
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 | 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 |
|
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 | 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 |
348 def cxx_decl(cls): 349 if str(cls) != 'SimObject': 350 base = cls.__bases__[0].type 351 else: 352 base = None | 352 def get_base(cls): 353 if str(cls) == 'SimObject': 354 return None |
353 | 355 |
356 return cls.__bases__[0].type 357 358 def cxx_decl(cls): |
|
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 | 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() |
|
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): | 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): |
411 if str(cls) != 'SimObject': 412 base = cls.__bases__[0] 413 else: 414 base = None 415 | 417 base = cls.get_base() |
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): | 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 |
|
430 code = '%%module %s\n' % cls 431 432 code += '%{\n' 433 code += '#include "params/%s.hh"\n' % cls 434 code += '%}\n\n' 435 | 434 code = '%%module %s\n' % cls 435 436 code += '%{\n' 437 code += '#include "params/%s.hh"\n' % cls 438 code += '%}\n\n' 439 |
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") | 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): | 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 | 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 |
843 system_ptr = internal.sim_object.convertToSystemPtr(self._ccObject) 844 return system_ptr.getMemoryMode() | 842 return self._ccObject.getMemoryMode() |
845 846 def changeTiming(self, mode): | 843 844 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 | 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 |
852 system_ptr = internal.sim_object.convertToSystemPtr(self._ccObject) 853 system_ptr.setMemoryMode(mode) | 849 self._ccObject.setMemoryMode(mode) |
854 for child in self._children.itervalues(): 855 child.changeTiming(mode) 856 857 def takeOverFrom(self, old_cpu): | 850 for child in self._children.itervalues(): 851 child.changeTiming(mode) 852 853 def takeOverFrom(self, old_cpu): |
858 import internal 859 cpu_ptr = internal.sim_object.convertToBaseCPUPtr(old_cpu._ccObject) 860 self._ccObject.takeOverFrom(cpu_ptr) | 854 self._ccObject.takeOverFrom(old_cpu._ccObject) |
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 --- | 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 --- |