mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Provide access to AssemblyStack's AST.
This commit is contained in:
parent
10888b21d8
commit
a344381d5e
@ -178,3 +178,11 @@ string AssemblyStack::print() const
|
|||||||
solAssert(m_parserResult->code, "");
|
solAssert(m_parserResult->code, "");
|
||||||
return m_parserResult->toString(m_language == Language::Yul) + "\n";
|
return m_parserResult->toString(m_language == Language::Yul) + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shared_ptr<Object> AssemblyStack::parserResult() const
|
||||||
|
{
|
||||||
|
solAssert(m_analysisSuccessful, "Analysis was not successful.");
|
||||||
|
solAssert(m_parserResult, "");
|
||||||
|
solAssert(m_parserResult->code, "");
|
||||||
|
return m_parserResult;
|
||||||
|
}
|
||||||
|
@ -82,6 +82,9 @@ public:
|
|||||||
/// Pretty-print the input after having parsed it.
|
/// Pretty-print the input after having parsed it.
|
||||||
std::string print() const;
|
std::string print() const;
|
||||||
|
|
||||||
|
/// Return the parsed and analyzed object.
|
||||||
|
std::shared_ptr<Object> parserResult() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool analyzeParsed();
|
bool analyzeParsed();
|
||||||
bool analyzeParsed(yul::Object& _object);
|
bool analyzeParsed(yul::Object& _object);
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <libyul/AsmParser.h>
|
#include <libyul/AsmParser.h>
|
||||||
#include <libyul/AsmAnalysis.h>
|
#include <libyul/AsmAnalysis.h>
|
||||||
#include <libyul/AsmPrinter.h>
|
#include <libyul/AsmPrinter.h>
|
||||||
|
#include <libyul/AssemblyStack.h>
|
||||||
#include <libyul/backends/evm/EVMDialect.h>
|
#include <libyul/backends/evm/EVMDialect.h>
|
||||||
|
|
||||||
#include <liblangutil/Scanner.h>
|
#include <liblangutil/Scanner.h>
|
||||||
@ -63,33 +64,13 @@ void yul::test::printErrors(ErrorList const& _errors)
|
|||||||
|
|
||||||
pair<shared_ptr<Block>, shared_ptr<yul::AsmAnalysisInfo>> yul::test::parse(string const& _source, bool _yul)
|
pair<shared_ptr<Block>, shared_ptr<yul::AsmAnalysisInfo>> yul::test::parse(string const& _source, bool _yul)
|
||||||
{
|
{
|
||||||
shared_ptr<Dialect> dialect = defaultDialect(_yul);
|
AssemblyStack stack(
|
||||||
ErrorList errors;
|
dev::test::Options::get().evmVersion(),
|
||||||
ErrorReporter errorReporter(errors);
|
_yul ? AssemblyStack::Language::Yul : AssemblyStack::Language::StrictAssembly
|
||||||
auto scanner = make_shared<Scanner>(CharStream(_source, ""));
|
);
|
||||||
auto parserResult = yul::Parser(errorReporter, dialect).parse(scanner, false);
|
if (!stack.parseAndAnalyze("", _source) || !stack.errors().empty())
|
||||||
if (parserResult)
|
BOOST_FAIL("Invalid source.");
|
||||||
{
|
return make_pair(stack.parserResult()->code, stack.parserResult()->analysisInfo);
|
||||||
BOOST_REQUIRE(errorReporter.errors().empty());
|
|
||||||
auto analysisInfo = make_shared<yul::AsmAnalysisInfo>();
|
|
||||||
yul::AsmAnalyzer analyzer(
|
|
||||||
*analysisInfo,
|
|
||||||
errorReporter,
|
|
||||||
dev::test::Options::get().evmVersion(),
|
|
||||||
boost::none,
|
|
||||||
dialect
|
|
||||||
);
|
|
||||||
if (analyzer.analyze(*parserResult))
|
|
||||||
{
|
|
||||||
BOOST_REQUIRE(errorReporter.errors().empty());
|
|
||||||
return make_pair(parserResult, analysisInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printErrors(errors);
|
|
||||||
BOOST_FAIL("Invalid source.");
|
|
||||||
|
|
||||||
// Unreachable.
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
yul::Block yul::test::disambiguate(string const& _source, bool _yul)
|
yul::Block yul::test::disambiguate(string const& _source, bool _yul)
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
#include <libyul/AsmPrinter.h>
|
#include <libyul/AsmPrinter.h>
|
||||||
#include <libyul/AsmParser.h>
|
#include <libyul/AsmParser.h>
|
||||||
#include <libyul/AsmAnalysis.h>
|
#include <libyul/AsmAnalysis.h>
|
||||||
|
#include <libyul/AssemblyStack.h>
|
||||||
#include <liblangutil/SourceReferenceFormatter.h>
|
#include <liblangutil/SourceReferenceFormatter.h>
|
||||||
|
|
||||||
#include <liblangutil/ErrorReporter.h>
|
#include <liblangutil/ErrorReporter.h>
|
||||||
@ -97,9 +98,6 @@ YulOptimizerTest::YulOptimizerTest(string const& _filename)
|
|||||||
|
|
||||||
bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
||||||
{
|
{
|
||||||
yul::AsmPrinter printer{m_yul};
|
|
||||||
shared_ptr<Block> ast;
|
|
||||||
shared_ptr<yul::AsmAnalysisInfo> analysisInfo;
|
|
||||||
if (!parse(_stream, _linePrefix, _formatted))
|
if (!parse(_stream, _linePrefix, _formatted))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -257,7 +255,7 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_obtainedResult = m_optimizerStep + "\n" + printer(*m_ast) + "\n";
|
m_obtainedResult = m_optimizerStep + "\n" + AsmPrinter{m_yul}(*m_ast) + "\n";
|
||||||
|
|
||||||
if (m_expectation != m_obtainedResult)
|
if (m_expectation != m_obtainedResult)
|
||||||
{
|
{
|
||||||
@ -292,31 +290,19 @@ void YulOptimizerTest::printIndented(ostream& _stream, string const& _output, st
|
|||||||
|
|
||||||
bool YulOptimizerTest::parse(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
bool YulOptimizerTest::parse(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
||||||
{
|
{
|
||||||
m_dialect = m_yul ? yul::Dialect::yul() : yul::EVMDialect::strictAssemblyForEVMObjects();
|
AssemblyStack stack(
|
||||||
ErrorList errors;
|
dev::test::Options::get().evmVersion(),
|
||||||
ErrorReporter errorReporter(errors);
|
m_yul ? AssemblyStack::Language::Yul : AssemblyStack::Language::StrictAssembly
|
||||||
shared_ptr<Scanner> scanner = make_shared<Scanner>(CharStream(m_source, ""));
|
);
|
||||||
m_ast = yul::Parser(errorReporter, m_dialect).parse(scanner, false);
|
if (!stack.parseAndAnalyze("", m_source) || !stack.errors().empty())
|
||||||
if (!m_ast || !errorReporter.errors().empty())
|
|
||||||
{
|
{
|
||||||
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl;
|
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing source." << endl;
|
||||||
printErrors(_stream, errorReporter.errors());
|
printErrors(_stream, stack.errors());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_analysisInfo = make_shared<yul::AsmAnalysisInfo>();
|
|
||||||
yul::AsmAnalyzer analyzer(
|
|
||||||
*m_analysisInfo,
|
|
||||||
errorReporter,
|
|
||||||
dev::test::Options::get().evmVersion(),
|
|
||||||
boost::none,
|
|
||||||
m_dialect
|
|
||||||
);
|
|
||||||
if (!analyzer.analyze(*m_ast) || !errorReporter.errors().empty())
|
|
||||||
{
|
|
||||||
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error analyzing source." << endl;
|
|
||||||
printErrors(_stream, errorReporter.errors());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
m_dialect = m_yul ? Dialect::yul() : EVMDialect::strictAssemblyForEVMObjects();
|
||||||
|
m_ast = stack.parserResult()->code;
|
||||||
|
m_analysisInfo = stack.parserResult()->analysisInfo;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user