mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9575 from ethereum/yul-optim-check
Parse optimiser output in yulOptimiserTests
This commit is contained in:
commit
488fd5a27a
@ -111,7 +111,8 @@ YulOptimizerTest::YulOptimizerTest(string const& _filename):
|
||||
|
||||
TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
||||
{
|
||||
if (!parse(_stream, _linePrefix, _formatted))
|
||||
std::tie(m_object, m_analysisInfo) = parse(_stream, _linePrefix, _formatted, m_source);
|
||||
if (!m_object)
|
||||
return TestResult::FatalError;
|
||||
|
||||
soltestAssert(m_dialect, "Dialect not set.");
|
||||
@ -141,7 +142,11 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
|
||||
else if (m_optimizerStep == "varDeclInitializer")
|
||||
VarDeclInitializer::run(*m_context, *m_object->code);
|
||||
else if (m_optimizerStep == "varNameCleaner")
|
||||
{
|
||||
disambiguate();
|
||||
FunctionGrouper::run(*m_context, *m_object->code);
|
||||
VarNameCleaner::run(*m_context, *m_object->code);
|
||||
}
|
||||
else if (m_optimizerStep == "forLoopConditionIntoBody")
|
||||
{
|
||||
disambiguate();
|
||||
@ -354,26 +359,42 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
|
||||
return TestResult::FatalError;
|
||||
}
|
||||
|
||||
m_obtainedResult =
|
||||
"step: " + m_optimizerStep + "\n\n" +
|
||||
(m_object->subObjects.empty() ? AsmPrinter{ *m_dialect }(*m_object->code) : m_object->toString(m_dialect)) +
|
||||
"\n";
|
||||
auto const printed = (m_object->subObjects.empty() ? AsmPrinter{ *m_dialect }(*m_object->code) : m_object->toString(m_dialect));
|
||||
|
||||
// Re-parse new code for compilability
|
||||
// TODO: support for wordSizeTransform which needs different input and output dialects
|
||||
if (m_optimizerStep != "wordSizeTransform" && !std::get<0>(parse(_stream, _linePrefix, _formatted, printed)))
|
||||
{
|
||||
util::AnsiColorized(_stream, _formatted, {util::formatting::BOLD, util::formatting::CYAN})
|
||||
<< _linePrefix << "Result after the optimiser:" << endl;
|
||||
printIndented(_stream, printed, _linePrefix + " ");
|
||||
return TestResult::FatalError;
|
||||
}
|
||||
|
||||
m_obtainedResult = "step: " + m_optimizerStep + "\n\n" + printed + "\n";
|
||||
|
||||
return checkResult(_stream, _linePrefix, _formatted);
|
||||
}
|
||||
|
||||
bool YulOptimizerTest::parse(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
||||
std::pair<std::shared_ptr<Object>, std::shared_ptr<AsmAnalysisInfo>> YulOptimizerTest::parse(
|
||||
ostream& _stream,
|
||||
string const& _linePrefix,
|
||||
bool const _formatted,
|
||||
string const& _source
|
||||
)
|
||||
{
|
||||
ErrorList errors;
|
||||
soltestAssert(m_dialect, "");
|
||||
std::tie(m_object, m_analysisInfo) = yul::test::parse(m_source, *m_dialect, errors);
|
||||
if (!m_object || !m_analysisInfo || !Error::containsOnlyWarnings(errors))
|
||||
shared_ptr<Object> object;
|
||||
shared_ptr<AsmAnalysisInfo> analysisInfo;
|
||||
std::tie(object, analysisInfo) = yul::test::parse(_source, *m_dialect, errors);
|
||||
if (!object || !analysisInfo || !Error::containsOnlyWarnings(errors))
|
||||
{
|
||||
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl;
|
||||
printErrors(_stream, errors);
|
||||
return false;
|
||||
return {};
|
||||
}
|
||||
return true;
|
||||
return {std::move(object), std::move(analysisInfo)};
|
||||
}
|
||||
|
||||
void YulOptimizerTest::disambiguate()
|
||||
|
@ -58,7 +58,9 @@ public:
|
||||
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override;
|
||||
|
||||
private:
|
||||
bool parse(std::ostream& _stream, std::string const& _linePrefix, bool const _formatted);
|
||||
std::pair<std::shared_ptr<Object>, std::shared_ptr<AsmAnalysisInfo>> parse(
|
||||
std::ostream& _stream, std::string const& _linePrefix, bool const _formatted, std::string const& _source
|
||||
);
|
||||
void disambiguate();
|
||||
void updateContext();
|
||||
|
||||
|
@ -4,4 +4,4 @@
|
||||
// ----
|
||||
// step: varNameCleaner
|
||||
//
|
||||
// { let datasize_1 := 1 }
|
||||
// { { let datasize_1 := 1 } }
|
||||
|
@ -1,14 +1,16 @@
|
||||
{
|
||||
let f_2
|
||||
function f() { let f_1 }
|
||||
let f_2
|
||||
let f_10
|
||||
}
|
||||
// ----
|
||||
// step: varNameCleaner
|
||||
//
|
||||
// {
|
||||
// let f_1
|
||||
// {
|
||||
// let f_1
|
||||
// let f_2
|
||||
// }
|
||||
// function f()
|
||||
// { let f_1 }
|
||||
// let f_2
|
||||
// }
|
||||
|
@ -12,12 +12,14 @@
|
||||
// step: varNameCleaner
|
||||
//
|
||||
// {
|
||||
// let f_1
|
||||
// {
|
||||
// let f_1
|
||||
// let f_2
|
||||
// }
|
||||
// function f(x) -> x_1, y
|
||||
// {
|
||||
// let y_1 := x
|
||||
// y := y_1
|
||||
// x_1 := y
|
||||
// }
|
||||
// let f_2
|
||||
// }
|
||||
|
@ -6,6 +6,7 @@
|
||||
// step: varNameCleaner
|
||||
//
|
||||
// {
|
||||
// { }
|
||||
// function f()
|
||||
// { let x := 0 }
|
||||
// function g()
|
||||
|
@ -4,4 +4,4 @@
|
||||
// ----
|
||||
// step: varNameCleaner
|
||||
//
|
||||
// { let mul_1 := 1 }
|
||||
// { { let mul_1 := 1 } }
|
||||
|
@ -8,8 +8,10 @@
|
||||
// step: varNameCleaner
|
||||
//
|
||||
// {
|
||||
// let a := 1
|
||||
// let a_1 := 2
|
||||
// let a_2 := 0xdeadbeef
|
||||
// let _1 := 21718
|
||||
// {
|
||||
// let a := 1
|
||||
// let a_1 := 2
|
||||
// let a_2 := 0xdeadbeef
|
||||
// let _1 := 21718
|
||||
// }
|
||||
// }
|
||||
|
@ -8,8 +8,10 @@
|
||||
// step: varNameCleaner
|
||||
//
|
||||
// {
|
||||
// let x := 1
|
||||
// let x_1 := 2
|
||||
// let x_2 := 3
|
||||
// let x_3 := 4
|
||||
// {
|
||||
// let x := 1
|
||||
// let x_1 := 2
|
||||
// let x_2 := 3
|
||||
// let x_3 := 4
|
||||
// }
|
||||
// }
|
||||
|
@ -7,7 +7,9 @@
|
||||
// step: varNameCleaner
|
||||
//
|
||||
// {
|
||||
// let x := 1
|
||||
// let x_1 := 2
|
||||
// let x_2 := 3
|
||||
// {
|
||||
// let x := 1
|
||||
// let x_1 := 2
|
||||
// let x_2 := 3
|
||||
// }
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user