From 55e60bd4938bc8a8afbfcbdd5e22f5bf6fa38b0f Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 17 Aug 2021 13:04:40 +0200 Subject: [PATCH] Reuse stack helpers from tests. --- test/libyul/ControlFlowGraphTest.cpp | 21 +-------------------- test/libyul/StackLayoutGeneratorTest.cpp | 21 +-------------------- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/test/libyul/ControlFlowGraphTest.cpp b/test/libyul/ControlFlowGraphTest.cpp index 1107f4ca2..c77c190d3 100644 --- a/test/libyul/ControlFlowGraphTest.cpp +++ b/test/libyul/ControlFlowGraphTest.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -52,26 +53,6 @@ ControlFlowGraphTest::ControlFlowGraphTest(string const& _filename): namespace { -static std::string stackSlotToString(StackSlot const& _slot) -{ - return std::visit(util::GenericVisitor{ - [](FunctionCallReturnLabelSlot const& _ret) -> std::string { return "RET[" + _ret.call.get().functionName.name.str() + "]"; }, - [](FunctionReturnLabelSlot const&) -> std::string { return "RET"; }, - [](VariableSlot const& _var) { return _var.variable.get().name.str(); }, - [](LiteralSlot const& _lit) { return util::toCompactHexWithPrefix(_lit.value); }, - [](TemporarySlot const& _tmp) -> std::string { return "TMP[" + _tmp.call.get().functionName.name.str() + ", " + std::to_string(_tmp.index) + "]"; }, - [](JunkSlot const&) -> std::string { return "JUNK"; } - }, _slot); -} - -static std::string stackToString(Stack const& _stack) -{ - std::string result("[ "); - for (auto const& slot: _stack) - result += stackSlotToString(slot) + ' '; - result += ']'; - return result; -} static std::string variableSlotToString(VariableSlot const& _slot) { return _slot.variable.get().name.str(); diff --git a/test/libyul/StackLayoutGeneratorTest.cpp b/test/libyul/StackLayoutGeneratorTest.cpp index 6dbed8f67..35d4c07ee 100644 --- a/test/libyul/StackLayoutGeneratorTest.cpp +++ b/test/libyul/StackLayoutGeneratorTest.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -55,26 +56,6 @@ StackLayoutGeneratorTest::StackLayoutGeneratorTest(string const& _filename): namespace { -static std::string stackSlotToString(StackSlot const& _slot) -{ - return std::visit(util::GenericVisitor{ - [](FunctionCallReturnLabelSlot const& _ret) -> std::string { return "RET[" + _ret.call.get().functionName.name.str() + "]"; }, - [](FunctionReturnLabelSlot const&) -> std::string { return "RET"; }, - [](VariableSlot const& _var) { return _var.variable.get().name.str(); }, - [](LiteralSlot const& _lit) { return util::toCompactHexWithPrefix(_lit.value); }, - [](TemporarySlot const& _tmp) -> std::string { return "TMP[" + _tmp.call.get().functionName.name.str() + ", " + std::to_string(_tmp.index) + "]"; }, - [](JunkSlot const&) -> std::string { return "JUNK"; } - }, _slot); -} - -static std::string stackToString(Stack const& _stack) -{ - std::string result("[ "); - for (auto const& slot: _stack) - result += stackSlotToString(slot) + ' '; - result += ']'; - return result; -} static std::string variableSlotToString(VariableSlot const& _slot) { return _slot.variable.get().name.str();