solidity/libsolidity/codegen/Compiler.cpp

69 lines
2.2 KiB
C++
Raw Normal View History

2014-10-20 10:41:56 +00:00
/*
This file is part of solidity.
2014-10-20 10:41:56 +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.
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
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
* Solidity compiler.
2014-10-20 10:41:56 +00:00
*/
2015-10-20 22:21:52 +00:00
#include <libsolidity/codegen/Compiler.h>
#include <libevmasm/Assembly.h>
#include <libsolidity/codegen/ContractCompiler.h>
using namespace std;
using namespace dev;
using namespace dev::solidity;
2014-10-20 10:41:56 +00:00
void Compiler::compileContract(
ContractDefinition const& _contract,
2015-09-11 13:25:00 +00:00
std::map<const ContractDefinition*, eth::Assembly const*> const& _contracts
)
2014-10-20 10:41:56 +00:00
{
ContractCompiler runtimeCompiler(nullptr, m_runtimeContext, m_optimize);
runtimeCompiler.compileContract(_contract, _contracts);
// 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
m_context.optimise(m_optimize, m_optimizeRuns);
2015-10-06 12:13:07 +00:00
if (_contract.isLibrary())
{
solAssert(m_runtimeSub != size_t(-1), "");
m_context.injectVersionStampIntoSub(m_runtimeSub);
}
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,
map<ContractDefinition const*, eth::Assembly const*> const& _contracts
2015-07-31 17:23:31 +00:00
)
{
ContractCompiler runtimeCompiler(nullptr, m_runtimeContext, m_optimize);
ContractCompiler cloneCompiler(&runtimeCompiler, m_context, m_optimize);
m_runtimeSub = cloneCompiler.compileClone(_contract, _contracts);
2015-07-31 17:23:31 +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
}