| 36 | using namespace solidity::langutil; |
| 37 | |
| 38 | std::vector<AssemblyItem> CommonSubexpressionEliminator::getOptimizedItems() |
| 39 | { |
| 40 | optimizeBreakingItem(); |
| 41 | |
| 42 | KnownState nextInitialState = m_state; |
| 43 | if (m_breakingItem) |
| 44 | nextInitialState.feedItem(*m_breakingItem); |
| 45 | KnownState nextState = nextInitialState; |
| 46 | |
| 47 | ScopeGuard reset([&]() |
| 48 | { |
| 49 | m_breakingItem = nullptr; |
| 50 | m_storeOperations.clear(); |
| 51 | m_initialState = std::move(nextInitialState); |
| 52 | m_state = std::move(nextState); |
| 53 | }); |
| 54 | |
| 55 | std::map<int, Id> initialStackContents; |
| 56 | std::map<int, Id> targetStackContents; |
| 57 | int minHeight = m_state.stackHeight() + 1; |
| 58 | if (!m_state.stackElements().empty()) |
| 59 | minHeight = std::min(minHeight, m_state.stackElements().begin()->first); |
| 60 | for (int height = minHeight; height <= m_initialState.stackHeight(); ++height) |
| 61 | initialStackContents[height] = m_initialState.stackElement(height, langutil::DebugData::create()); |
| 62 | for (int height = minHeight; height <= m_state.stackHeight(); ++height) |
| 63 | targetStackContents[height] = m_state.stackElement(height, langutil::DebugData::create()); |
| 64 | |
| 65 | AssemblyItems items = CSECodeGenerator(m_state.expressionClasses(), m_storeOperations, m_evmVersion).generateCode( |
| 66 | m_initialState.sequenceNumber(), |
| 67 | m_initialState.stackHeight(), |
| 68 | initialStackContents, |
| 69 | targetStackContents |
| 70 | ); |
| 71 | if (m_breakingItem) |
| 72 | items.push_back(*m_breakingItem); |
| 73 | |
| 74 | return items; |
| 75 | } |
| 76 | |
| 77 | void CommonSubexpressionEliminator::feedItem(AssemblyItem const& _item, bool _copyItem) |
| 78 | { |
no test coverage detected