From f01465f6280e2eae2459819597fda0fc2f46b703 Mon Sep 17 00:00:00 2001 From: Tarik Graba Date: Tue, 17 Dec 2024 11:30:39 +0100 Subject: [PATCH] Add attributes to the hierarchical cells (#1405) * Adds attributes to the hierarchical cells * python: add binding for hierarchical cells attributes * frontend/base: import hierarchical cells attributes --- common/kernel/nextpnr_types.h | 2 ++ common/kernel/pybindings.cc | 3 +++ frontend/frontend_base.h | 3 +++ 3 files changed, 8 insertions(+) diff --git a/common/kernel/nextpnr_types.h b/common/kernel/nextpnr_types.h index fbe16daf..5ee030b1 100644 --- a/common/kernel/nextpnr_types.h +++ b/common/kernel/nextpnr_types.h @@ -519,6 +519,8 @@ struct HierarchicalCell dict ports; // Name inside cell instance -> global name dict hier_cells; + // Cell attributes + dict attrs; }; NEXTPNR_NAMESPACE_END diff --git a/common/kernel/pybindings.cc b/common/kernel/pybindings.cc index 8cf8e424..737bccd5 100644 --- a/common/kernel/pybindings.cc +++ b/common/kernel/pybindings.cc @@ -283,6 +283,9 @@ PYBIND11_EMBEDDED_MODULE(MODULE_NAME, m) wrap_context>::def_wrap(hierarchy_cls, "nets"); readonly_wrapper>::def_wrap(hierarchy_cls, "hier_cells"); + readonly_wrapper>::def_wrap(hierarchy_cls, "attrs"); + WRAP_MAP(m, AttrMap, conv_to_str, "AttrMap"); WRAP_MAP(m, PortMap, wrap_context, "PortMap"); WRAP_MAP(m, IdIdMap, conv_to_str, "IdIdMap"); diff --git a/frontend/frontend_base.h b/frontend/frontend_base.h index bdc8a896..cd26349f 100644 --- a/frontend/frontend_base.h +++ b/frontend/frontend_base.h @@ -535,6 +535,9 @@ template struct GenericFrontend // Do the submodule import auto type = impl.get_cell_type(cd); import_module(submod, name, type, mod_refs.at(type)); + // Add current cell attributes to the imported module + impl.foreach_attr( cd, [&](const std::string &name, const Property &value) + { ctx->hierarchy[submod.path].attrs[ctx->id(name)] = value; } ); } // Import the cells section of a module