Skip to content

Commit

Permalink
Use side-effects of user defined functions in evm code transform.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Oct 13, 2021
1 parent a904964 commit 21386df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion libyul/backends/evm/ControlFlowGraphBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <libyul/AST.h>
#include <libyul/Exceptions.h>
#include <libyul/Utilities.h>
#include <libyul/ControlFlowSideEffectsCollector.h>

#include <libsolutil/cxx20.h>
#include <libsolutil/Visitor.h>
Expand Down Expand Up @@ -135,7 +136,9 @@ std::unique_ptr<CFG> ControlFlowGraphBuilder::build(
auto result = std::make_unique<CFG>();
result->entry = &result->makeBlock(debugDataOf(_block));

ControlFlowGraphBuilder builder(*result, _analysisInfo, _dialect);
// TODO this only works for hoisted and disambiguated functions :(
ControlFlowSideEffectsCollector sideEffects(_dialect, _block);
ControlFlowGraphBuilder builder(*result, _analysisInfo, sideEffects.functionSideEffects(), _dialect);
builder.m_currentBlock = result->entry;
builder(_block);

Expand All @@ -151,10 +154,12 @@ std::unique_ptr<CFG> ControlFlowGraphBuilder::build(
ControlFlowGraphBuilder::ControlFlowGraphBuilder(
CFG& _graph,
AsmAnalysisInfo const& _analysisInfo,
map<YulString, ControlFlowSideEffects> const& _functionSideEffects,
Dialect const& _dialect
):
m_graph(_graph),
m_info(_analysisInfo),
m_functionSideEffects(_functionSideEffects),
m_dialect(_dialect)
{
}
Expand Down Expand Up @@ -447,6 +452,7 @@ CFG::Operation const& ControlFlowGraphBuilder::visitFunctionCall(FunctionCall co
Stack inputs{FunctionCallReturnLabelSlot{_call}};
for (auto const& arg: _call.arguments | ranges::views::reverse)
inputs.emplace_back(std::visit(*this, arg));
// TODO incorporate side-effects (especially "does not continue")
return m_currentBlock->operations.emplace_back(CFG::Operation{
// input
std::move(inputs),
Expand Down
3 changes: 3 additions & 0 deletions libyul/backends/evm/ControlFlowGraphBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <libyul/backends/evm/ControlFlowGraph.h>
#include <libyul/ControlFlowSideEffects.h>

namespace solidity::yul
{
Expand Down Expand Up @@ -55,6 +56,7 @@ class ControlFlowGraphBuilder
ControlFlowGraphBuilder(
CFG& _graph,
AsmAnalysisInfo const& _analysisInfo,
std::map<YulString, ControlFlowSideEffects> const& _functionSideEffects,
Dialect const& _dialect
);
CFG::Operation const& visitFunctionCall(FunctionCall const&);
Expand All @@ -76,6 +78,7 @@ class ControlFlowGraphBuilder
);
CFG& m_graph;
AsmAnalysisInfo const& m_info;
std::map<YulString, ControlFlowSideEffects> const& m_functionSideEffects;
Dialect const& m_dialect;
CFG::BasicBlock* m_currentBlock = nullptr;
Scope* m_scope = nullptr;
Expand Down

0 comments on commit 21386df

Please sign in to comment.