mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11319 from ethereum/optimization-level-in-object-compiler-test
optimizationPreset setting in object compiler tests + refactor
This commit is contained in:
commit
b5b8833116
@ -23,12 +23,22 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <liblangutil/Exceptions.h>
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace solidity::frontend
|
namespace solidity::frontend
|
||||||
{
|
{
|
||||||
|
|
||||||
|
enum class OptimisationPreset
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Minimal,
|
||||||
|
Standard,
|
||||||
|
Full,
|
||||||
|
};
|
||||||
|
|
||||||
struct OptimiserSettings
|
struct OptimiserSettings
|
||||||
{
|
{
|
||||||
static char constexpr DefaultYulOptimiserSteps[] =
|
static char constexpr DefaultYulOptimiserSteps[] =
|
||||||
@ -84,6 +94,18 @@ struct OptimiserSettings
|
|||||||
return standard();
|
return standard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static OptimiserSettings preset(OptimisationPreset _preset)
|
||||||
|
{
|
||||||
|
switch (_preset)
|
||||||
|
{
|
||||||
|
case OptimisationPreset::None: return none();
|
||||||
|
case OptimisationPreset::Minimal: return minimal();
|
||||||
|
case OptimisationPreset::Standard: return standard();
|
||||||
|
case OptimisationPreset::Full: return full();
|
||||||
|
default: solAssert(false, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(OptimiserSettings const& _other) const
|
bool operator==(OptimiserSettings const& _other) const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
|
@ -18,18 +18,12 @@
|
|||||||
|
|
||||||
#include <test/TestCaseReader.h>
|
#include <test/TestCaseReader.h>
|
||||||
|
|
||||||
#include <libsolidity/parsing/Parser.h>
|
|
||||||
#include <libsolutil/StringUtils.h>
|
|
||||||
#include <libsolutil/CommonIO.h>
|
#include <libsolutil/CommonIO.h>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/throw_exception.hpp>
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include <range/v3/view/map.hpp>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace solidity::langutil;
|
|
||||||
using namespace solidity::frontend::test;
|
using namespace solidity::frontend::test;
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
@ -162,7 +156,7 @@ pair<SourceMap, size_t> TestCaseReader::parseSourcesAndSettingsWithLineNumber(is
|
|||||||
else
|
else
|
||||||
externalSourceName = externalSourceString;
|
externalSourceName = externalSourceString;
|
||||||
|
|
||||||
solAssert(!externalSourceName.empty(), "");
|
soltestAssert(!externalSourceName.empty(), "");
|
||||||
fs::path externalSourceTarget(externalSourceString);
|
fs::path externalSourceTarget(externalSourceString);
|
||||||
fs::path testCaseParentDir = m_fileName.parent_path();
|
fs::path testCaseParentDir = m_fileName.parent_path();
|
||||||
if (!externalSourceTarget.is_relative())
|
if (!externalSourceTarget.is_relative())
|
||||||
|
@ -16,13 +16,21 @@
|
|||||||
*/
|
*/
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <test/libsolidity/util/SoltestErrors.h>
|
||||||
|
|
||||||
|
#include <libsolutil/StringUtils.h>
|
||||||
|
|
||||||
|
#include <range/v3/view/map.hpp>
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/throw_exception.hpp>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace solidity::frontend::test
|
namespace solidity::frontend::test
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -58,6 +66,9 @@ public:
|
|||||||
size_t sizetSetting(std::string const& _name, size_t _defaultValue);
|
size_t sizetSetting(std::string const& _name, size_t _defaultValue);
|
||||||
std::string stringSetting(std::string const& _name, std::string const& _defaultValue);
|
std::string stringSetting(std::string const& _name, std::string const& _defaultValue);
|
||||||
|
|
||||||
|
template <typename E>
|
||||||
|
E enumSetting(std::string const& _name, std::map<std::string, E> const& _choices, std::string const& _defaultChoice);
|
||||||
|
|
||||||
void ensureAllSettingsRead() const;
|
void ensureAllSettingsRead() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -71,4 +82,20 @@ private:
|
|||||||
std::map<std::string, std::string> m_settings;
|
std::map<std::string, std::string> m_settings;
|
||||||
std::map<std::string, std::string> m_unreadSettings; ///< tracks which settings are left unread
|
std::map<std::string, std::string> m_unreadSettings; ///< tracks which settings are left unread
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename E>
|
||||||
|
E TestCaseReader::enumSetting(std::string const& _name, std::map<std::string, E> const& _choices, std::string const& _defaultChoice)
|
||||||
|
{
|
||||||
|
soltestAssert(_choices.count(_defaultChoice) > 0, "");
|
||||||
|
|
||||||
|
std::string value = stringSetting(_name, _defaultChoice);
|
||||||
|
|
||||||
|
if (_choices.count(value) == 0)
|
||||||
|
BOOST_THROW_EXCEPTION(std::runtime_error(
|
||||||
|
"Invalid Enum value: " + value + ". Available choices: " + util::joinHumanReadable(_choices | ranges::views::keys) + "."
|
||||||
|
));
|
||||||
|
|
||||||
|
return _choices.at(value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace solidity::frontend::test
|
|||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
if (!(CONDITION)) \
|
if (!(CONDITION)) \
|
||||||
BOOST_THROW_EXCEPTION(runtime_error(DESCRIPTION)); \
|
BOOST_THROW_EXCEPTION(std::runtime_error(DESCRIPTION)); \
|
||||||
} \
|
} \
|
||||||
while (false)
|
while (false)
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
#include <test/libyul/ObjectCompilerTest.h>
|
#include <test/libyul/ObjectCompilerTest.h>
|
||||||
|
|
||||||
|
#include <test/libsolidity/util/SoltestErrors.h>
|
||||||
|
|
||||||
#include <libsolutil/AnsiColorized.h>
|
#include <libsolutil/AnsiColorized.h>
|
||||||
|
|
||||||
#include <libyul/AssemblyStack.h>
|
#include <libyul/AssemblyStack.h>
|
||||||
@ -43,7 +45,16 @@ ObjectCompilerTest::ObjectCompilerTest(string const& _filename):
|
|||||||
TestCase(_filename)
|
TestCase(_filename)
|
||||||
{
|
{
|
||||||
m_source = m_reader.source();
|
m_source = m_reader.source();
|
||||||
m_optimize = m_reader.boolSetting("optimize", false);
|
m_optimisationPreset = m_reader.enumSetting<OptimisationPreset>(
|
||||||
|
"optimizationPreset",
|
||||||
|
{
|
||||||
|
{"none", OptimisationPreset::None},
|
||||||
|
{"minimal", OptimisationPreset::Minimal},
|
||||||
|
{"standard", OptimisationPreset::Standard},
|
||||||
|
{"full", OptimisationPreset::Full},
|
||||||
|
},
|
||||||
|
"minimal"
|
||||||
|
);
|
||||||
m_wasm = m_reader.boolSetting("wasm", false);
|
m_wasm = m_reader.boolSetting("wasm", false);
|
||||||
m_expectation = m_reader.simpleExpectations();
|
m_expectation = m_reader.simpleExpectations();
|
||||||
}
|
}
|
||||||
@ -53,7 +64,7 @@ TestCase::TestResult ObjectCompilerTest::run(ostream& _stream, string const& _li
|
|||||||
AssemblyStack stack(
|
AssemblyStack stack(
|
||||||
EVMVersion(),
|
EVMVersion(),
|
||||||
m_wasm ? AssemblyStack::Language::Ewasm : AssemblyStack::Language::StrictAssembly,
|
m_wasm ? AssemblyStack::Language::Ewasm : AssemblyStack::Language::StrictAssembly,
|
||||||
m_optimize ? OptimiserSettings::full() : OptimiserSettings::minimal()
|
OptimiserSettings::preset(m_optimisationPreset)
|
||||||
);
|
);
|
||||||
if (!stack.parseAndAnalyze("source", m_source))
|
if (!stack.parseAndAnalyze("source", m_source))
|
||||||
{
|
{
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include <test/TestCase.h>
|
#include <test/TestCase.h>
|
||||||
|
|
||||||
|
#include <libsolidity/interface/OptimiserSettings.h>
|
||||||
|
|
||||||
namespace solidity::langutil
|
namespace solidity::langutil
|
||||||
{
|
{
|
||||||
class Scanner;
|
class Scanner;
|
||||||
@ -54,7 +56,7 @@ private:
|
|||||||
|
|
||||||
static void printErrors(std::ostream& _stream, langutil::ErrorList const& _errors);
|
static void printErrors(std::ostream& _stream, langutil::ErrorList const& _errors);
|
||||||
|
|
||||||
bool m_optimize = false;
|
frontend::OptimisationPreset m_optimisationPreset;
|
||||||
bool m_wasm = false;
|
bool m_wasm = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ object "Contract" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// optimizationPreset: none
|
||||||
// ----
|
// ----
|
||||||
// Assembly:
|
// Assembly:
|
||||||
// /* "source":33:48 */
|
// /* "source":33:48 */
|
||||||
|
@ -6,6 +6,8 @@ object "Contract" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// optimizationPreset: none
|
||||||
// ----
|
// ----
|
||||||
// Assembly:
|
// Assembly:
|
||||||
// /* "source":33:54 */
|
// /* "source":33:54 */
|
||||||
|
@ -7,7 +7,7 @@ object "t" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ====
|
// ====
|
||||||
// optimize: true
|
// optimizationPreset: full
|
||||||
// ----
|
// ----
|
||||||
// Assembly:
|
// Assembly:
|
||||||
// /* "source":23:147 */
|
// /* "source":23:147 */
|
||||||
|
@ -15,7 +15,7 @@ object "a" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ====
|
// ====
|
||||||
// optimize: true
|
// optimizationPreset: full
|
||||||
// ----
|
// ----
|
||||||
// Assembly:
|
// Assembly:
|
||||||
// /* "source":48:49 */
|
// /* "source":48:49 */
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
sstore(add(x, 0), z)
|
sstore(add(x, 0), z)
|
||||||
}
|
}
|
||||||
// ====
|
// ====
|
||||||
// optimize: true
|
// optimizationPreset: full
|
||||||
// ----
|
// ----
|
||||||
// Assembly:
|
// Assembly:
|
||||||
// /* "source":26:27 */
|
// /* "source":26:27 */
|
||||||
|
Loading…
Reference in New Issue
Block a user