mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix implementation of leave.
This commit is contained in:
@@ -396,6 +396,7 @@ bytes BinaryTransform::operator()(BranchIf const& _branchIf)
|
||||
|
||||
bytes BinaryTransform::operator()(Return const&)
|
||||
{
|
||||
// Note that this does not work if the function returns a value.
|
||||
return toBytes(Opcode::Return);
|
||||
}
|
||||
|
||||
|
||||
@@ -280,7 +280,8 @@ wasm::Expression WasmCodeTransform::operator()(Continue const&)
|
||||
|
||||
wasm::Expression WasmCodeTransform::operator()(Leave const&)
|
||||
{
|
||||
return wasm::Return{};
|
||||
yulAssert(!m_functionBodyLabel.empty(), "");
|
||||
return wasm::Branch{wasm::Label{m_functionBodyLabel}};
|
||||
}
|
||||
|
||||
wasm::Expression WasmCodeTransform::operator()(Block const& _block)
|
||||
@@ -330,10 +331,16 @@ wasm::FunctionDefinition WasmCodeTransform::translateFunction(yul::FunctionDefin
|
||||
fun.returns = !_fun.returnVariables.empty();
|
||||
|
||||
yulAssert(m_localVariables.empty(), "");
|
||||
fun.body = visit(_fun.body.statements);
|
||||
yulAssert(m_functionBodyLabel.empty(), "");
|
||||
m_functionBodyLabel = newLabel();
|
||||
fun.body.emplace_back(wasm::Expression(wasm::Block{
|
||||
m_functionBodyLabel,
|
||||
visit(_fun.body.statements)
|
||||
}));
|
||||
fun.locals += m_localVariables;
|
||||
|
||||
m_localVariables.clear();
|
||||
m_functionBodyLabel = {};
|
||||
|
||||
if (!_fun.returnVariables.empty())
|
||||
{
|
||||
|
||||
@@ -95,6 +95,7 @@ private:
|
||||
std::vector<wasm::VariableDeclaration> m_localVariables;
|
||||
std::vector<wasm::GlobalVariableDeclaration> m_globalVariables;
|
||||
std::map<YulString, wasm::FunctionImport> m_functionsToImport;
|
||||
std::string m_functionBodyLabel;
|
||||
std::stack<std::pair<std::string, std::string>> m_breakContinueLabelNames;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user