Deleted Added
sdiff udiff text old ( 5952:c1ee8282291d ) new ( 6654:4c84e771cca7 )
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

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

26#
27# Authors: Steve Reinhardt
28# Nathan Binkert
29
30import math
31import sys
32import types
33
34import proxy
35import m5
36from util import *
37
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)...
64from params import *
65# There are a few things we need that aren't in params.__all__ since
66# normal users don't need them
67from params import ParamDesc, VectorParamDesc, isNullPointer, SimObjVector
68from proxy import *
69
70noDot = False
71try:
72 import pydot
73except:
74 noDot = True
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):
144 assert name not in allClasses
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)
681 if value != None and proxy.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:
752 m5.fatal("%s.%s without default or user set value",
753 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
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' ]