gem5  v21.2.0.0
sc_time_python.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "pybind11/operators.h"
29 
30 #include "systemc/core/python.hh"
32 
33 namespace
34 {
35 
36 ::sc_gem5::PythonInitFunc installScTime([](pybind11::module_ &systemc) {
37  pybind11::class_<sc_core::sc_time> sc_time(systemc, "sc_time");
38  sc_time
39  // Constructors (omitting nonstandard and deprecated)
40  .def(pybind11::init<>())
41  .def(pybind11::init<double, sc_core::sc_time_unit>())
42  .def(pybind11::init<const sc_core::sc_time &>())
43 
44  // Converters.
45  .def("value", &sc_core::sc_time::value)
46  .def("to_double", &sc_core::sc_time::to_double)
47  .def("to_seconds", &sc_core::sc_time::to_seconds)
48  .def("to_string", &sc_core::sc_time::to_string)
49  .def("__str__", &sc_core::sc_time::to_string)
50 
51  // Operators.
52  .def(pybind11::self == pybind11::self)
53  .def(pybind11::self != pybind11::self)
54  .def(pybind11::self < pybind11::self)
55  .def(pybind11::self <= pybind11::self)
56  .def(pybind11::self > pybind11::self)
57  .def(pybind11::self >= pybind11::self)
58  .def(pybind11::self += pybind11::self)
59  .def(pybind11::self -= pybind11::self)
60  .def(pybind11::self *= double())
61  .def(pybind11::self /= double())
62  ;
63 
64  pybind11::enum_<sc_core::sc_time_unit>(sc_time, "sc_time_unit")
65  .value("SC_FS", sc_core::SC_FS)
66  .value("SC_PS", sc_core::SC_PS)
67  .value("SC_NS", sc_core::SC_NS)
68  .value("SC_US", sc_core::SC_US)
69  .value("SC_MS", sc_core::SC_MS)
70  .value("SC_SEC", sc_core::SC_SEC)
71  .export_values()
72  ;
73 });
74 
75 } // anonymous namespace
sc_core::SC_MS
@ SC_MS
Definition: sc_time.hh:45
sc_core::SC_FS
@ SC_FS
Definition: sc_time.hh:41
sc_core::SC_US
@ SC_US
Definition: sc_time.hh:44
sc_core::sc_time::to_double
double to_double() const
Definition: sc_time.cc:121
python.hh
sc_core::SC_NS
@ SC_NS
Definition: sc_time.hh:43
sc_core::sc_time::to_seconds
double to_seconds() const
Definition: sc_time.cc:126
sc_core::sc_time::value
sc_dt::uint64 value() const
Definition: sc_time.cc:115
sc_core::SC_SEC
@ SC_SEC
Definition: sc_time.hh:46
sc_core::SC_PS
@ SC_PS
Definition: sc_time.hh:42
sc_time.hh
sc_gem5::PythonInitFunc
Definition: python.hh:36
sc_core::sc_time::to_string
const std::string to_string() const
Definition: sc_time.cc:132

Generated on Tue Dec 21 2021 11:34:35 for gem5 by doxygen 1.8.17