Merge pull request #7964 from ethereum/wasm

Rename EWasmToText to TextTransform and EWasmAST to WasmAST
This commit is contained in:
Christian Parpart 2019-12-11 14:19:23 +01:00 committed by GitHub
commit c5f74587dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 32 deletions

View File

@ -50,10 +50,10 @@ add_library(yul
backends/wasm/EWasmCodeTransform.h
backends/wasm/EWasmObjectCompiler.cpp
backends/wasm/EWasmObjectCompiler.h
backends/wasm/EWasmToText.cpp
backends/wasm/EWasmToText.h
backends/wasm/BinaryTransform.cpp
backends/wasm/BinaryTransform.h
backends/wasm/TextTransform.cpp
backends/wasm/TextTransform.h
backends/wasm/WasmDialect.cpp
backends/wasm/WasmDialect.h
backends/wasm/WordSizeTransform.cpp

View File

@ -20,7 +20,7 @@
#pragma once
#include <libyul/backends/wasm/EWasmAST.h>
#include <libyul/backends/wasm/WasmAST.h>
#include <libdevcore/Common.h>

View File

@ -20,7 +20,7 @@
#pragma once
#include <libyul/backends/wasm/EWasmAST.h>
#include <libyul/backends/wasm/WasmAST.h>
#include <libyul/AsmDataForward.h>
#include <libyul/Dialect.h>
#include <libyul/optimiser/NameDispenser.h>

View File

@ -15,14 +15,14 @@
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Compiler that transforms Yul Objects to EWasm text representation.
* Compiler that transforms Yul Objects to Wasm text and binary representation (Ewasm flavoured).
*/
#include <libyul/backends/wasm/EWasmObjectCompiler.h>
#include <libyul/backends/wasm/EWasmCodeTransform.h>
#include <libyul/backends/wasm/BinaryTransform.h>
#include <libyul/backends/wasm/EWasmToText.h>
#include <libyul/backends/wasm/TextTransform.h>
#include <libyul/Object.h>
#include <libyul/Exceptions.h>
@ -36,7 +36,7 @@ pair<string, dev::bytes> EWasmObjectCompiler::compile(Object& _object, Dialect c
{
EWasmObjectCompiler compiler(_dialect);
wasm::Module module = compiler.run(_object);
return {EWasmToText().run(module), wasm::BinaryTransform::run(module)};
return {wasm::TextTransform().run(module), wasm::BinaryTransform::run(module)};
}
wasm::Module EWasmObjectCompiler::run(Object& _object)

View File

@ -15,7 +15,7 @@
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Compiler that transforms Yul Objects to EWasm text representation.
* Compiler that transforms Yul Objects to Wasm text and binary representation (Ewasm flavoured).
*/
#pragma once

View File

@ -15,10 +15,10 @@
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Component that transforms interval EWasm representation to text.
* Component that transforms interval Wasm representation to text.
*/
#include <libyul/backends/wasm/EWasmToText.h>
#include <libyul/backends/wasm/TextTransform.h>
#include <libdevcore/StringUtils.h>
@ -29,8 +29,9 @@
using namespace std;
using namespace yul;
using namespace dev;
using namespace yul::wasm;
string EWasmToText::run(wasm::Module const& _module)
string TextTransform::run(wasm::Module const& _module)
{
string ret = "(module\n";
for (auto const& sub: _module.subModules)
@ -61,51 +62,51 @@ string EWasmToText::run(wasm::Module const& _module)
return move(ret) + ")\n";
}
string EWasmToText::operator()(wasm::Literal const& _literal)
string TextTransform::operator()(wasm::Literal const& _literal)
{
return "(i64.const " + to_string(_literal.value) + ")";
}
string EWasmToText::operator()(wasm::StringLiteral const& _literal)
string TextTransform::operator()(wasm::StringLiteral const& _literal)
{
string quoted = boost::replace_all_copy(_literal.value, "\\", "\\\\");
boost::replace_all(quoted, "\"", "\\\"");
return "\"" + quoted + "\"";
}
string EWasmToText::operator()(wasm::LocalVariable const& _identifier)
string TextTransform::operator()(wasm::LocalVariable const& _identifier)
{
return "(local.get $" + _identifier.name + ")";
}
string EWasmToText::operator()(wasm::GlobalVariable const& _identifier)
string TextTransform::operator()(wasm::GlobalVariable const& _identifier)
{
return "(global.get $" + _identifier.name + ")";
}
string EWasmToText::operator()(wasm::BuiltinCall const& _builtinCall)
string TextTransform::operator()(wasm::BuiltinCall const& _builtinCall)
{
string args = joinTransformed(_builtinCall.arguments);
return "(" + _builtinCall.functionName + (args.empty() ? "" : " " + args) + ")";
}
string EWasmToText::operator()(wasm::FunctionCall const& _functionCall)
string TextTransform::operator()(wasm::FunctionCall const& _functionCall)
{
string args = joinTransformed(_functionCall.arguments);
return "(call $" + _functionCall.functionName + (args.empty() ? "" : " " + args) + ")";
}
string EWasmToText::operator()(wasm::LocalAssignment const& _assignment)
string TextTransform::operator()(wasm::LocalAssignment const& _assignment)
{
return "(local.set $" + _assignment.variableName + " " + visit(*_assignment.value) + ")\n";
}
string EWasmToText::operator()(wasm::GlobalAssignment const& _assignment)
string TextTransform::operator()(wasm::GlobalAssignment const& _assignment)
{
return "(global.set $" + _assignment.variableName + " " + visit(*_assignment.value) + ")\n";
}
string EWasmToText::operator()(wasm::If const& _if)
string TextTransform::operator()(wasm::If const& _if)
{
string text = "(if " + visit(*_if.condition) + " (then\n" + indented(joinTransformed(_if.statements, '\n')) + ")";
if (_if.elseStatements)
@ -113,34 +114,34 @@ string EWasmToText::operator()(wasm::If const& _if)
return std::move(text) + ")\n";
}
string EWasmToText::operator()(wasm::Loop const& _loop)
string TextTransform::operator()(wasm::Loop const& _loop)
{
string label = _loop.labelName.empty() ? "" : " $" + _loop.labelName;
return "(loop" + move(label) + "\n" + indented(joinTransformed(_loop.statements, '\n')) + ")\n";
}
string EWasmToText::operator()(wasm::Break const& _break)
string TextTransform::operator()(wasm::Break const& _break)
{
return "(break $" + _break.label.name + ")\n";
}
string EWasmToText::operator()(wasm::BreakIf const& _break)
string TextTransform::operator()(wasm::BreakIf const& _break)
{
return "(br_if $" + _break.label.name + " " + visit(*_break.condition) + ")\n";
}
string EWasmToText::operator()(wasm::Return const&)
string TextTransform::operator()(wasm::Return const&)
{
return "(return)\n";
}
string EWasmToText::operator()(wasm::Block const& _block)
string TextTransform::operator()(wasm::Block const& _block)
{
string label = _block.labelName.empty() ? "" : " $" + _block.labelName;
return "(block" + move(label) + "\n" + indented(joinTransformed(_block.statements, '\n')) + "\n)\n";
}
string EWasmToText::indented(string const& _in)
string TextTransform::indented(string const& _in)
{
string replacement;
@ -157,7 +158,7 @@ string EWasmToText::indented(string const& _in)
return replacement;
}
string EWasmToText::transform(wasm::FunctionDefinition const& _function)
string TextTransform::transform(wasm::FunctionDefinition const& _function)
{
string ret = "(func $" + _function.name + "\n";
for (auto const& param: _function.parameterNames)
@ -174,12 +175,12 @@ string EWasmToText::transform(wasm::FunctionDefinition const& _function)
}
string EWasmToText::visit(wasm::Expression const& _expression)
string TextTransform::visit(wasm::Expression const& _expression)
{
return std::visit(*this, _expression);
}
string EWasmToText::joinTransformed(vector<wasm::Expression> const& _expressions, char _separator)
string TextTransform::joinTransformed(vector<wasm::Expression> const& _expressions, char _separator)
{
string ret;
for (auto const& e: _expressions)

View File

@ -15,12 +15,12 @@
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Component that transforms interval EWasm representation to text.
* Component that transforms interval Wasm representation to text.
*/
#pragma once
#include <libyul/backends/wasm/EWasmAST.h>
#include <libyul/backends/wasm/WasmAST.h>
#include <vector>
@ -28,7 +28,10 @@ namespace yul
{
struct AsmAnalysisInfo;
class EWasmToText
namespace wasm
{
class TextTransform
{
public:
std::string run(wasm::Module const& _module);
@ -62,3 +65,4 @@ private:
};
}
}