From 6a1d8abf7c9d6be812f3a1ed5abfc2539d08acd3 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Mon, 8 Sep 2025 11:49:21 +0200 Subject: [PATCH] Add a compile time check that kernel/constids.inc is sorted This is an invariant now required by the ID macro, so it's better to have an actual check and not rely on a comment at the top of kernel/constids.inc. --- kernel/rtlil.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 6d72704f4..b2e53b510 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -72,6 +72,19 @@ void RTLIL::IdString::prepopulate() #undef X } +static constexpr bool check_well_known_id_order() +{ + int size = sizeof(IdTable) / sizeof(IdTable[0]); + for (int i = 1; i < size; ++i) + if (IdTable[i - 1].name >= IdTable[i].name) + return false; + return true; +} + +// Ensure the statically allocated IdStrings in kernel/constids.inc are unique +// and in sorted ascii order, as required by the ID macro. +static_assert(check_well_known_id_order()); + dict RTLIL::constpad; const pool &RTLIL::builtin_ff_cell_types() {