1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#ifndef wasm_analysis_lattice_h
#define wasm_analysis_lattice_h
#include "wasm.h"
#include <bitset>
#include <iostream>
namespace wasm::analysis {
enum LatticeComparison { NO_RELATION, EQUAL, LESS, GREATER };
template<typename T>
constexpr bool has_compare = std::is_invocable_r<LatticeComparison,
decltype(T::compare),
const T&,
const T&>::value;
template<typename T>
constexpr bool has_getLeastUpperBound = std::
is_invocable_r<void, decltype(&T::getLeastUpperBound), T, const T&>::value;
template<typename T>
constexpr bool has_isTop =
std::is_invocable_r<bool, decltype(T::isTop), const T&>::value;
template<typename T>
constexpr bool has_isBottom =
std::is_invocable_r<bool, decltype(T::isBottom), const T&>::value;
template<typename T>
constexpr bool is_lattice =
has_compare<T>&& has_getLeastUpperBound<T>&& has_isTop<T>&& has_isBottom<T>;
// Represents a powerset lattice element (i.e. a set) as a bitvector. A true
// means that an element is present in the set.
template<size_t N> struct BitsetPowersetLattice {
std::bitset<N> value;
static BitsetPowersetLattice<N> getBottom();
static bool isTop(const BitsetPowersetLattice<N>& element);
static bool isBottom(const BitsetPowersetLattice<N>& element);
// Compares two lattice elements and returns a result indicating the
// left element's relation to the right element.
static LatticeComparison compare(const BitsetPowersetLattice<N>& left,
const BitsetPowersetLattice<N>& right);
// Calculates the LUB of this current (left) lattice element with some right
// element. It then updates this current lattice element to the LUB in place.
void getLeastUpperBound(const BitsetPowersetLattice<N>& right);
// Prints out the bits in the bitvector for a lattice element.
void print(std::ostream& os);
};
} // namespace wasm::analysis
#include "powerset-lattice-impl.h"
#endif // wasm_analysis_lattice_h
|