diff options
author | Nikos Nikoleris <nikos.nikoleris@arm.com> | 2019-06-04 13:21:30 +0100 |
---|---|---|
committer | Nikos Nikoleris <nikos.nikoleris@arm.com> | 2019-06-19 10:13:01 +0000 |
commit | a2f0167b6e951e3a293f3c8d2c11188eb5c59012 (patch) | |
tree | 817a2fdeed50953febaf30d08c756348b0f5a5f3 /src/python/m5/util/pybind.py | |
parent | b510f95f43fd0714b87899ee553ae9301b773dd2 (diff) | |
download | gem5-a2f0167b6e951e3a293f3c8d2c11188eb5c59012.tar.xz |
python: Add support for exporting static class methods from c++
This change adds support for exporting static methods in a c++
SimObject from the coressponsing python wrapper class. This will allow
us to define and use c++ methods without the need to instantiate an
object of the corresponding class.
Change-Id: Iaf24c1aa6f20feb5c91241f46ec8db005a6a0c0c
Signed-off-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Signed-off-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/19168
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Diffstat (limited to 'src/python/m5/util/pybind.py')
-rw-r--r-- | src/python/m5/util/pybind.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/python/m5/util/pybind.py b/src/python/m5/util/pybind.py index 4664c1602..e194e37a1 100644 --- a/src/python/m5/util/pybind.py +++ b/src/python/m5/util/pybind.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017 ARM Limited +# Copyright (c) 2017, 2019 ARM Limited # All rights reserved. # # The license below extends only to copyright in the software and shall @@ -59,11 +59,12 @@ class PyBindProperty(PyBindExport): class PyBindMethod(PyBindExport): def __init__(self, name, cxx_name=None, args=None, - return_value_policy=None): + return_value_policy=None, static=False): self.name = name self.cxx_name = cxx_name if cxx_name else name self.args = args self.return_value_policy = return_value_policy + self.method_def = 'def_static' if static else 'def' def _conv_arg(self, value): if isinstance(value, bool): @@ -88,4 +89,4 @@ class PyBindMethod(PyBindExport): return 'py::arg("%s")' % arg arguments.extend(list([ get_arg_decl(a) for a in self.args ])) - code('.def(' + ', '.join(arguments) + ')') + code('.' + self.method_def + '(' + ', '.join(arguments) + ')') |