sc_time_python.cc revision 13722
16226Snate@binkert.org/*
26226Snate@binkert.org * Copyright 2019 Google, Inc.
36226Snate@binkert.org *
46226Snate@binkert.org * Redistribution and use in source and binary forms, with or without
56226Snate@binkert.org * modification, are permitted provided that the following conditions are
66226Snate@binkert.org * met: redistributions of source code must retain the above copyright
76226Snate@binkert.org * notice, this list of conditions and the following disclaimer;
86226Snate@binkert.org * redistributions in binary form must reproduce the above copyright
96226Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
106226Snate@binkert.org * documentation and/or other materials provided with the distribution;
116226Snate@binkert.org * neither the name of the copyright holders nor the names of its
126226Snate@binkert.org * contributors may be used to endorse or promote products derived from
136226Snate@binkert.org * this software without specific prior written permission.
146226Snate@binkert.org *
156226Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
166226Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
176226Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
186226Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
196226Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
206226Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
216226Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
226226Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
236226Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
246226Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
256226Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
266226Snate@binkert.org *
276226Snate@binkert.org * Authors: Gabe Black
286226Snate@binkert.org */
296226Snate@binkert.org
306226Snate@binkert.org#include "pybind11/operators.h"
316226Snate@binkert.org
326226Snate@binkert.org#include "systemc/core/python.hh"
3310281SAndreas.Sandberg@ARM.com#include "systemc/ext/core/sc_time.hh"
3410281SAndreas.Sandberg@ARM.com
359480Snilay@cs.wisc.edunamespace
3610281SAndreas.Sandberg@ARM.com{
3710281SAndreas.Sandberg@ARM.com
3810281SAndreas.Sandberg@ARM.comstruct InstallScTime : public ::sc_gem5::PythonInitFunc
3910281SAndreas.Sandberg@ARM.com{
4010281SAndreas.Sandberg@ARM.com    void
4110281SAndreas.Sandberg@ARM.com    run(pybind11::module &systemc) override
4210281SAndreas.Sandberg@ARM.com    {
4310281SAndreas.Sandberg@ARM.com        pybind11::class_<sc_core::sc_time> sc_time(systemc, "sc_time");
4410281SAndreas.Sandberg@ARM.com        sc_time
4510281SAndreas.Sandberg@ARM.com            // Constructors (omitting nonstandard and deprecated)
46            .def(pybind11::init<>())
47            .def(pybind11::init<double, sc_core::sc_time_unit>())
48            .def(pybind11::init<const sc_core::sc_time &>())
49
50            // Converters.
51            .def("value", &sc_core::sc_time::value)
52            .def("to_double", &sc_core::sc_time::to_double)
53            .def("to_seconds", &sc_core::sc_time::to_seconds)
54            .def("to_string", &sc_core::sc_time::to_string)
55            .def("__str__", &sc_core::sc_time::to_string)
56
57            // Operators.
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 += pybind11::self)
65            .def(pybind11::self -= pybind11::self)
66            .def(pybind11::self *= double())
67            .def(pybind11::self /= double())
68            ;
69
70        pybind11::enum_<sc_core::sc_time_unit>(sc_time, "sc_time_unit")
71            .value("SC_FS", sc_core::SC_FS)
72            .value("SC_PS", sc_core::SC_PS)
73            .value("SC_NS", sc_core::SC_NS)
74            .value("SC_US", sc_core::SC_US)
75            .value("SC_MS", sc_core::SC_MS)
76            .value("SC_SEC", sc_core::SC_SEC)
77            .export_values()
78            ;
79    }
80} installScTime;
81
82} // anonymous namespace
83