Transition from bytecode to more general linker objects.

This commit is contained in:
chriseth
2015-09-11 15:21:37 +02:00
parent 337fde9d11
commit a9edc7b1a6
16 changed files with 90 additions and 78 deletions
+22 -20
View File
@@ -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);