SimObject.py (7673:b28bd1fa9a35) SimObject.py (7675:2221ec64132f)
1# Copyright (c) 2004-2006 The Regents of The University of Michigan
2# Copyright (c) 2010 Advanced Micro Devices, Inc.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

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

93
94# list of all SimObject classes
95allClasses = {}
96
97# dict to look up SimObjects based on path
98instanceDict = {}
99
100def default_cxx_predecls(cls, code):
1# Copyright (c) 2004-2006 The Regents of The University of Michigan
2# Copyright (c) 2010 Advanced Micro Devices, Inc.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

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

93
94# list of all SimObject classes
95allClasses = {}
96
97# dict to look up SimObjects based on path
98instanceDict = {}
99
100def default_cxx_predecls(cls, code):
101 '''A forward class declaration is sufficient since we are
102 just declaring a pointer.'''
101 code('#include "params/$cls.hh"')
103
102
104 class_path = cls._value_dict['cxx_class'].split('::')
105 for ns in class_path[:-1]:
106 code('namespace $ns {')
107 code('class $0;', class_path[-1])
108 for ns in reversed(class_path[:-1]):
109 code('/* namespace $ns */ }')
103def default_swig_predecls(cls, code):
104 code('%import "params/$cls.i"')
110
111def default_swig_objdecls(cls, code):
112 class_path = cls.cxx_class.split('::')
113 classname = class_path[-1]
114 namespaces = class_path[:-1]
115
116 for ns in namespaces:
117 code('namespace $ns {')

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

228
229 cls._value_dict['cxx_type'] = '%s *' % cls._value_dict['cxx_class']
230
231 if 'cxx_predecls' not in cls.__dict__:
232 m = MethodType(default_cxx_predecls, cls, MetaSimObject)
233 setattr(cls, 'cxx_predecls', m)
234
235 if 'swig_predecls' not in cls.__dict__:
105
106def default_swig_objdecls(cls, code):
107 class_path = cls.cxx_class.split('::')
108 classname = class_path[-1]
109 namespaces = class_path[:-1]
110
111 for ns in namespaces:
112 code('namespace $ns {')

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

223
224 cls._value_dict['cxx_type'] = '%s *' % cls._value_dict['cxx_class']
225
226 if 'cxx_predecls' not in cls.__dict__:
227 m = MethodType(default_cxx_predecls, cls, MetaSimObject)
228 setattr(cls, 'cxx_predecls', m)
229
230 if 'swig_predecls' not in cls.__dict__:
236 setattr(cls, 'swig_predecls', getattr(cls, 'cxx_predecls'))
231 m = MethodType(default_swig_predecls, cls, MetaSimObject)
232 setattr(cls, 'swig_predecls', m)
237
238 if 'swig_objdecls' not in cls.__dict__:
239 m = MethodType(default_swig_objdecls, cls, MetaSimObject)
240 setattr(cls, 'swig_objdecls', m)
241
242 # Now process the _value_dict items. They could be defining
243 # new (or overriding existing) parameters or ports, setting
244 # class keywords (e.g., 'abstract'), or setting parameter

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

341 cls._children[attr] = coerceSimObjectOrVector(value)
342 return
343
344 # no valid assignment... raise exception
345 raise AttributeError, \
346 "Class %s has no parameter \'%s\'" % (cls.__name__, attr)
347
348 def __getattr__(cls, attr):
233
234 if 'swig_objdecls' not in cls.__dict__:
235 m = MethodType(default_swig_objdecls, cls, MetaSimObject)
236 setattr(cls, 'swig_objdecls', m)
237
238 # Now process the _value_dict items. They could be defining
239 # new (or overriding existing) parameters or ports, setting
240 # class keywords (e.g., 'abstract'), or setting parameter

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

337 cls._children[attr] = coerceSimObjectOrVector(value)
338 return
339
340 # no valid assignment... raise exception
341 raise AttributeError, \
342 "Class %s has no parameter \'%s\'" % (cls.__name__, attr)
343
344 def __getattr__(cls, attr):
345 if attr == 'cxx_class_path':
346 return cls.cxx_class.split('::')
347
348 if attr == 'cxx_class_name':
349 return cls.cxx_class_path[-1]
350
351 if attr == 'cxx_namespaces':
352 return cls.cxx_class_path[:-1]
353
349 if cls._values.has_key(attr):
350 return cls._values[attr]
351
352 if cls._children.has_key(attr):
353 return cls._children[attr]
354
355 raise AttributeError, \
356 "object '%s' has no attribute '%s'" % (cls.__name__, attr)
357
358 def __str__(cls):
359 return cls.__name__
360
361 def cxx_decl(cls, code):
354 if cls._values.has_key(attr):
355 return cls._values[attr]
356
357 if cls._children.has_key(attr):
358 return cls._children[attr]
359
360 raise AttributeError, \
361 "object '%s' has no attribute '%s'" % (cls.__name__, attr)
362
363 def __str__(cls):
364 return cls.__name__
365
366 def cxx_decl(cls, code):
362 code('''\
363#ifndef __PARAMS__${cls}__
364#define __PARAMS__${cls}__
365
366''')
367
368 # The 'dict' attribute restricts us to the params declared in
369 # the object itself, not including inherited params (which
370 # will also be inherited from the base class's param struct
371 # here).
372 params = cls._params.local.values()
373 try:
374 ptypes = [p.ptype for p in params]
375 except:
376 print cls, p, p.ptype_str
377 print params
378 raise
379
367 # The 'dict' attribute restricts us to the params declared in
368 # the object itself, not including inherited params (which
369 # will also be inherited from the base class's param struct
370 # here).
371 params = cls._params.local.values()
372 try:
373 ptypes = [p.ptype for p in params]
374 except:
375 print cls, p, p.ptype_str
376 print params
377 raise
378
380 # get all predeclarations
381 cls.cxx_predecls(code)
379 class_path = cls._value_dict['cxx_class'].split('::')
380
381 code('''\
382#ifndef __PARAMS__${cls}__
383#define __PARAMS__${cls}__
384
385''')
386
387 # A forward class declaration is sufficient since we are just
388 # declaring a pointer.
389 for ns in class_path[:-1]:
390 code('namespace $ns {')
391 code('class $0;', class_path[-1])
392 for ns in reversed(class_path[:-1]):
393 code('/* namespace $ns */ }')
394 code()
395
382 for param in params:
383 param.cxx_predecls(code)
384 code()
385
386 if cls._base:
387 code('#include "params/${{cls._base.type}}.hh"')
388 code()
389
390 for ptype in ptypes:
391 if issubclass(ptype, Enum):
392 code('#include "enums/${{ptype.__name__}}.hh"')
393 code()
394
395 cls.cxx_struct(code, cls._base, params)
396
396 for param in params:
397 param.cxx_predecls(code)
398 code()
399
400 if cls._base:
401 code('#include "params/${{cls._base.type}}.hh"')
402 code()
403
404 for ptype in ptypes:
405 if issubclass(ptype, Enum):
406 code('#include "enums/${{ptype.__name__}}.hh"')
407 code()
408
409 cls.cxx_struct(code, cls._base, params)
410
397 # close #ifndef __PARAMS__* guard
398 code()
399 code('#endif // __PARAMS__${cls}__')
400 return code
401
402 def cxx_struct(cls, code, base, params):
403 if cls == SimObject:
404 code('#include "sim/sim_object_params.hh"')
405 return

--- 553 unchanged lines hidden ---
411 code()
412 code('#endif // __PARAMS__${cls}__')
413 return code
414
415 def cxx_struct(cls, code, base, params):
416 if cls == SimObject:
417 code('#include "sim/sim_object_params.hh"')
418 return

--- 553 unchanged lines hidden ---