[yul-phaser] Printing and JSON conversion for the Program class

This commit is contained in:
cameel 2020-01-23 10:27:50 +01:00
parent 2aa42b32e5
commit 3baa191b94
2 changed files with 25 additions and 1 deletions

View File

@ -25,7 +25,9 @@
#include <libyul/AsmAnalysis.h>
#include <libyul/AsmAnalysisInfo.h>
#include <libyul/AsmJsonConverter.h>
#include <libyul/AsmParser.h>
#include <libyul/AsmPrinter.h>
#include <libyul/YulString.h>
#include <libyul/backends/evm/EVMDialect.h>
#include <libyul/optimiser/Disambiguator.h>
@ -33,10 +35,10 @@
#include <libyul/optimiser/FunctionGrouper.h>
#include <libyul/optimiser/FunctionHoister.h>
#include <libyul/optimiser/Metrics.h>
#include <libyul/optimiser/Suite.h>
#include <libsolutil/CommonIO.h>
#include <libsolutil/JSON.h>
#include <boost/filesystem.hpp>
@ -50,6 +52,13 @@ using namespace solidity::yul;
using namespace solidity::util;
using namespace solidity::phaser;
namespace solidity::phaser
{
ostream& operator<<(ostream& _stream, Program const& _program);
}
set<YulString> const Program::s_externallyUsedIdentifiers = {};
Program Program::load(string const& _sourcePath)
@ -76,6 +85,17 @@ void Program::optimise(vector<string> const& _optimisationSteps)
applyOptimisationSteps(m_optimiserStepContext, *m_ast, _optimisationSteps);
}
ostream& phaser::operator<<(ostream& _stream, Program const& _program)
{
return _stream << AsmPrinter()(*_program.m_ast);
}
string Program::toJson() const
{
Json::Value serializedAst = AsmJsonConverter(0)(*m_ast);
return jsonPrettyPrint(serializedAst);
}
CharStream Program::loadSource(string const& _sourcePath)
{
assertThrow(boost::filesystem::exists(_sourcePath), InvalidProgram, "Source file does not exist");

View File

@ -24,6 +24,7 @@
#include <boost/noncopyable.hpp>
#include <optional>
#include <ostream>
#include <set>
#include <string>
#include <vector>
@ -73,6 +74,9 @@ public:
size_t codeSize() const { return computeCodeSize(*m_ast); }
yul::Block const& ast() const { return *m_ast; }
friend std::ostream& operator<<(std::ostream& _stream, Program const& _program);
std::string toJson() const;
private:
Program(
yul::Dialect const& _dialect,