2014-10-20 10:41:56 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2014-10-20 10:41:56 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2014-10-20 10:41:56 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2014-10-20 10:41:56 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2016-11-18 23:13:20 +00:00
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2014-10-20 10:41:56 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @author Christian <c@ethdev.com>
|
|
|
|
* @date 2014
|
2014-10-30 00:20:32 +00:00
|
|
|
* Solidity compiler.
|
2014-10-20 10:41:56 +00:00
|
|
|
*/
|
|
|
|
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/codegen/Compiler.h>
|
2015-04-24 15:35:16 +00:00
|
|
|
#include <libevmasm/Assembly.h>
|
2016-05-19 17:32:14 +00:00
|
|
|
#include <libsolidity/codegen/ContractCompiler.h>
|
|
|
|
|
2014-10-30 00:20:32 +00:00
|
|
|
using namespace std;
|
2015-06-15 10:10:41 +00:00
|
|
|
using namespace dev;
|
|
|
|
using namespace dev::solidity;
|
2014-10-20 10:41:56 +00:00
|
|
|
|
2015-09-10 10:01:05 +00:00
|
|
|
void Compiler::compileContract(
|
|
|
|
ContractDefinition const& _contract,
|
2016-11-14 10:46:43 +00:00
|
|
|
std::map<const ContractDefinition*, eth::Assembly const*> const& _contracts,
|
2016-11-29 16:47:47 +00:00
|
|
|
bytes const& _metadata
|
2015-09-11 13:25:00 +00:00
|
|
|
)
|
2014-10-20 10:41:56 +00:00
|
|
|
{
|
2016-11-10 17:16:21 +00:00
|
|
|
ContractCompiler runtimeCompiler(nullptr, m_runtimeContext, m_optimize);
|
2016-05-19 17:32:14 +00:00
|
|
|
runtimeCompiler.compileContract(_contract, _contracts);
|
2016-11-29 16:47:47 +00:00
|
|
|
m_runtimeContext.appendAuxiliaryData(_metadata);
|
2016-05-19 17:32:14 +00:00
|
|
|
|
2016-11-10 17:16:21 +00:00
|
|
|
// This might modify m_runtimeContext because it can access runtime functions at
|
|
|
|
// creation time.
|
|
|
|
ContractCompiler creationCompiler(&runtimeCompiler, m_context, m_optimize);
|
|
|
|
m_runtimeSub = creationCompiler.compileConstructor(_contract, _contracts);
|
2015-01-26 15:58:54 +00:00
|
|
|
|
2016-11-11 13:11:07 +00:00
|
|
|
m_context.optimise(m_optimize, m_optimizeRuns);
|
2014-12-15 21:57:39 +00:00
|
|
|
}
|
2014-11-19 09:24:22 +00:00
|
|
|
|
2015-07-31 17:23:31 +00:00
|
|
|
void Compiler::compileClone(
|
|
|
|
ContractDefinition const& _contract,
|
2015-09-10 10:01:05 +00:00
|
|
|
map<ContractDefinition const*, eth::Assembly const*> const& _contracts
|
2015-07-31 17:23:31 +00:00
|
|
|
)
|
|
|
|
{
|
2017-11-14 11:58:04 +00:00
|
|
|
solAssert(!_contract.isLibrary(), "");
|
2016-11-10 17:16:21 +00:00
|
|
|
ContractCompiler runtimeCompiler(nullptr, m_runtimeContext, m_optimize);
|
|
|
|
ContractCompiler cloneCompiler(&runtimeCompiler, m_context, m_optimize);
|
2016-05-19 17:32:14 +00:00
|
|
|
m_runtimeSub = cloneCompiler.compileClone(_contract, _contracts);
|
2015-07-31 17:23:31 +00:00
|
|
|
|
2016-11-11 13:11:07 +00:00
|
|
|
m_context.optimise(m_optimize, m_optimizeRuns);
|
2015-07-31 17:23:31 +00:00
|
|
|
}
|
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
eth::AssemblyItem Compiler::functionEntryLabel(FunctionDefinition const& _function) const
|
2015-05-26 09:27:59 +00:00
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
return m_runtimeContext.functionEntryLabelIfExists(_function);
|
2015-05-26 09:27:59 +00:00
|
|
|
}
|