-
Notifications
You must be signed in to change notification settings - Fork 6.1k
/
Copy pathSSAControlFlowGraphTest.cpp
112 lines (94 loc) · 3.75 KB
/
SSAControlFlowGraphTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
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,
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/>.
*/
// SPDX-License-Identifier: GPL-3.0
#include <test/libyul/SSAControlFlowGraphTest.h>
#include <test/libyul/Common.h>
#include <test/Common.h>
#include <libyul/backends/evm/SSAControlFlowGraphBuilder.h>
#include <libyul/backends/evm/StackHelpers.h>
#include <libyul/AsmAnalysis.h>
#include <libyul/Object.h>
#include <libyul/YulStack.h>
#ifdef ISOLTEST
#include <boost/version.hpp>
#if (BOOST_VERSION < 108800)
#include <boost/process.hpp>
#else
#define BOOST_PROCESS_VERSION 1
#include <boost/process/v1/child.hpp>
#include <boost/process/v1/io.hpp>
#include <boost/process/v1/pipe.hpp>
#endif
#endif
using namespace solidity;
using namespace solidity::util;
using namespace solidity::langutil;
using namespace solidity::yul;
using namespace solidity::yul::test;
using namespace solidity::frontend;
using namespace solidity::frontend::test;
std::unique_ptr<TestCase> SSAControlFlowGraphTest::create(TestCase::Config const& _config) {
return std::make_unique<SSAControlFlowGraphTest>(_config.filename);
}
SSAControlFlowGraphTest::SSAControlFlowGraphTest(std::string const& _filename): TestCase(_filename)
{
m_source = m_reader.source();
auto dialectName = m_reader.stringSetting("dialect", "evm");
soltestAssert(dialectName == "evm"); // We only have one dialect now
m_expectation = m_reader.simpleExpectations();
}
TestCase::TestResult SSAControlFlowGraphTest::run(std::ostream& _stream, std::string const& _linePrefix, bool const _formatted)
{
YulStack yulStack = parseYul(m_source);
solUnimplementedAssert(yulStack.parserResult()->subObjects.empty(), "Tests with subobjects not supported.");
if (yulStack.hasErrors())
{
printYulErrors(yulStack, _stream, _linePrefix, _formatted);
return TestResult::FatalError;
}
std::unique_ptr<ControlFlow> controlFlow = SSAControlFlowGraphBuilder::build(
*yulStack.parserResult()->analysisInfo,
yulStack.dialect(),
yulStack.parserResult()->code()->root()
);
ControlFlowLiveness liveness(*controlFlow);
m_obtainedResult = controlFlow->toDot(&liveness);
auto result = checkResult(_stream, _linePrefix, _formatted);
#ifdef ISOLTEST
char* graphDisplayer = nullptr;
// The environment variables specify an optional command that will receive the graph encoded in DOT through stdin.
// Examples for suitable commands are ``dot -Tx11:cairo`` or ``xdot -``.
if (result == TestResult::Failure)
// ISOLTEST_DISPLAY_GRAPHS_ON_FAILURE_COMMAND will run on all failing tests (intended for use during modifications).
graphDisplayer = getenv("ISOLTEST_DISPLAY_GRAPHS_ON_FAILURE_COMMAND");
else if (result == TestResult::Success)
// ISOLTEST_DISPLAY_GRAPHS_ON_FAILURE_COMMAND will run on all succeeding tests (intended for use during reviews).
graphDisplayer = getenv("ISOLTEST_DISPLAY_GRAPHS_ON_SUCCESS_COMMAND");
if (graphDisplayer)
{
if (result == TestResult::Success)
std::cout << std::endl << m_source << std::endl;
boost::process::opstream pipe;
boost::process::child child(graphDisplayer, boost::process::std_in < pipe);
pipe << m_obtainedResult;
pipe.flush();
pipe.pipe().close();
if (result == TestResult::Success)
child.wait();
else
child.detach();
}
#endif
return result;
}