fixup! Implementation of Lengauer-Tarjan algorithm to find dominators

This commit is contained in:
Kamil Śliwak 2023-08-11 18:14:08 +02:00 committed by r0qs
parent 0bf0d1943a
commit d33f8f951d
No known key found for this signature in database
GPG Key ID: 61503DBA6667276C

View File

@ -20,6 +20,9 @@
#include <boost/test/unit_test.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/transform.hpp>
using namespace solidity::yul;
namespace solidity::yul::test
@ -83,6 +86,15 @@ protected:
graph->expectedDFSIndices = _expectedDFSIndices;
return graph;
}
std::map<std::string, size_t> toDFSIndices(std::map<Vertex, size_t> const& _vertexIndices)
{
auto convertIndex = [](std::pair<Vertex, size_t> const& _pair) -> std::pair<std::string, size_t>
{
return {_pair.first.name, _pair.second};
};
return _vertexIndices | ranges::views::transform(convertIndex) | ranges::to<std::map>;
}
};
BOOST_AUTO_TEST_SUITE(Dominators)
@ -456,8 +468,7 @@ BOOST_FIXTURE_TEST_CASE(immediate_dominator, DominatorFixture)
ImmediateDominatorTest::ForEachVertexSuccessorTest
> dominatorFinder(*test->entry, test->numVertices);
for (auto const&[v, idx]: dominatorFinder.vertexIndices())
BOOST_CHECK(test->expectedDFSIndices.at(v.name) == idx);
BOOST_TEST(toDFSIndices(dominatorFinder.vertexIndices()) == test->expectedDFSIndices);
BOOST_TEST(dominatorFinder.immediateDominators() == test->expectedIdom);
}
}