gem5  v20.1.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 struct InstallScTime : public ::sc_gem5::PythonInitFunc
37 {
38  void
39  run(pybind11::module &systemc) override
40  {
41  pybind11::class_<sc_core::sc_time> sc_time(systemc, "sc_time");
42  sc_time
43  // Constructors (omitting nonstandard and deprecated)
44  .def(pybind11::init<>())
45  .def(pybind11::init<double, sc_core::sc_time_unit>())
46  .def(pybind11::init<const sc_core::sc_time &>())
47 
48  // Converters.
49  .def("value", &sc_core::sc_time::value)
50  .def("to_double", &sc_core::sc_time::to_double)
51  .def("to_seconds", &sc_core::sc_time::to_seconds)
52  .def("to_string", &sc_core::sc_time::to_string)
53  .def("__str__", &sc_core::sc_time::to_string)
54 
55  // Operators.
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 > pybind11::self)
61  .def(pybind11::self >= pybind11::self)
62  .def(pybind11::self += pybind11::self)
63  .def(pybind11::self -= pybind11::self)
64  .def(pybind11::self *= double())
65  .def(pybind11::self /= double())
66  ;
67 
68  pybind11::enum_<sc_core::sc_time_unit>(sc_time, "sc_time_unit")
69  .value("SC_FS", sc_core::SC_FS)
70  .value("SC_PS", sc_core::SC_PS)
71  .value("SC_NS", sc_core::SC_NS)
72  .value("SC_US", sc_core::SC_US)
73  .value("SC_MS", sc_core::SC_MS)
74  .value("SC_SEC", sc_core::SC_SEC)
75  .export_values()
76  ;
77  }
78 } installScTime;
79 
80 } // 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_gem5::PythonInitFunc::run
virtual void run(pybind11::module &systemc)=0
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:45
sc_core::sc_time::to_string
const std::string to_string() const
Definition: sc_time.cc:132

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17