From 0657aff937275721dcd4950bc9e88251219604d4 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 17 Oct 2019 12:56:01 +0200 Subject: [PATCH 1/2] Remove continue from wasm. --- libyul/backends/wasm/EWasmAST.h | 4 +--- libyul/backends/wasm/EWasmCodeTransform.cpp | 2 +- libyul/backends/wasm/EWasmToText.cpp | 5 ----- libyul/backends/wasm/EWasmToText.h | 1 - 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/libyul/backends/wasm/EWasmAST.h b/libyul/backends/wasm/EWasmAST.h index e3ce6604f..c25c079d5 100644 --- a/libyul/backends/wasm/EWasmAST.h +++ b/libyul/backends/wasm/EWasmAST.h @@ -42,11 +42,10 @@ struct Block; struct If; struct Loop; struct Break; -struct Continue; using Expression = boost::variant< Literal, StringLiteral, LocalVariable, GlobalVariable, Label, FunctionCall, BuiltinCall, LocalAssignment, GlobalAssignment, - Block, If, Loop, Break, Continue + Block, If, Loop, Break >; struct Literal { uint64_t value; }; @@ -66,7 +65,6 @@ struct If { }; struct Loop { std::string labelName; std::vector statements; }; struct Break { Label label; }; -struct Continue { Label label; }; struct VariableDeclaration { std::string variableName; }; struct GlobalVariableDeclaration { std::string variableName; }; diff --git a/libyul/backends/wasm/EWasmCodeTransform.cpp b/libyul/backends/wasm/EWasmCodeTransform.cpp index f9e28e94a..f8eb3c68e 100644 --- a/libyul/backends/wasm/EWasmCodeTransform.cpp +++ b/libyul/backends/wasm/EWasmCodeTransform.cpp @@ -267,7 +267,7 @@ wasm::Expression EWasmCodeTransform::operator()(Break const&) wasm::Expression EWasmCodeTransform::operator()(Continue const&) { - return wasm::Continue{wasm::Label{m_breakContinueLabelNames.top().second}}; + return wasm::Break{wasm::Label{m_breakContinueLabelNames.top().second}}; } wasm::Expression EWasmCodeTransform::operator()(Block const& _block) diff --git a/libyul/backends/wasm/EWasmToText.cpp b/libyul/backends/wasm/EWasmToText.cpp index 9d3bce0f5..adeca6e13 100644 --- a/libyul/backends/wasm/EWasmToText.cpp +++ b/libyul/backends/wasm/EWasmToText.cpp @@ -128,11 +128,6 @@ string EWasmToText::operator()(wasm::Break const& _break) return "(break $" + _break.label.name + ")\n"; } -string EWasmToText::operator()(wasm::Continue const& _continue) -{ - return "(continue $" + _continue.label.name + ")\n"; -} - string EWasmToText::operator()(wasm::Block const& _block) { string label = _block.labelName.empty() ? "" : " $" + _block.labelName; diff --git a/libyul/backends/wasm/EWasmToText.h b/libyul/backends/wasm/EWasmToText.h index 7eed8c076..be7931aed 100644 --- a/libyul/backends/wasm/EWasmToText.h +++ b/libyul/backends/wasm/EWasmToText.h @@ -50,7 +50,6 @@ public: std::string operator()(wasm::If const& _if); std::string operator()(wasm::Loop const& _loop); std::string operator()(wasm::Break const& _break); - std::string operator()(wasm::Continue const& _continue); std::string operator()(wasm::Block const& _block); private: From f8ade0122a7de628e4fe965205e25aaee4950790 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 17 Oct 2019 13:14:19 +0200 Subject: [PATCH 2/2] Remove label from expression and add br_if. --- libyul/backends/wasm/EWasmAST.h | 7 ++++--- libyul/backends/wasm/EWasmCodeTransform.cpp | 3 +-- libyul/backends/wasm/EWasmToText.cpp | 10 +++++----- libyul/backends/wasm/EWasmToText.h | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libyul/backends/wasm/EWasmAST.h b/libyul/backends/wasm/EWasmAST.h index c25c079d5..24a678908 100644 --- a/libyul/backends/wasm/EWasmAST.h +++ b/libyul/backends/wasm/EWasmAST.h @@ -33,7 +33,6 @@ struct Literal; struct StringLiteral; struct LocalVariable; struct GlobalVariable; -struct Label; struct FunctionCall; struct BuiltinCall; struct LocalAssignment; @@ -42,10 +41,11 @@ struct Block; struct If; struct Loop; struct Break; +struct BreakIf; using Expression = boost::variant< - Literal, StringLiteral, LocalVariable, GlobalVariable, Label, + Literal, StringLiteral, LocalVariable, GlobalVariable, FunctionCall, BuiltinCall, LocalAssignment, GlobalAssignment, - Block, If, Loop, Break + Block, If, Loop, Break, BreakIf >; struct Literal { uint64_t value; }; @@ -65,6 +65,7 @@ struct If { }; struct Loop { std::string labelName; std::vector statements; }; struct Break { Label label; }; +struct BreakIf { Label label; std::unique_ptr condition; }; struct VariableDeclaration { std::string variableName; }; struct GlobalVariableDeclaration { std::string variableName; }; diff --git a/libyul/backends/wasm/EWasmCodeTransform.cpp b/libyul/backends/wasm/EWasmCodeTransform.cpp index f8eb3c68e..0670c7bc9 100644 --- a/libyul/backends/wasm/EWasmCodeTransform.cpp +++ b/libyul/backends/wasm/EWasmCodeTransform.cpp @@ -248,8 +248,7 @@ wasm::Expression EWasmCodeTransform::operator()(ForLoop const& _for) wasm::Loop loop; loop.statements = visit(_for.pre.statements); - loop.statements.emplace_back(wasm::BuiltinCall{"br_if", make_vector( - wasm::Label{breakLabel}, + loop.statements.emplace_back(wasm::BreakIf{wasm::Label{breakLabel}, make_unique( wasm::BuiltinCall{"i64.eqz", make_vector( visitReturnByValue(*_for.condition) )} diff --git a/libyul/backends/wasm/EWasmToText.cpp b/libyul/backends/wasm/EWasmToText.cpp index adeca6e13..6e2b26487 100644 --- a/libyul/backends/wasm/EWasmToText.cpp +++ b/libyul/backends/wasm/EWasmToText.cpp @@ -82,11 +82,6 @@ string EWasmToText::operator()(wasm::GlobalVariable const& _identifier) return "(get_global $" + _identifier.name + ")"; } -string EWasmToText::operator()(wasm::Label const& _label) -{ - return "$" + _label.name; -} - string EWasmToText::operator()(wasm::BuiltinCall const& _builtinCall) { string args = joinTransformed(_builtinCall.arguments); @@ -128,6 +123,11 @@ string EWasmToText::operator()(wasm::Break const& _break) return "(break $" + _break.label.name + ")\n"; } +string EWasmToText::operator()(wasm::BreakIf const& _break) +{ + return "(br_if $" + _break.label.name + " " + visit(*_break.condition) + ")\n"; +} + string EWasmToText::operator()(wasm::Block const& _block) { string label = _block.labelName.empty() ? "" : " $" + _block.labelName; diff --git a/libyul/backends/wasm/EWasmToText.h b/libyul/backends/wasm/EWasmToText.h index be7931aed..377561869 100644 --- a/libyul/backends/wasm/EWasmToText.h +++ b/libyul/backends/wasm/EWasmToText.h @@ -42,7 +42,6 @@ public: std::string operator()(wasm::StringLiteral const& _literal); std::string operator()(wasm::LocalVariable const& _identifier); std::string operator()(wasm::GlobalVariable const& _identifier); - std::string operator()(wasm::Label const& _label); std::string operator()(wasm::BuiltinCall const& _builinCall); std::string operator()(wasm::FunctionCall const& _functionCall); std::string operator()(wasm::LocalAssignment const& _assignment); @@ -50,6 +49,7 @@ public: std::string operator()(wasm::If const& _if); std::string operator()(wasm::Loop const& _loop); std::string operator()(wasm::Break const& _break); + std::string operator()(wasm::BreakIf const& _break); std::string operator()(wasm::Block const& _block); private: