SimObject.py (6654:4c84e771cca7) SimObject.py (7493:81328f5e764a)
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

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

24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Steve Reinhardt
28# Nathan Binkert
29
30import math
31import sys
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

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

24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Steve Reinhardt
28# Nathan Binkert
29
30import math
31import sys
32import types
32from types import FunctionType
33
34try:
35 import pydot
36except:
37 pydot = False
38
39import m5
40from m5.util import *

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

97instanceDict = {}
98
99# The metaclass for SimObject. This class controls how new classes
100# that derive from SimObject are instantiated, and provides inherited
101# class behavior (just like a class controls how instances of that
102# class are instantiated, and provides inherited instance behavior).
103class MetaSimObject(type):
104 # Attributes that can be set only at initialization time
33
34try:
35 import pydot
36except:
37 pydot = False
38
39import m5
40from m5.util import *

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

97instanceDict = {}
98
99# The metaclass for SimObject. This class controls how new classes
100# that derive from SimObject are instantiated, and provides inherited
101# class behavior (just like a class controls how instances of that
102# class are instantiated, and provides inherited instance behavior).
103class MetaSimObject(type):
104 # Attributes that can be set only at initialization time
105 init_keywords = { 'abstract' : types.BooleanType,
106 'cxx_class' : types.StringType,
107 'cxx_type' : types.StringType,
108 'cxx_predecls' : types.ListType,
109 'swig_objdecls' : types.ListType,
110 'swig_predecls' : types.ListType,
111 'type' : types.StringType }
105 init_keywords = { 'abstract' : bool,
106 'cxx_class' : str,
107 'cxx_type' : str,
108 'cxx_predecls' : list,
109 'swig_objdecls' : list,
110 'swig_predecls' : list,
111 'type' : str }
112 # Attributes that can be set any time
112 # Attributes that can be set any time
113 keywords = { 'check' : types.FunctionType }
113 keywords = { 'check' : 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():
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,
130 types.TypeType)):
129 if key.startswith('_') or isinstance(val, (FunctionType,
130 classmethod,
131 type)):
131 cls_dict[key] = val
132 else:
133 # must be a param/port setting
134 value_dict[key] = val
135 if 'abstract' not in value_dict:
136 value_dict['abstract'] = False
137 cls_dict['_value_dict'] = value_dict
138 cls = super(MetaSimObject, mcls).__new__(mcls, name, bases, cls_dict)

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

228 # default: use normal path (ends up in __setattr__)
229 else:
230 setattr(cls, key, val)
231
232 def _set_keyword(cls, keyword, val, kwtype):
233 if not isinstance(val, kwtype):
234 raise TypeError, 'keyword %s has bad type %s (expecting %s)' % \
235 (keyword, type(val), kwtype)
132 cls_dict[key] = val
133 else:
134 # must be a param/port setting
135 value_dict[key] = val
136 if 'abstract' not in value_dict:
137 value_dict['abstract'] = False
138 cls_dict['_value_dict'] = value_dict
139 cls = super(MetaSimObject, mcls).__new__(mcls, name, bases, cls_dict)

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

229 # default: use normal path (ends up in __setattr__)
230 else:
231 setattr(cls, key, val)
232
233 def _set_keyword(cls, keyword, val, kwtype):
234 if not isinstance(val, kwtype):
235 raise TypeError, 'keyword %s has bad type %s (expecting %s)' % \
236 (keyword, type(val), kwtype)
236 if isinstance(val, types.FunctionType):
237 if isinstance(val, FunctionType):
237 val = classmethod(val)
238 type.__setattr__(cls, keyword, val)
239
240 def _new_param(cls, name, pdesc):
241 # each param desc should be uniquely assigned to one variable
242 assert(not hasattr(pdesc, 'name'))
243 pdesc.name = name
244 cls._params[name] = pdesc

--- 653 unchanged lines hidden ---
238 val = classmethod(val)
239 type.__setattr__(cls, keyword, val)
240
241 def _new_param(cls, name, pdesc):
242 # each param desc should be uniquely assigned to one variable
243 assert(not hasattr(pdesc, 'name'))
244 pdesc.name = name
245 cls._params[name] = pdesc

--- 653 unchanged lines hidden ---