solidity/libsolidity/codegen/Compiler.cpp

64 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>
2018-12-17 16:06:11 +00:00
#include <libsolidity/codegen/ContractCompiler.h>
2018-12-17 16:06:11 +00:00
#include <libevmasm/Assembly.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,
std::map<ContractDefinition const*, shared_ptr<Compiler const>> const& _otherCompilers,
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
{
ContractCompiler runtimeCompiler(nullptr, m_runtimeContext, m_optimiserSettings, m_revertStrings);
runtimeCompiler.compileContract(_contract, _otherCompilers);
2016-11-29 16:47:47 +00:00
m_runtimeContext.appendAuxiliaryData(_metadata);
// This might modify m_runtimeContext because it can access runtime functions at
// creation time.
OptimiserSettings creationSettings{m_optimiserSettings};
// The creation code will be executed at most once, so we modify the optimizer
// settings accordingly.
creationSettings.expectedExecutionsPerDeployment = 1;
ContractCompiler creationCompiler(&runtimeCompiler, m_context, creationSettings, m_revertStrings);
m_runtimeSub = creationCompiler.compileConstructor(_contract, _otherCompilers);
2015-01-26 15:58:54 +00:00
2017-07-17 11:12:00 +00:00
m_context.optimise(m_optimiserSettings);
2014-12-15 21:57:39 +00:00
}
2014-11-19 09:24:22 +00:00
2019-01-16 10:44:11 +00:00
std::shared_ptr<eth::Assembly> Compiler::runtimeAssemblyPtr() const
{
solAssert(m_context.runtimeContext(), "");
return m_context.runtimeContext()->assemblyPtr();
}
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
}