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
|
||||
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
namespace solidity::frontend
|
||||
{
|
||||
|
||||
enum class OptimisationPreset
|
||||
{
|
||||
None,
|
||||
Minimal,
|
||||
Standard,
|
||||
Full,
|
||||
};
|
||||
|
||||
struct OptimiserSettings
|
||||
{
|
||||
static char constexpr DefaultYulOptimiserSteps[] =
|
||||
@ -84,6 +94,18 @@ struct OptimiserSettings
|
||||
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
|
||||
{
|
||||
return
|
||||
|
@ -18,18 +18,12 @@
|
||||
|
||||
#include <test/TestCaseReader.h>
|
||||
|
||||
#include <libsolidity/parsing/Parser.h>
|
||||
#include <libsolutil/StringUtils.h>
|
||||
#include <libsolutil/CommonIO.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <range/v3/view/map.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity::langutil;
|
||||
using namespace solidity::frontend::test;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
@ -162,7 +156,7 @@ pair<SourceMap, size_t> TestCaseReader::parseSourcesAndSettingsWithLineNumber(is
|
||||
else
|
||||
externalSourceName = externalSourceString;
|
||||
|
||||
solAssert(!externalSourceName.empty(), "");
|
||||
soltestAssert(!externalSourceName.empty(), "");
|
||||
fs::path externalSourceTarget(externalSourceString);
|
||||
fs::path testCaseParentDir = m_fileName.parent_path();
|
||||
if (!externalSourceTarget.is_relative())
|
||||
|
@ -16,13 +16,21 @@
|
||||
*/
|
||||
// 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/throw_exception.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace solidity::frontend::test
|
||||
{
|
||||
|
||||
@ -58,6 +66,9 @@ public:
|
||||
size_t sizetSetting(std::string const& _name, size_t _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;
|
||||
|
||||
private:
|
||||
@ -71,4 +82,20 @@ private:
|
||||
std::map<std::string, std::string> m_settings;
|
||||
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 \
|
||||
{ \
|
||||
if (!(CONDITION)) \
|
||||
BOOST_THROW_EXCEPTION(runtime_error(DESCRIPTION)); \
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(DESCRIPTION)); \
|
||||
} \
|
||||
while (false)
|
||||
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
#include <test/libyul/ObjectCompilerTest.h>
|
||||
|
||||
#include <test/libsolidity/util/SoltestErrors.h>
|
||||
|
||||
#include <libsolutil/AnsiColorized.h>
|
||||
|
||||
#include <libyul/AssemblyStack.h>
|
||||
@ -43,7 +45,16 @@ ObjectCompilerTest::ObjectCompilerTest(string const& _filename):
|
||||
TestCase(_filename)
|
||||
{
|
||||
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_expectation = m_reader.simpleExpectations();
|
||||
}
|
||||
@ -53,7 +64,7 @@ TestCase::TestResult ObjectCompilerTest::run(ostream& _stream, string const& _li
|
||||
AssemblyStack stack(
|
||||
EVMVersion(),
|
||||
m_wasm ? AssemblyStack::Language::Ewasm : AssemblyStack::Language::StrictAssembly,
|
||||
m_optimize ? OptimiserSettings::full() : OptimiserSettings::minimal()
|
||||
OptimiserSettings::preset(m_optimisationPreset)
|
||||
);
|
||||
if (!stack.parseAndAnalyze("source", m_source))
|
||||
{
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include <test/TestCase.h>
|
||||
|
||||
#include <libsolidity/interface/OptimiserSettings.h>
|
||||
|
||||
namespace solidity::langutil
|
||||
{
|
||||
class Scanner;
|
||||
@ -54,7 +56,7 @@ private:
|
||||
|
||||
static void printErrors(std::ostream& _stream, langutil::ErrorList const& _errors);
|
||||
|
||||
bool m_optimize = false;
|
||||
frontend::OptimisationPreset m_optimisationPreset;
|
||||
bool m_wasm = false;
|
||||
};
|
||||
|
||||
|
@ -6,6 +6,8 @@ object "Contract" {
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// optimizationPreset: none
|
||||
// ----
|
||||
// Assembly:
|
||||
// /* "source":33:48 */
|
||||
|
@ -6,6 +6,8 @@ object "Contract" {
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// optimizationPreset: none
|
||||
// ----
|
||||
// Assembly:
|
||||
// /* "source":33:54 */
|
||||
|
@ -7,7 +7,7 @@ object "t" {
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// optimize: true
|
||||
// optimizationPreset: full
|
||||
// ----
|
||||
// Assembly:
|
||||
// /* "source":23:147 */
|
||||
|
@ -15,7 +15,7 @@ object "a" {
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// optimize: true
|
||||
// optimizationPreset: full
|
||||
// ----
|
||||
// Assembly:
|
||||
// /* "source":48:49 */
|
||||
|
@ -5,7 +5,7 @@
|
||||
sstore(add(x, 0), z)
|
||||
}
|
||||
// ====
|
||||
// optimize: true
|
||||
// optimizationPreset: full
|
||||
// ----
|
||||
// Assembly:
|
||||
// /* "source":26:27 */
|
||||
|
Loading…
Reference in New Issue
Block a user