diff --git a/libyul/backends/wasm/EWasmAST.h b/libyul/backends/wasm/EWasmAST.h index e3ce6604f..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,11 +41,11 @@ struct Block; struct If; struct Loop; struct Break; -struct Continue; +struct BreakIf; using Expression = boost::variant< - Literal, StringLiteral, LocalVariable, GlobalVariable, Label, + Literal, StringLiteral, LocalVariable, GlobalVariable, FunctionCall, BuiltinCall, LocalAssignment, GlobalAssignment, - Block, If, Loop, Break, Continue + Block, If, Loop, Break, BreakIf >; struct Literal { uint64_t value; }; @@ -66,7 +65,7 @@ struct If { }; struct Loop { std::string labelName; std::vector statements; }; struct Break { Label label; }; -struct Continue { 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 f9e28e94a..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) )} @@ -267,7 +266,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..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,9 +123,9 @@ string EWasmToText::operator()(wasm::Break const& _break) return "(break $" + _break.label.name + ")\n"; } -string EWasmToText::operator()(wasm::Continue const& _continue) +string EWasmToText::operator()(wasm::BreakIf const& _break) { - return "(continue $" + _continue.label.name + ")\n"; + return "(br_if $" + _break.label.name + " " + visit(*_break.condition) + ")\n"; } string EWasmToText::operator()(wasm::Block const& _block) diff --git a/libyul/backends/wasm/EWasmToText.h b/libyul/backends/wasm/EWasmToText.h index 7eed8c076..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,7 +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::Continue const& _continue); + std::string operator()(wasm::BreakIf const& _break); std::string operator()(wasm::Block const& _block); private: