import proxy
import m5
from util import *
-from multidict import multidict
# These utility functions have to come first because they're
# referenced in params.py... otherwise they won't be defined when we
# just declaring a pointer.
decl = 'class %s;' % _cxx_class
if namespace:
- decl = 'namespace %s { %s }' % (namespace, decl)
+ namespaces = namespace.split('::')
+ namespaces.reverse()
+ for namespace in namespaces:
+ decl = 'namespace %s { %s }' % (namespace, decl)
cls._value_dict['cxx_predecls'] = [decl]
if 'swig_predecls' not in cls._value_dict:
code += '#include "enums/%s.hh"\n' % ptype.__name__
code += "\n\n"
+ code += cls.cxx_struct(base, params)
+
+ # close #ifndef __PARAMS__* guard
+ code += "\n#endif\n"
+ return code
+
+ def cxx_struct(cls, base, params):
+ if cls == SimObject:
+ return '#include "sim/sim_object_params.hh"\n'
+
# now generate the actual param struct
- code += "struct %sParams" % cls
+ code = "struct %sParams" % cls
if base:
code += " : public %sParams" % base
code += "\n{\n"
- if cls == SimObject:
- code += " virtual ~%sParams() {}\n" % cls
if not hasattr(cls, 'abstract') or not cls.abstract:
if 'type' in cls.__dict__:
code += " %s create();\n" % cls.cxx_type
code += "".join([" %s\n" % d for d in decls])
code += "};\n"
- # close #ifndef __PARAMS__* guard
- code += "\n#endif\n"
return code
def cxx_type_decl(cls):
type = 'SimObject'
abstract = True
- name = Param.String("Object name")
swig_objdecls = [ '%include "python/swig/sim_object.i"' ]
# Initialize new instance. For objects with SimObject-valued
for child in child_names:
self._children[child].unproxy_all()
- def print_ini(self):
- print '[' + self.path() + ']' # .ini section header
+ def print_ini(self, ini_file):
+ print >>ini_file, '[' + self.path() + ']' # .ini section header
instanceDict[self.path()] = self
if hasattr(self, 'type'):
- print 'type=%s' % self.type
+ print >>ini_file, 'type=%s' % self.type
child_names = self._children.keys()
child_names.sort()
if len(child_names):
- print 'children=%s' % ' '.join(child_names)
+ print >>ini_file, 'children=%s' % ' '.join(child_names)
param_names = self._params.keys()
param_names.sort()
for param in param_names:
value = self._values.get(param)
if value != None:
- print '%s=%s' % (param, self._values[param].ini_str())
+ print >>ini_file, '%s=%s' % (param,
+ self._values[param].ini_str())
port_names = self._ports.keys()
port_names.sort()
for port_name in port_names:
port = self._port_refs.get(port_name, None)
if port != None:
- print '%s=%s' % (port_name, port.ini_str())
+ print >>ini_file, '%s=%s' % (port_name, port.ini_str())
- print # blank line between objects
+ print >>ini_file # blank line between objects
for child in child_names:
- self._children[child].print_ini()
+ self._children[child].print_ini(ini_file)
def getCCParams(self):
if self._ccParams:
cc_params_struct = getattr(m5.objects.params, '%sParams' % self.type)
cc_params = cc_params_struct()
- cc_params.object = self
+ cc_params.pyobj = self
cc_params.name = str(self)
param_names = self._params.keys()
# necessary to construct it. Does *not* recursively create
# children.
def getCCObject(self):
- params = self.getCCParams()
if not self._ccObject:
- self._ccObject = -1 # flag to catch cycles in recursion
+ # Cycles in the configuration heirarchy are not supported. This
+ # will catch the resulting recursion and stop.
+ self._ccObject = -1
+ params = self.getCCParams()
self._ccObject = params.create()
elif self._ccObject == -1:
- raise RuntimeError, "%s: recursive call to getCCObject()" \
+ raise RuntimeError, "%s: Cycle found in configuration heirarchy." \
% self.path()
return self._ccObject