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 |
34try: 35 import pydot 36except: 37 pydot = False 38 |
39import m5 |
40from m5.util import * |
41 |
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)... |
45from m5.params import * |
46# There are a few things we need that aren't in params.__all__ since 47# normal users don't need them |
48from m5.params import ParamDesc, VectorParamDesc, isNullPointer, SimObjVector |
49 |
50from m5.proxy import * 51from m5.proxy import isproxy |
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): |
121 assert name not in allClasses, "SimObject %s already present" % name |
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) |
658 if value != None and isproxy(value): |
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: |
729 fatal("%s.%s without default or user set value", 730 self.path(), param) |
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 |
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' ] |