/src/solidity/libyul/CompilabilityChecker.cpp
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 | | /** |
18 | | * Component that checks whether all variables are reachable on the stack. |
19 | | */ |
20 | | |
21 | | #include <libyul/CompilabilityChecker.h> |
22 | | |
23 | | #include <libyul/AsmAnalysis.h> |
24 | | #include <libyul/AsmAnalysisInfo.h> |
25 | | |
26 | | #include <libyul/backends/evm/EVMCodeTransform.h> |
27 | | #include <libyul/backends/evm/NoOutputAssembly.h> |
28 | | |
29 | | using namespace std; |
30 | | using namespace solidity; |
31 | | using namespace solidity::yul; |
32 | | using namespace solidity::util; |
33 | | |
34 | | CompilabilityChecker::CompilabilityChecker( |
35 | | Dialect const& _dialect, |
36 | | Object const& _object, |
37 | | bool _optimizeStackAllocation |
38 | | ) |
39 | 11.5k | { |
40 | 11.5k | if (auto const* evmDialect = dynamic_cast<EVMDialect const*>(&_dialect)) |
41 | 11.5k | { |
42 | 11.5k | NoOutputEVMDialect noOutputDialect(*evmDialect); |
43 | | |
44 | 11.5k | yul::AsmAnalysisInfo analysisInfo = |
45 | 11.5k | yul::AsmAnalyzer::analyzeStrictAssertCorrect(noOutputDialect, _object); |
46 | | |
47 | 11.5k | BuiltinContext builtinContext; |
48 | 11.5k | builtinContext.currentObject = &_object; |
49 | 11.5k | if (!_object.name.empty()) |
50 | 11.5k | builtinContext.subIDs[_object.name] = 1; |
51 | 11.5k | for (auto const& subNode: _object.subObjects) |
52 | 577 | builtinContext.subIDs[subNode->name] = 1; |
53 | 11.5k | NoOutputAssembly assembly; |
54 | 11.5k | CodeTransform transform( |
55 | 11.5k | assembly, |
56 | 11.5k | analysisInfo, |
57 | 11.5k | *_object.code, |
58 | 11.5k | noOutputDialect, |
59 | 11.5k | builtinContext, |
60 | 11.5k | _optimizeStackAllocation |
61 | 11.5k | ); |
62 | 11.5k | transform(*_object.code); |
63 | | |
64 | 11.5k | for (StackTooDeepError const& error: transform.stackErrors()) |
65 | 29.0k | { |
66 | 29.0k | unreachableVariables[error.functionName].emplace(error.variable); |
67 | 29.0k | int& deficit = stackDeficit[error.functionName]; |
68 | 29.0k | deficit = std::max(error.depth, deficit); |
69 | 29.0k | } |
70 | 11.5k | } |
71 | 11.5k | } |