-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
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/libsolidity/OptimizedIRCachingTest.h> | ||
#include <test/libsolidity/util/SoltestErrors.h> | ||
|
||
#include <liblangutil/Exceptions.h> | ||
|
||
#include <libsolutil/StringUtils.h> | ||
|
||
using namespace solidity::util; | ||
using namespace solidity::langutil; | ||
using namespace solidity::frontend; | ||
using namespace solidity::frontend::test; | ||
|
||
void OptimizedIRCachingTest::setupCompiler(CompilerStack& _compiler) | ||
{ | ||
AnalysisFramework::setupCompiler(_compiler); | ||
_compiler.setOptimiserSettings(true); | ||
_compiler.setViaIR(true); | ||
} | ||
|
||
TestCase::TestResult OptimizedIRCachingTest::run(std::ostream& _stream, std::string const& _linePrefix, bool _formatted) | ||
{ | ||
soltestAssert(compiler().objectOptimizer().size() == 0); | ||
|
||
if (!runFramework(m_source, PipelineStage::Compilation)) | ||
{ | ||
printPrefixed(_stream, formatErrors(filteredErrors(), _formatted), _linePrefix); | ||
return TestResult::FatalError; | ||
} | ||
|
||
m_obtainedResult = "cachedObjects: " + toString(compiler().objectOptimizer().size()) + "\n"; | ||
return checkResult(_stream, _linePrefix, _formatted); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
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 | ||
/** | ||
* Unit tests for the optimized IR caching in CompilerStack. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <test/libsolidity/AnalysisFramework.h> | ||
#include <test/TestCase.h> | ||
|
||
#include <ostream> | ||
#include <string> | ||
|
||
namespace solidity::frontend::test | ||
{ | ||
|
||
class OptimizedIRCachingTest: public AnalysisFramework, public EVMVersionRestrictedTestCase | ||
{ | ||
public: | ||
OptimizedIRCachingTest(std::string const& _filename): | ||
EVMVersionRestrictedTestCase(_filename) | ||
{ | ||
m_source = m_reader.source(); | ||
m_expectation = m_reader.simpleExpectations(); | ||
} | ||
|
||
static std::unique_ptr<TestCase> create(Config const& _config) | ||
{ | ||
return std::make_unique<OptimizedIRCachingTest>(_config.filename); | ||
} | ||
|
||
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override; | ||
|
||
protected: | ||
void setupCompiler(CompilerStack& _compiler) override; | ||
}; | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
test/libsolidity/optimizedIRCaching/bytecode_dependency_creation.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
contract A {} | ||
|
||
contract C { | ||
A a = new A(); | ||
} | ||
// ---- | ||
// cachedObjects: 4 |
12 changes: 12 additions & 0 deletions
12
test/libsolidity/optimizedIRCaching/bytecode_dependency_creation_and_runtime.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
contract A {} | ||
contract B {} | ||
|
||
contract C { | ||
A a = new A(); | ||
|
||
function f() public returns (B) { | ||
return new B(); | ||
} | ||
} | ||
// ---- | ||
// cachedObjects: 6 |
11 changes: 11 additions & 0 deletions
11
test/libsolidity/optimizedIRCaching/bytecode_dependency_creation_and_runtime_shared.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
contract A {} | ||
|
||
contract C { | ||
A a = new A(); | ||
|
||
function f() public returns (A) { | ||
return new A(); | ||
} | ||
} | ||
// ---- | ||
// cachedObjects: 4 |
9 changes: 9 additions & 0 deletions
9
test/libsolidity/optimizedIRCaching/bytecode_dependency_runtime.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
contract A {} | ||
|
||
contract C { | ||
function f() public returns (A) { | ||
return new A(); | ||
} | ||
} | ||
// ---- | ||
// cachedObjects: 4 |
19 changes: 19 additions & 0 deletions
19
test/libsolidity/optimizedIRCaching/bytecode_dependency_shared_by_multiple_contracts.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
contract A {} | ||
|
||
contract C { | ||
A a = new A(); | ||
|
||
function f() public returns (A) { | ||
return new A(); | ||
} | ||
} | ||
|
||
contract D { | ||
A a = new A(); | ||
|
||
function f() public returns (A) { | ||
return new A(); | ||
} | ||
} | ||
// ---- | ||
// cachedObjects: 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
contract C {} | ||
contract D {} | ||
contract E {} | ||
// ---- | ||
// cachedObjects: 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// ---- | ||
// cachedObjects: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract C {} | ||
// ---- | ||
// cachedObjects: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters