#ifndef wasm_analysis_monotone_analyzer_h
#define wasm_analysis_monotone_analyzer_h
#include <iostream>
#include <queue>
#include <vector>
#include "cfg.h"
#include "lattice.h"
#include "wasm-traversal.h"
namespace wasm::analysis {
template<size_t N> struct MonotoneCFGAnalyzer;
template<size_t N> struct BlockState : public Visitor<BlockState<N>> {
static_assert(is_lattice<BitsetPowersetLattice<N>>);
BlockState(const BasicBlock* underlyingBlock);
void addPredecessor(BlockState* pred);
void addSuccessor(BlockState* succ);
BitsetPowersetLattice<N>& getFirstState();
BitsetPowersetLattice<N>& getLastState();
void visitLocalSet(LocalSet* curr);
void visitLocalGet(LocalGet* curr);
void transfer();
void print(std::ostream& os);
private:
Index index;
const BasicBlock* cfgBlock;
BitsetPowersetLattice<N> beginningState;
BitsetPowersetLattice<N> endState;
BitsetPowersetLattice<N> currState;
std::vector<BlockState*> predecessors;
std::vector<BlockState*> successors;
friend MonotoneCFGAnalyzer<N>;
};
template<size_t N> struct MonotoneCFGAnalyzer {
static_assert(is_lattice<BitsetPowersetLattice<N>>);
static MonotoneCFGAnalyzer<N> fromCFG(CFG* cfg);
void evaluate();
void print(std::ostream& os);
private:
std::vector<BlockState<N>> stateBlocks;
friend BlockState<N>;
};
}
#include "monotone-analyzer-impl.h"
#endif