mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Semantic tests for compilation via Yul.
This commit is contained in:
parent
420a7dc3d6
commit
141c6da534
@ -44,6 +44,12 @@ SemanticTest::SemanticTest(string const& _filename, string const& _ipcPath, lang
|
||||
file.exceptions(ios::badbit);
|
||||
|
||||
m_source = parseSourceAndSettings(file);
|
||||
if (m_settings.count("compileViaYul"))
|
||||
{
|
||||
m_validatedSettings["compileViaYul"] = m_settings["compileViaYul"];
|
||||
m_compileViaYul = true;
|
||||
m_settings.erase("compileViaYul");
|
||||
}
|
||||
parseExpectations(file);
|
||||
}
|
||||
|
||||
@ -105,7 +111,7 @@ void SemanticTest::parseExpectations(istream& _stream)
|
||||
{
|
||||
TestFileParser parser{_stream};
|
||||
auto functionCalls = parser.parseFunctionCalls();
|
||||
move(functionCalls.begin(), functionCalls.end(), back_inserter(m_tests));
|
||||
std::move(functionCalls.begin(), functionCalls.end(), back_inserter(m_tests));
|
||||
}
|
||||
|
||||
bool SemanticTest::deploy(string const& _contractName, u256 const& _value, bytes const& _arguments)
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
contract C {
|
||||
function f() public returns (uint) {
|
||||
}
|
||||
function g(uint x, uint y) public returns (uint) {
|
||||
}
|
||||
function h() public payable returns (uint) {
|
||||
}
|
||||
function i(bytes32 b) public returns (bytes32) {
|
||||
}
|
||||
function j(bool b) public returns (bool) {
|
||||
}
|
||||
function k(bytes32 b) public returns (bytes32) {
|
||||
}
|
||||
function s() public returns (uint256[] memory) {
|
||||
}
|
||||
function t(uint) public pure {
|
||||
}
|
||||
}
|
||||
// ===
|
||||
// compileViaYul: true
|
||||
// ----
|
||||
// f() -> 0
|
||||
// g(uint256,uint256): 1, -2 -> 0
|
||||
// h(), 1 ether -> 0
|
||||
// i(bytes32), 1 ether: 2 -> FAILURE
|
||||
// i(bytes32): 2 -> 0
|
||||
// j(bool): true -> false
|
||||
// k(bytes32): 0x31 -> 0x00
|
||||
// s(): hex"4200ef" -> 0x20, 0
|
||||
// t(uint256) -> FAILURE
|
6
test/libsolidity/semanticTests/viaYul/smoke_test.sol
Normal file
6
test/libsolidity/semanticTests/viaYul/smoke_test.sol
Normal file
@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: true
|
||||
// ----
|
||||
// f() -> FAILURE
|
Loading…
Reference in New Issue
Block a user