| 50 | } |
| 51 | |
| 52 | void EVMObjectCompiler::run(Object const& _object, bool _optimize, bool _viaSSACFG) |
| 53 | { |
| 54 | yulAssert(_object.dialect()); |
| 55 | auto const* evmDialect = dynamic_cast<EVMDialect const*>(_object.dialect()); |
| 56 | yulAssert(evmDialect); |
| 57 | |
| 58 | BuiltinContext context; |
| 59 | context.currentObject = &_object; |
| 60 | |
| 61 | |
| 62 | for (auto const& subNode: _object.subObjects) |
| 63 | if (auto* subObject = dynamic_cast<Object*>(subNode.get())) |
| 64 | { |
| 65 | bool isCreation = !boost::ends_with(subObject->name, "_deployed"); |
| 66 | auto subAssemblyAndID = m_assembly.createSubAssembly(isCreation, subObject->name); |
| 67 | context.subIDs[subObject->name] = subAssemblyAndID.second; |
| 68 | subObject->subId = subAssemblyAndID.second; |
| 69 | compile(*subObject, *subAssemblyAndID.first, _optimize, _viaSSACFG); |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | Data const& data = dynamic_cast<Data const&>(*subNode); |
| 74 | // Special handling of metadata. |
| 75 | if (data.name == Object::metadataName()) |
| 76 | m_assembly.appendToAuxiliaryData(data.data); |
| 77 | else |
| 78 | context.subIDs[data.name] = m_assembly.appendData(data.data); |
| 79 | } |
| 80 | |
| 81 | yulAssert(_object.analysisInfo, "No analysis info."); |
| 82 | yulAssert(_object.hasCode(), "No code."); |
| 83 | if (evmDialect->eofVersion().has_value()) |
| 84 | { |
| 85 | solUnimplementedAssert(_optimize, "EOF supported only for optimized compilation via IR."); |
| 86 | yulAssert(evmDialect->evmVersion().supportsEOF()); |
| 87 | } |
| 88 | if (_optimize && evmDialect->evmVersion().canOverchargeGasForCall()) |
| 89 | { |
| 90 | if (_viaSSACFG) |
| 91 | { |
| 92 | std::unique_ptr<ssa::ControlFlowGraphs> controlFlowGraphs = ssa::SSACFGBuilder::build( |
| 93 | *_object.analysisInfo, |
| 94 | *evmDialect, |
| 95 | _object.code()->root(), |
| 96 | false |
| 97 | ); |
| 98 | ssa::ControlFlowGraphsLiveness const liveness(*controlFlowGraphs); |
| 99 | ssa::CodeTransform::run( |
| 100 | m_assembly, |
| 101 | liveness, |
| 102 | context |
| 103 | ); |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | auto stackErrors = OptimizedEVMCodeTransform::run( |
| 108 | m_assembly, |
| 109 | *_object.analysisInfo, |
no test coverage detected