solidity/test/tools/ossfuzz/abiV2FuzzerCommon.cpp

43 lines
1.2 KiB
C++
Raw Normal View History

#include <test/tools/ossfuzz/abiV2FuzzerCommon.h>
2020-11-02 14:29:33 +00:00
#include <liblangutil/Exceptions.h>
2020-12-01 13:22:15 +00:00
#include <liblangutil/SourceReferenceFormatter.h>
2020-11-02 14:29:33 +00:00
using namespace solidity::test::abiv2fuzzer;
SolidityCompilationFramework::SolidityCompilationFramework(langutil::EVMVersion _evmVersion)
{
m_evmVersion = _evmVersion;
}
solidity::bytes SolidityCompilationFramework::compileContract(
std::string const& _sourceCode,
std::string const& _contractName,
std::map<std::string, solidity::util::h160> const& _libraryAddresses,
frontend::OptimiserSettings _optimization
)
{
std::string sourceCode = _sourceCode;
m_compiler.setSources({{"", sourceCode}});
m_compiler.setLibraries(_libraryAddresses);
m_compiler.setEVMVersion(m_evmVersion);
m_compiler.setOptimiserSettings(_optimization);
if (!m_compiler.compile())
{
2020-12-01 13:22:15 +00:00
langutil::SourceReferenceFormatter formatter(std::cerr, false, false);
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(
_contractName.empty() ?
m_compiler.lastContractName() :
_contractName
);
return obj.bytecode;
}