Merge pull request #8054 from ethereum/wasm

Rename some generic Wasm helpers from Ewasm
This commit is contained in:
Alex Beregszaszi 2019-12-18 18:16:52 +00:00 committed by GitHub
commit 12dac24871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 79 additions and 82 deletions

View File

@ -51,10 +51,6 @@
#include <libyul/YulString.h>
#include <libyul/AsmPrinter.h>
#include <libyul/backends/wasm/EVMToEWasmTranslator.h>
#include <libyul/backends/wasm/EWasmObjectCompiler.h>
#include <libyul/backends/wasm/WasmDialect.h>
#include <libyul/backends/evm/EVMDialect.h>
#include <libyul/AssemblyStack.h>
#include <liblangutil/Scanner.h>

View File

@ -33,8 +33,8 @@
#include <libyul/backends/evm/EVMObjectCompiler.h>
#include <libyul/backends/evm/EVMMetrics.h>
#include <libyul/backends/wasm/WasmDialect.h>
#include <libyul/backends/wasm/EWasmObjectCompiler.h>
#include <libyul/backends/wasm/EVMToEWasmTranslator.h>
#include <libyul/backends/wasm/WasmObjectCompiler.h>
#include <libyul/backends/wasm/EVMToEwasmTranslator.h>
#include <libyul/optimiser/Metrics.h>
#include <libyul/ObjectParser.h>
#include <libyul/optimiser/Suite.h>
@ -112,7 +112,7 @@ void AssemblyStack::translate(AssemblyStack::Language _targetLanguage)
"Invalid language combination"
);
*m_parserResult = EVMToEWasmTranslator(
*m_parserResult = EVMToEwasmTranslator(
languageToDialect(m_language, m_evmVersion)
).run(*parserResult());
@ -220,7 +220,7 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
Dialect const& dialect = languageToDialect(m_language, EVMVersion{});
MachineAssemblyObject object;
auto result = EWasmObjectCompiler::compile(*m_parserResult, dialect);
auto result = WasmObjectCompiler::compile(*m_parserResult, dialect);
object.assembly = std::move(result.first);
object.bytecode = make_shared<dev::eth::LinkerObject>();
object.bytecode->bytecode = std::move(result.second);

View File

@ -44,18 +44,18 @@ add_library(yul
backends/evm/EVMMetrics.h
backends/evm/NoOutputAssembly.h
backends/evm/NoOutputAssembly.cpp
backends/wasm/EVMToEWasmTranslator.cpp
backends/wasm/EVMToEWasmTranslator.h
backends/wasm/EWasmCodeTransform.cpp
backends/wasm/EWasmCodeTransform.h
backends/wasm/EWasmObjectCompiler.cpp
backends/wasm/EWasmObjectCompiler.h
backends/wasm/EVMToEwasmTranslator.cpp
backends/wasm/EVMToEwasmTranslator.h
backends/wasm/BinaryTransform.cpp
backends/wasm/BinaryTransform.h
backends/wasm/TextTransform.cpp
backends/wasm/TextTransform.h
backends/wasm/WasmCodeTransform.cpp
backends/wasm/WasmCodeTransform.h
backends/wasm/WasmDialect.cpp
backends/wasm/WasmDialect.h
backends/wasm/WasmObjectCompiler.cpp
backends/wasm/WasmObjectCompiler.h
backends/wasm/WordSizeTransform.cpp
backends/wasm/WordSizeTransform.h
optimiser/ASTCopier.cpp

View File

@ -15,10 +15,10 @@
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Translates Yul code from EVM dialect to eWasm dialect.
* Translates Yul code from EVM dialect to Ewasm dialect.
*/
#include <libyul/backends/wasm/EVMToEWasmTranslator.h>
#include <libyul/backends/wasm/EVMToEwasmTranslator.h>
#include <libyul/backends/wasm/WordSizeTransform.h>
#include <libyul/backends/wasm/WasmDialect.h>
@ -701,7 +701,7 @@ function invalid() {
}
Object EVMToEWasmTranslator::run(Object const& _object)
Object EVMToEwasmTranslator::run(Object const& _object)
{
if (!m_polyfill)
parsePolyfill();
@ -749,7 +749,7 @@ Object EVMToEWasmTranslator::run(Object const& _object)
return ret;
}
void EVMToEWasmTranslator::parsePolyfill()
void EVMToEwasmTranslator::parsePolyfill()
{
ErrorList errors;
ErrorReporter errorReporter(errors);

View File

@ -15,7 +15,7 @@
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Translates Yul code from EVM dialect to eWasm dialect.
* Translates Yul code from EVM dialect to Ewasm dialect.
*/
#pragma once
@ -28,10 +28,10 @@ namespace yul
{
struct Object;
class EVMToEWasmTranslator: public ASTModifier
class EVMToEwasmTranslator: public ASTModifier
{
public:
EVMToEWasmTranslator(Dialect const& _evmDialect): m_dialect(_evmDialect) {}
EVMToEwasmTranslator(Dialect const& _evmDialect): m_dialect(_evmDialect) {}
Object run(Object const& _object);
private:

View File

@ -15,10 +15,10 @@
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Common code generator for translating Yul / inline assembly to EWasm.
* Common code generator for translating Yul / inline assembly to Wasm.
*/
#include <libyul/backends/wasm/EWasmCodeTransform.h>
#include <libyul/backends/wasm/WasmCodeTransform.h>
#include <libyul/optimiser/NameCollector.h>
@ -36,11 +36,11 @@ using namespace std;
using namespace dev;
using namespace yul;
wasm::Module EWasmCodeTransform::run(Dialect const& _dialect, yul::Block const& _ast)
wasm::Module WasmCodeTransform::run(Dialect const& _dialect, yul::Block const& _ast)
{
wasm::Module module;
EWasmCodeTransform transform(_dialect, _ast);
WasmCodeTransform transform(_dialect, _ast);
for (auto const& statement: _ast.statements)
{
@ -59,7 +59,7 @@ wasm::Module EWasmCodeTransform::run(Dialect const& _dialect, yul::Block const&
return module;
}
wasm::Expression EWasmCodeTransform::generateMultiAssignment(
wasm::Expression WasmCodeTransform::generateMultiAssignment(
vector<string> _variableNames,
unique_ptr<wasm::Expression> _firstValue
)
@ -82,7 +82,7 @@ wasm::Expression EWasmCodeTransform::generateMultiAssignment(
return { std::move(block) };
}
wasm::Expression EWasmCodeTransform::operator()(VariableDeclaration const& _varDecl)
wasm::Expression WasmCodeTransform::operator()(VariableDeclaration const& _varDecl)
{
vector<string> variableNames;
for (auto const& var: _varDecl.variables)
@ -97,7 +97,7 @@ wasm::Expression EWasmCodeTransform::operator()(VariableDeclaration const& _varD
return wasm::BuiltinCall{"nop", {}};
}
wasm::Expression EWasmCodeTransform::operator()(Assignment const& _assignment)
wasm::Expression WasmCodeTransform::operator()(Assignment const& _assignment)
{
vector<string> variableNames;
for (auto const& var: _assignment.variableNames)
@ -105,12 +105,12 @@ wasm::Expression EWasmCodeTransform::operator()(Assignment const& _assignment)
return generateMultiAssignment(move(variableNames), visit(*_assignment.value));
}
wasm::Expression EWasmCodeTransform::operator()(ExpressionStatement const& _statement)
wasm::Expression WasmCodeTransform::operator()(ExpressionStatement const& _statement)
{
return visitReturnByValue(_statement.expression);
}
wasm::Expression EWasmCodeTransform::operator()(FunctionCall const& _call)
wasm::Expression WasmCodeTransform::operator()(FunctionCall const& _call)
{
bool typeConversionNeeded = false;
@ -171,19 +171,19 @@ wasm::Expression EWasmCodeTransform::operator()(FunctionCall const& _call)
return {std::move(funCall)};
}
wasm::Expression EWasmCodeTransform::operator()(Identifier const& _identifier)
wasm::Expression WasmCodeTransform::operator()(Identifier const& _identifier)
{
return wasm::LocalVariable{_identifier.name.str()};
}
wasm::Expression EWasmCodeTransform::operator()(Literal const& _literal)
wasm::Expression WasmCodeTransform::operator()(Literal const& _literal)
{
u256 value = valueOfLiteral(_literal);
yulAssert(value <= numeric_limits<uint64_t>::max(), "Literal too large: " + value.str());
return wasm::Literal{uint64_t(value)};
}
wasm::Expression EWasmCodeTransform::operator()(If const& _if)
wasm::Expression WasmCodeTransform::operator()(If const& _if)
{
// TODO converting i64 to i32 might not always be needed.
@ -197,7 +197,7 @@ wasm::Expression EWasmCodeTransform::operator()(If const& _if)
};
}
wasm::Expression EWasmCodeTransform::operator()(Switch const& _switch)
wasm::Expression WasmCodeTransform::operator()(Switch const& _switch)
{
wasm::Block block;
string condition = m_nameDispenser.newName("condition"_yulstring).str();
@ -237,13 +237,13 @@ wasm::Expression EWasmCodeTransform::operator()(Switch const& _switch)
return { std::move(block) };
}
wasm::Expression EWasmCodeTransform::operator()(FunctionDefinition const&)
wasm::Expression WasmCodeTransform::operator()(FunctionDefinition const&)
{
yulAssert(false, "Should not have visited here.");
return {};
}
wasm::Expression EWasmCodeTransform::operator()(ForLoop const& _for)
wasm::Expression WasmCodeTransform::operator()(ForLoop const& _for)
{
string breakLabel = newLabel();
string continueLabel = newLabel();
@ -262,37 +262,37 @@ wasm::Expression EWasmCodeTransform::operator()(ForLoop const& _for)
return { wasm::Block{breakLabel, make_vector<wasm::Expression>(move(loop))} };
}
wasm::Expression EWasmCodeTransform::operator()(Break const&)
wasm::Expression WasmCodeTransform::operator()(Break const&)
{
return wasm::Break{wasm::Label{m_breakContinueLabelNames.top().first}};
}
wasm::Expression EWasmCodeTransform::operator()(Continue const&)
wasm::Expression WasmCodeTransform::operator()(Continue const&)
{
return wasm::Break{wasm::Label{m_breakContinueLabelNames.top().second}};
}
wasm::Expression EWasmCodeTransform::operator()(Leave const&)
wasm::Expression WasmCodeTransform::operator()(Leave const&)
{
return wasm::Return{};
}
wasm::Expression EWasmCodeTransform::operator()(Block const& _block)
wasm::Expression WasmCodeTransform::operator()(Block const& _block)
{
return wasm::Block{{}, visit(_block.statements)};
}
unique_ptr<wasm::Expression> EWasmCodeTransform::visit(yul::Expression const& _expression)
unique_ptr<wasm::Expression> WasmCodeTransform::visit(yul::Expression const& _expression)
{
return make_unique<wasm::Expression>(std::visit(*this, _expression));
}
wasm::Expression EWasmCodeTransform::visitReturnByValue(yul::Expression const& _expression)
wasm::Expression WasmCodeTransform::visitReturnByValue(yul::Expression const& _expression)
{
return std::visit(*this, _expression);
}
vector<wasm::Expression> EWasmCodeTransform::visit(vector<yul::Expression> const& _expressions)
vector<wasm::Expression> WasmCodeTransform::visit(vector<yul::Expression> const& _expressions)
{
vector<wasm::Expression> ret;
for (auto const& e: _expressions)
@ -300,12 +300,12 @@ vector<wasm::Expression> EWasmCodeTransform::visit(vector<yul::Expression> const
return ret;
}
wasm::Expression EWasmCodeTransform::visit(yul::Statement const& _statement)
wasm::Expression WasmCodeTransform::visit(yul::Statement const& _statement)
{
return std::visit(*this, _statement);
}
vector<wasm::Expression> EWasmCodeTransform::visit(vector<yul::Statement> const& _statements)
vector<wasm::Expression> WasmCodeTransform::visit(vector<yul::Statement> const& _statements)
{
vector<wasm::Expression> ret;
for (auto const& s: _statements)
@ -313,7 +313,7 @@ vector<wasm::Expression> EWasmCodeTransform::visit(vector<yul::Statement> const&
return ret;
}
wasm::FunctionDefinition EWasmCodeTransform::translateFunction(yul::FunctionDefinition const& _fun)
wasm::FunctionDefinition WasmCodeTransform::translateFunction(yul::FunctionDefinition const& _fun)
{
wasm::FunctionDefinition fun;
fun.name = _fun.name.str();
@ -344,7 +344,7 @@ wasm::FunctionDefinition EWasmCodeTransform::translateFunction(yul::FunctionDefi
return fun;
}
wasm::Expression EWasmCodeTransform::injectTypeConversionIfNeeded(wasm::FunctionCall _call) const
wasm::Expression WasmCodeTransform::injectTypeConversionIfNeeded(wasm::FunctionCall _call) const
{
wasm::FunctionImport const& import = m_functionsToImport.at(YulString{_call.functionName});
for (size_t i = 0; i < _call.arguments.size(); ++i)
@ -361,7 +361,7 @@ wasm::Expression EWasmCodeTransform::injectTypeConversionIfNeeded(wasm::Function
return {std::move(_call)};
}
vector<wasm::Expression> EWasmCodeTransform::injectTypeConversionIfNeeded(
vector<wasm::Expression> WasmCodeTransform::injectTypeConversionIfNeeded(
vector<wasm::Expression> _arguments,
vector<Type> const& _parameterTypes
) const
@ -378,12 +378,12 @@ vector<wasm::Expression> EWasmCodeTransform::injectTypeConversionIfNeeded(
return _arguments;
}
string EWasmCodeTransform::newLabel()
string WasmCodeTransform::newLabel()
{
return m_nameDispenser.newName("label_"_yulstring).str();
}
void EWasmCodeTransform::allocateGlobals(size_t _amount)
void WasmCodeTransform::allocateGlobals(size_t _amount)
{
while (m_globalVariables.size() < _amount)
m_globalVariables.emplace_back(wasm::GlobalVariableDeclaration{

View File

@ -15,7 +15,7 @@
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Common code generator for translating Yul / inline assembly to EWasm.
* Common code generator for translating Yul / inline assembly to Wasm.
*/
#pragma once
@ -32,7 +32,7 @@ namespace yul
{
struct AsmAnalysisInfo;
class EWasmCodeTransform
class WasmCodeTransform
{
public:
static wasm::Module run(Dialect const& _dialect, yul::Block const& _ast);
@ -54,7 +54,7 @@ public:
wasm::Expression operator()(yul::Block const& _block);
private:
EWasmCodeTransform(
WasmCodeTransform(
Dialect const& _dialect,
Block const& _ast
):

View File

@ -18,9 +18,9 @@
* Compiler that transforms Yul Objects to Wasm text and binary representation (Ewasm flavoured).
*/
#include <libyul/backends/wasm/EWasmObjectCompiler.h>
#include <libyul/backends/wasm/WasmObjectCompiler.h>
#include <libyul/backends/wasm/EWasmCodeTransform.h>
#include <libyul/backends/wasm/WasmCodeTransform.h>
#include <libyul/backends/wasm/BinaryTransform.h>
#include <libyul/backends/wasm/TextTransform.h>
@ -32,25 +32,25 @@
using namespace yul;
using namespace std;
pair<string, dev::bytes> EWasmObjectCompiler::compile(Object& _object, Dialect const& _dialect)
pair<string, dev::bytes> WasmObjectCompiler::compile(Object& _object, Dialect const& _dialect)
{
EWasmObjectCompiler compiler(_dialect);
WasmObjectCompiler compiler(_dialect);
wasm::Module module = compiler.run(_object);
return {wasm::TextTransform().run(module), wasm::BinaryTransform::run(module)};
}
wasm::Module EWasmObjectCompiler::run(Object& _object)
wasm::Module WasmObjectCompiler::run(Object& _object)
{
yulAssert(_object.analysisInfo, "No analysis info.");
yulAssert(_object.code, "No code.");
wasm::Module module = EWasmCodeTransform::run(m_dialect, *_object.code);
wasm::Module module = WasmCodeTransform::run(m_dialect, *_object.code);
for (auto& subNode: _object.subObjects)
if (Object* subObject = dynamic_cast<Object*>(subNode.get()))
module.subModules[subObject->name.str()] = run(*subObject);
else
yulAssert(false, "Data is not yet supported for EWasm.");
yulAssert(false, "Data is not yet supported for Wasm.");
return module;
}

View File

@ -28,6 +28,7 @@ namespace dev
{
using bytes = std::vector<uint8_t>;
}
namespace yul
{
struct Object;
@ -37,13 +38,13 @@ namespace wasm
struct Module;
}
class EWasmObjectCompiler
class WasmObjectCompiler
{
public:
/// Compiles the given object and returns the WAST and the binary representation.
/// Compiles the given object and returns the Wasm text and binary representation.
static std::pair<std::string, dev::bytes> compile(Object& _object, Dialect const& _dialect);
private:
EWasmObjectCompiler(Dialect const& _dialect):
WasmObjectCompiler(Dialect const& _dialect):
m_dialect(_dialect)
{}

View File

@ -131,8 +131,8 @@ set(libyul_sources
libyul/Common.cpp
libyul/Common.h
libyul/CompilabilityChecker.cpp
libyul/EWasmTranslationTest.cpp
libyul/EWasmTranslationTest.h
libyul/EwasmTranslationTest.cpp
libyul/EwasmTranslationTest.h
libyul/FunctionSideEffects.cpp
libyul/FunctionSideEffects.h
libyul/Inliner.cpp

View File

@ -25,7 +25,7 @@
#include <test/libsolidity/SemanticTest.h>
#include <test/libsolidity/SMTCheckerTest.h>
#include <test/libsolidity/SMTCheckerJSONTest.h>
#include <test/libyul/EWasmTranslationTest.h>
#include <test/libyul/EwasmTranslationTest.h>
#include <test/libyul/YulOptimizerTest.h>
#include <test/libyul/YulInterpreterTest.h>
#include <test/libyul/ObjectCompilerTest.h>
@ -56,7 +56,7 @@ struct Testsuite
Testsuite const g_interactiveTestsuites[] = {
/*
Title Path Subpath SMT NeedsVM Creator function */
{"EWasm Translation", "libyul", "ewasmTranslationTests",false,false, &yul::test::EWasmTranslationTest::create},
{"Ewasm Translation", "libyul", "ewasmTranslationTests",false,false, &yul::test::EwasmTranslationTest::create},
{"Yul Optimizer", "libyul", "yulOptimizerTests", false, false, &yul::test::YulOptimizerTest::create},
{"Yul Interpreter", "libyul", "yulInterpreterTests", false, false, &yul::test::YulInterpreterTest::create},
{"Yul Object Compiler", "libyul", "objectCompiler", false, false, &yul::test::ObjectCompilerTest::create},

View File

@ -15,7 +15,7 @@
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
#include <test/libyul/EWasmTranslationTest.h>
#include <test/libyul/EwasmTranslationTest.h>
#include <test/tools/yulInterpreter/Interpreter.h>
@ -23,7 +23,7 @@
#include <libyul/backends/evm/EVMDialect.h>
#include <libyul/backends/wasm/WasmDialect.h>
#include <libyul/backends/wasm/EVMToEWasmTranslator.h>
#include <libyul/backends/wasm/EVMToEwasmTranslator.h>
#include <libyul/AsmParser.h>
#include <libyul/AssemblyStack.h>
#include <libyul/AsmAnalysisInfo.h>
@ -47,7 +47,7 @@ using namespace dev::solidity::test;
using namespace std;
EWasmTranslationTest::EWasmTranslationTest(string const& _filename)
EwasmTranslationTest::EwasmTranslationTest(string const& _filename)
{
boost::filesystem::path path(_filename);
@ -60,12 +60,12 @@ EWasmTranslationTest::EWasmTranslationTest(string const& _filename)
m_expectation = parseSimpleExpectations(file);
}
TestCase::TestResult EWasmTranslationTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
TestCase::TestResult EwasmTranslationTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
{
if (!parse(_stream, _linePrefix, _formatted))
return TestResult::FatalError;
*m_object = EVMToEWasmTranslator(
*m_object = EVMToEwasmTranslator(
EVMDialect::strictAssemblyForEVMObjects(dev::test::Options::get().evmVersion())
).run(*m_object);
@ -89,17 +89,17 @@ TestCase::TestResult EWasmTranslationTest::run(ostream& _stream, string const& _
return TestResult::Success;
}
void EWasmTranslationTest::printSource(ostream& _stream, string const& _linePrefix, bool const) const
void EwasmTranslationTest::printSource(ostream& _stream, string const& _linePrefix, bool const) const
{
printIndented(_stream, m_source, _linePrefix);
}
void EWasmTranslationTest::printUpdatedExpectations(ostream& _stream, string const& _linePrefix) const
void EwasmTranslationTest::printUpdatedExpectations(ostream& _stream, string const& _linePrefix) const
{
printIndented(_stream, m_obtainedResult, _linePrefix);
}
void EWasmTranslationTest::printIndented(ostream& _stream, string const& _output, string const& _linePrefix) const
void EwasmTranslationTest::printIndented(ostream& _stream, string const& _output, string const& _linePrefix) const
{
stringstream output(_output);
string line;
@ -107,7 +107,7 @@ void EWasmTranslationTest::printIndented(ostream& _stream, string const& _output
_stream << _linePrefix << line << endl;
}
bool EWasmTranslationTest::parse(ostream& _stream, string const& _linePrefix, bool const _formatted)
bool EwasmTranslationTest::parse(ostream& _stream, string const& _linePrefix, bool const _formatted)
{
AssemblyStack stack(
dev::test::Options::get().evmVersion(),
@ -127,7 +127,7 @@ bool EWasmTranslationTest::parse(ostream& _stream, string const& _linePrefix, bo
}
}
string EWasmTranslationTest::interpret()
string EwasmTranslationTest::interpret()
{
InterpreterState state;
state.maxTraceSize = 10000;
@ -147,7 +147,7 @@ string EWasmTranslationTest::interpret()
return result.str();
}
void EWasmTranslationTest::printErrors(ostream& _stream, ErrorList const& _errors)
void EwasmTranslationTest::printErrors(ostream& _stream, ErrorList const& _errors)
{
SourceReferenceFormatter formatter(_stream);

View File

@ -32,15 +32,15 @@ namespace yul
namespace test
{
class EWasmTranslationTest: public dev::solidity::test::EVMVersionRestrictedTestCase
class EwasmTranslationTest: public dev::solidity::test::EVMVersionRestrictedTestCase
{
public:
static std::unique_ptr<TestCase> create(Config const& _config)
{
return std::make_unique<EWasmTranslationTest>(_config.filename);
return std::make_unique<EwasmTranslationTest>(_config.filename);
}
explicit EWasmTranslationTest(std::string const& _filename);
explicit EwasmTranslationTest(std::string const& _filename);
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override;

View File

@ -32,7 +32,7 @@ add_executable(isoltest
../libsolidity/SMTCheckerTest.cpp
../libsolidity/SMTCheckerJSONTest.cpp
../libyul/Common.cpp
../libyul/EWasmTranslationTest.cpp
../libyul/EwasmTranslationTest.cpp
../libyul/FunctionSideEffects.cpp
../libyul/ObjectCompilerTest.cpp
../libyul/YulOptimizerTest.cpp