Deleted Added
sdiff udiff text old ( 5543:3af77710f397 ) new ( 5610:0e1e9c186769 )
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

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

118
119# The metaclass for SimObject. This class controls how new classes
120# that derive from SimObject are instantiated, and provides inherited
121# class behavior (just like a class controls how instances of that
122# class are instantiated, and provides inherited instance behavior).
123class MetaSimObject(type):
124 # Attributes that can be set only at initialization time
125 init_keywords = { 'abstract' : types.BooleanType,
126 'cxx_class' : types.StringType,
127 'cxx_type' : types.StringType,
128 'cxx_predecls' : types.ListType,
129 'swig_objdecls' : types.ListType,
130 'swig_predecls' : types.ListType,
131 'type' : types.StringType }
132 # Attributes that can be set any time
133 keywords = { 'check' : types.FunctionType }

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

184
185 base = bases[0]
186
187 # Set up general inheritance via multidicts. A subclass will
188 # inherit all its settings from the base class. The only time
189 # the following is not true is when we define the SimObject
190 # class itself (in which case the multidicts have no parent).
191 if isinstance(base, MetaSimObject):
192 cls._base = base
193 cls._params.parent = base._params
194 cls._ports.parent = base._ports
195 cls._values.parent = base._values
196 cls._port_refs.parent = base._port_refs
197 # mark base as having been subclassed
198 base._instantiated = True
199 else:
200 cls._base = None
201
202 # default keyword values
203 if 'type' in cls._value_dict:
204 if 'cxx_class' not in cls._value_dict:
205 cls._value_dict['cxx_class'] = cls._value_dict['type']
206
207 cls._value_dict['cxx_type'] = '%s *' % cls._value_dict['cxx_class']
208
209 if 'cxx_predecls' not in cls._value_dict:
210 # A forward class declaration is sufficient since we are
211 # just declaring a pointer.
212 class_path = cls._value_dict['cxx_class'].split('::')
213 class_path.reverse()
214 decl = 'class %s;' % class_path[0]
215 for ns in class_path[1:]:
216 decl = 'namespace %s { %s }' % (ns, decl)
217 cls._value_dict['cxx_predecls'] = [decl]
218
219 if 'swig_predecls' not in cls._value_dict:
220 # A forward class declaration is sufficient since we are
221 # just declaring a pointer.
222 cls._value_dict['swig_predecls'] = \
223 cls._value_dict['cxx_predecls']
224

--- 115 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
348 def cxx_decl(cls):
349 code = "#ifndef __PARAMS__%s\n" % cls
350 code += "#define __PARAMS__%s\n\n" % cls
351
352 # The 'dict' attribute restricts us to the params declared in
353 # the object itself, not including inherited params (which
354 # will also be inherited from the base class's param struct
355 # here).

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

370 predecls2 = []
371 for pd in predecls:
372 if pd not in predecls2:
373 predecls2.append(pd)
374 predecls2.sort()
375 code += "\n".join(predecls2)
376 code += "\n\n";
377
378 if cls._base:
379 code += '#include "params/%s.hh"\n\n' % cls._base.type
380
381 for ptype in ptypes:
382 if issubclass(ptype, Enum):
383 code += '#include "enums/%s.hh"\n' % ptype.__name__
384 code += "\n\n"
385
386 code += cls.cxx_struct(cls._base, params)
387
388 # close #ifndef __PARAMS__* guard
389 code += "\n#endif\n"
390 return code
391
392 def cxx_struct(cls, base, params):
393 if cls == SimObject:
394 return '#include "sim/sim_object_params.hh"\n'
395
396 # now generate the actual param struct
397 code = "struct %sParams" % cls
398 if base:
399 code += " : public %sParams" % base.type
400 code += "\n{\n"
401 if not hasattr(cls, 'abstract') or not cls.abstract:
402 if 'type' in cls.__dict__:
403 code += " %s create();\n" % cls.cxx_type
404 decls = [p.cxx_decl() for p in params]
405 decls.sort()
406 code += "".join([" %s\n" % d for d in decls])
407 code += "};\n"
408
409 return code
410
411 def swig_decl(cls):
412 code = '%%module %s\n' % cls
413
414 code += '%{\n'
415 code += '#include "params/%s.hh"\n' % cls
416 code += '%}\n\n'
417
418 # The 'dict' attribute restricts us to the params declared in
419 # the object itself, not including inherited params (which

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

431 predecls2 = []
432 for pd in predecls:
433 if pd not in predecls2:
434 predecls2.append(pd)
435 predecls2.sort()
436 code += "\n".join(predecls2)
437 code += "\n\n";
438
439 if cls._base:
440 code += '%%import "params/%s.i"\n\n' % cls._base.type
441
442 for ptype in ptypes:
443 if issubclass(ptype, Enum):
444 code += '%%import "enums/%s.hh"\n' % ptype.__name__
445 code += "\n\n"
446
447 code += '%%import "params/%s_type.hh"\n\n' % cls
448 code += '%%include "params/%s.hh"\n\n' % cls

--- 439 unchanged lines hidden ---