/src/solidity/libyul/backends/evm/ssa/ControlFlowGraphs.h
Line | Count | Source |
1 | | /* |
2 | | This file is part of solidity. |
3 | | |
4 | | solidity is free software: you can redistribute it and/or modify |
5 | | it under the terms of the GNU General Public License as published by |
6 | | the Free Software Foundation, either version 3 of the License, or |
7 | | (at your option) any later version. |
8 | | |
9 | | solidity is distributed in the hope that it will be useful, |
10 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | GNU General Public License for more details. |
13 | | |
14 | | You should have received a copy of the GNU General Public License |
15 | | along with solidity. If not, see <http://www.gnu.org/licenses/>. |
16 | | */ |
17 | | // SPDX-License-Identifier: GPL-3.0 |
18 | | |
19 | | #pragma once |
20 | | |
21 | | #include <libyul/backends/evm/ssa/io/Printer.h> |
22 | | |
23 | | #include <libyul/backends/evm/ssa/LivenessAnalysis.h> |
24 | | #include <libyul/backends/evm/ssa/SSACFG.h> |
25 | | |
26 | | #include <libsolutil/Numeric.h> |
27 | | |
28 | | #include <optional> |
29 | | |
30 | | namespace solidity::yul::ssa |
31 | | { |
32 | | |
33 | | struct ControlFlowGraphs; |
34 | | |
35 | | struct ControlFlowGraphsLiveness{ |
36 | | explicit ControlFlowGraphsLiveness(ControlFlowGraphs const& _controlFlow); |
37 | | |
38 | | std::reference_wrapper<ControlFlowGraphs const> controlFlowGraphs; |
39 | | std::vector<std::unique_ptr<LivenessAnalysis>> cfgLiveness; |
40 | | |
41 | | std::string toDot() const; |
42 | | }; |
43 | | |
44 | | struct ControlFlowGraphs |
45 | | { |
46 | | using FunctionGraphID = ssa::FunctionGraphID; |
47 | | |
48 | 0 | static FunctionGraphID constexpr mainGraphID() noexcept { return 0; } |
49 | | |
50 | 0 | SSACFG const* mainGraph() const { return functionGraph(mainGraphID()); } |
51 | | |
52 | | SSACFG const* functionGraph(FunctionGraphID const _id) const |
53 | 0 | { |
54 | 0 | return functionGraphs.at(_id).get(); |
55 | 0 | } |
56 | | |
57 | | std::string toDot(ControlFlowGraphsLiveness const* _liveness=nullptr) const |
58 | 0 | { |
59 | 0 | if (_liveness) |
60 | 0 | yulAssert(&_liveness->controlFlowGraphs.get() == this); |
61 | 0 | std::ostringstream output; |
62 | 0 | output << "digraph SSACFG {\nnodesep=0.7;\ngraph[fontname=\"DejaVu Sans\"]\nnode[shape=box,fontname=\"DejaVu Sans\"];\n\n"; |
63 | |
|
64 | 0 | for (size_t index=0; index < functionGraphs.size(); ++index) |
65 | 0 | output << functionGraphs[index]->toDot( |
66 | 0 | false, |
67 | 0 | index, |
68 | 0 | _liveness ? _liveness->cfgLiveness[index].get() : nullptr, |
69 | 0 | this |
70 | 0 | ); |
71 | |
|
72 | 0 | output << "}\n"; |
73 | 0 | return output.str(); |
74 | 0 | } |
75 | | |
76 | | std::string print() const |
77 | 0 | { |
78 | 0 | std::ostringstream output; |
79 | 0 | io::print(output, *this); |
80 | 0 | return output.str(); |
81 | 0 | } |
82 | | |
83 | | /// Memoryguard boundary for this subobject. |
84 | | /// - empty: no `memoryguard(N)` call appears in the source |
85 | | /// - set: every MemoryGuard Inst lowers to a `pushN <value>` of this constant |
86 | | std::optional<u256> memoryGuard{}; |
87 | | |
88 | | std::vector<std::unique_ptr<SSACFG>> functionGraphs{}; |
89 | | }; |
90 | | |
91 | | } |