Semantic tests for compilation via Yul.

This commit is contained in:
chriseth
2019-04-04 15:02:43 +02:00
parent 420a7dc3d6
commit 141c6da534
4 changed files with 74 additions and 2 deletions
+31 -1
View File
@@ -27,6 +27,9 @@
#include <test/ExecutionFramework.h>
#include <libsolidity/interface/CompilerStack.h>
#include <libyul/AssemblyStack.h>
#include <liblangutil/Exceptions.h>
#include <liblangutil/SourceReferenceFormatter.h>
@@ -74,6 +77,7 @@ public:
m_compiler.setLibraries(_libraryAddresses);
m_compiler.setEVMVersion(m_evmVersion);
m_compiler.setOptimiserSettings(m_optimiserSettings);
m_compiler.enableIRGeneration(m_compileViaYul);
if (!m_compiler.compile())
{
langutil::SourceReferenceFormatter formatter(std::cerr);
@@ -85,13 +89,39 @@ public:
);
BOOST_ERROR("Compiling contract failed");
}
eth::LinkerObject obj = m_compiler.object(_contractName.empty() ? m_compiler.lastContractName() : _contractName);
eth::LinkerObject obj;
if (m_compileViaYul)
{
yul::AssemblyStack asmStack(
m_evmVersion,
yul::AssemblyStack::Language::StrictAssembly,
m_optimiserSettings
);
if (!asmStack.parseAndAnalyze("", m_compiler.yulIROptimized(
_contractName.empty() ? m_compiler.lastContractName() : _contractName
)))
{
langutil::SourceReferenceFormatter formatter(std::cerr);
for (auto const& error: m_compiler.errors())
formatter.printExceptionInformation(
*error,
(error->type() == langutil::Error::Type::Warning) ? "Warning" : "Error"
);
BOOST_ERROR("Assembly contract failed. IR: " + m_compiler.yulIROptimized({}));
}
asmStack.optimize();
obj = std::move(*asmStack.assemble(yul::AssemblyStack::Machine::EVM).bytecode);
}
else
obj = m_compiler.object(_contractName.empty() ? m_compiler.lastContractName() : _contractName);
BOOST_REQUIRE(obj.linkReferences.empty());
return obj.bytecode;
}
protected:
dev::solidity::CompilerStack m_compiler;
bool m_compileViaYul = false;
};
}