2018-07-04 20:13:55 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
2021-06-09 20:09:08 +08:00
|
|
|
* Copyright (C) 2018 Claire Xenia Wolf <claire@yosyshq.com>
|
|
|
|
* Copyright (C) 2018 gatecat <gatecat@ds0.me>
|
2018-07-04 20:13:55 +08:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef ARCH_PYBINDINGS_H
|
|
|
|
#define ARCH_PYBINDINGS_H
|
|
|
|
#ifndef NO_PYTHON
|
|
|
|
|
|
|
|
#include "nextpnr.h"
|
2018-07-04 21:26:09 +08:00
|
|
|
#include "pybindings.h"
|
2018-07-04 20:13:55 +08:00
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
namespace PythonConversion {
|
|
|
|
|
|
|
|
template <> struct string_converter<BelId>
|
|
|
|
{
|
2021-02-05 06:47:45 +08:00
|
|
|
BelId from_str(Context *ctx, std::string name) { return ctx->getBelByName(IdStringList::parse(ctx, name)); }
|
2018-07-04 20:13:55 +08:00
|
|
|
|
2018-07-04 21:26:09 +08:00
|
|
|
std::string to_str(Context *ctx, BelId id)
|
|
|
|
{
|
|
|
|
if (id == BelId())
|
|
|
|
throw bad_wrap();
|
|
|
|
return ctx->getBelName(id).str(ctx);
|
|
|
|
}
|
2018-07-04 20:13:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct string_converter<WireId>
|
|
|
|
{
|
2021-02-05 06:47:45 +08:00
|
|
|
WireId from_str(Context *ctx, std::string name) { return ctx->getWireByName(IdStringList::parse(ctx, name)); }
|
2018-07-04 20:13:55 +08:00
|
|
|
|
2018-11-22 21:42:20 +08:00
|
|
|
std::string to_str(Context *ctx, WireId id)
|
|
|
|
{
|
|
|
|
if (id == WireId())
|
|
|
|
throw bad_wrap();
|
|
|
|
return ctx->getWireName(id).str(ctx);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct string_converter<const WireId>
|
|
|
|
{
|
2021-02-05 06:47:45 +08:00
|
|
|
WireId from_str(Context *ctx, std::string name) { return ctx->getWireByName(IdStringList::parse(ctx, name)); }
|
2018-11-22 21:42:20 +08:00
|
|
|
|
|
|
|
std::string to_str(Context *ctx, WireId id)
|
|
|
|
{
|
|
|
|
if (id == WireId())
|
|
|
|
throw bad_wrap();
|
|
|
|
return ctx->getWireName(id).str(ctx);
|
|
|
|
}
|
2018-07-04 20:13:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct string_converter<PipId>
|
|
|
|
{
|
2021-02-05 06:47:45 +08:00
|
|
|
PipId from_str(Context *ctx, std::string name) { return ctx->getPipByName(IdStringList::parse(ctx, name)); }
|
2018-07-04 20:13:55 +08:00
|
|
|
|
2018-11-22 21:42:20 +08:00
|
|
|
std::string to_str(Context *ctx, PipId id)
|
|
|
|
{
|
|
|
|
if (id == PipId())
|
|
|
|
throw bad_wrap();
|
|
|
|
return ctx->getPipName(id).str(ctx);
|
|
|
|
}
|
2018-07-04 20:13:55 +08:00
|
|
|
};
|
|
|
|
|
2019-09-15 22:59:16 +08:00
|
|
|
template <> struct string_converter<BelPin>
|
|
|
|
{
|
2024-01-03 23:03:16 +08:00
|
|
|
BelPin from_str(Context * /*ctx*/, std::string /*name*/)
|
2019-09-15 22:59:16 +08:00
|
|
|
{
|
|
|
|
NPNR_ASSERT_FALSE("string_converter<BelPin>::from_str not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string to_str(Context *ctx, BelPin pin)
|
|
|
|
{
|
|
|
|
if (pin.bel == BelId())
|
|
|
|
throw bad_wrap();
|
|
|
|
return ctx->getBelName(pin.bel).str(ctx) + "/" + pin.pin.str(ctx);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-04 20:13:55 +08:00
|
|
|
} // namespace PythonConversion
|
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_END
|
|
|
|
#endif
|
|
|
|
#endif
|