Rename EWasmCodeTransform to WasmCodeTransform

This commit is contained in:
Alex Beregszaszi 2019-12-11 13:27:24 +00:00
parent f9a76f8c9b
commit cec45a7df5
4 changed files with 36 additions and 36 deletions

View File

@ -46,14 +46,14 @@ add_library(yul
backends/evm/NoOutputAssembly.cpp backends/evm/NoOutputAssembly.cpp
backends/wasm/EVMToEWasmTranslator.cpp backends/wasm/EVMToEWasmTranslator.cpp
backends/wasm/EVMToEWasmTranslator.h backends/wasm/EVMToEWasmTranslator.h
backends/wasm/EWasmCodeTransform.cpp
backends/wasm/EWasmCodeTransform.h
backends/wasm/EWasmObjectCompiler.cpp backends/wasm/EWasmObjectCompiler.cpp
backends/wasm/EWasmObjectCompiler.h backends/wasm/EWasmObjectCompiler.h
backends/wasm/BinaryTransform.cpp backends/wasm/BinaryTransform.cpp
backends/wasm/BinaryTransform.h backends/wasm/BinaryTransform.h
backends/wasm/TextTransform.cpp backends/wasm/TextTransform.cpp
backends/wasm/TextTransform.h backends/wasm/TextTransform.h
backends/wasm/WasmCodeTransform.cpp
backends/wasm/WasmCodeTransform.h
backends/wasm/WasmDialect.cpp backends/wasm/WasmDialect.cpp
backends/wasm/WasmDialect.h backends/wasm/WasmDialect.h
backends/wasm/WordSizeTransform.cpp backends/wasm/WordSizeTransform.cpp

View File

@ -20,7 +20,7 @@
#include <libyul/backends/wasm/EWasmObjectCompiler.h> #include <libyul/backends/wasm/EWasmObjectCompiler.h>
#include <libyul/backends/wasm/EWasmCodeTransform.h> #include <libyul/backends/wasm/WasmCodeTransform.h>
#include <libyul/backends/wasm/BinaryTransform.h> #include <libyul/backends/wasm/BinaryTransform.h>
#include <libyul/backends/wasm/TextTransform.h> #include <libyul/backends/wasm/TextTransform.h>
@ -44,7 +44,7 @@ wasm::Module EWasmObjectCompiler::run(Object& _object)
yulAssert(_object.analysisInfo, "No analysis info."); yulAssert(_object.analysisInfo, "No analysis info.");
yulAssert(_object.code, "No code."); 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) for (auto& subNode: _object.subObjects)
if (Object* subObject = dynamic_cast<Object*>(subNode.get())) if (Object* subObject = dynamic_cast<Object*>(subNode.get()))

View File

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

View File

@ -15,7 +15,7 @@
along with solidity. If not, see <http://www.gnu.org/licenses/>. 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 #pragma once
@ -32,7 +32,7 @@ namespace yul
{ {
struct AsmAnalysisInfo; struct AsmAnalysisInfo;
class EWasmCodeTransform class WasmCodeTransform
{ {
public: public:
static wasm::Module run(Dialect const& _dialect, yul::Block const& _ast); static wasm::Module run(Dialect const& _dialect, yul::Block const& _ast);
@ -54,7 +54,7 @@ public:
wasm::Expression operator()(yul::Block const& _block); wasm::Expression operator()(yul::Block const& _block);
private: private:
EWasmCodeTransform( WasmCodeTransform(
Dialect const& _dialect, Dialect const& _dialect,
Block const& _ast Block const& _ast
): ):