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 * Authors: Gabe Black 28 */ 29 30#include "pybind11/operators.h" 31 32#include "systemc/core/python.hh" 33#include "systemc/ext/core/sc_time.hh" 34 35namespace 36{ 37 38struct InstallScTime : public ::sc_gem5::PythonInitFunc 39{ 40 void 41 run(pybind11::module &systemc) override 42 { 43 pybind11::class_<sc_core::sc_time> sc_time(systemc, "sc_time"); 44 sc_time 45 // 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