mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Add ProgramSize metric
This commit is contained in:
@@ -16,3 +16,13 @@
|
||||
*/
|
||||
|
||||
#include <tools/yulPhaser/FitnessMetrics.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity::phaser;
|
||||
|
||||
size_t ProgramSize::evaluate(Chromosome const& _chromosome) const
|
||||
{
|
||||
Program programCopy = m_program;
|
||||
programCopy.optimise(_chromosome.optimisationSteps());
|
||||
return programCopy.codeSize();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <tools/yulPhaser/Chromosome.h>
|
||||
#include <tools/yulPhaser/Program.h>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
@@ -45,4 +46,19 @@ public:
|
||||
virtual size_t evaluate(Chromosome const& _chromosome) const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fitness metric based on the size of a specific program after applying the optimisations from the
|
||||
* chromosome to it.
|
||||
*/
|
||||
class ProgramSize: public FitnessMetric
|
||||
{
|
||||
public:
|
||||
ProgramSize(Program _program): m_program(std::move(_program)) {}
|
||||
|
||||
size_t evaluate(Chromosome const& _chromosome) const override;
|
||||
|
||||
private:
|
||||
Program m_program;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user