Merge pull request #2348 from ethereum/asmstack-analyze

Add analyze() to AssemblyStack
This commit is contained in:
chriseth 2017-06-08 15:45:41 +02:00 committed by GitHub
commit 21e0b69dcb
2 changed files with 22 additions and 0 deletions

View File

@ -43,6 +43,7 @@ Scanner const& AssemblyStack::scanner() const
bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string const& _source)
{
m_errors.clear();
m_analysisSuccessful = false;
m_scanner = make_shared<Scanner>(CharStream(_source), _sourceName);
m_parserResult = assembly::Parser(m_errorReporter, m_language == Language::JULIA).parse(m_scanner);
@ -50,6 +51,22 @@ bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string
return false;
solAssert(m_parserResult, "");
return analyzeParsed();
}
bool AssemblyStack::analyze(assembly::Block const& _block, Scanner const* _scanner)
{
m_errors.clear();
m_analysisSuccessful = false;
if (_scanner)
m_scanner = make_shared<Scanner>(*_scanner);
m_parserResult = make_shared<assembly::Block>(_block);
return analyzeParsed();
}
bool AssemblyStack::analyzeParsed()
{
m_analysisInfo = make_shared<assembly::AsmAnalysisInfo>();
assembly::AsmAnalyzer analyzer(*m_analysisInfo, m_errorReporter);
m_analysisSuccessful = analyzer.analyze(*m_parserResult);

View File

@ -60,6 +60,10 @@ public:
/// Multiple calls overwrite the previous state.
bool parseAndAnalyze(std::string const& _sourceName, std::string const& _source);
/// Runs analysis step on the supplied block, returns false if input cannot be assembled.
/// Multiple calls overwrite the previous state.
bool analyze(assembly::Block const& _block, Scanner const* _scanner = nullptr);
/// Run the assembly step (should only be called after parseAndAnalyze).
eth::LinkerObject assemble(Machine _machine);
@ -70,6 +74,7 @@ public:
std::string print();
private:
bool analyzeParsed();
Language m_language = Language::Assembly;