From eb70e950796ccb6b1d44fff2240fe30da5eecf7b Mon Sep 17 00:00:00 2001 From: gatecat Date: Fri, 10 Feb 2023 13:23:31 +0100 Subject: [PATCH] fabulous: Improve names for BRAM bels Signed-off-by: gatecat --- generic/viaduct/fabulous/fabric_parsing.h | 14 ++++++++++++++ generic/viaduct/fabulous/fabulous.cc | 17 +++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/generic/viaduct/fabulous/fabric_parsing.h b/generic/viaduct/fabulous/fabric_parsing.h index 3fa263ca..841b2465 100644 --- a/generic/viaduct/fabulous/fabric_parsing.h +++ b/generic/viaduct/fabulous/fabric_parsing.h @@ -68,6 +68,14 @@ struct parser_view return npos; } + size_t rfind(char tok) const + { + for (size_t i = m_length; i > 0; i--) + if (m_ptr[i - 1] == tok) + return i - 1; + return npos; + } + IdString to_id(const BaseCtx *ctx) { // This isn't really ideal, let's hope one day we can move to C++20 and have proper string_views instead :3 @@ -133,6 +141,12 @@ struct parser_view NPNR_ASSERT(pos != npos); return std::make_pair(parser_view(m_ptr, pos), parser_view(m_ptr + pos + 1, m_length - (pos + 1))); } + std::pair rsplit(char delim) const + { + size_t pos = rfind(delim); + NPNR_ASSERT(pos != npos); + return std::make_pair(parser_view(m_ptr, pos), parser_view(m_ptr + pos + 1, m_length - (pos + 1))); + } }; struct CsvParser diff --git a/generic/viaduct/fabulous/fabulous.cc b/generic/viaduct/fabulous/fabulous.cc index e2fe1b74..7dad0c66 100644 --- a/generic/viaduct/fabulous/fabulous.cc +++ b/generic/viaduct/fabulous/fabulous.cc @@ -237,6 +237,16 @@ struct FabulousImpl : ViaductAPI NPNR_ASSERT(bel_idx.size() == 1); int bel_z = bel_idx[0] - 'A'; NPNR_ASSERT(bel_z >= 0 && bel_z < 26); + std::vector ports; + parser_view port; + while (!(port = csv.next_field()).empty()) { + ports.push_back(port); + } + IdString bel_name = bel_idx.to_id(ctx); + if (bel_type.in(id_InPass4_frame_config, id_OutPass4_frame_config)) { + // Assign BRAM IO a nicer name than just a letter + bel_name = ports.front().rsplit('_').first.to_id(ctx); + } /* In the future we will need to handle optionally splitting SLICEs into separate LUT/COMB and FF bels This is the preferred approach in nextpnr for arches where the LUT and FF can be used separately of @@ -245,12 +255,7 @@ struct FabulousImpl : ViaductAPI While this isn't yet the standard fabulous SLICE, it should be considered as a future option in fabulous. */ Loc loc(bel_x, bel_y, bel_z); - BelId bel = ctx->addBel(IdStringList::concat(tile, bel_idx.to_id(ctx)), bel_type, loc, false, false); - std::vector ports; - parser_view port; - while (!(port = csv.next_field()).empty()) { - ports.push_back(port); - } + BelId bel = ctx->addBel(IdStringList::concat(tile, bel_name), bel_type, loc, false, false); handle_bel_ports(bel, tile, bel_type, ports); } postprocess_bels();