2019-08-14 16:07:15 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2019-08-14 16:07:15 +00:00
|
|
|
|
|
|
|
#include <test/libyul/FunctionSideEffects.h>
|
2020-01-14 16:48:17 +00:00
|
|
|
#include <test/Common.h>
|
2019-08-14 16:07:15 +00:00
|
|
|
#include <test/libyul/Common.h>
|
|
|
|
|
2020-01-06 10:52:23 +00:00
|
|
|
#include <libsolutil/AnsiColorized.h>
|
2019-08-14 16:07:15 +00:00
|
|
|
|
|
|
|
#include <libyul/SideEffects.h>
|
|
|
|
#include <libyul/optimiser/CallGraphGenerator.h>
|
|
|
|
#include <libyul/optimiser/Semantics.h>
|
|
|
|
#include <libyul/Object.h>
|
|
|
|
#include <libyul/backends/evm/EVMDialect.h>
|
|
|
|
|
2020-01-06 10:52:23 +00:00
|
|
|
#include <libsolutil/StringUtils.h>
|
2019-08-14 16:07:15 +00:00
|
|
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
|
|
|
|
2019-12-23 15:50:30 +00:00
|
|
|
using namespace solidity;
|
|
|
|
using namespace solidity::util;
|
|
|
|
using namespace solidity::langutil;
|
|
|
|
using namespace solidity::yul;
|
|
|
|
using namespace solidity::yul::test;
|
|
|
|
using namespace solidity::frontend;
|
|
|
|
using namespace solidity::frontend::test;
|
2019-08-14 16:07:15 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
string toString(SideEffects const& _sideEffects)
|
|
|
|
{
|
|
|
|
vector<string> ret;
|
|
|
|
if (_sideEffects.movable)
|
2020-04-01 02:39:38 +00:00
|
|
|
ret.emplace_back("movable");
|
2019-08-14 16:07:15 +00:00
|
|
|
if (_sideEffects.sideEffectFree)
|
2020-04-01 02:39:38 +00:00
|
|
|
ret.emplace_back("sideEffectFree");
|
2019-08-14 16:07:15 +00:00
|
|
|
if (_sideEffects.sideEffectFreeIfNoMSize)
|
2020-04-01 02:39:38 +00:00
|
|
|
ret.emplace_back("sideEffectFreeIfNoMSize");
|
2019-08-14 16:07:15 +00:00
|
|
|
if (_sideEffects.invalidatesStorage)
|
2020-04-01 02:39:38 +00:00
|
|
|
ret.emplace_back("invalidatesStorage");
|
2019-08-14 16:07:15 +00:00
|
|
|
if (_sideEffects.invalidatesMemory)
|
2020-04-01 02:39:38 +00:00
|
|
|
ret.emplace_back("invalidatesMemory");
|
2019-08-14 16:07:15 +00:00
|
|
|
return joinHumanReadable(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-06 00:22:51 +00:00
|
|
|
FunctionSideEffects::FunctionSideEffects(string const& _filename):
|
|
|
|
TestCase(_filename)
|
2019-08-14 16:07:15 +00:00
|
|
|
{
|
2020-03-06 00:22:51 +00:00
|
|
|
m_source = m_reader.source();
|
|
|
|
m_expectation = m_reader.simpleExpectations();
|
2020-02-04 18:40:56 +00:00
|
|
|
}
|
2019-08-14 16:07:15 +00:00
|
|
|
|
|
|
|
TestCase::TestResult FunctionSideEffects::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
|
|
|
{
|
|
|
|
Object obj;
|
|
|
|
std::tie(obj.code, obj.analysisInfo) = yul::test::parse(m_source, false);
|
|
|
|
if (!obj.code)
|
|
|
|
BOOST_THROW_EXCEPTION(runtime_error("Parsing input failed."));
|
|
|
|
|
|
|
|
map<YulString, SideEffects> functionSideEffects = SideEffectsPropagator::sideEffects(
|
|
|
|
EVMDialect::strictAssemblyForEVM(langutil::EVMVersion()),
|
|
|
|
CallGraphGenerator::callGraph(*obj.code)
|
|
|
|
);
|
|
|
|
|
|
|
|
std::map<std::string, std::string> functionSideEffectsStr;
|
|
|
|
for (auto const& fun: functionSideEffects)
|
|
|
|
functionSideEffectsStr[fun.first.str()] = toString(fun.second);
|
|
|
|
|
|
|
|
m_obtainedResult.clear();
|
|
|
|
for (auto const& fun: functionSideEffectsStr)
|
2019-12-03 07:54:46 +00:00
|
|
|
m_obtainedResult += fun.first + ":" + (fun.second.empty() ? "" : " ") + fun.second + "\n";
|
2019-08-14 16:07:15 +00:00
|
|
|
|
2020-05-25 13:31:24 +00:00
|
|
|
return checkResult(_stream, _linePrefix, _formatted);
|
2019-08-14 16:07:15 +00:00
|
|
|
}
|