mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move analysis out of code generator.
This commit is contained in:
@@ -59,7 +59,11 @@ class AsmAnalyzer: public boost::static_visitor<bool>
|
||||
{
|
||||
public:
|
||||
using Scopes = std::map<assembly::Block const*, std::shared_ptr<Scope>>;
|
||||
AsmAnalyzer(Scopes& _scopes, ErrorList& _errors, ExternalIdentifierAccess::Resolver const& _resolver);
|
||||
AsmAnalyzer(
|
||||
Scopes& _scopes,
|
||||
ErrorList& _errors,
|
||||
ExternalIdentifierAccess::Resolver const& _resolver = ExternalIdentifierAccess::Resolver()
|
||||
);
|
||||
|
||||
bool analyze(assembly::Block const& _block);
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@ using namespace dev::solidity::assembly;
|
||||
|
||||
struct GeneratorState
|
||||
{
|
||||
GeneratorState(ErrorList& _errors, eth::Assembly& _assembly):
|
||||
errors(_errors), assembly(_assembly) {}
|
||||
GeneratorState(ErrorList& _errors, AsmAnalyzer::Scopes& _scopes, eth::Assembly& _assembly):
|
||||
errors(_errors), scopes(_scopes), assembly(_assembly) {}
|
||||
|
||||
size_t newLabelId()
|
||||
{
|
||||
@@ -62,8 +62,8 @@ struct GeneratorState
|
||||
return size_t(id);
|
||||
}
|
||||
|
||||
AsmAnalyzer::Scopes scopes;
|
||||
ErrorList& errors;
|
||||
AsmAnalyzer::Scopes scopes;
|
||||
eth::Assembly& assembly;
|
||||
};
|
||||
|
||||
@@ -260,20 +260,25 @@ private:
|
||||
ExternalIdentifierAccess m_identifierAccess;
|
||||
};
|
||||
|
||||
eth::Assembly assembly::CodeGenerator::assemble(ExternalIdentifierAccess const& _identifierAccess)
|
||||
eth::Assembly assembly::CodeGenerator::assemble(
|
||||
Block const& _parsedData,
|
||||
AsmAnalyzer::Scopes& _scopes,
|
||||
ExternalIdentifierAccess const& _identifierAccess
|
||||
)
|
||||
{
|
||||
eth::Assembly assembly;
|
||||
GeneratorState state(m_errors, assembly);
|
||||
if (!(AsmAnalyzer(state.scopes, m_errors, _identifierAccess.resolve)).analyze(m_parsedData))
|
||||
solAssert(false, "Assembly error");
|
||||
CodeTransform(state, m_parsedData, _identifierAccess);
|
||||
GeneratorState state(m_errors, _scopes, assembly);
|
||||
CodeTransform(state, _parsedData, _identifierAccess);
|
||||
return assembly;
|
||||
}
|
||||
|
||||
void assembly::CodeGenerator::assemble(eth::Assembly& _assembly, ExternalIdentifierAccess const& _identifierAccess)
|
||||
void assembly::CodeGenerator::assemble(
|
||||
Block const& _parsedData,
|
||||
AsmAnalyzer::Scopes& _scopes,
|
||||
eth::Assembly& _assembly,
|
||||
ExternalIdentifierAccess const& _identifierAccess
|
||||
)
|
||||
{
|
||||
GeneratorState state(m_errors, _assembly);
|
||||
if (!(AsmAnalyzer(state.scopes, m_errors, _identifierAccess.resolve)).analyze(m_parsedData))
|
||||
solAssert(false, "Assembly error");
|
||||
CodeTransform(state, m_parsedData, _identifierAccess);
|
||||
GeneratorState state(m_errors, _scopes, _assembly);
|
||||
CodeTransform(state, _parsedData, _identifierAccess);
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/inlineasm/AsmAnalysis.h>
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <libsolidity/inlineasm/AsmStack.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
@@ -42,15 +42,23 @@ struct Block;
|
||||
class CodeGenerator
|
||||
{
|
||||
public:
|
||||
CodeGenerator(Block const& _parsedData, ErrorList& _errors):
|
||||
m_parsedData(_parsedData), m_errors(_errors) {}
|
||||
CodeGenerator(ErrorList& _errors):
|
||||
m_errors(_errors) {}
|
||||
/// Performs code generation and @returns the result.
|
||||
eth::Assembly assemble(ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess());
|
||||
eth::Assembly assemble(
|
||||
Block const& _parsedData,
|
||||
AsmAnalyzer::Scopes& _scopes,
|
||||
ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess()
|
||||
);
|
||||
/// Performs code generation and appends generated to to _assembly.
|
||||
void assemble(eth::Assembly& _assembly, ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess());
|
||||
void assemble(
|
||||
Block const& _parsedData,
|
||||
AsmAnalyzer::Scopes& _scopes,
|
||||
eth::Assembly& _assembly,
|
||||
ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess()
|
||||
);
|
||||
|
||||
private:
|
||||
Block const& m_parsedData;
|
||||
ErrorList& m_errors;
|
||||
};
|
||||
|
||||
|
||||
@@ -62,8 +62,11 @@ string InlineAssemblyStack::toString()
|
||||
|
||||
eth::Assembly InlineAssemblyStack::assemble()
|
||||
{
|
||||
CodeGenerator codeGen(*m_parserResult, m_errors);
|
||||
return codeGen.assemble();
|
||||
AsmAnalyzer::Scopes scopes;
|
||||
AsmAnalyzer analyzer(scopes, m_errors);
|
||||
solAssert(analyzer.analyze(*m_parserResult), "");
|
||||
CodeGenerator codeGen(m_errors);
|
||||
return codeGen.assemble(*m_parserResult, scopes);
|
||||
}
|
||||
|
||||
bool InlineAssemblyStack::parseAndAssemble(
|
||||
@@ -78,7 +81,10 @@ bool InlineAssemblyStack::parseAndAssemble(
|
||||
if (!errors.empty())
|
||||
return false;
|
||||
|
||||
CodeGenerator(*parserResult, errors).assemble(_assembly, _identifierAccess);
|
||||
AsmAnalyzer::Scopes scopes;
|
||||
AsmAnalyzer analyzer(scopes, m_errors);
|
||||
solAssert(analyzer.analyze(*m_parserResult), "");
|
||||
CodeGenerator(errors).assemble(*parserResult, scopes, _assembly, _identifierAccess);
|
||||
|
||||
// At this point, the assembly might be messed up, but we should throw an
|
||||
// internal compiler error anyway.
|
||||
|
||||
Reference in New Issue
Block a user