/src/solidity/libevmasm/PeepholeOptimiser.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 | | * @file PeepholeOptimiser.h |
20 | | * Performs local optimising code changes to assembly. |
21 | | */ |
22 | | #pragma once |
23 | | |
24 | | #include <vector> |
25 | | #include <cstddef> |
26 | | #include <iterator> |
27 | | |
28 | | namespace solidity::evmasm |
29 | | { |
30 | | class AssemblyItem; |
31 | | using AssemblyItems = std::vector<AssemblyItem>; |
32 | | |
33 | | class PeepholeOptimisationMethod |
34 | | { |
35 | | public: |
36 | | virtual ~PeepholeOptimisationMethod() = default; |
37 | | virtual size_t windowSize() const; |
38 | | virtual bool apply(AssemblyItems::const_iterator _in, std::back_insert_iterator<AssemblyItems> _out); |
39 | | }; |
40 | | |
41 | | class PeepholeOptimiser |
42 | | { |
43 | | public: |
44 | 2.14k | explicit PeepholeOptimiser(AssemblyItems& _items): m_items(_items) {} |
45 | 2.14k | virtual ~PeepholeOptimiser() = default; |
46 | | |
47 | | bool optimise(); |
48 | | |
49 | | private: |
50 | | AssemblyItems& m_items; |
51 | | AssemblyItems m_optimisedItems; |
52 | | }; |
53 | | |
54 | | } |