mirror of
https://github.com/YosysHQ/yosys
synced 2025-10-11 02:08:08 +00:00
pyosys: rewrite wrapper generator
[skip ci]
This commit is contained in:
parent
88be728353
commit
384f7431fd
7 changed files with 738 additions and 2011 deletions
1
pyosys/.gitignore
vendored
1
pyosys/.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
wrappers.cc
|
wrappers.cc
|
||||||
|
wrappers.inc.cc
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
2617
pyosys/generator.py
2617
pyosys/generator.py
File diff suppressed because it is too large
Load diff
|
@ -48,6 +48,7 @@
|
||||||
#include "kernel/hashlib.h"
|
#include "kernel/hashlib.h"
|
||||||
|
|
||||||
namespace pybind11 {
|
namespace pybind11 {
|
||||||
|
namespace hashlib {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_pointer { static const bool value = false; };
|
struct is_pointer { static const bool value = false; };
|
||||||
|
@ -59,6 +60,11 @@ bool is_mapping(object obj) {
|
||||||
return isinstance(obj, mapping);
|
return isinstance(obj, mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// shim
|
||||||
|
template <typename C, typename V>
|
||||||
|
void bind_vector(module &m, const char *name_cstr) {
|
||||||
|
pybind11::bind_vector<C>(m, name_cstr);
|
||||||
|
}
|
||||||
|
|
||||||
// also used for std::set because the semantics are close enough
|
// also used for std::set because the semantics are close enough
|
||||||
template <typename C, typename T>
|
template <typename C, typename T>
|
||||||
|
@ -106,6 +112,13 @@ void bind_pool(module &m, const char *name_cstr) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// shim
|
||||||
|
template <typename C, typename T>
|
||||||
|
void bind_set(module &m, const char *name_cstr) {
|
||||||
|
bind_pool<C, T>(m, name_cstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename C, typename K, typename V>
|
template <typename C, typename K, typename V>
|
||||||
void update_dict(C *target, iterable &iterable_or_mapping) {
|
void update_dict(C *target, iterable &iterable_or_mapping) {
|
||||||
if (is_mapping(iterable_or_mapping)) {
|
if (is_mapping(iterable_or_mapping)) {
|
||||||
|
@ -272,4 +285,5 @@ void bind_idict(module &m, const char *name_cstr) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}; // namespace hashlib
|
||||||
}; // namespace pybind11
|
}; // namespace pybind11
|
||||||
|
|
|
@ -26,7 +26,12 @@
|
||||||
|
|
||||||
USING_YOSYS_NAMESPACE
|
USING_YOSYS_NAMESPACE
|
||||||
|
|
||||||
// <!-- generated top-level code -->
|
using std::set;
|
||||||
|
using std::regex;
|
||||||
|
using std::ostream;
|
||||||
|
using namespace RTLIL;
|
||||||
|
|
||||||
|
#include "wrappers.inc.cc"
|
||||||
|
|
||||||
namespace YOSYS_PYTHON {
|
namespace YOSYS_PYTHON {
|
||||||
|
|
||||||
|
@ -37,8 +42,6 @@ namespace YOSYS_PYTHON {
|
||||||
|
|
||||||
struct YosysStatics{};
|
struct YosysStatics{};
|
||||||
|
|
||||||
// <!-- generated YOSYS_PYTHON namespace-level code -->
|
|
||||||
|
|
||||||
// Trampolines for Classes with Python-Overridable Virtual Methods
|
// Trampolines for Classes with Python-Overridable Virtual Methods
|
||||||
// https://pybind11.readthedocs.io/en/stable/advanced/classes.html#overriding-virtual-functions-in-python
|
// https://pybind11.readthedocs.io/en/stable/advanced/classes.html#overriding-virtual-functions-in-python
|
||||||
class PassTrampoline : public Pass {
|
class PassTrampoline : public Pass {
|
||||||
|
@ -182,7 +185,18 @@ namespace YOSYS_PYTHON {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
m.def("log_to_stream", &log_to_stream, "pipes yosys logs to a Python stream");
|
// Logging Methods
|
||||||
|
m.def("log_header", [](Design *d, std::string s) { log_formatted_header(d, "%s", s); });
|
||||||
|
m.def("log", [](std::string s) { log_formatted_string("%s", s); });
|
||||||
|
m.def("log_file_info", [](std::string_view file, int line, std::string s) { log_formatted_file_info(file, line, s); });
|
||||||
|
m.def("log_warning", [](std::string s) { log_formatted_warning("Warning: ", s); });
|
||||||
|
m.def("log_warning_noprefix", [](std::string s) { log_formatted_warning("", s); });
|
||||||
|
m.def("log_file_warning", [](std::string_view file, int line, std::string s) { log_formatted_file_warning(file, line, s); });
|
||||||
|
m.def("log_error", [](std::string s) { log_formatted_error(s); });
|
||||||
|
m.def("log_file_error", [](std::string_view file, int line, std::string s) { log_formatted_file_error(file, line, s); });
|
||||||
|
|
||||||
|
// Namespace to host global objects
|
||||||
|
auto global_variables = py::class_<YosysStatics>(m, "Yosys");
|
||||||
|
|
||||||
// Trampoline Classes
|
// Trampoline Classes
|
||||||
py::class_<Pass, YOSYS_PYTHON::PassTrampoline, std::unique_ptr<Pass, py::nodelete>>(m, "Pass")
|
py::class_<Pass, YOSYS_PYTHON::PassTrampoline, std::unique_ptr<Pass, py::nodelete>>(m, "Pass")
|
||||||
|
@ -241,6 +255,9 @@ namespace YOSYS_PYTHON {
|
||||||
.def("notify_blackout", &RTLIL::Monitor::notify_blackout)
|
.def("notify_blackout", &RTLIL::Monitor::notify_blackout)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
// Bind Opaque Containers
|
||||||
|
bind_autogenerated_opaque_containers(m);
|
||||||
|
|
||||||
// <!-- generated pymod-level code -->
|
// <!-- generated pymod-level code -->
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,5 +2,6 @@
|
||||||
requires = [
|
requires = [
|
||||||
"setuptools>=42",
|
"setuptools>=42",
|
||||||
"pybind11>=3,<4",
|
"pybind11>=3,<4",
|
||||||
|
"cxxheaderparser",
|
||||||
]
|
]
|
||||||
build-backend = "setuptools.build_meta"
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
8
tests/pyosys/test_logs.py
Normal file
8
tests/pyosys/test_logs.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
from pyosys import libyosys as ys
|
||||||
|
|
||||||
|
d = ys.Design(); ys.log_header(d, "foo\n")
|
||||||
|
ys.log("foo\n")
|
||||||
|
ys.log_warning("foo\n")
|
||||||
|
ys.log_warning_noprefix("foo\n")
|
||||||
|
ys.log_file_info("foo.ys", 1, "foo\n")
|
||||||
|
ys.log_file_warning("foo.ys", 1, "foo\n")
|
Loading…
Add table
Add a link
Reference in a new issue