2019-05-15 19:09:44 +00:00
|
|
|
#include <test/tools/ossfuzz/abiV2FuzzerCommon.h>
|
|
|
|
|
2019-12-23 15:50:30 +00:00
|
|
|
using namespace solidity::test::abiv2fuzzer;
|
2019-05-15 19:09:44 +00:00
|
|
|
|
|
|
|
SolidityCompilationFramework::SolidityCompilationFramework(langutil::EVMVersion _evmVersion)
|
|
|
|
{
|
|
|
|
m_evmVersion = _evmVersion;
|
|
|
|
}
|
|
|
|
|
2019-12-23 15:50:30 +00:00
|
|
|
solidity::bytes SolidityCompilationFramework::compileContract(
|
2019-05-15 19:09:44 +00:00
|
|
|
std::string const& _sourceCode,
|
2020-04-20 12:28:38 +00:00
|
|
|
std::string const& _contractName,
|
|
|
|
std::map<std::string, solidity::util::h160> const& _libraryAddresses,
|
|
|
|
frontend::OptimiserSettings _optimization
|
2019-05-15 19:09:44 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
std::string sourceCode = _sourceCode;
|
|
|
|
m_compiler.setSources({{"", sourceCode}});
|
2020-04-20 12:28:38 +00:00
|
|
|
m_compiler.setLibraries(_libraryAddresses);
|
2019-05-15 19:09:44 +00:00
|
|
|
m_compiler.setEVMVersion(m_evmVersion);
|
2020-04-20 12:28:38 +00:00
|
|
|
m_compiler.setOptimiserSettings(_optimization);
|
2019-05-15 19:09:44 +00:00
|
|
|
if (!m_compiler.compile())
|
|
|
|
{
|
|
|
|
langutil::SourceReferenceFormatter formatter(std::cerr);
|
|
|
|
|
|
|
|
for (auto const& error: m_compiler.errors())
|
|
|
|
formatter.printExceptionInformation(
|
|
|
|
*error,
|
|
|
|
formatter.formatErrorInformation(*error)
|
|
|
|
);
|
|
|
|
std::cerr << "Compiling contract failed" << std::endl;
|
|
|
|
}
|
2019-12-11 16:31:36 +00:00
|
|
|
evmasm::LinkerObject obj = m_compiler.object(
|
2019-05-15 19:09:44 +00:00
|
|
|
_contractName.empty() ?
|
|
|
|
m_compiler.lastContractName() :
|
|
|
|
_contractName
|
|
|
|
);
|
|
|
|
return obj.bytecode;
|
|
|
|
}
|