mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Add print-optimised-programs and print-optimised-asts modes
This commit is contained in:
parent
1272a9335c
commit
d33ba54a38
@ -49,6 +49,8 @@ namespace
|
|||||||
map<PhaserMode, string> const PhaserModeToStringMap =
|
map<PhaserMode, string> const PhaserModeToStringMap =
|
||||||
{
|
{
|
||||||
{PhaserMode::RunAlgorithm, "run-algorithm"},
|
{PhaserMode::RunAlgorithm, "run-algorithm"},
|
||||||
|
{PhaserMode::PrintOptimisedPrograms, "print-optimised-programs"},
|
||||||
|
{PhaserMode::PrintOptimisedASTs, "print-optimised-asts"},
|
||||||
};
|
};
|
||||||
map<string, PhaserMode> const StringToPhaserModeMap = invertMap(PhaserModeToStringMap);
|
map<string, PhaserMode> const StringToPhaserModeMap = invertMap(PhaserModeToStringMap);
|
||||||
|
|
||||||
@ -642,11 +644,13 @@ void Phaser::runPhaser(po::variables_map const& _arguments)
|
|||||||
vector<Program> programs = ProgramFactory::build(programOptions);
|
vector<Program> programs = ProgramFactory::build(programOptions);
|
||||||
vector<shared_ptr<ProgramCache>> programCaches = ProgramCacheFactory::build(cacheOptions, programs);
|
vector<shared_ptr<ProgramCache>> programCaches = ProgramCacheFactory::build(cacheOptions, programs);
|
||||||
|
|
||||||
unique_ptr<FitnessMetric> fitnessMetric = FitnessMetricFactory::build(metricOptions, move(programs), programCaches);
|
unique_ptr<FitnessMetric> fitnessMetric = FitnessMetricFactory::build(metricOptions, programs, programCaches);
|
||||||
Population population = PopulationFactory::build(populationOptions, move(fitnessMetric));
|
Population population = PopulationFactory::build(populationOptions, move(fitnessMetric));
|
||||||
|
|
||||||
if (_arguments["mode"].as<PhaserMode>() == PhaserMode::RunAlgorithm)
|
if (_arguments["mode"].as<PhaserMode>() == PhaserMode::RunAlgorithm)
|
||||||
runAlgorithm(_arguments, move(population), move(programCaches));
|
runAlgorithm(_arguments, move(population), move(programCaches));
|
||||||
|
else
|
||||||
|
printOptimisedProgramsOrASTs(_arguments, population, move(programs), _arguments["mode"].as<PhaserMode>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Phaser::runAlgorithm(
|
void Phaser::runAlgorithm(
|
||||||
@ -665,3 +669,38 @@ void Phaser::runAlgorithm(
|
|||||||
AlgorithmRunner algorithmRunner(move(_population), move(_programCaches), buildAlgorithmRunnerOptions(_arguments), cout);
|
AlgorithmRunner algorithmRunner(move(_population), move(_programCaches), buildAlgorithmRunnerOptions(_arguments), cout);
|
||||||
algorithmRunner.run(*geneticAlgorithm);
|
algorithmRunner.run(*geneticAlgorithm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Phaser::printOptimisedProgramsOrASTs(
|
||||||
|
po::variables_map const& _arguments,
|
||||||
|
Population const& _population,
|
||||||
|
vector<Program> _programs,
|
||||||
|
PhaserMode phaserMode
|
||||||
|
)
|
||||||
|
{
|
||||||
|
assert(phaserMode == PhaserMode::PrintOptimisedPrograms || phaserMode == PhaserMode::PrintOptimisedASTs);
|
||||||
|
assert(_programs.size() == _arguments["input-files"].as<vector<string>>().size());
|
||||||
|
|
||||||
|
if (_population.individuals().size() == 0)
|
||||||
|
{
|
||||||
|
cout << "<EMPTY POPULATION>" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string> const& paths = _arguments["input-files"].as<vector<string>>();
|
||||||
|
for (auto& individual: _population.individuals())
|
||||||
|
{
|
||||||
|
cout << "Chromosome: " << individual.chromosome << endl;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < _programs.size(); ++i)
|
||||||
|
{
|
||||||
|
for (size_t j = 0; j < _arguments["chromosome-repetitions"].as<size_t>(); ++j)
|
||||||
|
_programs[i].optimise(individual.chromosome.optimisationSteps());
|
||||||
|
|
||||||
|
cout << "Program: " << paths[i] << endl;
|
||||||
|
if (phaserMode == PhaserMode::PrintOptimisedPrograms)
|
||||||
|
cout << _programs[i] << endl;
|
||||||
|
else
|
||||||
|
cout << _programs[i].toJson() << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -50,6 +50,8 @@ class ProgramCache;
|
|||||||
enum class PhaserMode
|
enum class PhaserMode
|
||||||
{
|
{
|
||||||
RunAlgorithm,
|
RunAlgorithm,
|
||||||
|
PrintOptimisedPrograms,
|
||||||
|
PrintOptimisedASTs,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Algorithm
|
enum class Algorithm
|
||||||
@ -236,6 +238,12 @@ private:
|
|||||||
Population _population,
|
Population _population,
|
||||||
std::vector<std::shared_ptr<ProgramCache>> _programCaches
|
std::vector<std::shared_ptr<ProgramCache>> _programCaches
|
||||||
);
|
);
|
||||||
|
static void printOptimisedProgramsOrASTs(
|
||||||
|
boost::program_options::variables_map const& _arguments,
|
||||||
|
Population const& _population,
|
||||||
|
std::vector<Program> _programs,
|
||||||
|
PhaserMode phaserMode
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user