Deleted Added
sdiff udiff text old ( 11802:be62996c95d1 ) new ( 11988:665cd5f8b52b )
full compact
1# Copyright (c) 2012 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license
9# terms below provided that you ensure that this notice is replicated

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

36# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40#
41# Authors: Steve Reinhardt
42# Nathan Binkert
43# Andreas Hansson
44
45import sys
46from types import FunctionType, MethodType, ModuleType
47
48import m5
49from m5.util import *
50
51# Have to import params up top since Param is referenced on initial
52# load (when SimObject class references Param to create a class
53# variable, the 'name' param)...
54from m5.params import *
55# There are a few things we need that aren't in params.__all__ since
56# normal users don't need them
57from m5.params import ParamDesc, VectorParamDesc, \

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

263 code()
264 code('void ${member_prefix}setName(const std::string &name_)'
265 '${end_of_decl}')
266
267 if not is_header:
268 code('{')
269 code.indent()
270 code('this->name = name_;')
271 code('this->pyobj = NULL;')
272 code.dedent()
273 code('}')
274
275 if is_header:
276 code('const std::string &${member_prefix}getName()')
277 code('{ return this->name; }')
278
279 code()

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

388 code('};')
389
390# The metaclass for SimObject. This class controls how new classes
391# that derive from SimObject are instantiated, and provides inherited
392# class behavior (just like a class controls how instances of that
393# class are instantiated, and provides inherited instance behavior).
394class MetaSimObject(type):
395 # Attributes that can be set only at initialization time
396 init_keywords = { 'abstract' : bool,
397 'cxx_class' : str,
398 'cxx_type' : str,
399 'cxx_header' : str,
400 'type' : str,
401 'cxx_bases' : list }
402 # Attributes that can be set any time
403 keywords = { 'check' : FunctionType }
404
405 # __new__ is called before __init__, and is where the statements
406 # in the body of the class definition get loaded into the class's
407 # __dict__. We intercept this to filter out parameter & port assignments
408 # and only allow "private" attributes to be passed to the base
409 # __new__ (starting with underscore).
410 def __new__(mcls, name, bases, dict):
411 assert name not in allClasses, "SimObject %s already present" % name
412
413 # Copy "private" attributes, functions, and classes to the
414 # official dict. Everything else goes in _init_dict to be
415 # filtered in __init__.
416 cls_dict = {}
417 value_dict = {}
418 for key,val in dict.items():
419 if public_value(key, val):
420 cls_dict[key] = val
421 else:
422 # must be a param/port setting
423 value_dict[key] = val
424 if 'abstract' not in value_dict:
425 value_dict['abstract'] = False
426 if 'cxx_bases' not in value_dict:
427 value_dict['cxx_bases'] = []
428 cls_dict['_value_dict'] = value_dict
429 cls = super(MetaSimObject, mcls).__new__(mcls, name, bases, cls_dict)
430 if 'type' in value_dict:
431 allClasses[name] = cls
432 return cls
433
434 # subclass initialization
435 def __init__(cls, name, bases, dict):

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

649
650 def __str__(cls):
651 return cls.__name__
652
653 # See ParamValue.cxx_predecls for description.
654 def cxx_predecls(cls, code):
655 code('#include "params/$cls.hh"')
656
657 # See ParamValue.swig_predecls for description.
658 def swig_predecls(cls, code):
659 code('%import "python/_m5/param_$cls.i"')
660
661 # Hook for exporting additional C++ methods to Python via SWIG.
662 # Default is none, override using @classmethod in class definition.
663 def export_methods(cls, code):
664 pass

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

750 code('};')
751
752 for ns in reversed(namespaces):
753 code('} // namespace $ns')
754
755 code()
756 code('%include "params/$cls.hh"')
757
758
759 # Generate the C++ declaration (.hh file) for this SimObject's
760 # param struct. Called from src/SConscript.
761 def cxx_param_decl(cls, code):
762 # The 'local' attribute restricts us to the params declared in
763 # the object itself, not including inherited params (which
764 # will also be inherited from the base class's param struct
765 # here). Sort the params based on their key
766 params = map(lambda (k, v): v, sorted(cls._params.local.items()))

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

775 class_path = cls._value_dict['cxx_class'].split('::')
776
777 code('''\
778#ifndef __PARAMS__${cls}__
779#define __PARAMS__${cls}__
780
781''')
782
783 # A forward class declaration is sufficient since we are just
784 # declaring a pointer.
785 for ns in class_path[:-1]:
786 code('namespace $ns {')
787 code('class $0;', class_path[-1])
788 for ns in reversed(class_path[:-1]):
789 code('} // namespace $ns')
790 code()
791
792 # The base SimObject has a couple of params that get
793 # automatically set from Python without being declared through
794 # the normal Param mechanism; we slip them in here (needed
795 # predecls now, actual declarations below)
796 if cls == SimObject:
797 code('''
798#ifndef PY_VERSION
799struct PyObject;
800#endif
801
802#include <string>
803''')
804 for param in params:
805 param.cxx_predecls(code)
806 for port in ports.itervalues():
807 port.cxx_predecls(code)
808 code()
809
810 if cls._base:
811 code('#include "params/${{cls._base.type}}.hh"')

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

827
828 code.indent()
829 if cls == SimObject:
830 code('''
831 SimObjectParams() {}
832 virtual ~SimObjectParams() {}
833
834 std::string name;
835 PyObject *pyobj;
836 ''')
837 for param in params:
838 param.cxx_decl(code)
839 for port in ports.itervalues():
840 port.cxx_decl(code)
841
842 code.dedent()
843 code('};')
844

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

856# SimObject class definition to the MetaSimObject methods (in
857# particular _set_param, which gets called for parameters with default
858# values defined on the SimObject class itself). It will get
859# overridden by the permanent definition (which requires that
860# SimObject be defined) lower in this file.
861def isSimObjectOrVector(value):
862 return False
863
864# This class holds information about each simobject parameter
865# that should be displayed on the command line for use in the
866# configuration system.
867class ParamInfo(object):
868 def __init__(self, type, desc, type_str, example, default_val, access_str):
869 self.type = type
870 self.desc = desc
871 self.type_str = type_str

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

916 void memWriteback();
917 void regStats();
918 void resetStats();
919 void regProbePoints();
920 void regProbeListeners();
921 void startup();
922''')
923
924 # Returns a dict of all the option strings that can be
925 # generated as command line options for this simobject instance
926 # by tracing all reachable params in the top level instance and
927 # any children it contains.
928 def enumerateParams(self, flags_dict = {},
929 cmd_line_str = "", access_str = ""):
930 if hasattr(self, "_paramEnumed"):
931 print "Cycle detected enumerating params"

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

1374 return d
1375
1376 def getCCParams(self):
1377 if self._ccParams:
1378 return self._ccParams
1379
1380 cc_params_struct = getattr(m5.internal.params, '%sParams' % self.type)
1381 cc_params = cc_params_struct()
1382 cc_params.pyobj = self
1383 cc_params.name = str(self)
1384
1385 param_names = self._params.keys()
1386 param_names.sort()
1387 for param in param_names:
1388 value = self._values.get(param)
1389 if value is None:
1390 fatal("%s.%s without default or user set value",
1391 self.path(), param)
1392
1393 value = value.getValue()
1394 if isinstance(self._params[param], VectorParamDesc):
1395 assert isinstance(value, list)
1396 vec = getattr(cc_params, param)
1397 assert not len(vec)
1398 for v in value:
1399 vec.append(v)
1400 else:
1401 setattr(cc_params, param, value)
1402
1403 port_names = self._ports.keys()
1404 port_names.sort()
1405 for port_name in port_names:
1406 port = self._port_refs.get(port_name, None)
1407 if port != None:

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

1512
1513 allClasses = baseClasses.copy()
1514 instanceDict = baseInstances.copy()
1515 noCxxHeader = False
1516
1517# __all__ defines the list of symbols that get exported when
1518# 'from config import *' is invoked. Try to keep this reasonably
1519# short to avoid polluting other namespaces.
1520__all__ = [ 'SimObject' ]