Merge pull request #7547 from ethereum/wasmCleanup

Wasm: Remove continue and add br_if.
This commit is contained in:
chriseth 2019-10-22 13:26:23 +02:00 committed by GitHub
commit eca2b9bdba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 17 deletions

View File

@ -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<Expression> statements; };
struct Break { Label label; };
struct Continue { Label label; };
struct BreakIf { Label label; std::unique_ptr<Expression> condition; };
struct VariableDeclaration { std::string variableName; };
struct GlobalVariableDeclaration { std::string variableName; };

View File

@ -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::Expression>(
wasm::Label{breakLabel},
loop.statements.emplace_back(wasm::BreakIf{wasm::Label{breakLabel}, make_unique<wasm::Expression>(
wasm::BuiltinCall{"i64.eqz", make_vector<wasm::Expression>(
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)

View File

@ -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)

View File

@ -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: