[yul-phaser] Add ProgramSize metric

This commit is contained in:
cameel
2020-02-19 16:36:14 +01:00
committed by Kamil Śliwak
parent 096129fbc4
commit 2238919c76
4 changed files with 107 additions and 0 deletions
+10
View File
@@ -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();
}
+16
View File
@@ -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;
};
}