Deleted Added
sdiff udiff text old ( 7673:b28bd1fa9a35 ) new ( 7675:2221ec64132f )
full compact
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.'''
103
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 */ }')
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__:
236 setattr(cls, 'swig_predecls', getattr(cls, 'cxx_predecls'))
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):
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):
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
380 # get all predeclarations
381 cls.cxx_predecls(code)
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
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 ---