[Yul] leave statement.

This commit is contained in:
chriseth
2019-10-29 14:32:16 +01:00
parent edf1e83fda
commit ceb8ee9124
41 changed files with 214 additions and 27 deletions
+3 -1
View File
@@ -42,10 +42,11 @@ struct If;
struct Loop;
struct Break;
struct BreakIf;
struct Return;
using Expression = boost::variant<
Literal, StringLiteral, LocalVariable, GlobalVariable,
FunctionCall, BuiltinCall, LocalAssignment, GlobalAssignment,
Block, If, Loop, Break, BreakIf
Block, If, Loop, Break, BreakIf, Return
>;
struct Literal { uint64_t value; };
@@ -65,6 +66,7 @@ struct If {
};
struct Loop { std::string labelName; std::vector<Expression> statements; };
struct Break { Label label; };
struct Return {};
struct BreakIf { Label label; std::unique_ptr<Expression> condition; };
struct VariableDeclaration { std::string variableName; };
@@ -257,6 +257,11 @@ wasm::Expression EWasmCodeTransform::operator()(Continue const&)
return wasm::Break{wasm::Label{m_breakContinueLabelNames.top().second}};
}
wasm::Expression EWasmCodeTransform::operator()(Leave const&)
{
return wasm::Return{};
}
wasm::Expression EWasmCodeTransform::operator()(Block const& _block)
{
return wasm::Block{{}, visit(_block.statements)};
@@ -52,6 +52,7 @@ public:
wasm::Expression operator()(yul::ForLoop const&);
wasm::Expression operator()(yul::Break const&);
wasm::Expression operator()(yul::Continue const&);
wasm::Expression operator()(yul::Leave const&);
wasm::Expression operator()(yul::Block const& _block);
private:
+5
View File
@@ -128,6 +128,11 @@ string EWasmToText::operator()(wasm::BreakIf const& _break)
return "(br_if $" + _break.label.name + " " + visit(*_break.condition) + ")\n";
}
string EWasmToText::operator()(wasm::Return const&)
{
return "(return)\n";
}
string EWasmToText::operator()(wasm::Block const& _block)
{
string label = _block.labelName.empty() ? "" : " $" + _block.labelName;
+1
View File
@@ -49,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::Return const& _return);
std::string operator()(wasm::BreakIf const& _break);
std::string operator()(wasm::Block const& _block);