mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
OptimiserSuite: Allow validating the optimisation sequence without executing it
- Create a separate validateSequence() that can be used independently. - Tweak the exception messages a bit to be usable as command-line errors
This commit is contained in:
parent
e2c0e6331c
commit
69b79f848b
@ -253,22 +253,21 @@ map<char, string> const& OptimiserSuite::stepAbbreviationToNameMap()
|
||||
return lookupTable;
|
||||
}
|
||||
|
||||
void OptimiserSuite::runSequence(string const& _stepAbbreviations, Block& _ast)
|
||||
void OptimiserSuite::validateSequence(string const& _stepAbbreviations)
|
||||
{
|
||||
string input = _stepAbbreviations;
|
||||
boost::remove_erase(input, ' ');
|
||||
boost::remove_erase(input, '\n');
|
||||
|
||||
bool insideLoop = false;
|
||||
for (char abbreviation: input)
|
||||
for (char abbreviation: _stepAbbreviations)
|
||||
switch (abbreviation)
|
||||
{
|
||||
case ' ':
|
||||
case '\n':
|
||||
break;
|
||||
case '[':
|
||||
assertThrow(!insideLoop, OptimizerException, "Nested brackets not supported");
|
||||
assertThrow(!insideLoop, OptimizerException, "Nested brackets are not supported");
|
||||
insideLoop = true;
|
||||
break;
|
||||
case ']':
|
||||
assertThrow(insideLoop, OptimizerException, "Unbalanced bracket");
|
||||
assertThrow(insideLoop, OptimizerException, "Unbalanced brackets");
|
||||
insideLoop = false;
|
||||
break;
|
||||
default:
|
||||
@ -279,10 +278,19 @@ void OptimiserSuite::runSequence(string const& _stepAbbreviations, Block& _ast)
|
||||
assertThrow(
|
||||
stepAbbreviationToNameMap().find(abbreviation) != stepAbbreviationToNameMap().end(),
|
||||
OptimizerException,
|
||||
"Invalid optimisation step abbreviation"
|
||||
"'"s + abbreviation + "' is not a valid step abbreviation"
|
||||
);
|
||||
}
|
||||
assertThrow(!insideLoop, OptimizerException, "Unbalanced bracket");
|
||||
assertThrow(!insideLoop, OptimizerException, "Unbalanced brackets");
|
||||
}
|
||||
|
||||
void OptimiserSuite::runSequence(string const& _stepAbbreviations, Block& _ast)
|
||||
{
|
||||
validateSequence(_stepAbbreviations);
|
||||
|
||||
string input = _stepAbbreviations;
|
||||
boost::remove_erase(input, ' ');
|
||||
boost::remove_erase(input, '\n');
|
||||
|
||||
auto abbreviationsToSteps = [](string const& _sequence) -> vector<string>
|
||||
{
|
||||
|
@ -65,6 +65,10 @@ public:
|
||||
std::set<YulString> const& _externallyUsedIdentifiers = {}
|
||||
);
|
||||
|
||||
/// Ensures that specified sequence of step abbreviations is well-formed and can be executed.
|
||||
/// @throw OptimizerException if the sequence is invalid
|
||||
static void validateSequence(std::string const& _stepAbbreviations);
|
||||
|
||||
void runSequence(std::vector<std::string> const& _steps, Block& _ast);
|
||||
void runSequence(std::string const& _stepAbbreviations, Block& _ast);
|
||||
void runSequenceUntilStable(
|
||||
|
Loading…
Reference in New Issue
Block a user