Skip to content

Commit a83ea40

Browse files
authored
Merge pull request #15535 from ipsilon/extend-create-function-interface
Add `ControlFlowSideEffects` parameter to `createFunction` in EVMDialect
2 parents 66a1edb + cbb604e commit a83ea40

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

libyul/ControlFlowSideEffects.h

+24
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
#pragma once
2020

21+
#include <libevmasm/Instruction.h>
22+
#include <libevmasm/SemanticInformation.h>
23+
2124
namespace solidity::yul
2225
{
2326

@@ -44,6 +47,27 @@ struct ControlFlowSideEffects
4447
{
4548
return (canTerminate || canRevert) && !canContinue;
4649
}
50+
51+
static ControlFlowSideEffects fromInstruction(evmasm::Instruction _instruction)
52+
{
53+
ControlFlowSideEffects controlFlowSideEffects;
54+
if (evmasm::SemanticInformation::terminatesControlFlow(_instruction))
55+
{
56+
controlFlowSideEffects.canContinue = false;
57+
if (evmasm::SemanticInformation::reverts(_instruction))
58+
{
59+
controlFlowSideEffects.canTerminate = false;
60+
controlFlowSideEffects.canRevert = true;
61+
}
62+
else
63+
{
64+
controlFlowSideEffects.canTerminate = true;
65+
controlFlowSideEffects.canRevert = false;
66+
}
67+
}
68+
69+
return controlFlowSideEffects;
70+
}
4771
};
4872

4973
}

libyul/backends/evm/EVMDialect.cpp

+15-19
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,7 @@ BuiltinFunctionForEVM createEVMFunction(
6868
f.numParameters = static_cast<size_t>(info.args);
6969
f.numReturns = static_cast<size_t>(info.ret);
7070
f.sideEffects = EVMDialect::sideEffectsOfInstruction(_instruction);
71-
if (evmasm::SemanticInformation::terminatesControlFlow(_instruction))
72-
{
73-
f.controlFlowSideEffects.canContinue = false;
74-
if (evmasm::SemanticInformation::reverts(_instruction))
75-
{
76-
f.controlFlowSideEffects.canTerminate = false;
77-
f.controlFlowSideEffects.canRevert = true;
78-
}
79-
else
80-
{
81-
f.controlFlowSideEffects.canTerminate = true;
82-
f.controlFlowSideEffects.canRevert = false;
83-
}
84-
}
71+
f.controlFlowSideEffects = ControlFlowSideEffects::fromInstruction(_instruction);
8572
f.isMSize = _instruction == evmasm::Instruction::MSIZE;
8673
f.literalArguments.clear();
8774
f.instruction = _instruction;
@@ -100,6 +87,7 @@ BuiltinFunctionForEVM createFunction(
10087
size_t _params,
10188
size_t _returns,
10289
SideEffects _sideEffects,
90+
ControlFlowSideEffects _controlFlowSideEffects,
10391
std::vector<std::optional<LiteralKind>> _literalArguments,
10492
std::function<void(FunctionCall const&, AbstractAssembly&, BuiltinContext&)> _generateCode
10593
)
@@ -111,6 +99,7 @@ BuiltinFunctionForEVM createFunction(
11199
f.numParameters = _params;
112100
f.numReturns = _returns;
113101
f.sideEffects = _sideEffects;
102+
f.controlFlowSideEffects = _controlFlowSideEffects;
114103
f.literalArguments = std::move(_literalArguments);
115104
f.isMSize = false;
116105
f.instruction = {};
@@ -231,16 +220,17 @@ std::vector<std::optional<BuiltinFunctionForEVM>> createBuiltins(langutil::EVMVe
231220
size_t _params,
232221
size_t _returns,
233222
SideEffects _sideEffects,
223+
ControlFlowSideEffects _controlFlowSideEffects,
234224
std::vector<std::optional<LiteralKind>> _literalArguments,
235225
std::function<void(FunctionCall const&, AbstractAssembly&, BuiltinContext&)> _generateCode
236226
) -> std::optional<BuiltinFunctionForEVM>
237227
{
238228
if (!_objectAccess)
239229
return std::nullopt;
240-
return createFunction(_name, _params, _returns, _sideEffects, std::move(_literalArguments), std::move(_generateCode));
230+
return createFunction(_name, _params, _returns, _sideEffects, _controlFlowSideEffects, std::move(_literalArguments), std::move(_generateCode));
241231
};
242232

243-
builtins.emplace_back(createIfObjectAccess("linkersymbol", 1, 1, SideEffects{}, {LiteralKind::String}, [](
233+
builtins.emplace_back(createIfObjectAccess("linkersymbol", 1, 1, SideEffects{}, ControlFlowSideEffects{}, {LiteralKind::String}, [](
244234
FunctionCall const& _call,
245235
AbstractAssembly& _assembly,
246236
BuiltinContext&
@@ -254,6 +244,7 @@ std::vector<std::optional<BuiltinFunctionForEVM>> createBuiltins(langutil::EVMVe
254244
1,
255245
1,
256246
SideEffects{},
247+
ControlFlowSideEffects{},
257248
{LiteralKind::Number},
258249
[](
259250
FunctionCall const& _call,
@@ -268,7 +259,7 @@ std::vector<std::optional<BuiltinFunctionForEVM>> createBuiltins(langutil::EVMVe
268259
);
269260
if (!_eofVersion.has_value())
270261
{
271-
builtins.emplace_back(createIfObjectAccess("datasize", 1, 1, SideEffects{}, {LiteralKind::String}, [](
262+
builtins.emplace_back(createIfObjectAccess("datasize", 1, 1, SideEffects{}, ControlFlowSideEffects{}, {LiteralKind::String}, [](
272263
FunctionCall const& _call,
273264
AbstractAssembly& _assembly,
274265
BuiltinContext& _context
@@ -289,7 +280,7 @@ std::vector<std::optional<BuiltinFunctionForEVM>> createBuiltins(langutil::EVMVe
289280
_assembly.appendDataSize(subIdPath);
290281
}
291282
}));
292-
builtins.emplace_back(createIfObjectAccess("dataoffset", 1, 1, SideEffects{}, {LiteralKind::String}, [](
283+
builtins.emplace_back(createIfObjectAccess("dataoffset", 1, 1, SideEffects{}, ControlFlowSideEffects{}, {LiteralKind::String}, [](
293284
FunctionCall const& _call,
294285
AbstractAssembly& _assembly,
295286
BuiltinContext& _context
@@ -325,6 +316,7 @@ std::vector<std::optional<BuiltinFunctionForEVM>> createBuiltins(langutil::EVMVe
325316
SideEffects::Write, // memory
326317
SideEffects::None // transientStorage
327318
},
319+
ControlFlowSideEffects::fromInstruction(evmasm::Instruction::CODECOPY),
328320
{},
329321
[](
330322
FunctionCall const&,
@@ -349,6 +341,7 @@ std::vector<std::optional<BuiltinFunctionForEVM>> createBuiltins(langutil::EVMVe
349341
SideEffects::Write, // memory
350342
SideEffects::None // transientStorage
351343
},
344+
ControlFlowSideEffects{},
352345
{std::nullopt, LiteralKind::String, std::nullopt},
353346
[](
354347
FunctionCall const& _call,
@@ -365,6 +358,7 @@ std::vector<std::optional<BuiltinFunctionForEVM>> createBuiltins(langutil::EVMVe
365358
1,
366359
1,
367360
SideEffects{},
361+
ControlFlowSideEffects{},
368362
{LiteralKind::String},
369363
[](
370364
FunctionCall const& _call,
@@ -382,7 +376,8 @@ std::vector<std::optional<BuiltinFunctionForEVM>> createBuiltins(langutil::EVMVe
382376
"auxdataloadn",
383377
1,
384378
1,
385-
SideEffects{},
379+
EVMDialect::sideEffectsOfInstruction(evmasm::Instruction::DATALOADN),
380+
ControlFlowSideEffects::fromInstruction(evmasm::Instruction::DATALOADN),
386381
{LiteralKind::Number},
387382
[](
388383
FunctionCall const& _call,
@@ -531,6 +526,7 @@ BuiltinFunctionForEVM EVMDialect::createVerbatimFunction(size_t _arguments, size
531526
1 + _arguments,
532527
_returnVariables,
533528
SideEffects::worst(),
529+
ControlFlowSideEffects{},
534530
std::vector<std::optional<LiteralKind>>{LiteralKind::String} + std::vector<std::optional<LiteralKind>>(_arguments),
535531
[=](
536532
FunctionCall const& _call,

0 commit comments

Comments
 (0)