mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user