Skip to content

Commit 895eb45

Browse files
committed
Add literal assignment to SSACFG
1 parent 9f2ca6c commit 895eb45

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

libyul/YulControlFlowGraphExporter.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,20 @@ Json YulControlFlowGraphExporter::toJson(SSACFG const& _cfg, SSACFG::BlockId _bl
177177
Json YulControlFlowGraphExporter::toJson(Json& _ret, SSACFG const& _cfg, SSACFG::Operation const& _operation)
178178
{
179179
Json opJson = Json::object();
180-
std::visit(util::GenericVisitor{
181-
[&](SSACFG::Call const& _call) {
180+
std::visit(GenericVisitor{
181+
[&](SSACFG::Call const& _call)
182+
{
182183
_ret["type"] = "FunctionCall";
183184
opJson["op"] = _call.function.get().name.str();
184185
},
185-
[&](SSACFG::BuiltinCall const& _call) {
186+
[&](SSACFG::LiteralAssignment const&)
187+
{
188+
yulAssert(_operation.inputs.size() == 1);
189+
yulAssert(_cfg.isLiteralValue(_operation.inputs.back()));
190+
_ret["type"] = "LiteralAssignment";
191+
},
192+
[&](SSACFG::BuiltinCall const& _call)
193+
{
186194
_ret["type"] = "BuiltinCall";
187195
Json builtinArgsJson = Json::array();
188196
auto const& builtin = _call.builtin.get();

libyul/backends/evm/SSAControlFlowGraph.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,28 @@ class SSACFGPrinter
168168
[&](SSACFG::BuiltinCall const& _call) {
169169
return _call.builtin.get().name;
170170
},
171+
[&](SSACFG::LiteralAssignment const&)
172+
{
173+
yulAssert(operation.inputs.size() == 1);
174+
return varToString(m_cfg, operation.inputs.back());
175+
}
171176
}, operation.kind);
172177
if (!operation.outputs.empty())
173178
m_result << fmt::format(
174179
"{} := ",
175180
fmt::join(operation.outputs | ranges::views::transform(valueToString), ", ")
176181
);
177-
m_result << fmt::format(
178-
"{}({})\\l\\\n",
179-
escape(label),
180-
fmt::join(operation.inputs | ranges::views::transform(valueToString), ", ")
181-
);
182+
if (std::holds_alternative<SSACFG::LiteralAssignment>(operation.kind))
183+
m_result << fmt::format(
184+
"{}\\l\\\n",
185+
escape(label)
186+
);
187+
else
188+
m_result << fmt::format(
189+
"{}({})\\l\\\n",
190+
escape(label),
191+
fmt::join(operation.inputs | ranges::views::transform(valueToString), ", ")
192+
);
182193
}
183194
m_result << "\"];\n";
184195
std::visit(GenericVisitor{

libyul/backends/evm/SSAControlFlowGraph.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ class SSACFG
7878
std::reference_wrapper<FunctionCall const> call;
7979
bool canContinue;
8080
};
81+
struct LiteralAssignment
82+
{
83+
langutil::DebugData::ConstPtr debugData;
84+
};
8185

8286
struct Operation {
8387
std::vector<ValueId> outputs{};
84-
std::variant<BuiltinCall, Call> kind;
88+
std::variant<BuiltinCall, Call, LiteralAssignment> kind;
8589
std::vector<ValueId> inputs{};
8690
};
8791
struct BasicBlock
@@ -199,7 +203,7 @@ class SSACFG
199203
}
200204
ValueId newLiteral(langutil::DebugData::ConstPtr _debugData, u256 _value)
201205
{
202-
auto [it, inserted] = m_literals.emplace(_value, SSACFG::ValueId{m_valueInfos.size()});
206+
auto [it, inserted] = m_literals.emplace(_value, ValueId{m_valueInfos.size()});
203207
if (inserted)
204208
m_valueInfos.emplace_back(LiteralValue{std::move(_debugData), _value});
205209
else

0 commit comments

Comments
 (0)