SimObject.py (13892:0182a0601f66) SimObject.py (14061:bd3e8e7a983d)
1# Copyright (c) 2017-2018 ARM Limited
1# Copyright (c) 2017-2019 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

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

650 return cls.cxx_class.split('::')
651
652 if attr == 'cxx_class_name':
653 return cls.cxx_class_path[-1]
654
655 if attr == 'cxx_namespaces':
656 return cls.cxx_class_path[:-1]
657
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

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

650 return cls.cxx_class.split('::')
651
652 if attr == 'cxx_class_name':
653 return cls.cxx_class_path[-1]
654
655 if attr == 'cxx_namespaces':
656 return cls.cxx_class_path[:-1]
657
658 if attr == 'pybind_class':
659 return '_COLONS_'.join(cls.cxx_class_path)
660
658 if attr in cls._values:
659 return cls._values[attr]
660
661 if attr in cls._children:
662 return cls._children[attr]
663
661 if attr in cls._values:
662 return cls._values[attr]
663
664 if attr in cls._children:
665 return cls._children[attr]
666
664 raise AttributeError(
665 "object '%s' has no attribute '%s'" % (cls.__name__, attr))
667 try:
668 return getattr(cls.getCCClass(), attr)
669 except AttributeError:
670 raise AttributeError(
671 "object '%s' has no attribute '%s'" % (cls.__name__, attr))
666
667 def __str__(cls):
668 return cls.__name__
669
672
673 def __str__(cls):
674 return cls.__name__
675
676 def getCCClass(cls):
677 return getattr(m5.internal.params, cls.pybind_class)
678
670 # See ParamValue.cxx_predecls for description.
671 def cxx_predecls(cls, code):
672 code('#include "params/$cls.hh"')
673
674 def pybind_predecls(cls, code):
675 code('#include "${{cls.cxx_header}}"')
676
677 def pybind_decl(cls, code):
679 # See ParamValue.cxx_predecls for description.
680 def cxx_predecls(cls, code):
681 code('#include "params/$cls.hh"')
682
683 def pybind_predecls(cls, code):
684 code('#include "${{cls.cxx_header}}"')
685
686 def pybind_decl(cls, code):
678 class_path = cls.cxx_class.split('::')
679 namespaces, classname = class_path[:-1], class_path[-1]
680 py_class_name = '_COLONS_'.join(class_path) if namespaces else \
681 classname;
687 py_class_name = cls.pybind_class
682
683 # The 'local' attribute restricts us to the params declared in
684 # the object itself, not including inherited params (which
685 # will also be inherited from the base class's param struct
686 # here). Sort the params based on their key
687 params = map(lambda k_v: k_v[1], sorted(cls._params.local.items()))
688 ports = cls._ports.local
689

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

947def cxxMethod(*args, **kwargs):
948 """Decorator to export C++ functions to Python"""
949
950 def decorate(func):
951 name = func.__name__
952 override = kwargs.get("override", False)
953 cxx_name = kwargs.get("cxx_name", name)
954 return_value_policy = kwargs.get("return_value_policy", None)
688
689 # The 'local' attribute restricts us to the params declared in
690 # the object itself, not including inherited params (which
691 # will also be inherited from the base class's param struct
692 # here). Sort the params based on their key
693 params = map(lambda k_v: k_v[1], sorted(cls._params.local.items()))
694 ports = cls._ports.local
695

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

953def cxxMethod(*args, **kwargs):
954 """Decorator to export C++ functions to Python"""
955
956 def decorate(func):
957 name = func.__name__
958 override = kwargs.get("override", False)
959 cxx_name = kwargs.get("cxx_name", name)
960 return_value_policy = kwargs.get("return_value_policy", None)
961 static = kwargs.get("static", False)
955
956 args, varargs, keywords, defaults = inspect.getargspec(func)
957 if varargs or keywords:
958 raise ValueError("Wrapped methods must not contain variable " \
959 "arguments")
960
961 # Create tuples of (argument, default)
962 if defaults:
963 args = args[:-len(defaults)] + \
964 list(zip(args[-len(defaults):], defaults))
965 # Don't include self in the argument list to PyBind
966 args = args[1:]
967
968
969 @wraps(func)
970 def cxx_call(self, *args, **kwargs):
962
963 args, varargs, keywords, defaults = inspect.getargspec(func)
964 if varargs or keywords:
965 raise ValueError("Wrapped methods must not contain variable " \
966 "arguments")
967
968 # Create tuples of (argument, default)
969 if defaults:
970 args = args[:-len(defaults)] + \
971 list(zip(args[-len(defaults):], defaults))
972 # Don't include self in the argument list to PyBind
973 args = args[1:]
974
975
976 @wraps(func)
977 def cxx_call(self, *args, **kwargs):
971 ccobj = self.getCCObject()
978 ccobj = self.getCCClass() if static else self.getCCObject()
972 return getattr(ccobj, name)(*args, **kwargs)
973
974 @wraps(func)
975 def py_call(self, *args, **kwargs):
976 return func(self, *args, **kwargs)
977
978 f = py_call if override else cxx_call
979 f.__pybind = PyBindMethod(name, cxx_name=cxx_name, args=args,
979 return getattr(ccobj, name)(*args, **kwargs)
980
981 @wraps(func)
982 def py_call(self, *args, **kwargs):
983 return func(self, *args, **kwargs)
984
985 f = py_call if override else cxx_call
986 f.__pybind = PyBindMethod(name, cxx_name=cxx_name, args=args,
980 return_value_policy=return_value_policy)
987 return_value_policy=return_value_policy,
988 static=static)
981
982 return f
983
984 if len(args) == 0:
985 return decorate
986 elif len(args) == 1 and len(kwargs) == 0:
987 return decorate(*args)
988 else:

--- 766 unchanged lines hidden ---
989
990 return f
991
992 if len(args) == 0:
993 return decorate
994 elif len(args) == 1 and len(kwargs) == 0:
995 return decorate(*args)
996 else:

--- 766 unchanged lines hidden ---