113722Sgabeblack@google.com/*
213722Sgabeblack@google.com * Copyright 2019 Google, Inc.
313722Sgabeblack@google.com *
413722Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
513722Sgabeblack@google.com * modification, are permitted provided that the following conditions are
613722Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
713722Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
813722Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
913722Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1013722Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1113722Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1213722Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1313722Sgabeblack@google.com * this software without specific prior written permission.
1413722Sgabeblack@google.com *
1513722Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1613722Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1713722Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1813722Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1913722Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2013722Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2113722Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2213722Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2313722Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2413722Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2513722Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2613722Sgabeblack@google.com *
2713722Sgabeblack@google.com * Authors: Gabe Black
2813722Sgabeblack@google.com */
2913722Sgabeblack@google.com
3013722Sgabeblack@google.com#include "pybind11/operators.h"
3113722Sgabeblack@google.com
3213722Sgabeblack@google.com#include "systemc/core/python.hh"
3313722Sgabeblack@google.com#include "systemc/ext/core/sc_time.hh"
3413722Sgabeblack@google.com
3513722Sgabeblack@google.comnamespace
3613722Sgabeblack@google.com{
3713722Sgabeblack@google.com
3813722Sgabeblack@google.comstruct InstallScTime : public ::sc_gem5::PythonInitFunc
3913722Sgabeblack@google.com{
4013722Sgabeblack@google.com    void
4113722Sgabeblack@google.com    run(pybind11::module &systemc) override
4213722Sgabeblack@google.com    {
4313722Sgabeblack@google.com        pybind11::class_<sc_core::sc_time> sc_time(systemc, "sc_time");
4413722Sgabeblack@google.com        sc_time
4513722Sgabeblack@google.com            // Constructors (omitting nonstandard and deprecated)
4613722Sgabeblack@google.com            .def(pybind11::init<>())
4713722Sgabeblack@google.com            .def(pybind11::init<double, sc_core::sc_time_unit>())
4813722Sgabeblack@google.com            .def(pybind11::init<const sc_core::sc_time &>())
4913722Sgabeblack@google.com
5013722Sgabeblack@google.com            // Converters.
5113722Sgabeblack@google.com            .def("value", &sc_core::sc_time::value)
5213722Sgabeblack@google.com            .def("to_double", &sc_core::sc_time::to_double)
5313722Sgabeblack@google.com            .def("to_seconds", &sc_core::sc_time::to_seconds)
5413722Sgabeblack@google.com            .def("to_string", &sc_core::sc_time::to_string)
5513722Sgabeblack@google.com            .def("__str__", &sc_core::sc_time::to_string)
5613722Sgabeblack@google.com
5713722Sgabeblack@google.com            // Operators.
5813722Sgabeblack@google.com            .def(pybind11::self == pybind11::self)
5913722Sgabeblack@google.com            .def(pybind11::self != pybind11::self)
6013722Sgabeblack@google.com            .def(pybind11::self < pybind11::self)
6113722Sgabeblack@google.com            .def(pybind11::self <= pybind11::self)
6213722Sgabeblack@google.com            .def(pybind11::self > pybind11::self)
6313722Sgabeblack@google.com            .def(pybind11::self >= pybind11::self)
6413722Sgabeblack@google.com            .def(pybind11::self += pybind11::self)
6513722Sgabeblack@google.com            .def(pybind11::self -= pybind11::self)
6613722Sgabeblack@google.com            .def(pybind11::self *= double())
6713722Sgabeblack@google.com            .def(pybind11::self /= double())
6813722Sgabeblack@google.com            ;
6913722Sgabeblack@google.com
7013722Sgabeblack@google.com        pybind11::enum_<sc_core::sc_time_unit>(sc_time, "sc_time_unit")
7113722Sgabeblack@google.com            .value("SC_FS", sc_core::SC_FS)
7213722Sgabeblack@google.com            .value("SC_PS", sc_core::SC_PS)
7313722Sgabeblack@google.com            .value("SC_NS", sc_core::SC_NS)
7413722Sgabeblack@google.com            .value("SC_US", sc_core::SC_US)
7513722Sgabeblack@google.com            .value("SC_MS", sc_core::SC_MS)
7613722Sgabeblack@google.com            .value("SC_SEC", sc_core::SC_SEC)
7713722Sgabeblack@google.com            .export_values()
7813722Sgabeblack@google.com            ;
7913722Sgabeblack@google.com    }
8013722Sgabeblack@google.com} installScTime;
8113722Sgabeblack@google.com
8213722Sgabeblack@google.com} // anonymous namespace
83