diff options
author | chriseth <c@ethdev.com> | 2015-09-10 18:01:05 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-09-11 21:21:37 +0800 |
commit | a9edc7b1a601747f96e47fe60a5fc10df489696f (patch) | |
tree | 8165a9a44cc6cf23f6a8d8b152facfe3fd65a909 /libsolidity/CompilerStack.cpp | |
parent | 337fde9d11adac85800b405a3fdb4bcd09039ebf (diff) | |
download | dexon-solidity-a9edc7b1a601747f96e47fe60a5fc10df489696f.tar dexon-solidity-a9edc7b1a601747f96e47fe60a5fc10df489696f.tar.gz dexon-solidity-a9edc7b1a601747f96e47fe60a5fc10df489696f.tar.bz2 dexon-solidity-a9edc7b1a601747f96e47fe60a5fc10df489696f.tar.lz dexon-solidity-a9edc7b1a601747f96e47fe60a5fc10df489696f.tar.xz dexon-solidity-a9edc7b1a601747f96e47fe60a5fc10df489696f.tar.zst dexon-solidity-a9edc7b1a601747f96e47fe60a5fc10df489696f.zip |
Transition from bytecode to more general linker objects.
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); |