diff options
Diffstat (limited to 'libsolidity/CompilerStack.cpp')
-rw-r--r-- | libsolidity/CompilerStack.cpp | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/libsolidity/CompilerStack.cpp b/libsolidity/CompilerStack.cpp index 385533b2..3da982a4 100644 --- a/libsolidity/CompilerStack.cpp +++ b/libsolidity/CompilerStack.cpp @@ -153,7 +153,7 @@ void CompilerStack::compile(bool _optimize, unsigned _runs) if (!m_parseSuccessful) parse(); - map<ContractDefinition const*, bytes const*> contractBytecode; + map<ContractDefinition const*, eth::Assembly const*> compiledContracts; for (Source const* source: m_sourceOrder) for (ASTPointer<ASTNode> const& node: source->ast->nodes()) if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) @@ -161,26 +161,24 @@ void CompilerStack::compile(bool _optimize, unsigned _runs) if (!contract->isFullyImplemented()) continue; shared_ptr<Compiler> compiler = make_shared<Compiler>(_optimize, _runs); - compiler->compileContract(*contract, contractBytecode); + compiler->compileContract(*contract, compiledContracts); Contract& compiledContract = m_contracts.at(contract->name()); - compiledContract.bytecode = compiler->assembledBytecode(); - compiledContract.runtimeBytecode = compiler->runtimeBytecode(); - compiledContract.compiler = move(compiler); - compiler = make_shared<Compiler>(_optimize, _runs); - compiler->compileContract(*contract, contractBytecode); - contractBytecode[compiledContract.contract] = &compiledContract.bytecode; + compiledContract.compiler = compiler; + compiledContract.object = compiler->assembledObject(); + compiledContract.runtimeObject = compiler->runtimeObject(); + compiledContracts[compiledContract.contract] = &compiler->assembly(); Compiler cloneCompiler(_optimize, _runs); - cloneCompiler.compileClone(*contract, contractBytecode); - compiledContract.cloneBytecode = cloneCompiler.assembledBytecode(); + cloneCompiler.compileClone(*contract, compiledContracts); + compiledContract.cloneObject = cloneCompiler.assembledObject(); } } -bytes const& CompilerStack::compile(string const& _sourceCode, bool _optimize) +eth::LinkerObject const& CompilerStack::compile(string const& _sourceCode, bool _optimize) { parse(_sourceCode); compile(_optimize); - return bytecode(); + return object(); } eth::AssemblyItems const* CompilerStack::assemblyItems(string const& _contractName) const @@ -195,24 +193,28 @@ eth::AssemblyItems const* CompilerStack::runtimeAssemblyItems(string const& _con return currentContract.compiler ? &contract(_contractName).compiler->runtimeAssemblyItems() : nullptr; } -bytes const& CompilerStack::bytecode(string const& _contractName) const +eth::LinkerObject const& CompilerStack::object(string const& _contractName) const { - return contract(_contractName).bytecode; + return contract(_contractName).object; } -bytes const& CompilerStack::runtimeBytecode(string const& _contractName) const +eth::LinkerObject const& CompilerStack::runtimeObject(string const& _contractName) const { - return contract(_contractName).runtimeBytecode; + return contract(_contractName).runtimeObject; } -bytes const& CompilerStack::cloneBytecode(string const& _contractName) const +eth::LinkerObject const& CompilerStack::cloneObject(string const& _contractName) const { - return contract(_contractName).cloneBytecode; + return contract(_contractName).cloneObject; } dev::h256 CompilerStack::contractCodeHash(string const& _contractName) const { - return dev::sha3(runtimeBytecode(_contractName)); + auto const& obj = runtimeObject(_contractName); + if (obj.bytecode.empty() || !obj.linkReferences.empty()) + return dev::h256(); + else + return dev::sha3(obj.bytecode); } Json::Value CompilerStack::streamAssembly(ostream& _outStream, string const& _contractName, StringMap _sourceCodes, bool _inJsonFormat) const @@ -305,7 +307,7 @@ size_t CompilerStack::functionEntryPoint( return 0; } -bytes CompilerStack::staticCompile(std::string const& _sourceCode, bool _optimize) +eth::LinkerObject CompilerStack::staticCompile(std::string const& _sourceCode, bool _optimize) { CompilerStack stack; return stack.compile(_sourceCode, _optimize); |