params: Fix floating point parameters
[gem5.git] / src / python / m5 / SimObject.py
index 1e7d289e2d5e02f179b25a2aa01c6d5dbc0aa76f..41ed3df9e9e190a83a13f9c958caf7f2f527c55c 100644 (file)
@@ -32,7 +32,6 @@ import sys, types
 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
@@ -128,6 +127,7 @@ class MetaSimObject(type):
                       'cxx_class' : types.StringType,
                       'cxx_type' : types.StringType,
                       'cxx_predecls' : types.ListType,
+                      'swig_objdecls' : types.ListType,
                       'swig_predecls' : types.ListType,
                       'type' : types.StringType }
     # Attributes that can be set any time
@@ -216,7 +216,10 @@ class MetaSimObject(type):
                 # 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:
@@ -225,6 +228,9 @@ class MetaSimObject(type):
                 cls._value_dict['swig_predecls'] = \
                     cls._value_dict['cxx_predecls']
 
+        if 'swig_objdecls' not in cls._value_dict:
+            cls._value_dict['swig_objdecls'] = []
+
         # Now process the _value_dict items.  They could be defining
         # new (or overriding existing) parameters or ports, setting
         # class keywords (e.g., 'abstract'), or setting parameter
@@ -345,12 +351,13 @@ class MetaSimObject(type):
     def __str__(cls):
         return cls.__name__
 
-    def cxx_decl(cls):
-        if str(cls) != 'SimObject':
-            base = cls.__bases__[0].type
-        else:
-            base = None
+    def get_base(cls):
+        if str(cls) == 'SimObject':
+            return None
+
+        return  cls.__bases__[0].type
 
+    def cxx_decl(cls):
         code = "#ifndef __PARAMS__%s\n" % cls
         code += "#define __PARAMS__%s\n\n" % cls
 
@@ -380,6 +387,7 @@ class MetaSimObject(type):
         code += "\n".join(predecls2)
         code += "\n\n";
 
+        base = cls.get_base()
         if base:
             code += '#include "params/%s.hh"\n\n' % base
 
@@ -408,11 +416,7 @@ class MetaSimObject(type):
         return code
 
     def cxx_type_decl(cls):
-        if str(cls) != 'SimObject':
-            base = cls.__bases__[0]
-        else:
-            base = None
-
+        base = cls.get_base()
         code = ''
 
         if base:
@@ -427,17 +431,14 @@ class MetaSimObject(type):
         return code
 
     def swig_decl(cls):
+        base = cls.get_base()
+
         code = '%%module %s\n' % cls
 
         code += '%{\n'
         code += '#include "params/%s.hh"\n' % cls
         code += '%}\n\n'
 
-        if str(cls) != 'SimObject':
-            base = cls.__bases__[0]
-        else:
-            base = None
-
         # The 'dict' attribute restricts us to the params declared in
         # the object itself, not including inherited params (which
         # will also be inherited from the base class's param struct
@@ -483,6 +484,7 @@ class SimObject(object):
     abstract = True
 
     name = Param.String("Object name")
+    swig_objdecls = [ '%include "python/swig/sim_object.i"' ]
 
     # Initialize new instance.  For objects with SimObject-valued
     # children, we need to recursively clone the classes represented
@@ -721,43 +723,44 @@ class SimObject(object):
         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:
             return self._ccParams
 
-        cc_params_struct = eval('m5.objects.params.%sParams' % self.type)
+        cc_params_struct = getattr(m5.objects.params, '%sParams' % self.type)
         cc_params = cc_params_struct()
         cc_params.object = self
         cc_params.name = str(self)
@@ -792,13 +795,14 @@ class SimObject(object):
     # necessary to construct it.  Does *not* recursively create
     # children.
     def getCCObject(self):
-        import internal
-        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
 
@@ -840,24 +844,19 @@ class SimObject(object):
         if not isinstance(self, m5.objects.System):
             return None
 
-        system_ptr = internal.sim_object.convertToSystemPtr(self._ccObject)
-        return system_ptr.getMemoryMode()
+        return self._ccObject.getMemoryMode()
 
     def changeTiming(self, mode):
-        import internal
         if isinstance(self, m5.objects.System):
             # i don't know if there's a better way to do this - calling
             # setMemoryMode directly from self._ccObject results in calling
             # SimObject::setMemoryMode, not the System::setMemoryMode
-            system_ptr = internal.sim_object.convertToSystemPtr(self._ccObject)
-            system_ptr.setMemoryMode(mode)
+            self._ccObject.setMemoryMode(mode)
         for child in self._children.itervalues():
             child.changeTiming(mode)
 
     def takeOverFrom(self, old_cpu):
-        import internal
-        cpu_ptr = internal.sim_object.convertToBaseCPUPtr(old_cpu._ccObject)
-        self._ccObject.takeOverFrom(cpu_ptr)
+        self._ccObject.takeOverFrom(old_cpu._ccObject)
 
     # generate output file for 'dot' to display as a pretty graph.
     # this code is currently broken.