mirror of
https://github.com/YosysHQ/yosys
synced 2026-07-19 21:55:48 +00:00
Merge remote-tracking branch 'donn/pyosys_bugfixes' into merge_pybind11
This commit is contained in:
commit
dec28f65ae
127 changed files with 4674 additions and 7342 deletions
|
|
@ -37,6 +37,12 @@
|
|||
# include <tcl.h>
|
||||
#endif
|
||||
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
# include <Python.h>
|
||||
# include <pybind11/pybind11.h>
|
||||
namespace py = pybind11;
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
|
@ -91,9 +97,10 @@ int main(int argc, char **argv)
|
|||
log_error_stderr = true;
|
||||
yosys_banner();
|
||||
yosys_setup();
|
||||
#ifdef WITH_PYTHON
|
||||
PyRun_SimpleString(("sys.path.append(\""+proc_self_dirname()+"\")").c_str());
|
||||
PyRun_SimpleString(("sys.path.append(\""+proc_share_dirname()+"plugins\")").c_str());
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
py::object sys = py::module_::import("sys");
|
||||
sys.attr("path").attr("append")(proc_self_dirname());
|
||||
sys.attr("path").attr("append")(proc_share_dirname());
|
||||
#endif
|
||||
|
||||
if (argc == 2)
|
||||
|
|
@ -226,10 +233,10 @@ int main(int argc, char **argv)
|
|||
cxxopts::value<std::string>(),"<tcl_scriptfile>")
|
||||
("C,tcl-interactive", "enters TCL interactive shell mode")
|
||||
#endif // YOSYS_ENABLE_TCL
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
("y,py-scriptfile", "execute the Python <script>",
|
||||
cxxopts::value<std::string>(), "<script>")
|
||||
#endif // WITH_PYTHON
|
||||
#endif // YOSYS_ENABLE_PYTHON
|
||||
("p,commands", "execute <commands> (to chain commands, separate them with semicolon + whitespace: 'cmd1; cmd2')",
|
||||
cxxopts::value<std::vector<std::string>>(), "<commands>")
|
||||
("r,top", "elaborate the specified HDL <top> module",
|
||||
|
|
@ -515,9 +522,10 @@ int main(int argc, char **argv)
|
|||
#endif
|
||||
|
||||
yosys_setup();
|
||||
#ifdef WITH_PYTHON
|
||||
PyRun_SimpleString(("sys.path.append(\""+proc_self_dirname()+"\")").c_str());
|
||||
PyRun_SimpleString(("sys.path.append(\""+proc_share_dirname()+"plugins\")").c_str());
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
py::object sys = py::module_::import("sys");
|
||||
sys.attr("path").attr("append")(proc_self_dirname());
|
||||
sys.attr("path").attr("append")(proc_share_dirname());
|
||||
#endif
|
||||
log_error_atexit = yosys_atexit;
|
||||
|
||||
|
|
@ -566,22 +574,19 @@ int main(int argc, char **argv)
|
|||
log_error("Can't execute TCL script: this version of yosys is not built with TCL support enabled.\n");
|
||||
#endif
|
||||
} else if (scriptfile_python) {
|
||||
#ifdef WITH_PYTHON
|
||||
PyObject *sys = PyImport_ImportModule("sys");
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
py::list new_argv;
|
||||
int py_argc = special_args.size() + 1;
|
||||
PyObject *new_argv = PyList_New(py_argc);
|
||||
PyList_SetItem(new_argv, 0, PyUnicode_FromString(scriptfile.c_str()));
|
||||
new_argv.append(scriptfile);
|
||||
for (int i = 1; i < py_argc; ++i)
|
||||
PyList_SetItem(new_argv, i, PyUnicode_FromString(special_args[i - 1].c_str()));
|
||||
new_argv.append(special_args[i - 1]);
|
||||
|
||||
PyObject *old_argv = PyObject_GetAttrString(sys, "argv");
|
||||
PyObject_SetAttrString(sys, "argv", new_argv);
|
||||
Py_DECREF(old_argv);
|
||||
py::setattr(sys, "argv", new_argv);
|
||||
|
||||
PyObject *py_path = PyUnicode_FromString(scriptfile.c_str());
|
||||
PyObject_SetAttrString(sys, "_yosys_script_path", py_path);
|
||||
Py_DECREF(py_path);
|
||||
PyRun_SimpleString("import os, sys; sys.path.insert(0, os.path.dirname(os.path.abspath(sys._yosys_script_path)))");
|
||||
py::object Path = py::module_::import("pathlib").attr("Path");
|
||||
py::object scriptfile_python_path = Path(scriptfile).attr("parent");
|
||||
|
||||
sys.attr("path").attr("insert")(0, py::str(scriptfile_python_path));
|
||||
|
||||
FILE *scriptfp = fopen(scriptfile.c_str(), "r");
|
||||
if (scriptfp == nullptr) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#define HASHLIB_H
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
|
|
@ -1361,8 +1362,18 @@ public:
|
|||
template<typename K, typename OPS>
|
||||
class mfp
|
||||
{
|
||||
mutable idict<K, 0, OPS> database;
|
||||
mutable std::vector<int> parents;
|
||||
idict<K, 0, OPS> database;
|
||||
class AtomicParent {
|
||||
public:
|
||||
explicit AtomicParent(int p) : parent(p) {}
|
||||
AtomicParent(const AtomicParent &other) : parent(other.get()) {}
|
||||
AtomicParent &operator=(const AtomicParent &other) { set(other.get()); return *this; }
|
||||
int get() const { return parent.load(std::memory_order_relaxed); }
|
||||
void set(int p) { parent.store(p, std::memory_order_relaxed); }
|
||||
private:
|
||||
std::atomic<int> parent;
|
||||
};
|
||||
std::vector<AtomicParent> parents;
|
||||
|
||||
public:
|
||||
typedef typename idict<K, 0>::const_iterator const_iterator;
|
||||
|
|
@ -1373,12 +1384,14 @@ public:
|
|||
|
||||
// Finds a given element's index. If it isn't in the data structure,
|
||||
// it is added as its own set
|
||||
int operator()(const K &key) const
|
||||
int operator()(const K &key)
|
||||
{
|
||||
int i = database(key);
|
||||
// If the lookup caused the database to grow,
|
||||
// also add a corresponding entry in parents initialized to -1 (no parent)
|
||||
parents.resize(database.size(), -1);
|
||||
if (parents.size() < database.size()) {
|
||||
parents.emplace_back(-1);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
|
@ -1388,21 +1401,38 @@ public:
|
|||
return database[index];
|
||||
}
|
||||
|
||||
// Why this method is correct for concurent ifind() calls:
|
||||
// Consider the mfp state after the last non-const method call before
|
||||
// a particular call to ifind(i). In this state, i's parent chain leads
|
||||
// to some root R. Let S be the set of integers s such that ifind(s) = R
|
||||
// in this state. Let 'orig_parents' be the value of 'parents' in this state.
|
||||
//
|
||||
// Now consider the concurrent calls to ifind(s), s ∈ S, before the next non-const method
|
||||
// call. Consider the atomic writes performed by various ifind() calls, in any causally
|
||||
// consistent order. The first atomic write can only set parents[k] to R, because the
|
||||
// atomic read of parents[p] in the first while loop can only observe the value
|
||||
// 'orig_parents[p]'. Subsequent writes can also only set parents[k] to R, because the
|
||||
// parents[p] reads either observe 'orig_parents[p]' or R (and observing R ends the first
|
||||
// while loop immediately). Thus all parents[p] reads observe either 'orig_parents[p]'
|
||||
// or R, so ifind() always returns R.
|
||||
int ifind(int i) const
|
||||
{
|
||||
int p = i, k = i;
|
||||
|
||||
while (parents[p] != -1)
|
||||
p = parents[p];
|
||||
|
||||
while (true) {
|
||||
int pp = parents[p].get();
|
||||
if (pp < 0)
|
||||
break;
|
||||
p = pp;
|
||||
}
|
||||
// p is now the representative of i
|
||||
// Now we traverse from i up to the representative again
|
||||
// and make p the parent of all the nodes along the way.
|
||||
// This is a side effect and doesn't affect the return value.
|
||||
// It speeds up future find operations
|
||||
while (k != p) {
|
||||
int next_k = parents[k];
|
||||
parents[k] = p;
|
||||
int next_k = parents[k].get();
|
||||
const_cast<AtomicParent*>(&parents[k])->set(p);
|
||||
k = next_k;
|
||||
}
|
||||
|
||||
|
|
@ -1417,7 +1447,7 @@ public:
|
|||
j = ifind(j);
|
||||
|
||||
if (i != j)
|
||||
parents[i] = j;
|
||||
parents[i].set(j);
|
||||
}
|
||||
|
||||
void ipromote(int i)
|
||||
|
|
@ -1425,15 +1455,15 @@ public:
|
|||
int k = i;
|
||||
|
||||
while (k != -1) {
|
||||
int next_k = parents[k];
|
||||
parents[k] = i;
|
||||
int next_k = parents[k].get();
|
||||
parents[k].set(i);
|
||||
k = next_k;
|
||||
}
|
||||
|
||||
parents[i] = -1;
|
||||
parents[i].set(-1);
|
||||
}
|
||||
|
||||
int lookup(const K &a) const
|
||||
int lookup(const K &a)
|
||||
{
|
||||
return ifind((*this)(a));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -384,6 +384,13 @@ std::string escape_filename_spaces(const std::string& filename)
|
|||
return out;
|
||||
}
|
||||
|
||||
void append_globbed(std::vector<std::string>& paths, std::string pattern)
|
||||
{
|
||||
rewrite_filename(pattern);
|
||||
std::vector<std::string> globbed = glob_filename(pattern);
|
||||
copy(globbed.begin(), globbed.end(), back_inserter(paths));
|
||||
}
|
||||
|
||||
void format_emit_unescaped(std::string &result, std::string_view fmt)
|
||||
{
|
||||
result.reserve(result.size() + fmt.size());
|
||||
|
|
|
|||
|
|
@ -469,6 +469,7 @@ bool is_absolute_path(std::string filename);
|
|||
void remove_directory(std::string dirname);
|
||||
bool create_directory(const std::string& dirname);
|
||||
std::string escape_filename_spaces(const std::string& filename);
|
||||
void append_globbed(std::vector<std::string>& paths, std::string pattern);
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
||||
|
|
|
|||
|
|
@ -266,10 +266,10 @@ std::string& Const::get_str() {
|
|||
return *get_if_str();
|
||||
}
|
||||
|
||||
RTLIL::Const::Const(const std::string &str)
|
||||
RTLIL::Const::Const(std::string str)
|
||||
{
|
||||
flags = RTLIL::CONST_FLAG_STRING;
|
||||
new ((void*)&str_) std::string(str);
|
||||
new ((void*)&str_) std::string(std::move(str));
|
||||
tag = backing_tag::string;
|
||||
}
|
||||
|
||||
|
|
@ -1093,7 +1093,7 @@ RTLIL::Design::Design()
|
|||
refcount_modules_ = 0;
|
||||
push_full_selection();
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
RTLIL::Design::get_all_designs()->insert(std::pair<unsigned int, RTLIL::Design*>(hashidx_, this));
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1104,12 +1104,12 @@ RTLIL::Design::~Design()
|
|||
delete pr.second;
|
||||
for (auto n : bindings_)
|
||||
delete n;
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
RTLIL::Design::get_all_designs()->erase(hashidx_);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
static std::map<unsigned int, RTLIL::Design*> all_designs;
|
||||
std::map<unsigned int, RTLIL::Design*> *RTLIL::Design::get_all_designs(void)
|
||||
{
|
||||
|
|
@ -1446,7 +1446,7 @@ RTLIL::Module::Module()
|
|||
refcount_wires_ = 0;
|
||||
refcount_cells_ = 0;
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
RTLIL::Module::get_all_modules()->insert(std::pair<unsigned int, RTLIL::Module*>(hashidx_, this));
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1463,12 +1463,12 @@ RTLIL::Module::~Module()
|
|||
delete pr.second;
|
||||
for (auto binding : bindings_)
|
||||
delete binding;
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
RTLIL::Module::get_all_modules()->erase(hashidx_);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
static std::map<unsigned int, RTLIL::Module*> all_modules;
|
||||
std::map<unsigned int, RTLIL::Module*> *RTLIL::Module::get_all_modules(void)
|
||||
{
|
||||
|
|
@ -3082,7 +3082,7 @@ void RTLIL::Module::fixup_ports()
|
|||
RTLIL::Wire *RTLIL::Module::addWire(RTLIL::IdString name, int width)
|
||||
{
|
||||
RTLIL::Wire *wire = new RTLIL::Wire;
|
||||
wire->name = name;
|
||||
wire->name = std::move(name);
|
||||
wire->width = width;
|
||||
add(wire);
|
||||
return wire;
|
||||
|
|
@ -3090,7 +3090,7 @@ RTLIL::Wire *RTLIL::Module::addWire(RTLIL::IdString name, int width)
|
|||
|
||||
RTLIL::Wire *RTLIL::Module::addWire(RTLIL::IdString name, const RTLIL::Wire *other)
|
||||
{
|
||||
RTLIL::Wire *wire = addWire(name);
|
||||
RTLIL::Wire *wire = addWire(std::move(name));
|
||||
wire->width = other->width;
|
||||
wire->start_offset = other->start_offset;
|
||||
wire->port_id = other->port_id;
|
||||
|
|
@ -3105,7 +3105,7 @@ RTLIL::Wire *RTLIL::Module::addWire(RTLIL::IdString name, const RTLIL::Wire *oth
|
|||
RTLIL::Cell *RTLIL::Module::addCell(RTLIL::IdString name, RTLIL::IdString type)
|
||||
{
|
||||
RTLIL::Cell *cell = new RTLIL::Cell;
|
||||
cell->name = name;
|
||||
cell->name = std::move(name);
|
||||
cell->type = type;
|
||||
add(cell);
|
||||
return cell;
|
||||
|
|
@ -3113,17 +3113,25 @@ RTLIL::Cell *RTLIL::Module::addCell(RTLIL::IdString name, RTLIL::IdString type)
|
|||
|
||||
RTLIL::Cell *RTLIL::Module::addCell(RTLIL::IdString name, const RTLIL::Cell *other)
|
||||
{
|
||||
RTLIL::Cell *cell = addCell(name, other->type);
|
||||
RTLIL::Cell *cell = addCell(std::move(name), other->type);
|
||||
cell->connections_ = other->connections_;
|
||||
cell->parameters = other->parameters;
|
||||
cell->attributes = other->attributes;
|
||||
return cell;
|
||||
}
|
||||
|
||||
RTLIL::Memory *RTLIL::Module::addMemory(RTLIL::IdString name)
|
||||
{
|
||||
RTLIL::Memory *mem = new RTLIL::Memory;
|
||||
mem->name = std::move(name);
|
||||
memories[mem->name] = mem;
|
||||
return mem;
|
||||
}
|
||||
|
||||
RTLIL::Memory *RTLIL::Module::addMemory(RTLIL::IdString name, const RTLIL::Memory *other)
|
||||
{
|
||||
RTLIL::Memory *mem = new RTLIL::Memory;
|
||||
mem->name = name;
|
||||
mem->name = std::move(name);
|
||||
mem->width = other->width;
|
||||
mem->start_offset = other->start_offset;
|
||||
mem->size = other->size;
|
||||
|
|
@ -3135,7 +3143,7 @@ RTLIL::Memory *RTLIL::Module::addMemory(RTLIL::IdString name, const RTLIL::Memor
|
|||
RTLIL::Process *RTLIL::Module::addProcess(RTLIL::IdString name)
|
||||
{
|
||||
RTLIL::Process *proc = new RTLIL::Process;
|
||||
proc->name = name;
|
||||
proc->name = std::move(name);
|
||||
add(proc);
|
||||
return proc;
|
||||
}
|
||||
|
|
@ -3143,7 +3151,7 @@ RTLIL::Process *RTLIL::Module::addProcess(RTLIL::IdString name)
|
|||
RTLIL::Process *RTLIL::Module::addProcess(RTLIL::IdString name, const RTLIL::Process *other)
|
||||
{
|
||||
RTLIL::Process *proc = other->clone();
|
||||
proc->name = name;
|
||||
proc->name = std::move(name);
|
||||
add(proc);
|
||||
return proc;
|
||||
}
|
||||
|
|
@ -4162,19 +4170,19 @@ RTLIL::Wire::Wire()
|
|||
upto = false;
|
||||
is_signed = false;
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
RTLIL::Wire::get_all_wires()->insert(std::pair<unsigned int, RTLIL::Wire*>(hashidx_, this));
|
||||
#endif
|
||||
}
|
||||
|
||||
RTLIL::Wire::~Wire()
|
||||
{
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
RTLIL::Wire::get_all_wires()->erase(hashidx_);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
static std::map<unsigned int, RTLIL::Wire*> all_wires;
|
||||
std::map<unsigned int, RTLIL::Wire*> *RTLIL::Wire::get_all_wires(void)
|
||||
{
|
||||
|
|
@ -4191,7 +4199,7 @@ RTLIL::Memory::Memory()
|
|||
width = 1;
|
||||
start_offset = 0;
|
||||
size = 0;
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
RTLIL::Memory::get_all_memorys()->insert(std::pair<unsigned int, RTLIL::Memory*>(hashidx_, this));
|
||||
#endif
|
||||
}
|
||||
|
|
@ -4212,19 +4220,19 @@ RTLIL::Cell::Cell() : module(nullptr)
|
|||
// log("#memtrace# %p\n", this);
|
||||
memhasher();
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
RTLIL::Cell::get_all_cells()->insert(std::pair<unsigned int, RTLIL::Cell*>(hashidx_, this));
|
||||
#endif
|
||||
}
|
||||
|
||||
RTLIL::Cell::~Cell()
|
||||
{
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
RTLIL::Cell::get_all_cells()->erase(hashidx_);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
static std::map<unsigned int, RTLIL::Cell*> all_cells;
|
||||
std::map<unsigned int, RTLIL::Cell*> *RTLIL::Cell::get_all_cells(void)
|
||||
{
|
||||
|
|
@ -6026,7 +6034,7 @@ RTLIL::Process *RTLIL::Process::clone() const
|
|||
return new_proc;
|
||||
}
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
RTLIL::Memory::~Memory()
|
||||
{
|
||||
RTLIL::Memory::get_all_memorys()->erase(hashidx_);
|
||||
|
|
|
|||
|
|
@ -209,10 +209,15 @@ struct RTLIL::IdString
|
|||
}
|
||||
|
||||
static int get_reference(const char *p)
|
||||
{
|
||||
return get_reference(std::string_view(p));
|
||||
}
|
||||
|
||||
static int get_reference(std::string_view p)
|
||||
{
|
||||
log_assert(destruct_guard_ok);
|
||||
|
||||
auto it = global_id_index_.find((char*)p);
|
||||
auto it = global_id_index_.find(p);
|
||||
if (it != global_id_index_.end()) {
|
||||
#ifndef YOSYS_NO_IDS_REFCNT
|
||||
global_refcount_storage_.at(it->second)++;
|
||||
|
|
@ -226,14 +231,13 @@ struct RTLIL::IdString
|
|||
|
||||
ensure_prepopulated();
|
||||
|
||||
if (!p[0])
|
||||
if (p.empty())
|
||||
return 0;
|
||||
|
||||
log_assert(p[0] == '$' || p[0] == '\\');
|
||||
log_assert(p[1] != 0);
|
||||
for (const char *c = p; *c; c++)
|
||||
if ((unsigned)*c <= (unsigned)' ')
|
||||
log_error("Found control character or space (0x%02x) in string '%s' which is not allowed in RTLIL identifiers\n", *c, p);
|
||||
for (char ch : p)
|
||||
if ((unsigned)ch <= (unsigned)' ')
|
||||
log_error("Found control character or space (0x%02x) in string '%s' which is not allowed in RTLIL identifiers\n", ch, std::string(p).c_str());
|
||||
|
||||
#ifndef YOSYS_NO_IDS_REFCNT
|
||||
if (global_free_idx_list_.empty()) {
|
||||
|
|
@ -245,8 +249,11 @@ struct RTLIL::IdString
|
|||
|
||||
int idx = global_free_idx_list_.back();
|
||||
global_free_idx_list_.pop_back();
|
||||
global_id_storage_.at(idx) = strdup(p);
|
||||
global_id_index_[global_id_storage_.at(idx)] = idx;
|
||||
char* buf = static_cast<char*>(malloc(p.size() + 1));
|
||||
memcpy(buf, p.data(), p.size());
|
||||
buf[p.size()] = 0;
|
||||
global_id_storage_.at(idx) = buf;
|
||||
global_id_index_.insert(it, {std::string_view(buf, p.size()), idx});
|
||||
global_refcount_storage_.at(idx)++;
|
||||
#else
|
||||
int idx = global_id_storage_.size();
|
||||
|
|
@ -255,7 +262,7 @@ struct RTLIL::IdString
|
|||
#endif
|
||||
|
||||
if (yosys_xtrace) {
|
||||
log("#X# New IdString '%s' with index %d.\n", p, idx);
|
||||
log("#X# New IdString '%s' with index %d.\n", global_id_storage_.at(idx), idx);
|
||||
log_backtrace("-X- ", yosys_xtrace-1);
|
||||
}
|
||||
|
||||
|
|
@ -322,7 +329,8 @@ struct RTLIL::IdString
|
|||
inline IdString(const char *str) : index_(get_reference(str)) { }
|
||||
inline IdString(const IdString &str) : index_(get_reference(str.index_)) { }
|
||||
inline IdString(IdString &&str) : index_(str.index_) { str.index_ = 0; }
|
||||
inline IdString(const std::string &str) : index_(get_reference(str.c_str())) { }
|
||||
inline IdString(const std::string &str) : index_(get_reference(std::string_view(str))) { }
|
||||
inline IdString(std::string_view str) : index_(get_reference(str)) { }
|
||||
inline IdString(StaticId id) : index_(static_cast<short>(id)) {}
|
||||
inline ~IdString() { put_reference(index_); }
|
||||
|
||||
|
|
@ -331,6 +339,12 @@ struct RTLIL::IdString
|
|||
index_ = get_reference(rhs.index_);
|
||||
}
|
||||
|
||||
inline void operator=(IdString &&rhs) {
|
||||
put_reference(index_);
|
||||
index_ = rhs.index_;
|
||||
rhs.index_ = 0;
|
||||
}
|
||||
|
||||
inline void operator=(const char *rhs) {
|
||||
IdString id(rhs);
|
||||
*this = id;
|
||||
|
|
@ -866,9 +880,9 @@ private:
|
|||
|
||||
public:
|
||||
Const() : flags(RTLIL::CONST_FLAG_NONE), tag(backing_tag::bits), bits_(std::vector<RTLIL::State>()) {}
|
||||
Const(const std::string &str);
|
||||
Const(long long int val); // default width is 32
|
||||
Const(long long int val, int width);
|
||||
Const(std::string str);
|
||||
Const(long long val); // default width is 32
|
||||
Const(long long val, int width);
|
||||
Const(RTLIL::State bit, int width = 1);
|
||||
Const(std::vector<RTLIL::State> bits) : flags(RTLIL::CONST_FLAG_NONE), tag(backing_tag::bits), bits_(std::move(bits)) {}
|
||||
Const(const std::vector<bool> &bits);
|
||||
|
|
@ -1347,7 +1361,7 @@ public:
|
|||
inline bool is_bit() const { return width_ == 1; }
|
||||
|
||||
bool known_driver() const;
|
||||
|
||||
|
||||
bool is_mostly_const() const;
|
||||
bool is_fully_const() const;
|
||||
bool is_fully_zero() const;
|
||||
|
|
@ -1693,7 +1707,7 @@ struct RTLIL::Design
|
|||
// SILIMATE ADDED TO IMPROVE PYOSYS API
|
||||
void run_pass(std::string command);
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
static std::map<unsigned int, RTLIL::Design*> *get_all_designs(void);
|
||||
#endif
|
||||
};
|
||||
|
|
@ -1826,6 +1840,7 @@ public:
|
|||
RTLIL::Cell *addCell(RTLIL::IdString name, RTLIL::IdString type);
|
||||
RTLIL::Cell *addCell(RTLIL::IdString name, const RTLIL::Cell *other);
|
||||
|
||||
RTLIL::Memory *addMemory(RTLIL::IdString name);
|
||||
RTLIL::Memory *addMemory(RTLIL::IdString name, const RTLIL::Memory *other);
|
||||
|
||||
RTLIL::Process *addProcess(RTLIL::IdString name);
|
||||
|
|
@ -2056,7 +2071,7 @@ public:
|
|||
std::string rtlil_dump();
|
||||
unsigned int rtlil_hash();
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
static std::map<unsigned int, RTLIL::Module*> *get_all_modules(void);
|
||||
#endif
|
||||
};
|
||||
|
|
@ -2109,7 +2124,7 @@ public:
|
|||
return zero_index + start_offset;
|
||||
}
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
static std::map<unsigned int, RTLIL::Wire*> *get_all_wires(void);
|
||||
#endif
|
||||
};
|
||||
|
|
@ -2126,7 +2141,7 @@ struct RTLIL::Memory : public RTLIL::NamedObject
|
|||
Memory();
|
||||
|
||||
int width, start_offset, size;
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
~Memory();
|
||||
static std::map<unsigned int, RTLIL::Memory*> *get_all_memorys(void);
|
||||
#endif
|
||||
|
|
@ -2184,7 +2199,7 @@ public:
|
|||
template<typename T> void rewrite_sigspecs(T &functor);
|
||||
template<typename T> void rewrite_sigspecs2(T &functor);
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
static std::map<unsigned int, RTLIL::Cell*> *get_all_cells(void);
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,12 @@
|
|||
# include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
# include <Python.h>
|
||||
# include <pybind11/pybind11.h>
|
||||
namespace py = pybind11;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <windows.h>
|
||||
# include <io.h>
|
||||
|
|
@ -65,14 +71,9 @@
|
|||
# include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
# define INIT_MODULE PyInit_libyosys
|
||||
extern "C" PyObject* INIT_MODULE();
|
||||
#else
|
||||
# define INIT_MODULE initlibyosys
|
||||
extern "C" void INIT_MODULE();
|
||||
#endif
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
extern "C" PyObject* PyInit_libyosys();
|
||||
extern "C" PyObject* PyInit_pyosys();
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
|
|
@ -191,6 +192,25 @@ int run_command(const std::string &command, std::function<void(const std::string
|
|||
bool already_setup = false;
|
||||
bool already_shutdown = false;
|
||||
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
// Include pyosys as a package for some compatibility with wheels.
|
||||
//
|
||||
// This should not affect using wheels as the dylib has to actually be called
|
||||
// pyosys.so for this function to be interacted with at all.
|
||||
PYBIND11_MODULE(pyosys, m) {
|
||||
m.add_object("__path__", py::list());
|
||||
}
|
||||
|
||||
// Catch uses of 'import libyosys' which can import libyosys.so, causing a ton
|
||||
// of symbol collisions and overall weird behavior.
|
||||
//
|
||||
// This should not affect using wheels as the dylib has to actually be called
|
||||
// libyosys_dummy.so for this function to be interacted with at all.
|
||||
PYBIND11_MODULE(libyosys_dummy, _) {
|
||||
throw py::import_error("Change your import from 'import libyosys' to 'from pyosys import libyosys'.");
|
||||
}
|
||||
#endif
|
||||
|
||||
void yosys_setup()
|
||||
{
|
||||
if(already_setup)
|
||||
|
|
@ -201,12 +221,16 @@ void yosys_setup()
|
|||
|
||||
IdString::ensure_prepopulated();
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
// With Python 3.12, calling PyImport_AppendInittab on an already
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
// Starting Python 3.12, calling PyImport_AppendInittab on an already
|
||||
// initialized platform fails (such as when libyosys is imported
|
||||
// from a Python interpreter)
|
||||
if (!Py_IsInitialized()) {
|
||||
PyImport_AppendInittab((char*)"libyosys", INIT_MODULE);
|
||||
PyImport_AppendInittab((char*)"pyosys.libyosys", PyInit_libyosys);
|
||||
// compatibility with wheels
|
||||
PyImport_AppendInittab((char*)"pyosys", PyInit_pyosys);
|
||||
// prevent catastrophes
|
||||
PyImport_AppendInittab((char*)"libyosys", PyInit_libyosys_dummy);
|
||||
Py_Initialize();
|
||||
PyRun_SimpleString("import sys");
|
||||
}
|
||||
|
|
@ -263,13 +287,13 @@ void yosys_shutdown()
|
|||
dlclose(it.second);
|
||||
|
||||
loaded_plugins.clear();
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
loaded_python_plugins.clear();
|
||||
#endif
|
||||
loaded_plugin_aliases.clear();
|
||||
#endif
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
Py_Finalize();
|
||||
#endif
|
||||
}
|
||||
|
|
@ -545,7 +569,7 @@ void init_share_dirname()
|
|||
#else
|
||||
void init_share_dirname()
|
||||
{
|
||||
# ifdef WITH_PYTHON
|
||||
# ifdef YOSYS_ENABLE_PYTHON
|
||||
PyObject *sys_obj = PyImport_ImportModule("sys");
|
||||
|
||||
if (PyObject_HasAttrString(sys_obj, "_pyosys_share_dirname")) {
|
||||
|
|
@ -605,7 +629,7 @@ void init_abc_executable_name()
|
|||
yosys_abc_executable = proc_self_dirname() + "..\\" + proc_program_prefix() + "yosys-abc";
|
||||
# endif
|
||||
|
||||
# ifdef WITH_PYTHON
|
||||
# ifdef YOSYS_ENABLE_PYTHON
|
||||
PyObject *sys_obj = PyImport_ImportModule("sys");
|
||||
|
||||
if (PyObject_HasAttrString(sys_obj, "_pyosys_abc")) {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ YOSYS_NAMESPACE_BEGIN
|
|||
|
||||
void yosys_setup();
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
bool yosys_already_setup();
|
||||
#endif
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ extern std::vector<RTLIL::Design*> pushed_designs;
|
|||
|
||||
// from passes/cmds/pluginc.cc
|
||||
extern std::map<std::string, void*> loaded_plugins;
|
||||
#ifdef WITH_PYTHON
|
||||
#ifdef YOSYS_ENABLE_PYTHON
|
||||
extern std::map<std::string, void*> loaded_python_plugins;
|
||||
#endif
|
||||
extern std::map<std::string, std::string> loaded_plugin_aliases;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#define YOSYS_COMMON_H
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <tuple>
|
||||
|
|
@ -53,10 +54,6 @@
|
|||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
#include <Python.h>
|
||||
#endif
|
||||
|
||||
#ifndef _YOSYS_
|
||||
# error It looks like you are trying to build Yosys without the config defines set. \
|
||||
When building Yosys with a custom make system, make sure you set all the \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue