From e6fee257e68e7b145a47eee8c5937db7a7a99849 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 10 Jan 2019 16:44:31 +0100 Subject: Code generation for access to contract code. --- libsolidity/codegen/CompilerUtils.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libsolidity/codegen/CompilerUtils.cpp') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index bbc703c7..9b7244ba 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -1199,6 +1199,29 @@ void CompilerUtils::computeHashStatic() m_context << u256(32) << u256(0) << Instruction::KECCAK256; } +void CompilerUtils::copyContractCodeToMemory(ContractDefinition const& contract, bool _creation) +{ + string which = _creation ? "Creation" : "Runtime"; + m_context.callLowLevelFunction( + "$copyContract" + which + "CodeToMemory_" + contract.type()->identifier(), + 1, + 1, + [&contract, _creation](CompilerContext& _context) + { + // copy the contract's code into memory + eth::Assembly const& assembly = + _creation ? + _context.compiledContract(contract) : + _context.compiledContractRuntime(contract); + // pushes size + auto subroutine = _context.addSubroutine(make_shared(assembly)); + _context << Instruction::DUP1 << subroutine; + _context << Instruction::DUP4 << Instruction::CODECOPY; + _context << Instruction::ADD; + } + ); +} + void CompilerUtils::storeStringData(bytesConstRef _data) { //@todo provide both alternatives to the optimiser -- cgit v1.2.3 From 29f6aa7d560a7d82a9088489e663a079a3b41f73 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 16 Jan 2019 11:44:11 +0100 Subject: Do not create a copy of the assembly. --- libsolidity/codegen/CompilerUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libsolidity/codegen/CompilerUtils.cpp') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 9b7244ba..6cfb0777 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -1209,12 +1209,12 @@ void CompilerUtils::copyContractCodeToMemory(ContractDefinition const& contract, [&contract, _creation](CompilerContext& _context) { // copy the contract's code into memory - eth::Assembly const& assembly = + shared_ptr assembly = _creation ? _context.compiledContract(contract) : _context.compiledContractRuntime(contract); // pushes size - auto subroutine = _context.addSubroutine(make_shared(assembly)); + auto subroutine = _context.addSubroutine(assembly); _context << Instruction::DUP1 << subroutine; _context << Instruction::DUP4 << Instruction::CODECOPY; _context << Instruction::ADD; -- cgit v1.2.3