From ae7cc58b55e657db68048f461339760e49bd8509 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 9 Dec 2019 16:43:22 +0000 Subject: [PATCH] Rename EWasmToText to TextTransform --- libyul/CMakeLists.txt | 4 +- libyul/backends/wasm/EWasmObjectCompiler.cpp | 6 +-- libyul/backends/wasm/EWasmObjectCompiler.h | 2 +- .../{EWasmToText.cpp => TextTransform.cpp} | 43 ++++++++++--------- .../wasm/{EWasmToText.h => TextTransform.h} | 8 +++- 5 files changed, 34 insertions(+), 29 deletions(-) rename libyul/backends/wasm/{EWasmToText.cpp => TextTransform.cpp} (76%) rename libyul/backends/wasm/{EWasmToText.h => TextTransform.h} (94%) diff --git a/libyul/CMakeLists.txt b/libyul/CMakeLists.txt index 6292f07f0..2a0577edc 100644 --- a/libyul/CMakeLists.txt +++ b/libyul/CMakeLists.txt @@ -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 diff --git a/libyul/backends/wasm/EWasmObjectCompiler.cpp b/libyul/backends/wasm/EWasmObjectCompiler.cpp index 7ba72735a..9f0e30f47 100644 --- a/libyul/backends/wasm/EWasmObjectCompiler.cpp +++ b/libyul/backends/wasm/EWasmObjectCompiler.cpp @@ -15,14 +15,14 @@ along with solidity. If not, see . */ /** - * Compiler that transforms Yul Objects to EWasm text representation. + * Compiler that transforms Yul Objects to Wasm text and binary representation (Ewasm flavoured). */ #include #include #include -#include +#include #include #include @@ -36,7 +36,7 @@ pair 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) diff --git a/libyul/backends/wasm/EWasmObjectCompiler.h b/libyul/backends/wasm/EWasmObjectCompiler.h index c99d258e1..a4fcf1af8 100644 --- a/libyul/backends/wasm/EWasmObjectCompiler.h +++ b/libyul/backends/wasm/EWasmObjectCompiler.h @@ -15,7 +15,7 @@ along with solidity. If not, see . */ /** - * Compiler that transforms Yul Objects to EWasm text representation. + * Compiler that transforms Yul Objects to Wasm text and binary representation (Ewasm flavoured). */ #pragma once diff --git a/libyul/backends/wasm/EWasmToText.cpp b/libyul/backends/wasm/TextTransform.cpp similarity index 76% rename from libyul/backends/wasm/EWasmToText.cpp rename to libyul/backends/wasm/TextTransform.cpp index 4da913c32..f3589f5e9 100644 --- a/libyul/backends/wasm/EWasmToText.cpp +++ b/libyul/backends/wasm/TextTransform.cpp @@ -15,10 +15,10 @@ along with solidity. If not, see . */ /** - * Component that transforms interval EWasm representation to text. + * Component that transforms interval Wasm representation to text. */ -#include +#include #include @@ -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 const& _expressions, char _separator) +string TextTransform::joinTransformed(vector const& _expressions, char _separator) { string ret; for (auto const& e: _expressions) diff --git a/libyul/backends/wasm/EWasmToText.h b/libyul/backends/wasm/TextTransform.h similarity index 94% rename from libyul/backends/wasm/EWasmToText.h rename to libyul/backends/wasm/TextTransform.h index cf767623b..2fbbc1f10 100644 --- a/libyul/backends/wasm/EWasmToText.h +++ b/libyul/backends/wasm/TextTransform.h @@ -15,7 +15,7 @@ along with solidity. If not, see . */ /** - * Component that transforms interval EWasm representation to text. + * Component that transforms interval Wasm representation to text. */ #pragma once @@ -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: }; } +}