From 2afb1f632e3069c140c1a7619031e9bda20d2002 Mon Sep 17 00:00:00 2001 From: gatecat Date: Fri, 12 Jan 2024 10:09:28 +0100 Subject: [PATCH] clangformat Signed-off-by: gatecat --- common/kernel/base_arch.h | 15 +- common/kernel/command.h | 8 +- common/kernel/hashlib.h | 20 +- common/kernel/idstringlist.h | 8 +- common/kernel/nextpnr_types.h | 34 ++-- common/kernel/pycontainers.h | 10 +- common/kernel/pywrappers.h | 2 +- common/place/timing_opt.h | 2 +- gui/treemodel.h | 6 +- rust/rust.cc | 346 ++++++++++++++++++---------------- rust/rust.h | 2 +- 11 files changed, 243 insertions(+), 210 deletions(-) diff --git a/common/kernel/base_arch.h b/common/kernel/base_arch.h index fa852a7c..5aa655a5 100644 --- a/common/kernel/base_arch.h +++ b/common/kernel/base_arch.h @@ -185,7 +185,8 @@ template struct BaseArch : ArchAPI return empty_if_possible(); } - virtual typename R::CellBelPinRangeT getBelPinsForCellPin(const CellInfo * /*cell_info*/, IdString pin) const override + virtual typename R::CellBelPinRangeT getBelPinsForCellPin(const CellInfo * /*cell_info*/, + IdString pin) const override { return return_if_match, typename R::CellBelPinRangeT>({pin}); } @@ -314,7 +315,8 @@ template struct BaseArch : ArchAPI }; // Delay methods - virtual bool getArcDelayOverride(const NetInfo * /*net_info*/, const PortRef &/*sink*/, DelayQuad &/*delay*/) const override + virtual bool getArcDelayOverride(const NetInfo * /*net_info*/, const PortRef & /*sink*/, + DelayQuad & /*delay*/) const override { return false; } @@ -330,15 +332,18 @@ template struct BaseArch : ArchAPI virtual DecalXY getGroupDecal(GroupId /*group*/) const override { return DecalXY(); } // Cell timing methods - virtual bool getCellDelay(const CellInfo * /*cell*/, IdString /*fromPort*/, IdString /*toPort*/, DelayQuad &/*delay*/) const override + virtual bool getCellDelay(const CellInfo * /*cell*/, IdString /*fromPort*/, IdString /*toPort*/, + DelayQuad & /*delay*/) const override { return false; } - virtual TimingPortClass getPortTimingClass(const CellInfo * /*cell*/, IdString /*port*/, int &/*clockInfoCount*/) const override + virtual TimingPortClass getPortTimingClass(const CellInfo * /*cell*/, IdString /*port*/, + int & /*clockInfoCount*/) const override { return TMG_IGNORE; } - virtual TimingClockingInfo getPortClockingInfo(const CellInfo * /*cell*/, IdString /*port*/, int /*index*/) const override + virtual TimingClockingInfo getPortClockingInfo(const CellInfo * /*cell*/, IdString /*port*/, + int /*index*/) const override { NPNR_ASSERT_FALSE("unreachable"); } diff --git a/common/kernel/command.h b/common/kernel/command.h index 5f173e55..d4a34e89 100644 --- a/common/kernel/command.h +++ b/common/kernel/command.h @@ -34,7 +34,7 @@ class CommandHandler { public: CommandHandler(int argc, char **argv); - virtual ~CommandHandler() { } + virtual ~CommandHandler() {} int exec(); void load_json(Context *ctx, std::string filename); @@ -45,9 +45,9 @@ class CommandHandler virtual void setupArchContext(Context *ctx) = 0; virtual std::unique_ptr createContext(dict &values) = 0; virtual po::options_description getArchOptions() = 0; - virtual void validate() { } - virtual void customAfterLoad(Context * /*ctx*/) { } - virtual void customBitstream(Context * /*ctx*/) { } + virtual void validate() {} + virtual void customAfterLoad(Context * /*ctx*/) {} + virtual void customBitstream(Context * /*ctx*/) {} void conflicting_options(const boost::program_options::variables_map &vm, const char *opt1, const char *opt2); private: diff --git a/common/kernel/hashlib.h b/common/kernel/hashlib.h index 8ddfa0f8..10bc04d3 100644 --- a/common/kernel/hashlib.h +++ b/common/kernel/hashlib.h @@ -380,8 +380,8 @@ template class dict using iterator_category = std::forward_iterator_tag; using value_type = std::pair; using difference_type = std::ptrdiff_t; - using pointer = const std::pair*; - using reference = const std::pair&; + using pointer = const std::pair *; + using reference = const std::pair &; const_iterator() {} const_iterator operator++() { @@ -413,8 +413,8 @@ template class dict using iterator_category = std::forward_iterator_tag; using value_type = std::pair; using difference_type = std::ptrdiff_t; - using pointer = std::pair*; - using reference = std::pair&; + using pointer = std::pair *; + using reference = std::pair &; iterator() {} iterator operator++() { @@ -831,8 +831,8 @@ template class pool using iterator_category = std::forward_iterator_tag; using value_type = K; using difference_type = std::ptrdiff_t; - using pointer = const K*; - using reference = const K&; + using pointer = const K *; + using reference = const K &; const_iterator() {} const_iterator operator++() { @@ -858,8 +858,8 @@ template class pool using iterator_category = std::forward_iterator_tag; using value_type = K; using difference_type = std::ptrdiff_t; - using pointer = K*; - using reference = K&; + using pointer = K *; + using reference = K &; iterator() {} iterator operator++() { @@ -1068,8 +1068,8 @@ template class idict using iterator_category = std::forward_iterator_tag; using value_type = K; using difference_type = std::ptrdiff_t; - using pointer = const K*; - using reference = const K&; + using pointer = const K *; + using reference = const K &; const_iterator() {} const_iterator operator++() { diff --git a/common/kernel/idstringlist.h b/common/kernel/idstringlist.h index b8e37966..436e6ff0 100644 --- a/common/kernel/idstringlist.h +++ b/common/kernel/idstringlist.h @@ -35,10 +35,10 @@ struct IdStringList { SSOArray ids; - IdStringList() : ids(1, IdString()) { } - explicit IdStringList(size_t n) : ids(n, IdString()) { } - explicit IdStringList(IdString id) : ids(1, id) { } - template explicit IdStringList(const Tlist &list) : ids(list) { } + IdStringList() : ids(1, IdString()) {} + explicit IdStringList(size_t n) : ids(n, IdString()) {} + explicit IdStringList(IdString id) : ids(1, id) {} + template explicit IdStringList(const Tlist &list) : ids(list) {} static IdStringList parse(Context *ctx, const std::string &str); void build_str(const Context *ctx, std::string &str) const; diff --git a/common/kernel/nextpnr_types.h b/common/kernel/nextpnr_types.h index 5a239ca1..163ad2f2 100644 --- a/common/kernel/nextpnr_types.h +++ b/common/kernel/nextpnr_types.h @@ -81,8 +81,8 @@ struct PortRef struct DelayPair { DelayPair(){}; - explicit DelayPair(delay_t delay) : min_delay(delay), max_delay(delay) { } - DelayPair(delay_t min_delay, delay_t max_delay) : min_delay(min_delay), max_delay(max_delay) { } + explicit DelayPair(delay_t delay) : min_delay(delay), max_delay(delay) {} + DelayPair(delay_t min_delay, delay_t max_delay) : min_delay(min_delay), max_delay(max_delay) {} delay_t minDelay() const { return min_delay; } delay_t maxDelay() const { return max_delay; } delay_t min_delay, max_delay; @@ -100,12 +100,14 @@ struct DelayPair struct DelayQuad { DelayPair rise, fall; - DelayQuad() { } - explicit DelayQuad(delay_t delay) : rise(delay), fall(delay) { } - DelayQuad(delay_t min_delay, delay_t max_delay) : rise(min_delay, max_delay), fall(min_delay, max_delay) { } - DelayQuad(DelayPair rise, DelayPair fall) : rise(rise), fall(fall) { } + DelayQuad() {} + explicit DelayQuad(delay_t delay) : rise(delay), fall(delay) {} + DelayQuad(delay_t min_delay, delay_t max_delay) : rise(min_delay, max_delay), fall(min_delay, max_delay) {} + DelayQuad(DelayPair rise, DelayPair fall) : rise(rise), fall(fall) {} DelayQuad(delay_t min_rise, delay_t max_rise, delay_t min_fall, delay_t max_fall) - : rise(min_rise, max_rise), fall(min_fall, max_fall) { } + : rise(min_rise, max_rise), fall(min_fall, max_fall) + { + } delay_t minRiseDelay() const { return rise.minDelay(); } delay_t maxRiseDelay() const { return rise.maxDelay(); } @@ -124,7 +126,7 @@ struct ClockConstraint; struct NetInfo : ArchNetInfo { - explicit NetInfo(IdString name) : name(name) { } + explicit NetInfo(IdString name) : name(name) {} IdString name, hierpath; int32_t udata = 0; @@ -203,14 +205,20 @@ struct PseudoCell struct RegionPlug : PseudoCell { - RegionPlug(Loc loc) : loc(loc) { } // 'loc' is a notional location for the placer only + RegionPlug(Loc loc) : loc(loc) {} // 'loc' is a notional location for the placer only Loc getLocation() const override { return loc; } WireId getPortWire(IdString port) const override { return port_wires.at(port); } // TODO: partial reconfiguration region timing - bool getDelay(IdString /*fromPort*/, IdString /*toPort*/, DelayQuad &/*delay*/) const override { return false; } - TimingPortClass getPortTimingClass(IdString /*port*/, int &/*clockInfoCount*/) const override { return TMG_IGNORE; } - TimingClockingInfo getPortClockingInfo(IdString /*port*/, int /*index*/) const override { return TimingClockingInfo{}; } + bool getDelay(IdString /*fromPort*/, IdString /*toPort*/, DelayQuad & /*delay*/) const override { return false; } + TimingPortClass getPortTimingClass(IdString /*port*/, int & /*clockInfoCount*/) const override + { + return TMG_IGNORE; + } + TimingClockingInfo getPortClockingInfo(IdString /*port*/, int /*index*/) const override + { + return TimingClockingInfo{}; + } dict port_wires; Loc loc; @@ -218,7 +226,7 @@ struct RegionPlug : PseudoCell struct CellInfo : ArchCellInfo { - CellInfo(Context *ctx, IdString name, IdString type) : ctx(ctx), name(name), type(type) { } + CellInfo(Context *ctx, IdString name, IdString type) : ctx(ctx), name(name), type(type) {} Context *ctx = nullptr; IdString name, type, hierpath; diff --git a/common/kernel/pycontainers.h b/common/kernel/pycontainers.h index 626849ce..d79508b9 100644 --- a/common/kernel/pycontainers.h +++ b/common/kernel/pycontainers.h @@ -290,7 +290,7 @@ template struct pair_wrapper x.second = val.cast(); } - static int len(T &/*x*/) { return 2; } + static int len(T & /*x*/) { return 2; } static iter_pair iter(T &x) { return iter_pair(boost::ref(x), 0); }; @@ -348,7 +348,7 @@ template struct map_pair_wrapper x.base.first)); } - static int len(wrapped_pair &/*x*/) { return 2; } + static int len(wrapped_pair & /*x*/) { return 2; } static iter_pair iter(wrapped_pair &x) { @@ -472,11 +472,11 @@ template struct map_pair_wrapper_uptr if (i >= 2 || i < 0) KeyError(); return i == 1 ? py::cast(PythonConversion::ContextualWrapper(x.ctx, *x.base.second.get())) - : py::cast(PythonConversion::string_converter().to_str(x.ctx, - x.base.first)); + : py::cast(PythonConversion::string_converter().to_str(x.ctx, + x.base.first)); } - static int len(wrapped_pair &/*x*/) { return 2; } + static int len(wrapped_pair & /*x*/) { return 2; } static iter_pair iter(wrapped_pair &x) { diff --git a/common/kernel/pywrappers.h b/common/kernel/pywrappers.h index 69b94197..e6499fb6 100644 --- a/common/kernel/pywrappers.h +++ b/common/kernel/pywrappers.h @@ -35,7 +35,7 @@ template struct ContextualWrapper Context *ctx; T base; - inline ContextualWrapper(Context *c, T x) : ctx(c), base(x) { } + inline ContextualWrapper(Context *c, T x) : ctx(c), base(x) {} inline operator T() { return base; } typedef T base_type; diff --git a/common/place/timing_opt.h b/common/place/timing_opt.h index e5d0fd38..18c946c0 100644 --- a/common/place/timing_opt.h +++ b/common/place/timing_opt.h @@ -24,7 +24,7 @@ NEXTPNR_NAMESPACE_BEGIN struct TimingOptCfg { - TimingOptCfg(Context * /*ctx*/) { } + TimingOptCfg(Context * /*ctx*/) {} // The timing optimiser will *only* optimise cells of these types // Normally these would only be logic cells (or tiles if applicable), the algorithm makes little sense diff --git a/gui/treemodel.h b/gui/treemodel.h index 915258a6..84cdc165 100644 --- a/gui/treemodel.h +++ b/gui/treemodel.h @@ -103,8 +103,8 @@ class Item virtual void fetchMore() {} virtual boost::optional getById(IdStringList /*id*/) { return boost::none; } - virtual void search(QList &/*results*/, QString /*text*/, int /*limit*/) { } - virtual void updateElements(Context * /*ctx*/, std::vector /*elements*/) { } + virtual void search(QList & /*results*/, QString /*text*/, int /*limit*/) {} + virtual void updateElements(Context * /*ctx*/, std::vector /*elements*/) {} virtual ~Item() { @@ -147,7 +147,7 @@ class IdList : public Item public: // Create an IdList at given parent that will contain elements of // the given type. - IdList(ElementType type) : Item("root", nullptr), child_type_(type) { } + IdList(ElementType type) : Item("root", nullptr), child_type_(type) {} // Split a name into alpha/non-alpha parts, which is then used for sorting // of children. diff --git a/rust/rust.cc b/rust/rust.cc index f747d401..19e1b6ff 100644 --- a/rust/rust.cc +++ b/rust/rust.cc @@ -22,42 +22,43 @@ #include "nextpnr.h" namespace { - USING_NEXTPNR_NAMESPACE; +USING_NEXTPNR_NAMESPACE; - template static inline uint64_t wrap(const T &thing) noexcept { - static_assert(sizeof(T) <= 8, "T is too big for FFI"); - uint64_t b = 0; - memcpy(&b, &thing, sizeof(T)); - return b; - } - - template static inline T unwrap(const std::array &value) noexcept { - static_assert(sizeof(T) <= 8, "T is too big for FFI"); - T result{}; - memcpy(&result, value.data(), sizeof(result)); - return result; - } - - template static inline T unwrap(const uint64_t value) noexcept { - std::array data{}; - static_assert(sizeof(value) >= data.size(), "uint64_t is not an appropriate size"); - memcpy(data.data(), &value, data.size()); - return unwrap(data); - } - - static inline BelId unwrap_bel(const uint64_t bel) noexcept - { return unwrap(bel); } - - static inline PipId unwrap_pip(const uint64_t pip) noexcept - { return unwrap(pip); } - - static inline WireId unwrap_wire(const uint64_t wire) noexcept - { return unwrap(wire); } +template static inline uint64_t wrap(const T &thing) noexcept +{ + static_assert(sizeof(T) <= 8, "T is too big for FFI"); + uint64_t b = 0; + memcpy(&b, &thing, sizeof(T)); + return b; } +template static inline T unwrap(const std::array &value) noexcept +{ + static_assert(sizeof(T) <= 8, "T is too big for FFI"); + T result{}; + memcpy(&result, value.data(), sizeof(result)); + return result; +} + +template static inline T unwrap(const uint64_t value) noexcept +{ + std::array data{}; + static_assert(sizeof(value) >= data.size(), "uint64_t is not an appropriate size"); + memcpy(data.data(), &value, data.size()); + return unwrap(data); +} + +static inline BelId unwrap_bel(const uint64_t bel) noexcept { return unwrap(bel); } + +static inline PipId unwrap_pip(const uint64_t pip) noexcept { return unwrap(pip); } + +static inline WireId unwrap_wire(const uint64_t wire) noexcept { return unwrap(wire); } +} // namespace + using DownhillIter = decltype(Context(ArchArgs()).getPipsDownhill(WireId()).begin()); -struct DownhillIterWrapper { +struct DownhillIterWrapper +{ DownhillIter current; DownhillIter end; @@ -65,7 +66,8 @@ struct DownhillIterWrapper { }; using UphillIter = decltype(Context(ArchArgs()).getPipsUphill(WireId()).begin()); -struct UphillIterWrapper { +struct UphillIterWrapper +{ UphillIter current; UphillIter end; @@ -73,164 +75,182 @@ struct UphillIterWrapper { }; extern "C" { - USING_NEXTPNR_NAMESPACE; +USING_NEXTPNR_NAMESPACE; - void npnr_log_info(const char *string) { log_info("%s", string); } - void npnr_log_error(const char *string) { log_error("%s", string); } +void npnr_log_info(const char *string) { log_info("%s", string); } +void npnr_log_error(const char *string) { log_error("%s", string); } - uint64_t npnr_belid_null() { return wrap(BelId()); } - uint64_t npnr_wireid_null() { return wrap(WireId()); } - uint64_t npnr_pipid_null() { return wrap(PipId()); } +uint64_t npnr_belid_null() { return wrap(BelId()); } +uint64_t npnr_wireid_null() { return wrap(WireId()); } +uint64_t npnr_pipid_null() { return wrap(PipId()); } - int npnr_context_get_grid_dim_x(const Context *ctx) { return ctx->getGridDimX(); } - int npnr_context_get_grid_dim_y(const Context *ctx) { return ctx->getGridDimY(); } - void npnr_context_bind_bel(Context *ctx, uint64_t bel, CellInfo* cell, PlaceStrength strength) { return ctx->bindBel(unwrap_bel(bel), cell, strength); } - void npnr_context_unbind_bel(Context *ctx, uint64_t bel) { return ctx->unbindBel(unwrap_bel(bel)); } - bool npnr_context_check_bel_avail(Context *ctx, uint64_t bel) { return ctx->checkBelAvail(unwrap_bel(bel)); } - void npnr_context_bind_wire(Context *ctx, uint64_t wire, NetInfo* net, PlaceStrength strength) { ctx->bindWire(unwrap_wire(wire), net, strength); } - void npnr_context_unbind_wire(Context *ctx, uint64_t wire) { ctx->unbindWire(unwrap_wire(wire)); } - void npnr_context_bind_pip(Context *ctx, uint64_t pip, NetInfo* net, PlaceStrength strength) { ctx->bindPip(unwrap_pip(pip), net, strength); } - void npnr_context_unbind_pip(Context *ctx, uint64_t pip) { ctx->unbindPip(unwrap_pip(pip)); } - uint64_t npnr_context_get_pip_src_wire(const Context *ctx, uint64_t pip) { return wrap(ctx->getPipSrcWire(unwrap_pip(pip))); } - uint64_t npnr_context_get_pip_dst_wire(const Context *ctx, uint64_t pip) { return wrap(ctx->getPipDstWire(unwrap_pip(pip))); } - float npnr_context_estimate_delay(const Context *ctx, uint64_t src, uint64_t dst) { return ctx->getDelayNS(ctx->estimateDelay(unwrap_wire(src), unwrap_wire(dst))); } - float npnr_context_get_pip_delay(const Context *ctx, uint64_t pip) { return ctx->getDelayNS(ctx->getPipDelay(unwrap_pip(pip)).maxDelay()); } - float npnr_context_get_wire_delay(const Context *ctx, uint64_t wire) { return ctx->getDelayNS(ctx->getWireDelay(unwrap_wire(wire)).maxDelay()); } - float npnr_context_delay_epsilon(const Context *ctx) { return ctx->getDelayNS(ctx->getDelayEpsilon()); } - Loc npnr_context_get_pip_location(const Context *ctx, uint64_t pip) { return ctx->getPipLocation(unwrap_pip(pip)); } - bool npnr_context_check_pip_avail_for_net(const Context *ctx, uint64_t pip, NetInfo *net) { return ctx->checkPipAvailForNet(unwrap_pip(pip), net); } +int npnr_context_get_grid_dim_x(const Context *ctx) { return ctx->getGridDimX(); } +int npnr_context_get_grid_dim_y(const Context *ctx) { return ctx->getGridDimY(); } +void npnr_context_bind_bel(Context *ctx, uint64_t bel, CellInfo *cell, PlaceStrength strength) +{ + return ctx->bindBel(unwrap_bel(bel), cell, strength); +} +void npnr_context_unbind_bel(Context *ctx, uint64_t bel) { return ctx->unbindBel(unwrap_bel(bel)); } +bool npnr_context_check_bel_avail(Context *ctx, uint64_t bel) { return ctx->checkBelAvail(unwrap_bel(bel)); } +void npnr_context_bind_wire(Context *ctx, uint64_t wire, NetInfo *net, PlaceStrength strength) +{ + ctx->bindWire(unwrap_wire(wire), net, strength); +} +void npnr_context_unbind_wire(Context *ctx, uint64_t wire) { ctx->unbindWire(unwrap_wire(wire)); } +void npnr_context_bind_pip(Context *ctx, uint64_t pip, NetInfo *net, PlaceStrength strength) +{ + ctx->bindPip(unwrap_pip(pip), net, strength); +} +void npnr_context_unbind_pip(Context *ctx, uint64_t pip) { ctx->unbindPip(unwrap_pip(pip)); } +uint64_t npnr_context_get_pip_src_wire(const Context *ctx, uint64_t pip) +{ + return wrap(ctx->getPipSrcWire(unwrap_pip(pip))); +} +uint64_t npnr_context_get_pip_dst_wire(const Context *ctx, uint64_t pip) +{ + return wrap(ctx->getPipDstWire(unwrap_pip(pip))); +} +float npnr_context_estimate_delay(const Context *ctx, uint64_t src, uint64_t dst) +{ + return ctx->getDelayNS(ctx->estimateDelay(unwrap_wire(src), unwrap_wire(dst))); +} +float npnr_context_get_pip_delay(const Context *ctx, uint64_t pip) +{ + return ctx->getDelayNS(ctx->getPipDelay(unwrap_pip(pip)).maxDelay()); +} +float npnr_context_get_wire_delay(const Context *ctx, uint64_t wire) +{ + return ctx->getDelayNS(ctx->getWireDelay(unwrap_wire(wire)).maxDelay()); +} +float npnr_context_delay_epsilon(const Context *ctx) { return ctx->getDelayNS(ctx->getDelayEpsilon()); } +Loc npnr_context_get_pip_location(const Context *ctx, uint64_t pip) { return ctx->getPipLocation(unwrap_pip(pip)); } +bool npnr_context_check_pip_avail_for_net(const Context *ctx, uint64_t pip, NetInfo *net) +{ + return ctx->checkPipAvailForNet(unwrap_pip(pip), net); +} - uint64_t npnr_context_get_pips_leak(const Context *const ctx, uint64_t **const pips) { - const auto ctx_pips{ctx->getPips()}; - const auto size{ - std::accumulate(ctx_pips.begin(), ctx_pips.end(), /*initial value*/ size_t{}, - [](size_t value, const auto &/*pip*/) { return value + 1U; } - )}; - *pips = new uint64_t[size]; - auto idx = 0; - for (const auto &pip : ctx_pips) { - (*pips)[idx] = wrap(pip); - idx++; - } - // Yes, by never deleting pip_vec, we leak memory. - return size; +uint64_t npnr_context_get_pips_leak(const Context *const ctx, uint64_t **const pips) +{ + const auto ctx_pips{ctx->getPips()}; + const auto size{std::accumulate(ctx_pips.begin(), ctx_pips.end(), /*initial value*/ size_t{}, + [](size_t value, const auto & /*pip*/) { return value + 1U; })}; + *pips = new uint64_t[size]; + auto idx = 0; + for (const auto &pip : ctx_pips) { + (*pips)[idx] = wrap(pip); + idx++; } + // Yes, by never deleting pip_vec, we leak memory. + return size; +} - uint64_t npnr_context_get_wires_leak(const Context *const ctx, uint64_t **const wires) { - const auto ctx_wires{ctx->getWires()}; - const auto size{ - std::accumulate(ctx_wires.begin(), ctx_wires.end(), /*initial value*/ size_t{}, - [](size_t value, const auto &/*wire*/) { return value + 1U; } - )}; - *wires = new uint64_t[size]; - auto idx = 0; - for (const auto &wire : ctx_wires) { - (*wires)[idx] = wrap(wire); - idx++; - } - // Yes, by never deleting wires, we leak memory. - return size; +uint64_t npnr_context_get_wires_leak(const Context *const ctx, uint64_t **const wires) +{ + const auto ctx_wires{ctx->getWires()}; + const auto size{std::accumulate(ctx_wires.begin(), ctx_wires.end(), /*initial value*/ size_t{}, + [](size_t value, const auto & /*wire*/) { return value + 1U; })}; + *wires = new uint64_t[size]; + auto idx = 0; + for (const auto &wire : ctx_wires) { + (*wires)[idx] = wrap(wire); + idx++; } + // Yes, by never deleting wires, we leak memory. + return size; +} - void npnr_context_check(const Context *ctx) { ctx->check(); } - bool npnr_context_debug(const Context *ctx) { return ctx->debug; } - int npnr_context_id(const Context *ctx, const char *str) { return ctx->id(str).hash(); } - const char *npnr_context_name_of(const Context *ctx, IdString str) { return ctx->nameOf(str); } - const char *npnr_context_name_of_pip(const Context *ctx, uint64_t pip) { return ctx->nameOfPip(unwrap_pip(pip)); } - const char *npnr_context_name_of_wire(const Context *ctx, uint64_t wire) { return ctx->nameOfWire(unwrap_wire(wire)); } - bool npnr_context_verbose(const Context *ctx) { return ctx->verbose; } +void npnr_context_check(const Context *ctx) { ctx->check(); } +bool npnr_context_debug(const Context *ctx) { return ctx->debug; } +int npnr_context_id(const Context *ctx, const char *str) { return ctx->id(str).hash(); } +const char *npnr_context_name_of(const Context *ctx, IdString str) { return ctx->nameOf(str); } +const char *npnr_context_name_of_pip(const Context *ctx, uint64_t pip) { return ctx->nameOfPip(unwrap_pip(pip)); } +const char *npnr_context_name_of_wire(const Context *ctx, uint64_t wire) { return ctx->nameOfWire(unwrap_wire(wire)); } +bool npnr_context_verbose(const Context *ctx) { return ctx->verbose; } - uint64_t npnr_context_get_netinfo_source_wire(const Context *ctx, const NetInfo *net) { return wrap(ctx->getNetinfoSourceWire(net)); } - uint64_t npnr_context_get_netinfo_sink_wire(const Context *ctx, const NetInfo *net, const PortRef *sink, uint32_t n) { return wrap(ctx->getNetinfoSinkWire(net, *sink, n)); } +uint64_t npnr_context_get_netinfo_source_wire(const Context *ctx, const NetInfo *net) +{ + return wrap(ctx->getNetinfoSourceWire(net)); +} +uint64_t npnr_context_get_netinfo_sink_wire(const Context *ctx, const NetInfo *net, const PortRef *sink, uint32_t n) +{ + return wrap(ctx->getNetinfoSinkWire(net, *sink, n)); +} - uint32_t npnr_context_nets_leak(const Context *ctx, int **names, NetInfo ***nets) { - auto size = ctx->nets.size(); - *names = new int[size]; - *nets = new NetInfo*[size]; - auto idx = 0; - for (auto& item : ctx->nets) { - (*names)[idx] = item.first.index; - (*nets)[idx] = item.second.get(); - idx++; - } - // Yes, by never deleting `names` and `nets` we leak memory. - return size; +uint32_t npnr_context_nets_leak(const Context *ctx, int **names, NetInfo ***nets) +{ + auto size = ctx->nets.size(); + *names = new int[size]; + *nets = new NetInfo *[size]; + auto idx = 0; + for (auto &item : ctx->nets) { + (*names)[idx] = item.first.index; + (*nets)[idx] = item.second.get(); + idx++; } + // Yes, by never deleting `names` and `nets` we leak memory. + return size; +} - DownhillIterWrapper *npnr_context_get_pips_downhill(Context *ctx, uint64_t wire_id) { - auto wire = unwrap_wire(wire_id); - auto range = ctx->getPipsDownhill(wire); - return new DownhillIterWrapper(range.begin(), range.end()); - } - void npnr_delete_downhill_iter(DownhillIterWrapper *iter) { - delete iter; - } - UphillIterWrapper *npnr_context_get_pips_uphill(Context *ctx, uint64_t wire_id) { - auto wire = unwrap_wire(wire_id); - auto range = ctx->getPipsUphill(wire); - return new UphillIterWrapper(range.begin(), range.end()); - } - void npnr_delete_uphill_iter(UphillIterWrapper *iter) { - delete iter; - } +DownhillIterWrapper *npnr_context_get_pips_downhill(Context *ctx, uint64_t wire_id) +{ + auto wire = unwrap_wire(wire_id); + auto range = ctx->getPipsDownhill(wire); + return new DownhillIterWrapper(range.begin(), range.end()); +} +void npnr_delete_downhill_iter(DownhillIterWrapper *iter) { delete iter; } +UphillIterWrapper *npnr_context_get_pips_uphill(Context *ctx, uint64_t wire_id) +{ + auto wire = unwrap_wire(wire_id); + auto range = ctx->getPipsUphill(wire); + return new UphillIterWrapper(range.begin(), range.end()); +} +void npnr_delete_uphill_iter(UphillIterWrapper *iter) { delete iter; } - PortRef* npnr_netinfo_driver(NetInfo *net) { - if (net == nullptr) { - return nullptr; - } - return &net->driver; +PortRef *npnr_netinfo_driver(NetInfo *net) +{ + if (net == nullptr) { + return nullptr; } + return &net->driver; +} - uint32_t npnr_netinfo_users_leak(NetInfo *net, PortRef ***users) { - auto size = net->users.entries(); - *users = new PortRef*[size]; - auto idx = 0; - for (auto& item : net->users) { - (*users)[idx] = &item; - idx++; - } - // Yes, by not freeing `users`, we leak memory. - return size; +uint32_t npnr_netinfo_users_leak(NetInfo *net, PortRef ***users) +{ + auto size = net->users.entries(); + *users = new PortRef *[size]; + auto idx = 0; + for (auto &item : net->users) { + (*users)[idx] = &item; + idx++; } + // Yes, by not freeing `users`, we leak memory. + return size; +} #ifdef ARCH_ECP5 - bool npnr_netinfo_is_global(NetInfo *net) { return net->is_global; } +bool npnr_netinfo_is_global(NetInfo *net) { return net->is_global; } #else - bool npnr_netinfo_is_global(NetInfo * /*net*/) { return false; } +bool npnr_netinfo_is_global(NetInfo * /*net*/) { return false; } #endif - int32_t npnr_netinfo_udata(NetInfo *net) { return net->udata; } - void npnr_netinfo_udata_set(NetInfo *net, int32_t value) { net->udata = value; } +int32_t npnr_netinfo_udata(NetInfo *net) { return net->udata; } +void npnr_netinfo_udata_set(NetInfo *net, int32_t value) { net->udata = value; } - CellInfo* npnr_portref_cell(const PortRef *port) { return port->cell; } - Loc npnr_cellinfo_get_location(const CellInfo *info) { return info->getLocation(); } +CellInfo *npnr_portref_cell(const PortRef *port) { return port->cell; } +Loc npnr_cellinfo_get_location(const CellInfo *info) { return info->getLocation(); } - void npnr_inc_downhill_iter(DownhillIterWrapper *iter) { - ++iter->current; - } - uint64_t npnr_deref_downhill_iter(DownhillIterWrapper *iter) { - return wrap(*iter->current); - } - bool npnr_is_downhill_iter_done(DownhillIterWrapper *iter) { - return !(iter->current != iter->end); - } - void npnr_inc_uphill_iter(UphillIterWrapper *iter) { - ++iter->current; - } - uint64_t npnr_deref_uphill_iter(UphillIterWrapper *iter) { - return wrap(*iter->current); - } - bool npnr_is_uphill_iter_done(UphillIterWrapper *iter) { - return !(iter->current != iter->end); - } +void npnr_inc_downhill_iter(DownhillIterWrapper *iter) { ++iter->current; } +uint64_t npnr_deref_downhill_iter(DownhillIterWrapper *iter) { return wrap(*iter->current); } +bool npnr_is_downhill_iter_done(DownhillIterWrapper *iter) { return !(iter->current != iter->end); } +void npnr_inc_uphill_iter(UphillIterWrapper *iter) { ++iter->current; } +uint64_t npnr_deref_uphill_iter(UphillIterWrapper *iter) { return wrap(*iter->current); } +bool npnr_is_uphill_iter_done(UphillIterWrapper *iter) { return !(iter->current != iter->end); } - void rust_example_printnets(Context *ctx); +void rust_example_printnets(Context *ctx); } NEXTPNR_NAMESPACE_BEGIN -void example_printnets(Context *ctx) { - rust_example_printnets(ctx); -} +void example_printnets(Context *ctx) { rust_example_printnets(ctx); } NEXTPNR_NAMESPACE_END diff --git a/rust/rust.h b/rust/rust.h index 4830503f..2ca2ffe0 100644 --- a/rust/rust.h +++ b/rust/rust.h @@ -25,7 +25,7 @@ #include "nextpnr.h" NEXTPNR_NAMESPACE_BEGIN -void example_printnets(Context* ctx); +void example_printnets(Context *ctx); NEXTPNR_NAMESPACE_END