diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index b675650..51d1782 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -90,6 +90,9 @@ public: /// Generate a new id for forward declarations [[nodiscard]] Id ForwardDeclarationId(); + /// Returns the current generator id, useful for self-referencing phi nodes + [[nodiscard]] Id CurrentId() const noexcept; + /// Assign a new id and return the old one, useful for defining forward declarations Id ExchangeCurrentId(Id new_current_id); diff --git a/src/sirit.cpp b/src/sirit.cpp index ee4b76e..22a4570 100644 --- a/src/sirit.cpp +++ b/src/sirit.cpp @@ -99,6 +99,10 @@ Id Module::ForwardDeclarationId() { return Id{++bound}; } +Id Module::CurrentId() const noexcept { + return Id{bound + 1}; +} + Id Module::ExchangeCurrentId(Id new_current_id) { const std::uint32_t old_id = std::exchange(bound, new_current_id.value - 1); return Id{old_id + 1};