20#include <pybind11/embed.h>
23#include "scml_clock/scml_clock_if.h"
27namespace py = pybind11;
31 Logger(
const std::string& name)
33 void log(std::string
const& msg)
const { SCCINFO(name) << msg; }
34 std::string get_name()
const {
return name; }
40void wait(
int value, std::string
const& unit) {
42 sc_core::wait(value * 1_fs);
44 sc_core::wait(value * 1_ps);
46 sc_core::wait(value * 1_ns);
48 sc_core::wait(value * 1_us);
50 sc_core::wait(value * 1_ms);
52 sc_core::wait(value * 1_sec);
54 SCCERR(
"Python::wait") <<
"Illegal time unit specification: " << unit;
66void python4sc::run() {
67 wait(sc_core::SC_ZERO_TIME);
68 if(input_file_name.get_value().empty())
71 std::ifstream ifs(input_file_name.get_value());
73 SCCERR(SCMOD) <<
"Cannot read " << input_file_name.get_value() <<
"!";
75 py::scoped_interpreter guard{};
77 py::module_ mod = py::module_::create_extension_module(
"sysc",
nullptr,
new py::module_::module_def);
80 py::class_<Logger>(mod,
"Logger")
81 .def(py::init<std::string>())
82 .def(
"log", &Logger::log)
83 .def(
"get_name", &Logger::get_name);
85 mod.def(
"wait", &::scc::wait);
88 py::module_::import(
"sys").attr(
"modules")[
"sysc"] = mod;
90 py::module_::import(
"sys").attr(
"modules")[e.first.c_str()] = e.second;
93 py::eval_file(input_file_name.get_value());
94 }
catch(py::error_already_set& e) {
95 SCCERR(SCMOD) <<
"Python error: " << e.what();
bool icompare(std::string const &a, std::string const &b)
log
enum defining the log levels