SimObject.py (5952:c1ee8282291d) | SimObject.py (6654:4c84e771cca7) |
---|---|
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 --- 17 unchanged lines hidden (view full) --- 26# 27# Authors: Steve Reinhardt 28# Nathan Binkert 29 30import math 31import sys 32import types 33 | 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 --- 17 unchanged lines hidden (view full) --- 26# 27# Authors: Steve Reinhardt 28# Nathan Binkert 29 30import math 31import sys 32import types 33 |
34import proxy | 34try: 35 import pydot 36except: 37 pydot = False 38 |
35import m5 | 39import m5 |
36from util import * | 40from m5.util import * |
37 | 41 |
38# These utility functions have to come first because they're 39# referenced in params.py... otherwise they won't be defined when we 40# import params below, and the recursive import of this file from 41# params.py will not find these names. 42def isSimObject(value): 43 return isinstance(value, SimObject) 44 45def isSimObjectClass(value): 46 return issubclass(value, SimObject) 47 48def isSimObjectSequence(value): 49 if not isinstance(value, (list, tuple)) or len(value) == 0: 50 return False 51 52 for val in value: 53 if not isNullPointer(val) and not isSimObject(val): 54 return False 55 56 return True 57 58def isSimObjectOrSequence(value): 59 return isSimObject(value) or isSimObjectSequence(value) 60 | |
61# Have to import params up top since Param is referenced on initial 62# load (when SimObject class references Param to create a class 63# variable, the 'name' param)... | 42# Have to import params up top since Param is referenced on initial 43# load (when SimObject class references Param to create a class 44# variable, the 'name' param)... |
64from params import * | 45from m5.params import * |
65# There are a few things we need that aren't in params.__all__ since 66# normal users don't need them | 46# There are a few things we need that aren't in params.__all__ since 47# normal users don't need them |
67from params import ParamDesc, VectorParamDesc, isNullPointer, SimObjVector 68from proxy import * | 48from m5.params import ParamDesc, VectorParamDesc, isNullPointer, SimObjVector |
69 | 49 |
70noDot = False 71try: 72 import pydot 73except: 74 noDot = True | 50from m5.proxy import * 51from m5.proxy import isproxy |
75 76##################################################################### 77# 78# M5 Python Configuration Utility 79# 80# The basic idea is to write simple Python programs that build Python 81# objects corresponding to M5 SimObjects for the desired simulation 82# configuration. For now, the Python emits a .ini file that can be --- 53 unchanged lines hidden (view full) --- 136 keywords = { 'check' : types.FunctionType } 137 138 # __new__ is called before __init__, and is where the statements 139 # in the body of the class definition get loaded into the class's 140 # __dict__. We intercept this to filter out parameter & port assignments 141 # and only allow "private" attributes to be passed to the base 142 # __new__ (starting with underscore). 143 def __new__(mcls, name, bases, dict): | 52 53##################################################################### 54# 55# M5 Python Configuration Utility 56# 57# The basic idea is to write simple Python programs that build Python 58# objects corresponding to M5 SimObjects for the desired simulation 59# configuration. For now, the Python emits a .ini file that can be --- 53 unchanged lines hidden (view full) --- 113 keywords = { 'check' : types.FunctionType } 114 115 # __new__ is called before __init__, and is where the statements 116 # in the body of the class definition get loaded into the class's 117 # __dict__. We intercept this to filter out parameter & port assignments 118 # and only allow "private" attributes to be passed to the base 119 # __new__ (starting with underscore). 120 def __new__(mcls, name, bases, dict): |
144 assert name not in allClasses | 121 assert name not in allClasses, "SimObject %s already present" % name |
145 146 # Copy "private" attributes, functions, and classes to the 147 # official dict. Everything else goes in _init_dict to be 148 # filtered in __init__. 149 cls_dict = {} 150 value_dict = {} 151 for key,val in dict.items(): 152 if key.startswith('_') or isinstance(val, (types.FunctionType, --- 520 unchanged lines hidden (view full) --- 673 return found_obj, found_obj != None 674 675 def unproxy(self, base): 676 return self 677 678 def unproxy_all(self): 679 for param in self._params.iterkeys(): 680 value = self._values.get(param) | 122 123 # Copy "private" attributes, functions, and classes to the 124 # official dict. Everything else goes in _init_dict to be 125 # filtered in __init__. 126 cls_dict = {} 127 value_dict = {} 128 for key,val in dict.items(): 129 if key.startswith('_') or isinstance(val, (types.FunctionType, --- 520 unchanged lines hidden (view full) --- 650 return found_obj, found_obj != None 651 652 def unproxy(self, base): 653 return self 654 655 def unproxy_all(self): 656 for param in self._params.iterkeys(): 657 value = self._values.get(param) |
681 if value != None and proxy.isproxy(value): | 658 if value != None and isproxy(value): |
682 try: 683 value = value.unproxy(self) 684 except: 685 print "Error in unproxying param '%s' of %s" % \ 686 (param, self.path()) 687 raise 688 setattr(self, param, value) 689 --- 54 unchanged lines hidden (view full) --- 744 cc_params.pyobj = self 745 cc_params.name = str(self) 746 747 param_names = self._params.keys() 748 param_names.sort() 749 for param in param_names: 750 value = self._values.get(param) 751 if value is None: | 659 try: 660 value = value.unproxy(self) 661 except: 662 print "Error in unproxying param '%s' of %s" % \ 663 (param, self.path()) 664 raise 665 setattr(self, param, value) 666 --- 54 unchanged lines hidden (view full) --- 721 cc_params.pyobj = self 722 cc_params.name = str(self) 723 724 param_names = self._params.keys() 725 param_names.sort() 726 for param in param_names: 727 value = self._values.get(param) 728 if value is None: |
752 m5.fatal("%s.%s without default or user set value", 753 self.path(), param) | 729 fatal("%s.%s without default or user set value", 730 self.path(), param) |
754 755 value = value.getValue() 756 if isinstance(self._params[param], VectorParamDesc): 757 assert isinstance(value, list) 758 vec = getattr(cc_params, param) 759 assert not len(vec) 760 for v in value: 761 vec.append(v) --- 119 unchanged lines hidden (view full) --- 881 for c in self.children: 882 c.outputDot(dot) 883 884# Function to provide to C++ so it can look up instances based on paths 885def resolveSimObject(name): 886 obj = instanceDict[name] 887 return obj.getCCObject() 888 | 731 732 value = value.getValue() 733 if isinstance(self._params[param], VectorParamDesc): 734 assert isinstance(value, list) 735 vec = getattr(cc_params, param) 736 assert not len(vec) 737 for v in value: 738 vec.append(v) --- 119 unchanged lines hidden (view full) --- 858 for c in self.children: 859 c.outputDot(dot) 860 861# Function to provide to C++ so it can look up instances based on paths 862def resolveSimObject(name): 863 obj = instanceDict[name] 864 return obj.getCCObject() 865 |
866def isSimObject(value): 867 return isinstance(value, SimObject) 868 869def isSimObjectClass(value): 870 return issubclass(value, SimObject) 871 872def isSimObjectSequence(value): 873 if not isinstance(value, (list, tuple)) or len(value) == 0: 874 return False 875 876 for val in value: 877 if not isNullPointer(val) and not isSimObject(val): 878 return False 879 880 return True 881 882def isSimObjectOrSequence(value): 883 return isSimObject(value) or isSimObjectSequence(value) 884 885baseClasses = allClasses.copy() 886baseInstances = instanceDict.copy() 887 888def clear(): 889 global allClasses, instanceDict 890 891 allClasses = baseClasses.copy() 892 instanceDict = baseInstances.copy() 893 |
|
889# __all__ defines the list of symbols that get exported when 890# 'from config import *' is invoked. Try to keep this reasonably 891# short to avoid polluting other namespaces. 892__all__ = [ 'SimObject' ] | 894# __all__ defines the list of symbols that get exported when 895# 'from config import *' is invoked. Try to keep this reasonably 896# short to avoid polluting other namespaces. 897__all__ = [ 'SimObject' ] |