| 168 | } |
| 169 | |
| 170 | SubAssemblyID ContractCompiler::packIntoContractCreator(ContractDefinition const& _contract) |
| 171 | { |
| 172 | solAssert(!!m_runtimeCompiler, ""); |
| 173 | solAssert(!_contract.isLibrary(), "Tried to use contract creator or library."); |
| 174 | |
| 175 | appendInitAndConstructorCode(_contract); |
| 176 | |
| 177 | // We jump to the deploy routine because we first have to append all missing functions, |
| 178 | // which can cause further functions to be added to the runtime context. |
| 179 | evmasm::AssemblyItem deployRoutine = m_context.appendJumpToNew(); |
| 180 | |
| 181 | // We have to include copies of functions in the construction time and runtime context |
| 182 | // because of absolute jumps. |
| 183 | appendMissingFunctions(); |
| 184 | m_runtimeCompiler->appendMissingFunctions(); |
| 185 | |
| 186 | CompilerContext::LocationSetter locationSetter(m_context, _contract); |
| 187 | m_context << deployRoutine; |
| 188 | |
| 189 | solAssert(!m_context.runtimeSub().empty(), "Runtime sub not registered"); |
| 190 | |
| 191 | ContractType contractType(_contract); |
| 192 | auto const& immutables = contractType.immutableVariables(); |
| 193 | // Push all immutable values on the stack. |
| 194 | for (auto const& immutable: immutables) |
| 195 | CompilerUtils(m_context).loadFromMemory( |
| 196 | static_cast<unsigned>(m_context.immutableMemoryOffset(*immutable)), |
| 197 | *immutable->annotation().type, |
| 198 | false, |
| 199 | true |
| 200 | ); |
| 201 | m_context.pushSubroutineSize(m_context.runtimeSub()); |
| 202 | if (immutables.empty()) |
| 203 | m_context << Instruction::DUP1; |
| 204 | m_context.pushSubroutineOffset(m_context.runtimeSub()); |
| 205 | m_context << u256(0) << Instruction::CODECOPY; |
| 206 | // Assign immutable values from stack in reversed order. |
| 207 | for (auto const& immutable: immutables | ranges::views::reverse) |
| 208 | { |
| 209 | auto slotNames = m_context.immutableVariableSlotNames(*immutable); |
| 210 | for (auto&& slotName: slotNames | ranges::views::reverse) |
| 211 | { |
| 212 | m_context << u256(0); |
| 213 | m_context.appendImmutableAssignment(slotName); |
| 214 | } |
| 215 | } |
| 216 | if (!immutables.empty()) |
| 217 | m_context.pushSubroutineSize(m_context.runtimeSub()); |
| 218 | m_context << u256(0) << Instruction::RETURN; |
| 219 | |
| 220 | return m_context.runtimeSub(); |
| 221 | } |
| 222 | |
| 223 | SubAssemblyID ContractCompiler::deployLibrary(ContractDefinition const& _contract) |
| 224 | { |
nothing calls this directly
no test coverage detected