2018-06-01 21:53:46 +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-06-01 21:53:46 +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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-06-23 20:32:18 +08:00
|
|
|
#ifndef NO_PYTHON
|
|
|
|
|
2018-07-04 20:13:55 +08:00
|
|
|
#include "arch_pybindings.h"
|
2023-03-01 01:27:13 +08:00
|
|
|
#include "bitstream.h"
|
|
|
|
#include "log.h"
|
2018-06-12 02:12:57 +08:00
|
|
|
#include "nextpnr.h"
|
2018-07-04 21:26:09 +08:00
|
|
|
#include "pybindings.h"
|
2018-06-01 21:18:18 +08:00
|
|
|
|
2023-03-01 01:27:13 +08:00
|
|
|
#include <fstream>
|
|
|
|
|
2018-06-12 20:24:59 +08:00
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
2023-03-01 01:27:13 +08:00
|
|
|
static void write_bitstream(const Context *ctx, std::string asc_file)
|
|
|
|
{
|
|
|
|
std::ofstream out(asc_file);
|
|
|
|
if (!out)
|
|
|
|
log_error("Failed to open output file %s\n", asc_file.c_str());
|
|
|
|
write_asc(ctx, out);
|
|
|
|
}
|
|
|
|
|
2020-07-24 00:35:18 +08:00
|
|
|
void arch_wrap_python(py::module &m)
|
2018-06-07 19:10:53 +08:00
|
|
|
{
|
2018-07-02 21:13:09 +08:00
|
|
|
using namespace PythonConversion;
|
2020-07-24 00:35:18 +08:00
|
|
|
py::class_<ArchArgs>(m, "ArchArgs").def_readwrite("type", &ArchArgs::type);
|
2018-06-01 21:18:18 +08:00
|
|
|
|
2020-07-24 00:35:18 +08:00
|
|
|
py::enum_<decltype(std::declval<ArchArgs>().type)>(m, "iCE40Type")
|
2018-06-18 19:35:25 +08:00
|
|
|
.value("NONE", ArchArgs::NONE)
|
|
|
|
.value("LP384", ArchArgs::LP384)
|
|
|
|
.value("LP1K", ArchArgs::LP1K)
|
2020-07-08 22:45:27 +08:00
|
|
|
.value("LP4K", ArchArgs::LP4K)
|
2018-06-18 19:35:25 +08:00
|
|
|
.value("LP8K", ArchArgs::LP8K)
|
|
|
|
.value("HX1K", ArchArgs::HX1K)
|
2020-07-08 22:45:27 +08:00
|
|
|
.value("HX4K", ArchArgs::HX4K)
|
2018-06-18 19:35:25 +08:00
|
|
|
.value("HX8K", ArchArgs::HX8K)
|
2020-07-08 22:45:27 +08:00
|
|
|
.value("UP3K", ArchArgs::UP3K)
|
2018-06-18 19:35:25 +08:00
|
|
|
.value("UP5K", ArchArgs::UP5K)
|
2020-07-08 22:45:27 +08:00
|
|
|
.value("U1K", ArchArgs::U1K)
|
|
|
|
.value("U2K", ArchArgs::U2K)
|
2019-02-23 05:36:19 +08:00
|
|
|
.value("U4K", ArchArgs::U4K)
|
2018-06-01 21:18:18 +08:00
|
|
|
.export_values();
|
|
|
|
|
2020-07-24 00:35:18 +08:00
|
|
|
py::class_<BelId>(m, "BelId").def_readwrite("index", &BelId::index);
|
2018-06-01 21:53:46 +08:00
|
|
|
|
2020-07-24 00:35:18 +08:00
|
|
|
py::class_<WireId>(m, "WireId").def_readwrite("index", &WireId::index);
|
2018-06-01 21:53:46 +08:00
|
|
|
|
2020-07-24 00:35:18 +08:00
|
|
|
py::class_<PipId>(m, "PipId").def_readwrite("index", &PipId::index);
|
2018-06-07 20:36:35 +08:00
|
|
|
|
2020-07-24 00:35:18 +08:00
|
|
|
auto arch_cls = py::class_<Arch, BaseCtx>(m, "Arch").def(py::init<ArchArgs>());
|
|
|
|
auto ctx_cls = py::class_<Context, Arch>(m, "Context")
|
2018-07-13 21:16:44 +08:00
|
|
|
.def("checksum", &Context::checksum)
|
|
|
|
.def("pack", &Context::pack)
|
|
|
|
.def("place", &Context::place)
|
|
|
|
.def("route", &Context::route);
|
2018-07-02 21:59:18 +08:00
|
|
|
|
2021-06-01 23:51:18 +08:00
|
|
|
typedef dict<IdString, std::unique_ptr<CellInfo>> CellMap;
|
|
|
|
typedef dict<IdString, std::unique_ptr<NetInfo>> NetMap;
|
|
|
|
typedef dict<IdString, IdString> AliasMap;
|
|
|
|
typedef dict<IdString, HierarchicalCell> HierarchyMap;
|
2018-07-02 22:20:59 +08:00
|
|
|
|
2020-07-24 00:35:18 +08:00
|
|
|
auto belpin_cls = py::class_<ContextualWrapper<BelPin>>(m, "BelPin");
|
2019-09-15 22:59:16 +08:00
|
|
|
readonly_wrapper<BelPin, decltype(&BelPin::bel), &BelPin::bel, conv_to_str<BelId>>::def_wrap(belpin_cls, "bel");
|
|
|
|
readonly_wrapper<BelPin, decltype(&BelPin::pin), &BelPin::pin, conv_to_str<IdString>>::def_wrap(belpin_cls, "pin");
|
|
|
|
|
2024-07-02 21:15:20 +08:00
|
|
|
typedef PipRange UphillPipRange;
|
|
|
|
typedef PipRange DownhillPipRange;
|
2021-02-02 02:23:21 +08:00
|
|
|
|
2021-02-02 06:28:32 +08:00
|
|
|
typedef const std::vector<BelBucketId> &BelBucketRange;
|
|
|
|
typedef const std::vector<BelId> &BelRangeForBelBucket;
|
2019-09-15 23:15:07 +08:00
|
|
|
#include "arch_pybindings_shared.h"
|
|
|
|
|
2020-07-24 00:35:18 +08:00
|
|
|
WRAP_RANGE(m, Bel, conv_to_str<BelId>);
|
|
|
|
WRAP_RANGE(m, Wire, conv_to_str<WireId>);
|
|
|
|
WRAP_RANGE(m, AllPip, conv_to_str<PipId>);
|
|
|
|
WRAP_RANGE(m, Pip, conv_to_str<PipId>);
|
|
|
|
WRAP_RANGE(m, BelPin, wrap_context<BelPin>);
|
2018-07-02 22:20:59 +08:00
|
|
|
|
2020-07-24 00:35:18 +08:00
|
|
|
WRAP_MAP_UPTR(m, CellMap, "IdCellMap");
|
|
|
|
WRAP_MAP_UPTR(m, NetMap, "IdNetMap");
|
|
|
|
WRAP_MAP(m, HierarchyMap, wrap_context<HierarchicalCell &>, "HierarchyMap");
|
2023-03-01 01:27:13 +08:00
|
|
|
|
|
|
|
m.def("write_bitstream", &write_bitstream);
|
2018-06-01 21:18:18 +08:00
|
|
|
}
|
2018-06-12 20:24:59 +08:00
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_END
|
2018-06-23 20:32:18 +08:00
|
|
|
|
2018-06-24 01:51:22 +08:00
|
|
|
#endif // NO_PYTHON
|