diff options
author | chriseth <chris@ethereum.org> | 2019-01-16 18:44:11 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2019-01-18 03:36:48 +0800 |
commit | 29f6aa7d560a7d82a9088489e663a079a3b41f73 (patch) | |
tree | 2ef2c682489bc68f16d600d06643f1f39ec12105 | |
parent | a9fa2658d8690f18aa14c599a305cf59a5cd4e3c (diff) | |
download | dexon-solidity-29f6aa7d560a7d82a9088489e663a079a3b41f73.tar.gz dexon-solidity-29f6aa7d560a7d82a9088489e663a079a3b41f73.tar.zst dexon-solidity-29f6aa7d560a7d82a9088489e663a079a3b41f73.zip |
Do not create a copy of the assembly.
-rw-r--r-- | libsolidity/codegen/Compiler.cpp | 6 | ||||
-rw-r--r-- | libsolidity/codegen/Compiler.h | 4 | ||||
-rw-r--r-- | libsolidity/codegen/CompilerContext.cpp | 8 | ||||
-rw-r--r-- | libsolidity/codegen/CompilerContext.h | 12 | ||||
-rw-r--r-- | libsolidity/codegen/CompilerUtils.cpp | 4 | ||||
-rw-r--r-- | libsolidity/codegen/ContractCompiler.cpp | 2 |
6 files changed, 22 insertions, 14 deletions
diff --git a/libsolidity/codegen/Compiler.cpp b/libsolidity/codegen/Compiler.cpp index f0eaca4f..72efed33 100644 --- a/libsolidity/codegen/Compiler.cpp +++ b/libsolidity/codegen/Compiler.cpp @@ -47,6 +47,12 @@ void Compiler::compileContract( m_context.optimise(m_optimize, m_optimizeRuns); } +std::shared_ptr<eth::Assembly> Compiler::runtimeAssemblyPtr() const +{ + solAssert(m_context.runtimeContext(), ""); + return m_context.runtimeContext()->assemblyPtr(); +} + eth::AssemblyItem Compiler::functionEntryLabel(FunctionDefinition const& _function) const { return m_runtimeContext.functionEntryLabelIfExists(_function); diff --git a/libsolidity/codegen/Compiler.h b/libsolidity/codegen/Compiler.h index 953267a4..c21de96d 100644 --- a/libsolidity/codegen/Compiler.h +++ b/libsolidity/codegen/Compiler.h @@ -50,8 +50,10 @@ public: ); /// @returns Entire assembly. eth::Assembly const& assembly() const { return m_context.assembly(); } + /// @returns Entire assembly as a shared pointer to non-const. + std::shared_ptr<eth::Assembly> assemblyPtr() const { return m_context.assemblyPtr(); } /// @returns Runtime assembly. - eth::Assembly const& runtimeAssembly() const { return m_context.assembly().sub(m_runtimeSub); } + std::shared_ptr<eth::Assembly> runtimeAssemblyPtr() const; /// @returns The entire assembled object (with constructor). eth::LinkerObject assembledObject() const { return m_context.assembledObject(); } /// @returns Only the runtime object (without constructor). diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index 20e1af7c..861b1c98 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -167,18 +167,18 @@ unsigned CompilerContext::numberOfLocalVariables() const return m_localVariables.size(); } -eth::Assembly const& CompilerContext::compiledContract(ContractDefinition const& _contract) const +shared_ptr<eth::Assembly> CompilerContext::compiledContract(ContractDefinition const& _contract) const { auto ret = m_otherCompilers.find(&_contract); solAssert(ret != m_otherCompilers.end(), "Compiled contract not found."); - return ret->second->assembly(); + return ret->second->assemblyPtr(); } -eth::Assembly const& CompilerContext::compiledContractRuntime(ContractDefinition const& _contract) const +shared_ptr<eth::Assembly> CompilerContext::compiledContractRuntime(ContractDefinition const& _contract) const { auto ret = m_otherCompilers.find(&_contract); solAssert(ret != m_otherCompilers.end(), "Compiled contract not found."); - return ret->second->runtimeAssembly(); + return ret->second->runtimeAssemblyPtr(); } bool CompilerContext::isLocalVariable(Declaration const* _declaration) const diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h index 43e1ea77..e5ddfbc5 100644 --- a/libsolidity/codegen/CompilerContext.h +++ b/libsolidity/codegen/CompilerContext.h @@ -76,8 +76,8 @@ public: unsigned numberOfLocalVariables() const; void setOtherCompilers(std::map<ContractDefinition const*, std::shared_ptr<Compiler const>> const& _otherCompilers) { m_otherCompilers = _otherCompilers; } - eth::Assembly const& compiledContract(ContractDefinition const& _contract) const; - eth::Assembly const& compiledContractRuntime(ContractDefinition const& _contract) const; + std::shared_ptr<eth::Assembly> compiledContract(ContractDefinition const& _contract) const; + std::shared_ptr<eth::Assembly> compiledContractRuntime(ContractDefinition const& _contract) const; void setStackOffset(int _offset) { m_asm->setDeposit(_offset); } void adjustStackOffset(int _adjustment) { m_asm->adjustDeposit(_adjustment); } @@ -224,15 +224,15 @@ public: void optimise(bool _fullOptimsation, unsigned _runs = 200) { m_asm->optimise(_fullOptimsation, m_evmVersion, true, _runs); } /// @returns the runtime context if in creation mode and runtime context is set, nullptr otherwise. - CompilerContext* runtimeContext() { return m_runtimeContext; } + CompilerContext* runtimeContext() const { return m_runtimeContext; } /// @returns the identifier of the runtime subroutine. size_t runtimeSub() const { return m_runtimeSub; } /// @returns a const reference to the underlying assembly. eth::Assembly const& assembly() const { return *m_asm; } - /// @returns non-const reference to the underlying assembly. Should be avoided in favour of - /// wrappers in this class. - eth::Assembly& nonConstAssembly() { return *m_asm; } + /// @returns a shared pointer to the assembly. + /// Should be avoided except when adding sub-assemblies. + std::shared_ptr<eth::Assembly> assemblyPtr() const { return m_asm; } /// @arg _sourceCodes is the map of input files to source code strings std::string assemblyString(StringMap const& _sourceCodes = StringMap()) const 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<eth::Assembly> assembly = _creation ? _context.compiledContract(contract) : _context.compiledContractRuntime(contract); // pushes size - auto subroutine = _context.addSubroutine(make_shared<eth::Assembly>(assembly)); + auto subroutine = _context.addSubroutine(assembly); _context << Instruction::DUP1 << subroutine; _context << Instruction::DUP4 << Instruction::CODECOPY; _context << Instruction::ADD; diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index a718603b..f843e07a 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -716,7 +716,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) CodeGenerator::assemble( _inlineAssembly.operations(), *_inlineAssembly.annotation().analysisInfo, - m_context.nonConstAssembly(), + *m_context.assemblyPtr(), identifierAccess ); m_context.setStackOffset(startStackHeight); |