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:
@@ -38,11 +38,8 @@
|
||||
#include <libyul/optimiser/OptimiserStep.h>
|
||||
#include <libyul/optimiser/Suite.h>
|
||||
|
||||
#include <libsolutil/CommonIO.h>
|
||||
#include <libsolutil/JSON.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
@@ -60,10 +57,11 @@ ostream& operator<<(ostream& _stream, Program const& _program);
|
||||
|
||||
}
|
||||
|
||||
Program Program::load(string const& _sourcePath)
|
||||
Program Program::load(CharStream& _sourceCode)
|
||||
{
|
||||
// ASSUMPTION: parseSource() rewinds the stream on its own
|
||||
Dialect const& dialect = EVMDialect::strictAssemblyForEVMObjects(EVMVersion{});
|
||||
unique_ptr<Block> ast = parseSource(dialect, loadSource(_sourcePath));
|
||||
unique_ptr<Block> ast = parseSource(dialect, _sourceCode);
|
||||
unique_ptr<AsmAnalysisInfo> analysisInfo = analyzeAST(dialect, *ast);
|
||||
|
||||
Program program(
|
||||
@@ -95,14 +93,6 @@ string Program::toJson() const
|
||||
return jsonPrettyPrint(serializedAst);
|
||||
}
|
||||
|
||||
CharStream Program::loadSource(string const& _sourcePath)
|
||||
{
|
||||
assertThrow(boost::filesystem::exists(_sourcePath), InvalidProgram, "Source file does not exist");
|
||||
|
||||
string sourceCode = readFileAsString(_sourcePath);
|
||||
return CharStream(sourceCode, _sourcePath);
|
||||
}
|
||||
|
||||
unique_ptr<Block> Program::parseSource(Dialect const& _dialect, CharStream _source)
|
||||
{
|
||||
ErrorList errors;
|
||||
|
||||
Reference in New Issue
Block a user