mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use yul parser in assembly stack.
This commit is contained in:
parent
e016cb99e6
commit
728119bb11
@ -30,7 +30,7 @@
|
||||
#include <libyul/AsmCodeGen.h>
|
||||
#include <libyul/backends/evm/EVMCodeTransform.h>
|
||||
#include <libyul/backends/evm/EVMAssembly.h>
|
||||
#include <libyul/YulObjectParser.h>
|
||||
#include <libyul/ObjectParser.h>
|
||||
|
||||
#include <libevmasm/Assembly.h>
|
||||
|
||||
@ -70,19 +70,22 @@ bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string
|
||||
m_errors.clear();
|
||||
m_analysisSuccessful = false;
|
||||
m_scanner = make_shared<Scanner>(CharStream(_source), _sourceName);
|
||||
m_parserResult = yul::YulObjectParser(m_errorReporter, languageToAsmFlavour(m_language)).parse(m_scanner, false);
|
||||
m_parserResult = yul::ObjectParser(m_errorReporter, languageToAsmFlavour(m_language)).parse(m_scanner, false);
|
||||
if (!m_errorReporter.errors().empty())
|
||||
return false;
|
||||
solAssert(m_parserResult, "");
|
||||
solAssert(m_parserResult->code, "");
|
||||
|
||||
return analyzeParsed();
|
||||
}
|
||||
|
||||
bool AssemblyStack::analyzeParsed()
|
||||
{
|
||||
m_analysisInfo = make_shared<yul::AsmAnalysisInfo>();
|
||||
yul::AsmAnalyzer analyzer(*m_analysisInfo, m_errorReporter, m_evmVersion, boost::none, languageToAsmFlavour(m_language));
|
||||
m_analysisSuccessful = analyzer.analyze(*m_parserResult);
|
||||
solAssert(m_parserResult, "");
|
||||
solAssert(m_parserResult->code, "");
|
||||
m_parserResult->analysisInfo = make_shared<yul::AsmAnalysisInfo>();
|
||||
yul::AsmAnalyzer analyzer(*m_parserResult->analysisInfo, m_errorReporter, m_evmVersion, boost::none, languageToAsmFlavour(m_language));
|
||||
m_analysisSuccessful = analyzer.analyze(*m_parserResult->code);
|
||||
return m_analysisSuccessful;
|
||||
}
|
||||
|
||||
@ -90,7 +93,8 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
|
||||
{
|
||||
solAssert(m_analysisSuccessful, "");
|
||||
solAssert(m_parserResult, "");
|
||||
solAssert(m_analysisInfo, "");
|
||||
solAssert(m_parserResult->code, "");
|
||||
solAssert(m_parserResult->analysisInfo, "");
|
||||
|
||||
switch (_machine)
|
||||
{
|
||||
@ -98,7 +102,7 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
|
||||
{
|
||||
MachineAssemblyObject object;
|
||||
eth::Assembly assembly;
|
||||
yul::CodeGenerator::assemble(*m_parserResult, *m_analysisInfo, assembly);
|
||||
yul::CodeGenerator::assemble(*m_parserResult->code, *m_parserResult->analysisInfo, assembly);
|
||||
object.bytecode = make_shared<eth::LinkerObject>(assembly.assemble());
|
||||
object.assembly = assembly.assemblyString();
|
||||
return object;
|
||||
@ -107,7 +111,7 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
|
||||
{
|
||||
MachineAssemblyObject object;
|
||||
yul::EVMAssembly assembly(true);
|
||||
yul::CodeTransform(assembly, *m_analysisInfo, m_language == Language::Yul, true)(*m_parserResult);
|
||||
yul::CodeTransform(assembly, *m_parserResult->analysisInfo, m_language == Language::Yul, true)(*m_parserResult->code);
|
||||
object.bytecode = make_shared<eth::LinkerObject>(assembly.finalize());
|
||||
/// TODO: fill out text representation
|
||||
return object;
|
||||
@ -122,5 +126,6 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
|
||||
string AssemblyStack::print() const
|
||||
{
|
||||
solAssert(m_parserResult, "");
|
||||
return yul::AsmPrinter(m_language == Language::Yul)(*m_parserResult);
|
||||
solAssert(m_parserResult->code, "");
|
||||
return m_parserResult->toString(m_language == Language::Yul) + "\n";
|
||||
}
|
||||
|
@ -24,8 +24,8 @@
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
#include <libyul/YulObject.h>
|
||||
#include <libyul/YulObjectParser.h>
|
||||
#include <libyul/Object.h>
|
||||
#include <libyul/ObjectParser.h>
|
||||
|
||||
#include <libevmasm/LinkerObject.h>
|
||||
|
||||
@ -37,12 +37,6 @@ namespace langutil
|
||||
class Scanner;
|
||||
}
|
||||
|
||||
namespace yul
|
||||
{
|
||||
struct AsmAnalysisInfo;
|
||||
struct Block;
|
||||
}
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
@ -93,7 +87,7 @@ private:
|
||||
std::shared_ptr<langutil::Scanner> m_scanner;
|
||||
|
||||
bool m_analysisSuccessful = false;
|
||||
std::shared_ptr<yul::YulObject> m_parserResult;
|
||||
std::shared_ptr<yul::Object> m_parserResult;
|
||||
langutil::ErrorList m_errors;
|
||||
langutil::ErrorReporter m_errorReporter;
|
||||
};
|
||||
|
@ -124,7 +124,8 @@ void parsePrintCompare(string const& _source, bool _canWarn = false)
|
||||
BOOST_REQUIRE(Error::containsOnlyWarnings(stack.errors()));
|
||||
else
|
||||
BOOST_REQUIRE(stack.errors().empty());
|
||||
BOOST_CHECK_EQUAL(stack.print(), _source);
|
||||
string expectation = "object \"object\" {\n code " + boost::replace_all_copy(_source, "\n", "\n ") + "\n}\n";
|
||||
BOOST_CHECK_EQUAL(stack.print(), expectation);
|
||||
}
|
||||
|
||||
}
|
||||
@ -567,12 +568,14 @@ BOOST_AUTO_TEST_CASE(print_string_literals)
|
||||
BOOST_AUTO_TEST_CASE(print_string_literal_unicode)
|
||||
{
|
||||
string source = "{ let x := \"\\u1bac\" }";
|
||||
string parsed = "{\n let x := \"\\xe1\\xae\\xac\"\n}";
|
||||
string parsed = "object \"object\" {\n code {\n let x := \"\\xe1\\xae\\xac\"\n }\n}\n";
|
||||
AssemblyStack stack(dev::test::Options::get().evmVersion());
|
||||
BOOST_REQUIRE(stack.parseAndAnalyze("", source));
|
||||
BOOST_REQUIRE(stack.errors().empty());
|
||||
BOOST_CHECK_EQUAL(stack.print(), parsed);
|
||||
parsePrintCompare(parsed);
|
||||
|
||||
string parsedInner = "{\n let x := \"\\xe1\\xae\\xac\"\n}";
|
||||
parsePrintCompare(parsedInner);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(print_if)
|
||||
|
Loading…
Reference in New Issue
Block a user