From 6ba0f3d282714fa60be2634fbdf48a8ab5a3997d Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Wed, 25 Oct 2023 21:30:31 +0200 Subject: [analysis] Add a FullLattice concept and Inverted lattice (#6038) The FullLattice concept extends the base Lattice with `getTop` and `meet` operations. The `Inverted` lattice uses these operations to reverse the order of an arbitrary full lattice, for example to create a lattice of integers ordered by `>` rather than by `<`. --- src/analysis/lattices/int.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/analysis/lattices/int.h') diff --git a/src/analysis/lattices/int.h b/src/analysis/lattices/int.h index a2cd37c1e..682ac1063 100644 --- a/src/analysis/lattices/int.h +++ b/src/analysis/lattices/int.h @@ -34,6 +34,7 @@ template struct Integer { using Element = T; Element getBottom() const noexcept { return std::numeric_limits::min(); } + Element getTop() const noexcept { return std::numeric_limits::max(); } LatticeComparison compare(Element a, Element b) const noexcept { return a > b ? GREATER : a == b ? EQUAL : LESS; } @@ -44,6 +45,13 @@ struct Integer { } return false; } + bool meet(Element& self, Element other) const noexcept { + if (self > other) { + self = other; + return true; + } + return false; + } }; using Int32 = Integer; @@ -52,10 +60,10 @@ using Int64 = Integer; using UInt64 = Integer; #if __cplusplus >= 202002L -static_assert(Lattice); -static_assert(Lattice); -static_assert(Lattice); -static_assert(Lattice); +static_assert(FullLattice); +static_assert(FullLattice); +static_assert(FullLattice); +static_assert(FullLattice); #endif // __cplusplus >= 202002L } // namespace wasm::analysis -- cgit v1.2.3