[yul-phaser] Make Program and Population classes accept source code rather than file path

- I need some sample .yul files for testing but I see that existing tests generally have source code hard-coded in them rather than in standalone .yul files. There are lots of .yul files but they seem to be automatically processed by a special test case rather loaded ad-hoc by manually created tests.
- Program and Population required a file name until now. I'm making them accept loaded source code to be able to give them data hard-coded in a test.
This commit is contained in:
cameel
2020-02-05 18:13:30 +01:00
parent 7b7c88ae95
commit 785f65d0f5
5 changed files with 37 additions and 30 deletions
+16 -1
View File
@@ -18,13 +18,20 @@
#include <tools/yulPhaser/Exceptions.h>
#include <tools/yulPhaser/Population.h>
#include <libsolutil/Assertions.h>
#include <libsolutil/CommonIO.h>
#include <liblangutil/CharStream.h>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <iostream>
#include <string>
using namespace std;
using namespace solidity::langutil;
using namespace solidity::phaser;
using namespace solidity::util;
namespace po = boost::program_options;
@@ -37,9 +44,17 @@ struct CommandLineParsingResult
po::variables_map arguments;
};
CharStream loadSource(string const& _sourcePath)
{
assertThrow(boost::filesystem::exists(_sourcePath), InvalidProgram, "Source file does not exist");
string sourceCode = readFileAsString(_sourcePath);
return CharStream(sourceCode, _sourcePath);
}
void runAlgorithm(string const& _sourcePath)
{
auto population = Population::makeRandom(_sourcePath, 10);
auto population = Population::makeRandom(loadSource(_sourcePath), 10);
population.run(nullopt, cout);
}