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 |
658 if attr == 'pybind_class': 659 return '_COLONS_'.join(cls.cxx_class_path) 660 |
661 if attr in cls._values: 662 return cls._values[attr] 663 664 if attr in cls._children: 665 return cls._children[attr] 666 |
667 try: 668 return getattr(cls.getCCClass(), attr) 669 except AttributeError: 670 raise AttributeError( 671 "object '%s' has no attribute '%s'" % (cls.__name__, attr)) |
672 673 def __str__(cls): 674 return cls.__name__ 675 |
676 def getCCClass(cls): 677 return getattr(m5.internal.params, cls.pybind_class) 678 |
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): |
687 py_class_name = cls.pybind_class |
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) |
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): |
978 ccobj = self.getCCClass() if static else self.getCCObject() |
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, |
987 return_value_policy=return_value_policy, 988 static=static) |
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 --- |