summaryrefslogtreecommitdiff
path: root/test/gtest/cfg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/gtest/cfg.cpp')
-rw-r--r--test/gtest/cfg.cpp53
1 files changed, 47 insertions, 6 deletions
diff --git a/test/gtest/cfg.cpp b/test/gtest/cfg.cpp
index 65b449745..c18d81499 100644
--- a/test/gtest/cfg.cpp
+++ b/test/gtest/cfg.cpp
@@ -147,11 +147,13 @@ End
parseWast(wasm, moduleText);
CFG cfg = CFG::fromFunction(wasm.getFunction("bar"));
- FinitePowersetLattice lattice(wasm.getFunction("bar")->getNumLocals());
+ size_t numLocals = wasm.getFunction("bar")->getNumLocals();
+
+ FiniteIntPowersetLattice lattice(numLocals);
LivenessTransferFunction transferFunction;
- MonotoneCFGAnalyzer<FinitePowersetLattice, LivenessTransferFunction> analyzer(
- lattice, transferFunction, cfg);
+ MonotoneCFGAnalyzer<FiniteIntPowersetLattice, LivenessTransferFunction>
+ analyzer(lattice, transferFunction, cfg);
analyzer.evaluate();
std::stringstream ss;
@@ -237,11 +239,13 @@ End
parseWast(wasm, moduleText);
CFG cfg = CFG::fromFunction(wasm.getFunction("bar"));
- FinitePowersetLattice lattice(wasm.getFunction("bar")->getNumLocals());
+ size_t numLocals = wasm.getFunction("bar")->getNumLocals();
+
+ FiniteIntPowersetLattice lattice(numLocals);
LivenessTransferFunction transferFunction;
- MonotoneCFGAnalyzer<FinitePowersetLattice, LivenessTransferFunction> analyzer(
- lattice, transferFunction, cfg);
+ MonotoneCFGAnalyzer<FiniteIntPowersetLattice, LivenessTransferFunction>
+ analyzer(lattice, transferFunction, cfg);
analyzer.evaluate();
std::stringstream ss;
@@ -249,3 +253,40 @@ End
EXPECT_EQ(ss.str(), analyzerText);
}
+
+TEST_F(CFGTest, FinitePowersetLatticeFunctioning) {
+
+ std::vector<std::string> initialSet = {"a", "b", "c", "d", "e", "f"};
+ FinitePowersetLattice<std::string> lattice(std::move(initialSet));
+
+ auto element1 = lattice.getBottom();
+
+ EXPECT_TRUE(element1.isBottom());
+ EXPECT_FALSE(element1.isTop());
+
+ lattice.add(&element1, "c");
+ lattice.add(&element1, "d");
+ lattice.add(&element1, "a");
+
+ EXPECT_FALSE(element1.isBottom());
+ EXPECT_FALSE(element1.isTop());
+
+ auto element2 = element1;
+ lattice.remove(&element2, "c");
+ EXPECT_EQ(FinitePowersetLattice<std::string>::compare(element1, element2),
+ LatticeComparison::GREATER);
+ lattice.add(&element2, "f");
+ EXPECT_EQ(FinitePowersetLattice<std::string>::compare(element1, element2),
+ LatticeComparison::NO_RELATION);
+
+ std::stringstream ss;
+ element1.print(ss);
+ EXPECT_EQ(ss.str(), "101100");
+ ss.str(std::string());
+ element2.print(ss);
+ EXPECT_EQ(ss.str(), "100101");
+ ss.str(std::string());
+ element2.makeLeastUpperBound(element1);
+ element2.print(ss);
+ EXPECT_EQ(ss.str(), "101101");
+}