mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] main: Add --seed option
This commit is contained in:
parent
f29d3655f7
commit
2f67302ffc
@ -18,6 +18,7 @@
|
||||
#include <tools/yulPhaser/Exceptions.h>
|
||||
#include <tools/yulPhaser/Population.h>
|
||||
#include <tools/yulPhaser/Program.h>
|
||||
#include <tools/yulPhaser/SimulationRNG.h>
|
||||
|
||||
#include <libsolutil/Assertions.h>
|
||||
#include <libsolutil/CommonIO.h>
|
||||
@ -45,6 +46,19 @@ struct CommandLineParsingResult
|
||||
po::variables_map arguments;
|
||||
};
|
||||
|
||||
|
||||
void initializeRNG(po::variables_map const& arguments)
|
||||
{
|
||||
uint32_t seed;
|
||||
if (arguments.count("seed") > 0)
|
||||
seed = arguments["seed"].as<uint32_t>();
|
||||
else
|
||||
seed = SimulationRNG::generateSeed();
|
||||
|
||||
SimulationRNG::reset(seed);
|
||||
cout << "Random seed: " << seed << endl;
|
||||
}
|
||||
|
||||
CharStream loadSource(string const& _sourcePath)
|
||||
{
|
||||
assertThrow(boost::filesystem::exists(_sourcePath), InvalidProgram, "Source file does not exist");
|
||||
@ -79,6 +93,7 @@ CommandLineParsingResult parseCommandLine(int argc, char** argv)
|
||||
description.add_options()
|
||||
("help", "Show help message and exit.")
|
||||
("input-file", po::value<string>()->required(), "Input file")
|
||||
("seed", po::value<uint32_t>(), "Seed for the random number generator")
|
||||
;
|
||||
|
||||
po::positional_options_description positionalDescription;
|
||||
@ -121,6 +136,8 @@ int main(int argc, char** argv)
|
||||
if (parsingResult.exitCode != 0)
|
||||
return parsingResult.exitCode;
|
||||
|
||||
initializeRNG(parsingResult.arguments);
|
||||
|
||||
try
|
||||
{
|
||||
runAlgorithm(parsingResult.arguments["input-file"].as<string>());
|
||||
|
Loading…
Reference in New Issue
Block a user