mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Refactor to combined scope and stack height info.
This commit is contained in:
parent
68218387cf
commit
f3ec2ba39e
@ -26,6 +26,7 @@
|
|||||||
#include <libsolidity/interface/Exceptions.h>
|
#include <libsolidity/interface/Exceptions.h>
|
||||||
#include <libsolidity/analysis/ConstantEvaluator.h>
|
#include <libsolidity/analysis/ConstantEvaluator.h>
|
||||||
#include <libsolidity/inlineasm/AsmAnalysis.h>
|
#include <libsolidity/inlineasm/AsmAnalysis.h>
|
||||||
|
#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
|
||||||
#include <libsolidity/inlineasm/AsmData.h>
|
#include <libsolidity/inlineasm/AsmData.h>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
@ -190,8 +191,10 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly)
|
|||||||
_inlineAssembly.annotation().externalReferences[&_identifier].declaration = declarations.front();
|
_inlineAssembly.annotation().externalReferences[&_identifier].declaration = declarations.front();
|
||||||
return size_t(1);
|
return size_t(1);
|
||||||
};
|
};
|
||||||
assembly::AsmAnalyzer::Scopes scopes;
|
|
||||||
assembly::AsmAnalyzer(scopes, errorsIgnored, resolver).analyze(_inlineAssembly.operations());
|
// Will be re-generated later with correct information
|
||||||
|
assembly::AsmAnalysisInfo analysisInfo;
|
||||||
|
assembly::AsmAnalyzer(analysisInfo, errorsIgnored, resolver).analyze(_inlineAssembly.operations());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <boost/range/adaptor/reversed.hpp>
|
#include <boost/range/adaptor/reversed.hpp>
|
||||||
#include <libsolidity/ast/AST.h>
|
#include <libsolidity/ast/AST.h>
|
||||||
#include <libsolidity/inlineasm/AsmAnalysis.h>
|
#include <libsolidity/inlineasm/AsmAnalysis.h>
|
||||||
|
#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
|
||||||
#include <libsolidity/inlineasm/AsmData.h>
|
#include <libsolidity/inlineasm/AsmData.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -705,8 +706,13 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
|
|||||||
ref->second.valueSize = 1;
|
ref->second.valueSize = 1;
|
||||||
return size_t(1);
|
return size_t(1);
|
||||||
};
|
};
|
||||||
solAssert(_inlineAssembly.annotation().scopes.empty(), "");
|
solAssert(!_inlineAssembly.annotation().analysisInfo, "");
|
||||||
assembly::AsmAnalyzer analyzer(_inlineAssembly.annotation().scopes, m_errors, identifierAccess);
|
_inlineAssembly.annotation().analysisInfo = make_shared<assembly::AsmAnalysisInfo>();
|
||||||
|
assembly::AsmAnalyzer analyzer(
|
||||||
|
*_inlineAssembly.annotation().analysisInfo,
|
||||||
|
m_errors,
|
||||||
|
identifierAccess
|
||||||
|
);
|
||||||
if (!analyzer.analyze(_inlineAssembly.operations()))
|
if (!analyzer.analyze(_inlineAssembly.operations()))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -22,11 +22,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <libsolidity/ast/ASTForward.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <libsolidity/ast/ASTForward.h>
|
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
@ -112,9 +113,8 @@ struct StatementAnnotation: ASTAnnotation, DocumentedAnnotation
|
|||||||
|
|
||||||
namespace assembly
|
namespace assembly
|
||||||
{
|
{
|
||||||
struct Identifier; // forward
|
struct AsmAnalysisInfo;
|
||||||
struct Block; // forward
|
struct Identifier;
|
||||||
struct Scope; // forward
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InlineAssemblyAnnotation: StatementAnnotation
|
struct InlineAssemblyAnnotation: StatementAnnotation
|
||||||
@ -129,8 +129,8 @@ struct InlineAssemblyAnnotation: StatementAnnotation
|
|||||||
|
|
||||||
/// Mapping containing resolved references to external identifiers and their value size
|
/// Mapping containing resolved references to external identifiers and their value size
|
||||||
std::map<assembly::Identifier const*, ExternalIdentifierInfo> externalReferences;
|
std::map<assembly::Identifier const*, ExternalIdentifierInfo> externalReferences;
|
||||||
/// Mapping containing the scopes (the result of the analysis phase).
|
/// Information generated during analysis phase.
|
||||||
std::map<assembly::Block const*, std::shared_ptr<assembly::Scope>> scopes;
|
std::shared_ptr<assembly::AsmAnalysisInfo> analysisInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ReturnAnnotation: StatementAnnotation
|
struct ReturnAnnotation: StatementAnnotation
|
||||||
|
@ -637,9 +637,10 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
|
|||||||
_assembly.append(Instruction::POP);
|
_assembly.append(Instruction::POP);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
solAssert(_inlineAssembly.annotation().analysisInfo, "");
|
||||||
codeGen.assemble(
|
codeGen.assemble(
|
||||||
_inlineAssembly.operations(),
|
_inlineAssembly.operations(),
|
||||||
_inlineAssembly.annotation().scopes,
|
*_inlineAssembly.annotation().analysisInfo,
|
||||||
m_context.nonConstAssembly(),
|
m_context.nonConstAssembly(),
|
||||||
identifierAccess
|
identifierAccess
|
||||||
);
|
);
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <libsolidity/inlineasm/AsmData.h>
|
#include <libsolidity/inlineasm/AsmData.h>
|
||||||
#include <libsolidity/inlineasm/AsmScopeFiller.h>
|
#include <libsolidity/inlineasm/AsmScopeFiller.h>
|
||||||
#include <libsolidity/inlineasm/AsmScope.h>
|
#include <libsolidity/inlineasm/AsmScope.h>
|
||||||
|
#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
|
||||||
|
|
||||||
#include <libsolidity/interface/Exceptions.h>
|
#include <libsolidity/interface/Exceptions.h>
|
||||||
#include <libsolidity/interface/Utils.h>
|
#include <libsolidity/interface/Utils.h>
|
||||||
@ -37,35 +38,34 @@ using namespace dev;
|
|||||||
using namespace dev::solidity;
|
using namespace dev::solidity;
|
||||||
using namespace dev::solidity::assembly;
|
using namespace dev::solidity::assembly;
|
||||||
|
|
||||||
|
|
||||||
AsmAnalyzer::AsmAnalyzer(
|
AsmAnalyzer::AsmAnalyzer(
|
||||||
AsmAnalyzer::Scopes& _scopes,
|
AsmAnalysisInfo& _analysisInfo,
|
||||||
ErrorList& _errors,
|
ErrorList& _errors,
|
||||||
ExternalIdentifierAccess::Resolver const& _resolver,
|
ExternalIdentifierAccess::Resolver const& _resolver
|
||||||
StackHeightInfo* _stackHeightInfo
|
|
||||||
):
|
):
|
||||||
m_resolver(_resolver), m_scopes(_scopes), m_errors(_errors), m_stackHeightInfo(_stackHeightInfo)
|
m_resolver(_resolver), m_info(_analysisInfo), m_errors(_errors)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AsmAnalyzer::analyze(Block const& _block)
|
bool AsmAnalyzer::analyze(Block const& _block)
|
||||||
{
|
{
|
||||||
if (!(ScopeFiller(m_scopes, m_errors))(_block))
|
if (!(ScopeFiller(m_info.scopes, m_errors))(_block))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return (*this)(_block);
|
return (*this)(_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AsmAnalyzer::operator()(const Label& _label)
|
bool AsmAnalyzer::operator()(Label const& _label)
|
||||||
{
|
{
|
||||||
storeStackHeight(_label); return true;
|
m_info.stackHeightInfo[&_label] = m_stackHeight;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AsmAnalyzer::operator()(assembly::Instruction const& _instruction)
|
bool AsmAnalyzer::operator()(assembly::Instruction const& _instruction)
|
||||||
{
|
{
|
||||||
auto const& info = instructionInfo(_instruction.instruction);
|
auto const& info = instructionInfo(_instruction.instruction);
|
||||||
m_stackHeight += info.ret - info.args;
|
m_stackHeight += info.ret - info.args;
|
||||||
storeStackHeight(_instruction);
|
m_info.stackHeightInfo[&_instruction] = m_stackHeight;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ bool AsmAnalyzer::operator()(assembly::Literal const& _literal)
|
|||||||
));
|
));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
storeStackHeight(_literal);
|
m_info.stackHeightInfo[&_literal] = m_stackHeight;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ bool AsmAnalyzer::operator()(assembly::Identifier const& _identifier)
|
|||||||
}
|
}
|
||||||
m_stackHeight += stackSize == size_t(-1) ? 1 : stackSize;
|
m_stackHeight += stackSize == size_t(-1) ? 1 : stackSize;
|
||||||
}
|
}
|
||||||
storeStackHeight(_identifier);
|
m_info.stackHeightInfo[&_identifier] = m_stackHeight;
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,14 +156,14 @@ bool AsmAnalyzer::operator()(FunctionalInstruction const& _instr)
|
|||||||
solAssert(instructionInfo(_instr.instruction.instruction).args == int(_instr.arguments.size()), "");
|
solAssert(instructionInfo(_instr.instruction.instruction).args == int(_instr.arguments.size()), "");
|
||||||
if (!(*this)(_instr.instruction))
|
if (!(*this)(_instr.instruction))
|
||||||
success = false;
|
success = false;
|
||||||
storeStackHeight(_instr);
|
m_info.stackHeightInfo[&_instr] = m_stackHeight;
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AsmAnalyzer::operator()(assembly::Assignment const& _assignment)
|
bool AsmAnalyzer::operator()(assembly::Assignment const& _assignment)
|
||||||
{
|
{
|
||||||
bool success = checkAssignment(_assignment.variableName, size_t(-1));
|
bool success = checkAssignment(_assignment.variableName, size_t(-1));
|
||||||
storeStackHeight(_assignment);
|
m_info.stackHeightInfo[&_assignment] = m_stackHeight;
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ bool AsmAnalyzer::operator()(FunctionalAssignment const& _assignment)
|
|||||||
solAssert(m_stackHeight >= stackHeight, "Negative value size.");
|
solAssert(m_stackHeight >= stackHeight, "Negative value size.");
|
||||||
if (!checkAssignment(_assignment.variableName, m_stackHeight - stackHeight))
|
if (!checkAssignment(_assignment.variableName, m_stackHeight - stackHeight))
|
||||||
success = false;
|
success = false;
|
||||||
storeStackHeight(_assignment);
|
m_info.stackHeightInfo[&_assignment] = m_stackHeight;
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ bool AsmAnalyzer::operator()(assembly::VariableDeclaration const& _varDecl)
|
|||||||
bool success = boost::apply_visitor(*this, *_varDecl.value);
|
bool success = boost::apply_visitor(*this, *_varDecl.value);
|
||||||
solAssert(m_stackHeight - stackHeight == 1, "Invalid value size.");
|
solAssert(m_stackHeight - stackHeight == 1, "Invalid value size.");
|
||||||
boost::get<Scope::Variable>(m_currentScope->identifiers.at(_varDecl.name)).active = true;
|
boost::get<Scope::Variable>(m_currentScope->identifiers.at(_varDecl.name)).active = true;
|
||||||
storeStackHeight(_varDecl);
|
m_info.stackHeightInfo[&_varDecl] = m_stackHeight;
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ bool AsmAnalyzer::operator()(assembly::FunctionDefinition const& _funDef)
|
|||||||
bool success = (*this)(_funDef.body);
|
bool success = (*this)(_funDef.body);
|
||||||
|
|
||||||
m_stackHeight = stackHeight;
|
m_stackHeight = stackHeight;
|
||||||
storeStackHeight(_funDef);
|
m_info.stackHeightInfo[&_funDef] = m_stackHeight;
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,7 +269,7 @@ bool AsmAnalyzer::operator()(assembly::FunctionCall const& _funCall)
|
|||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
m_stackHeight += int(returns) - int(arguments);
|
m_stackHeight += int(returns) - int(arguments);
|
||||||
storeStackHeight(_funCall);
|
m_info.stackHeightInfo[&_funCall] = m_stackHeight;
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ bool AsmAnalyzer::operator()(Block const& _block)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_currentScope = m_currentScope->superScope;
|
m_currentScope = m_currentScope->superScope;
|
||||||
storeStackHeight(_block);
|
m_info.stackHeightInfo[&_block] = m_stackHeight;
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,12 +372,6 @@ bool AsmAnalyzer::checkAssignment(assembly::Identifier const& _variable, size_t
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsmAnalyzer::storeStackHeight(const assembly::Statement& _statement)
|
|
||||||
{
|
|
||||||
if (m_stackHeightInfo)
|
|
||||||
(*m_stackHeightInfo)[&_statement] = m_stackHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AsmAnalyzer::expectDeposit(int const _deposit, int const _oldHeight, SourceLocation const& _location)
|
bool AsmAnalyzer::expectDeposit(int const _deposit, int const _oldHeight, SourceLocation const& _location)
|
||||||
{
|
{
|
||||||
int stackDiff = m_stackHeight - _oldHeight;
|
int stackDiff = m_stackHeight - _oldHeight;
|
||||||
@ -400,7 +394,7 @@ bool AsmAnalyzer::expectDeposit(int const _deposit, int const _oldHeight, Source
|
|||||||
|
|
||||||
Scope& AsmAnalyzer::scope(Block const* _block)
|
Scope& AsmAnalyzer::scope(Block const* _block)
|
||||||
{
|
{
|
||||||
auto scopePtr = m_scopes.at(_block);
|
auto scopePtr = m_info.scopes.at(_block);
|
||||||
solAssert(scopePtr, "Scope requested but not present.");
|
solAssert(scopePtr, "Scope requested but not present.");
|
||||||
return *scopePtr;
|
return *scopePtr;
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,7 @@ struct FunctionCall;
|
|||||||
|
|
||||||
struct Scope;
|
struct Scope;
|
||||||
|
|
||||||
using Statement = boost::variant<Instruction, Literal, Label, Assignment, Identifier, FunctionalAssignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Block>;
|
struct AsmAnalysisInfo;
|
||||||
using StackHeightInfo = std::map<assembly::Statement const*, int>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the full analysis stage, calls the ScopeFiller internally, then resolves
|
* Performs the full analysis stage, calls the ScopeFiller internally, then resolves
|
||||||
@ -61,12 +60,10 @@ using StackHeightInfo = std::map<assembly::Statement const*, int>;
|
|||||||
class AsmAnalyzer: public boost::static_visitor<bool>
|
class AsmAnalyzer: public boost::static_visitor<bool>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Scopes = std::map<assembly::Block const*, std::shared_ptr<Scope>>;
|
|
||||||
AsmAnalyzer(
|
AsmAnalyzer(
|
||||||
Scopes& _scopes,
|
AsmAnalysisInfo& _analysisInfo,
|
||||||
ErrorList& _errors,
|
ErrorList& _errors,
|
||||||
ExternalIdentifierAccess::Resolver const& _resolver = ExternalIdentifierAccess::Resolver(),
|
ExternalIdentifierAccess::Resolver const& _resolver = ExternalIdentifierAccess::Resolver()
|
||||||
StackHeightInfo* _stackHeightInfo = nullptr
|
|
||||||
);
|
);
|
||||||
|
|
||||||
bool analyze(assembly::Block const& _block);
|
bool analyze(assembly::Block const& _block);
|
||||||
@ -88,7 +85,6 @@ private:
|
|||||||
/// as the value, @a _valueSize, unless that is equal to -1.
|
/// as the value, @a _valueSize, unless that is equal to -1.
|
||||||
bool checkAssignment(assembly::Identifier const& _assignment, size_t _valueSize = size_t(-1));
|
bool checkAssignment(assembly::Identifier const& _assignment, size_t _valueSize = size_t(-1));
|
||||||
bool expectDeposit(int _deposit, int _oldHeight, SourceLocation const& _location);
|
bool expectDeposit(int _deposit, int _oldHeight, SourceLocation const& _location);
|
||||||
void storeStackHeight(assembly::Statement const& _statement);
|
|
||||||
Scope& scope(assembly::Block const* _block);
|
Scope& scope(assembly::Block const* _block);
|
||||||
|
|
||||||
/// This is used when we enter the body of a function definition. There, the parameters
|
/// This is used when we enter the body of a function definition. There, the parameters
|
||||||
@ -98,9 +94,8 @@ private:
|
|||||||
int m_stackHeight = 0;
|
int m_stackHeight = 0;
|
||||||
ExternalIdentifierAccess::Resolver const& m_resolver;
|
ExternalIdentifierAccess::Resolver const& m_resolver;
|
||||||
Scope* m_currentScope = nullptr;
|
Scope* m_currentScope = nullptr;
|
||||||
Scopes& m_scopes;
|
AsmAnalysisInfo& m_info;
|
||||||
ErrorList& m_errors;
|
ErrorList& m_errors;
|
||||||
StackHeightInfo* m_stackHeightInfo;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
26
libsolidity/inlineasm/AsmAnalysisInfo.cpp
Normal file
26
libsolidity/inlineasm/AsmAnalysisInfo.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
This file is part of solidity.
|
||||||
|
|
||||||
|
solidity is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
solidity is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Information generated during analyzer part of inline assembly.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
|
||||||
|
|
||||||
|
#include <libsolidity/inlineasm/AsmScope.h>
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
|
|
61
libsolidity/inlineasm/AsmAnalysisInfo.h
Normal file
61
libsolidity/inlineasm/AsmAnalysisInfo.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
This file is part of solidity.
|
||||||
|
|
||||||
|
solidity is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
solidity is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Information generated during analyzer part of inline assembly.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <boost/variant.hpp>
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace solidity
|
||||||
|
{
|
||||||
|
namespace assembly
|
||||||
|
{
|
||||||
|
|
||||||
|
struct Literal;
|
||||||
|
struct Block;
|
||||||
|
struct Label;
|
||||||
|
struct FunctionalInstruction;
|
||||||
|
struct FunctionalAssignment;
|
||||||
|
struct VariableDeclaration;
|
||||||
|
struct Instruction;
|
||||||
|
struct Identifier;
|
||||||
|
struct Assignment;
|
||||||
|
struct FunctionDefinition;
|
||||||
|
struct FunctionCall;
|
||||||
|
|
||||||
|
struct Scope;
|
||||||
|
|
||||||
|
using Statement = boost::variant<Instruction, Literal, Label, Assignment, Identifier, FunctionalAssignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Block>;
|
||||||
|
|
||||||
|
struct AsmAnalysisInfo
|
||||||
|
{
|
||||||
|
using StackHeightInfo = std::map<void const*, int>;
|
||||||
|
using Scopes = std::map<assembly::Block const*, std::shared_ptr<Scope>>;
|
||||||
|
Scopes scopes;
|
||||||
|
StackHeightInfo stackHeightInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,7 @@
|
|||||||
#include <libsolidity/inlineasm/AsmData.h>
|
#include <libsolidity/inlineasm/AsmData.h>
|
||||||
#include <libsolidity/inlineasm/AsmScope.h>
|
#include <libsolidity/inlineasm/AsmScope.h>
|
||||||
#include <libsolidity/inlineasm/AsmAnalysis.h>
|
#include <libsolidity/inlineasm/AsmAnalysis.h>
|
||||||
|
#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
|
||||||
|
|
||||||
#include <libevmasm/Assembly.h>
|
#include <libevmasm/Assembly.h>
|
||||||
#include <libevmasm/SourceLocation.h>
|
#include <libevmasm/SourceLocation.h>
|
||||||
@ -47,8 +48,8 @@ using namespace dev::solidity::assembly;
|
|||||||
|
|
||||||
struct GeneratorState
|
struct GeneratorState
|
||||||
{
|
{
|
||||||
GeneratorState(ErrorList& _errors, AsmAnalyzer::Scopes& _scopes, eth::Assembly& _assembly):
|
GeneratorState(ErrorList& _errors, AsmAnalysisInfo& _analysisInfo, eth::Assembly& _assembly):
|
||||||
errors(_errors), scopes(_scopes), assembly(_assembly) {}
|
errors(_errors), info(_analysisInfo), assembly(_assembly) {}
|
||||||
|
|
||||||
size_t newLabelId()
|
size_t newLabelId()
|
||||||
{
|
{
|
||||||
@ -63,7 +64,7 @@ struct GeneratorState
|
|||||||
}
|
}
|
||||||
|
|
||||||
ErrorList& errors;
|
ErrorList& errors;
|
||||||
AsmAnalyzer::Scopes scopes;
|
AsmAnalysisInfo info;
|
||||||
eth::Assembly& assembly;
|
eth::Assembly& assembly;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ public:
|
|||||||
assembly::ExternalIdentifierAccess const& _identifierAccess = assembly::ExternalIdentifierAccess()
|
assembly::ExternalIdentifierAccess const& _identifierAccess = assembly::ExternalIdentifierAccess()
|
||||||
):
|
):
|
||||||
m_state(_state),
|
m_state(_state),
|
||||||
m_scope(*m_state.scopes.at(&_block)),
|
m_scope(*m_state.info.scopes.at(&_block)),
|
||||||
m_initialDeposit(m_state.assembly.deposit()),
|
m_initialDeposit(m_state.assembly.deposit()),
|
||||||
m_identifierAccess(_identifierAccess)
|
m_identifierAccess(_identifierAccess)
|
||||||
{
|
{
|
||||||
@ -262,23 +263,23 @@ private:
|
|||||||
|
|
||||||
eth::Assembly assembly::CodeGenerator::assemble(
|
eth::Assembly assembly::CodeGenerator::assemble(
|
||||||
Block const& _parsedData,
|
Block const& _parsedData,
|
||||||
AsmAnalyzer::Scopes& _scopes,
|
AsmAnalysisInfo& _analysisInfo,
|
||||||
ExternalIdentifierAccess const& _identifierAccess
|
ExternalIdentifierAccess const& _identifierAccess
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
eth::Assembly assembly;
|
eth::Assembly assembly;
|
||||||
GeneratorState state(m_errors, _scopes, assembly);
|
GeneratorState state(m_errors, _analysisInfo, assembly);
|
||||||
CodeTransform(state, _parsedData, _identifierAccess);
|
CodeTransform(state, _parsedData, _identifierAccess);
|
||||||
return assembly;
|
return assembly;
|
||||||
}
|
}
|
||||||
|
|
||||||
void assembly::CodeGenerator::assemble(
|
void assembly::CodeGenerator::assemble(
|
||||||
Block const& _parsedData,
|
Block const& _parsedData,
|
||||||
AsmAnalyzer::Scopes& _scopes,
|
AsmAnalysisInfo& _analysisInfo,
|
||||||
eth::Assembly& _assembly,
|
eth::Assembly& _assembly,
|
||||||
ExternalIdentifierAccess const& _identifierAccess
|
ExternalIdentifierAccess const& _identifierAccess
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
GeneratorState state(m_errors, _scopes, _assembly);
|
GeneratorState state(m_errors, _analysisInfo, _assembly);
|
||||||
CodeTransform(state, _parsedData, _identifierAccess);
|
CodeTransform(state, _parsedData, _identifierAccess);
|
||||||
}
|
}
|
||||||
|
@ -47,13 +47,13 @@ public:
|
|||||||
/// Performs code generation and @returns the result.
|
/// Performs code generation and @returns the result.
|
||||||
eth::Assembly assemble(
|
eth::Assembly assemble(
|
||||||
Block const& _parsedData,
|
Block const& _parsedData,
|
||||||
AsmAnalyzer::Scopes& _scopes,
|
AsmAnalysisInfo& _analysisInfo,
|
||||||
ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess()
|
ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess()
|
||||||
);
|
);
|
||||||
/// Performs code generation and appends generated to to _assembly.
|
/// Performs code generation and appends generated to to _assembly.
|
||||||
void assemble(
|
void assemble(
|
||||||
Block const& _parsedData,
|
Block const& _parsedData,
|
||||||
AsmAnalyzer::Scopes& _scopes,
|
AsmAnalysisInfo& _analysisInfo,
|
||||||
eth::Assembly& _assembly,
|
eth::Assembly& _assembly,
|
||||||
ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess()
|
ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess()
|
||||||
);
|
);
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <libsolidity/inlineasm/AsmCodeGen.h>
|
#include <libsolidity/inlineasm/AsmCodeGen.h>
|
||||||
#include <libsolidity/inlineasm/AsmPrinter.h>
|
#include <libsolidity/inlineasm/AsmPrinter.h>
|
||||||
#include <libsolidity/inlineasm/AsmAnalysis.h>
|
#include <libsolidity/inlineasm/AsmAnalysis.h>
|
||||||
|
#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
|
||||||
|
|
||||||
#include <libsolidity/parsing/Scanner.h>
|
#include <libsolidity/parsing/Scanner.h>
|
||||||
|
|
||||||
@ -51,8 +52,8 @@ bool InlineAssemblyStack::parse(
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
*m_parserResult = std::move(*result);
|
*m_parserResult = std::move(*result);
|
||||||
AsmAnalyzer::Scopes scopes;
|
AsmAnalysisInfo analysisInfo;
|
||||||
return (AsmAnalyzer(scopes, m_errors, _resolver)).analyze(*m_parserResult);
|
return (AsmAnalyzer(analysisInfo, m_errors, _resolver)).analyze(*m_parserResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
string InlineAssemblyStack::toString()
|
string InlineAssemblyStack::toString()
|
||||||
@ -62,11 +63,11 @@ string InlineAssemblyStack::toString()
|
|||||||
|
|
||||||
eth::Assembly InlineAssemblyStack::assemble()
|
eth::Assembly InlineAssemblyStack::assemble()
|
||||||
{
|
{
|
||||||
AsmAnalyzer::Scopes scopes;
|
AsmAnalysisInfo analysisInfo;
|
||||||
AsmAnalyzer analyzer(scopes, m_errors);
|
AsmAnalyzer analyzer(analysisInfo, m_errors);
|
||||||
solAssert(analyzer.analyze(*m_parserResult), "");
|
solAssert(analyzer.analyze(*m_parserResult), "");
|
||||||
CodeGenerator codeGen(m_errors);
|
CodeGenerator codeGen(m_errors);
|
||||||
return codeGen.assemble(*m_parserResult, scopes);
|
return codeGen.assemble(*m_parserResult, analysisInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InlineAssemblyStack::parseAndAssemble(
|
bool InlineAssemblyStack::parseAndAssemble(
|
||||||
@ -82,10 +83,10 @@ bool InlineAssemblyStack::parseAndAssemble(
|
|||||||
return false;
|
return false;
|
||||||
solAssert(parserResult, "");
|
solAssert(parserResult, "");
|
||||||
|
|
||||||
AsmAnalyzer::Scopes scopes;
|
AsmAnalysisInfo analysisInfo;
|
||||||
AsmAnalyzer analyzer(scopes, errors, _identifierAccess.resolve);
|
AsmAnalyzer analyzer(analysisInfo, errors, _identifierAccess.resolve);
|
||||||
solAssert(analyzer.analyze(*parserResult), "");
|
solAssert(analyzer.analyze(*parserResult), "");
|
||||||
CodeGenerator(errors).assemble(*parserResult, scopes, _assembly, _identifierAccess);
|
CodeGenerator(errors).assemble(*parserResult, analysisInfo, _assembly, _identifierAccess);
|
||||||
|
|
||||||
// At this point, the assembly might be messed up, but we should throw an
|
// At this point, the assembly might be messed up, but we should throw an
|
||||||
// internal compiler error anyway.
|
// internal compiler error anyway.
|
||||||
|
Loading…
Reference in New Issue
Block a user