From bcdfa72afe41746ac13d27e6d02866c7d11e7fb5 Mon Sep 17 00:00:00 2001 From: Bruce He <44327446+zm2he@users.noreply.github.com> Date: Thu, 3 Aug 2023 17:45:27 +0000 Subject: Lattice to model Stack (#5849) This change introduces StackLattice, a lattice to model stack-related behavior. It is templated on a separate lattice whose elements model some property of individual values on the stack. The StackLattice allows users to access the top of the stack, push abstract values, and pop them. Comparisons and least upper bound operations are done on a value by value basis starting from the top of the stack and moving toward the bottom. This is because it allows stacks from different scopes to be joined easily. An application of StackLattice is to model the wasm value stack. The goal is to organize lattice elements representing individual stack values in a natural way which mirrors the wasm value stack. Transfer functions operate on each stack value individually. The stack lattice is an intermediate structure which is not intended to be directly operated on. Rather, it simulates the push and pop behavior of instructions. --- src/analysis/lattice.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/analysis/lattice.h') diff --git a/src/analysis/lattice.h b/src/analysis/lattice.h index cd634c09c..1f2669c89 100644 --- a/src/analysis/lattice.h +++ b/src/analysis/lattice.h @@ -43,10 +43,10 @@ constexpr bool has_makeLeastUpperBound = const Element&>::value; template constexpr bool has_isTop = - std::is_invocable_r::value; + std::is_invocable_r::value; template constexpr bool has_isBottom = - std::is_invocable_r::value; + std::is_invocable_r::value; template constexpr bool is_lattice = has_getBottom&& has_compare&& @@ -82,7 +82,7 @@ public: public: Element(Element&& source) = default; - Element(Element& source) = default; + Element(const Element& source) = default; Element& operator=(Element&& source) = default; Element& operator=(const Element& source) = default; @@ -90,13 +90,13 @@ public: // Counts the number of members present the element itself. For instance, if // we had {true, false, true}, the count would be 2. O(N) operation which // iterates through the bitvector. - size_t count(); + size_t count() const; bool get(size_t index) { return bitvector[index]; } void set(size_t index, bool value) { bitvector[index] = value; } - bool isTop() { return count() == bitvector.size(); } - bool isBottom() { return count() == 0; } + bool isTop() const { return count() == bitvector.size(); } + bool isBottom() const { return count() == 0; } // Calculates the LUB of this element with some other element and sets // this element to the LUB in place. Returns true if this element before -- cgit v1.2.3