mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] main: Command-line option for algorithm selection
This commit is contained in:
parent
fc4fedb214
commit
0c61f6d18f
@ -39,6 +39,34 @@ using namespace solidity::util;
|
|||||||
|
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
|
enum class Algorithm
|
||||||
|
{
|
||||||
|
Random
|
||||||
|
};
|
||||||
|
|
||||||
|
istream& operator>>(istream& inputStream, Algorithm& algorithm)
|
||||||
|
{
|
||||||
|
string value;
|
||||||
|
inputStream >> value;
|
||||||
|
|
||||||
|
if (value == "random")
|
||||||
|
algorithm = Algorithm::Random;
|
||||||
|
else
|
||||||
|
inputStream.setstate(ios_base::failbit);
|
||||||
|
|
||||||
|
return inputStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& outputStream, Algorithm algorithm)
|
||||||
|
{
|
||||||
|
if (algorithm == Algorithm::Random)
|
||||||
|
outputStream << "random";
|
||||||
|
else
|
||||||
|
outputStream.setstate(ios_base::failbit);
|
||||||
|
|
||||||
|
return outputStream;
|
||||||
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -69,7 +97,7 @@ CharStream loadSource(string const& _sourcePath)
|
|||||||
return CharStream(sourceCode, _sourcePath);
|
return CharStream(sourceCode, _sourcePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void runAlgorithm(string const& _sourcePath)
|
void runAlgorithm(string const& _sourcePath, Algorithm _algorithm)
|
||||||
{
|
{
|
||||||
constexpr size_t populationSize = 20;
|
constexpr size_t populationSize = 20;
|
||||||
constexpr size_t minChromosomeLength = 12;
|
constexpr size_t minChromosomeLength = 12;
|
||||||
@ -83,6 +111,11 @@ void runAlgorithm(string const& _sourcePath)
|
|||||||
minChromosomeLength,
|
minChromosomeLength,
|
||||||
maxChromosomeLength
|
maxChromosomeLength
|
||||||
);
|
);
|
||||||
|
|
||||||
|
switch (_algorithm)
|
||||||
|
{
|
||||||
|
case Algorithm::Random:
|
||||||
|
{
|
||||||
RandomAlgorithm(
|
RandomAlgorithm(
|
||||||
population,
|
population,
|
||||||
cout,
|
cout,
|
||||||
@ -92,6 +125,10 @@ void runAlgorithm(string const& _sourcePath)
|
|||||||
/* maxChromosomeLength = */ maxChromosomeLength,
|
/* maxChromosomeLength = */ maxChromosomeLength,
|
||||||
}
|
}
|
||||||
).run();
|
).run();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandLineParsingResult parseCommandLine(int argc, char** argv)
|
CommandLineParsingResult parseCommandLine(int argc, char** argv)
|
||||||
@ -114,6 +151,11 @@ CommandLineParsingResult parseCommandLine(int argc, char** argv)
|
|||||||
("help", "Show help message and exit.")
|
("help", "Show help message and exit.")
|
||||||
("input-file", po::value<string>()->required(), "Input file")
|
("input-file", po::value<string>()->required(), "Input file")
|
||||||
("seed", po::value<uint32_t>(), "Seed for the random number generator")
|
("seed", po::value<uint32_t>(), "Seed for the random number generator")
|
||||||
|
(
|
||||||
|
"algorithm",
|
||||||
|
po::value<Algorithm>()->default_value(Algorithm::Random),
|
||||||
|
"Algorithm"
|
||||||
|
)
|
||||||
;
|
;
|
||||||
|
|
||||||
po::positional_options_description positionalDescription;
|
po::positional_options_description positionalDescription;
|
||||||
@ -160,7 +202,10 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
runAlgorithm(parsingResult.arguments["input-file"].as<string>());
|
runAlgorithm(
|
||||||
|
parsingResult.arguments["input-file"].as<string>(),
|
||||||
|
parsingResult.arguments["algorithm"].as<Algorithm>()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch (InvalidProgram const& _exception)
|
catch (InvalidProgram const& _exception)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user