mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Isolating libyul library API into its own namespace yul.
This commit is contained in:
@@ -273,7 +273,7 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly)
|
||||
ErrorList errors;
|
||||
ErrorReporter errorsIgnored(errors);
|
||||
yul::ExternalIdentifierAccess::Resolver resolver =
|
||||
[&](assembly::Identifier const& _identifier, yul::IdentifierContext, bool _crossesFunctionBoundary) {
|
||||
[&](yul::Identifier const& _identifier, yul::IdentifierContext, bool _crossesFunctionBoundary) {
|
||||
auto declarations = m_resolver.nameFromCurrentScope(_identifier.name.str());
|
||||
bool isSlot = boost::algorithm::ends_with(_identifier.name.str(), "_slot");
|
||||
bool isOffset = boost::algorithm::ends_with(_identifier.name.str(), "_offset");
|
||||
@@ -314,9 +314,9 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly)
|
||||
|
||||
// Will be re-generated later with correct information
|
||||
// We use the latest EVM version because we will re-run it anyway.
|
||||
assembly::AsmAnalysisInfo analysisInfo;
|
||||
yul::AsmAnalysisInfo analysisInfo;
|
||||
boost::optional<Error::Type> errorTypeForLoose = Error::Type::SyntaxError;
|
||||
assembly::AsmAnalyzer(analysisInfo, errorsIgnored, EVMVersion(), errorTypeForLoose, assembly::AsmFlavour::Loose, resolver).analyze(_inlineAssembly.operations());
|
||||
yul::AsmAnalyzer(analysisInfo, errorsIgnored, EVMVersion(), errorTypeForLoose, yul::AsmFlavour::Loose, resolver).analyze(_inlineAssembly.operations());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -954,7 +954,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
|
||||
// External references have already been resolved in a prior stage and stored in the annotation.
|
||||
// We run the resolve step again regardless.
|
||||
yul::ExternalIdentifierAccess::Resolver identifierAccess = [&](
|
||||
assembly::Identifier const& _identifier,
|
||||
yul::Identifier const& _identifier,
|
||||
yul::IdentifierContext _context,
|
||||
bool
|
||||
)
|
||||
@@ -1039,13 +1039,13 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
|
||||
return size_t(1);
|
||||
};
|
||||
solAssert(!_inlineAssembly.annotation().analysisInfo, "");
|
||||
_inlineAssembly.annotation().analysisInfo = make_shared<assembly::AsmAnalysisInfo>();
|
||||
assembly::AsmAnalyzer analyzer(
|
||||
_inlineAssembly.annotation().analysisInfo = make_shared<yul::AsmAnalysisInfo>();
|
||||
yul::AsmAnalyzer analyzer(
|
||||
*_inlineAssembly.annotation().analysisInfo,
|
||||
m_errorReporter,
|
||||
m_evmVersion,
|
||||
Error::Type::SyntaxError,
|
||||
assembly::AsmFlavour::Loose,
|
||||
yul::AsmFlavour::Loose,
|
||||
identifierAccess
|
||||
);
|
||||
if (!analyzer.analyze(_inlineAssembly.operations()))
|
||||
|
||||
@@ -40,48 +40,48 @@ public:
|
||||
explicit AssemblyViewPureChecker(std::function<void(StateMutability, SourceLocation const&)> _reportMutability):
|
||||
m_reportMutability(_reportMutability) {}
|
||||
|
||||
void operator()(assembly::Label const&) { }
|
||||
void operator()(assembly::Instruction const& _instruction)
|
||||
void operator()(yul::Label const&) { }
|
||||
void operator()(yul::Instruction const& _instruction)
|
||||
{
|
||||
checkInstruction(_instruction.location, _instruction.instruction);
|
||||
}
|
||||
void operator()(assembly::Literal const&) {}
|
||||
void operator()(assembly::Identifier const&) {}
|
||||
void operator()(assembly::FunctionalInstruction const& _instr)
|
||||
void operator()(yul::Literal const&) {}
|
||||
void operator()(yul::Identifier const&) {}
|
||||
void operator()(yul::FunctionalInstruction const& _instr)
|
||||
{
|
||||
checkInstruction(_instr.location, _instr.instruction);
|
||||
for (auto const& arg: _instr.arguments)
|
||||
boost::apply_visitor(*this, arg);
|
||||
}
|
||||
void operator()(assembly::ExpressionStatement const& _expr)
|
||||
void operator()(yul::ExpressionStatement const& _expr)
|
||||
{
|
||||
boost::apply_visitor(*this, _expr.expression);
|
||||
}
|
||||
void operator()(assembly::StackAssignment const&) {}
|
||||
void operator()(assembly::Assignment const& _assignment)
|
||||
void operator()(yul::StackAssignment const&) {}
|
||||
void operator()(yul::Assignment const& _assignment)
|
||||
{
|
||||
boost::apply_visitor(*this, *_assignment.value);
|
||||
}
|
||||
void operator()(assembly::VariableDeclaration const& _varDecl)
|
||||
void operator()(yul::VariableDeclaration const& _varDecl)
|
||||
{
|
||||
if (_varDecl.value)
|
||||
boost::apply_visitor(*this, *_varDecl.value);
|
||||
}
|
||||
void operator()(assembly::FunctionDefinition const& _funDef)
|
||||
void operator()(yul::FunctionDefinition const& _funDef)
|
||||
{
|
||||
(*this)(_funDef.body);
|
||||
}
|
||||
void operator()(assembly::FunctionCall const& _funCall)
|
||||
void operator()(yul::FunctionCall const& _funCall)
|
||||
{
|
||||
for (auto const& arg: _funCall.arguments)
|
||||
boost::apply_visitor(*this, arg);
|
||||
}
|
||||
void operator()(assembly::If const& _if)
|
||||
void operator()(yul::If const& _if)
|
||||
{
|
||||
boost::apply_visitor(*this, *_if.condition);
|
||||
(*this)(_if.body);
|
||||
}
|
||||
void operator()(assembly::Switch const& _switch)
|
||||
void operator()(yul::Switch const& _switch)
|
||||
{
|
||||
boost::apply_visitor(*this, *_switch.expression);
|
||||
for (auto const& _case: _switch.cases)
|
||||
@@ -91,14 +91,14 @@ public:
|
||||
(*this)(_case.body);
|
||||
}
|
||||
}
|
||||
void operator()(assembly::ForLoop const& _for)
|
||||
void operator()(yul::ForLoop const& _for)
|
||||
{
|
||||
(*this)(_for.pre);
|
||||
boost::apply_visitor(*this, *_for.condition);
|
||||
(*this)(_for.body);
|
||||
(*this)(_for.post);
|
||||
}
|
||||
void operator()(assembly::Block const& _block)
|
||||
void operator()(yul::Block const& _block)
|
||||
{
|
||||
for (auto const& s: _block.statements)
|
||||
boost::apply_visitor(*this, s);
|
||||
|
||||
@@ -41,6 +41,12 @@
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace yul
|
||||
{
|
||||
// Forward-declaration to <yul/AsmData.h>
|
||||
struct Block;
|
||||
}
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
@@ -1028,12 +1034,6 @@ public:
|
||||
StatementAnnotation& annotation() const override;
|
||||
};
|
||||
|
||||
namespace assembly
|
||||
{
|
||||
// Forward-declaration to AsmData.h
|
||||
struct Block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inline assembly.
|
||||
*/
|
||||
@@ -1043,18 +1043,18 @@ public:
|
||||
InlineAssembly(
|
||||
SourceLocation const& _location,
|
||||
ASTPointer<ASTString> const& _docString,
|
||||
std::shared_ptr<assembly::Block> const& _operations
|
||||
std::shared_ptr<yul::Block> const& _operations
|
||||
):
|
||||
Statement(_location, _docString), m_operations(_operations) {}
|
||||
void accept(ASTVisitor& _visitor) override;
|
||||
void accept(ASTConstVisitor& _visitor) const override;
|
||||
|
||||
assembly::Block const& operations() const { return *m_operations; }
|
||||
yul::Block const& operations() const { return *m_operations; }
|
||||
|
||||
InlineAssemblyAnnotation& annotation() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<assembly::Block> m_operations;
|
||||
std::shared_ptr<yul::Block> m_operations;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,12 @@
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
namespace yul
|
||||
{
|
||||
struct AsmAnalysisInfo;
|
||||
struct Identifier;
|
||||
}
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
@@ -120,12 +126,6 @@ struct StatementAnnotation: ASTAnnotation, DocumentedAnnotation
|
||||
{
|
||||
};
|
||||
|
||||
namespace assembly
|
||||
{
|
||||
struct AsmAnalysisInfo;
|
||||
struct Identifier;
|
||||
}
|
||||
|
||||
struct InlineAssemblyAnnotation: StatementAnnotation
|
||||
{
|
||||
struct ExternalIdentifierInfo
|
||||
@@ -137,9 +137,9 @@ struct InlineAssemblyAnnotation: StatementAnnotation
|
||||
};
|
||||
|
||||
/// Mapping containing resolved references to external identifiers and their value size
|
||||
std::map<assembly::Identifier const*, ExternalIdentifierInfo> externalReferences;
|
||||
std::map<yul::Identifier const*, ExternalIdentifierInfo> externalReferences;
|
||||
/// Information generated during analysis phase.
|
||||
std::shared_ptr<assembly::AsmAnalysisInfo> analysisInfo;
|
||||
std::shared_ptr<yul::AsmAnalysisInfo> analysisInfo;
|
||||
};
|
||||
|
||||
struct ReturnAnnotation: StatementAnnotation
|
||||
|
||||
@@ -172,7 +172,7 @@ void ASTJsonConverter::appendExpressionAttributes(
|
||||
_attributes += exprAttributes;
|
||||
}
|
||||
|
||||
Json::Value ASTJsonConverter::inlineAssemblyIdentifierToJson(pair<assembly::Identifier const* ,InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const
|
||||
Json::Value ASTJsonConverter::inlineAssemblyIdentifierToJson(pair<yul::Identifier const* ,InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const
|
||||
{
|
||||
Json::Value tuple(Json::objectValue);
|
||||
tuple["src"] = sourceLocationToString(_info.first->location);
|
||||
@@ -465,7 +465,7 @@ bool ASTJsonConverter::visit(InlineAssembly const& _node)
|
||||
}
|
||||
}
|
||||
setJsonNode(_node, "InlineAssembly", {
|
||||
make_pair("operations", Json::Value(assembly::AsmPrinter()(_node.operations()))),
|
||||
make_pair("operations", Json::Value(yul::AsmPrinter()(_node.operations()))),
|
||||
make_pair("externalReferences", std::move(externalReferences))
|
||||
});
|
||||
return false;
|
||||
|
||||
@@ -135,7 +135,7 @@ private:
|
||||
{
|
||||
return _node ? toJson(*_node) : Json::nullValue;
|
||||
}
|
||||
Json::Value inlineAssemblyIdentifierToJson(std::pair<assembly::Identifier const* , InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const;
|
||||
Json::Value inlineAssemblyIdentifierToJson(std::pair<yul::Identifier const* , InlineAssemblyAnnotation::ExternalIdentifierInfo> _info) const;
|
||||
static std::string location(VariableDeclaration::Location _location);
|
||||
static std::string contractKind(ContractDefinition::ContractKind _kind);
|
||||
static std::string functionCallKind(FunctionCallKind _kind);
|
||||
|
||||
@@ -323,7 +323,7 @@ void CompilerContext::appendInlineAssembly(
|
||||
|
||||
yul::ExternalIdentifierAccess identifierAccess;
|
||||
identifierAccess.resolve = [&](
|
||||
assembly::Identifier const& _identifier,
|
||||
yul::Identifier const& _identifier,
|
||||
yul::IdentifierContext,
|
||||
bool
|
||||
)
|
||||
@@ -332,7 +332,7 @@ void CompilerContext::appendInlineAssembly(
|
||||
return it == _localVariables.end() ? size_t(-1) : 1;
|
||||
};
|
||||
identifierAccess.generateCode = [&](
|
||||
assembly::Identifier const& _identifier,
|
||||
yul::Identifier const& _identifier,
|
||||
yul::IdentifierContext _context,
|
||||
yul::AbstractAssembly& _assembly
|
||||
)
|
||||
@@ -361,19 +361,19 @@ void CompilerContext::appendInlineAssembly(
|
||||
ErrorList errors;
|
||||
ErrorReporter errorReporter(errors);
|
||||
auto scanner = make_shared<langutil::Scanner>(langutil::CharStream(_assembly), "--CODEGEN--");
|
||||
auto parserResult = assembly::Parser(errorReporter, assembly::AsmFlavour::Strict).parse(scanner, false);
|
||||
auto parserResult = yul::Parser(errorReporter, yul::AsmFlavour::Strict).parse(scanner, false);
|
||||
#ifdef SOL_OUTPUT_ASM
|
||||
cout << assembly::AsmPrinter()(*parserResult) << endl;
|
||||
cout << yul::AsmPrinter()(*parserResult) << endl;
|
||||
#endif
|
||||
assembly::AsmAnalysisInfo analysisInfo;
|
||||
yul::AsmAnalysisInfo analysisInfo;
|
||||
bool analyzerResult = false;
|
||||
if (parserResult)
|
||||
analyzerResult = assembly::AsmAnalyzer(
|
||||
analyzerResult = yul::AsmAnalyzer(
|
||||
analysisInfo,
|
||||
errorReporter,
|
||||
m_evmVersion,
|
||||
boost::none,
|
||||
assembly::AsmFlavour::Strict,
|
||||
yul::AsmFlavour::Strict,
|
||||
identifierAccess.resolve
|
||||
).analyze(*parserResult);
|
||||
if (!parserResult || !errorReporter.errors().empty() || !analyzerResult)
|
||||
@@ -395,7 +395,7 @@ void CompilerContext::appendInlineAssembly(
|
||||
}
|
||||
|
||||
solAssert(errorReporter.errors().empty(), "Failed to analyze inline assembly block.");
|
||||
assembly::CodeGenerator::assemble(*parserResult, analysisInfo, *m_asm, identifierAccess, _system);
|
||||
yul::CodeGenerator::assemble(*parserResult, analysisInfo, *m_asm, identifierAccess, _system);
|
||||
|
||||
// Reset the source location to the one of the node (instead of the CODEGEN source location)
|
||||
updateSourceLocation();
|
||||
|
||||
@@ -496,14 +496,14 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
|
||||
{
|
||||
unsigned startStackHeight = m_context.stackHeight();
|
||||
yul::ExternalIdentifierAccess identifierAccess;
|
||||
identifierAccess.resolve = [&](assembly::Identifier const& _identifier, yul::IdentifierContext, bool)
|
||||
identifierAccess.resolve = [&](yul::Identifier const& _identifier, yul::IdentifierContext, bool)
|
||||
{
|
||||
auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier);
|
||||
if (ref == _inlineAssembly.annotation().externalReferences.end())
|
||||
return size_t(-1);
|
||||
return ref->second.valueSize;
|
||||
};
|
||||
identifierAccess.generateCode = [&](assembly::Identifier const& _identifier, yul::IdentifierContext _context, yul::AbstractAssembly& _assembly)
|
||||
identifierAccess.generateCode = [&](yul::Identifier const& _identifier, yul::IdentifierContext _context, yul::AbstractAssembly& _assembly)
|
||||
{
|
||||
auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier);
|
||||
solAssert(ref != _inlineAssembly.annotation().externalReferences.end(), "");
|
||||
@@ -615,7 +615,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
|
||||
}
|
||||
};
|
||||
solAssert(_inlineAssembly.annotation().analysisInfo, "");
|
||||
assembly::CodeGenerator::assemble(
|
||||
yul::CodeGenerator::assemble(
|
||||
_inlineAssembly.operations(),
|
||||
*_inlineAssembly.annotation().analysisInfo,
|
||||
m_context.nonConstAssembly(),
|
||||
|
||||
@@ -40,19 +40,19 @@ using namespace dev::solidity;
|
||||
|
||||
namespace
|
||||
{
|
||||
assembly::AsmFlavour languageToAsmFlavour(AssemblyStack::Language _language)
|
||||
yul::AsmFlavour languageToAsmFlavour(AssemblyStack::Language _language)
|
||||
{
|
||||
switch (_language)
|
||||
{
|
||||
case AssemblyStack::Language::Assembly:
|
||||
return assembly::AsmFlavour::Loose;
|
||||
return yul::AsmFlavour::Loose;
|
||||
case AssemblyStack::Language::StrictAssembly:
|
||||
return assembly::AsmFlavour::Strict;
|
||||
return yul::AsmFlavour::Strict;
|
||||
case AssemblyStack::Language::Yul:
|
||||
return assembly::AsmFlavour::Yul;
|
||||
return yul::AsmFlavour::Yul;
|
||||
}
|
||||
solAssert(false, "");
|
||||
return assembly::AsmFlavour::Yul;
|
||||
return yul::AsmFlavour::Yul;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -69,7 +69,7 @@ bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string
|
||||
m_errors.clear();
|
||||
m_analysisSuccessful = false;
|
||||
m_scanner = make_shared<Scanner>(CharStream(_source), _sourceName);
|
||||
m_parserResult = assembly::Parser(m_errorReporter, languageToAsmFlavour(m_language)).parse(m_scanner, false);
|
||||
m_parserResult = yul::Parser(m_errorReporter, languageToAsmFlavour(m_language)).parse(m_scanner, false);
|
||||
if (!m_errorReporter.errors().empty())
|
||||
return false;
|
||||
solAssert(m_parserResult, "");
|
||||
@@ -77,21 +77,21 @@ bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string
|
||||
return analyzeParsed();
|
||||
}
|
||||
|
||||
bool AssemblyStack::analyze(assembly::Block const& _block, Scanner const* _scanner)
|
||||
bool AssemblyStack::analyze(yul::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);
|
||||
m_parserResult = make_shared<yul::Block>(_block);
|
||||
|
||||
return analyzeParsed();
|
||||
}
|
||||
|
||||
bool AssemblyStack::analyzeParsed()
|
||||
{
|
||||
m_analysisInfo = make_shared<assembly::AsmAnalysisInfo>();
|
||||
assembly::AsmAnalyzer analyzer(*m_analysisInfo, m_errorReporter, m_evmVersion, boost::none, languageToAsmFlavour(m_language));
|
||||
m_analysisInfo = make_shared<yul::AsmAnalysisInfo>();
|
||||
yul::AsmAnalyzer analyzer(*m_analysisInfo, m_errorReporter, m_evmVersion, boost::none, languageToAsmFlavour(m_language));
|
||||
m_analysisSuccessful = analyzer.analyze(*m_parserResult);
|
||||
return m_analysisSuccessful;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
|
||||
{
|
||||
MachineAssemblyObject object;
|
||||
eth::Assembly assembly;
|
||||
assembly::CodeGenerator::assemble(*m_parserResult, *m_analysisInfo, assembly);
|
||||
yul::CodeGenerator::assemble(*m_parserResult, *m_analysisInfo, assembly);
|
||||
object.bytecode = make_shared<eth::LinkerObject>(assembly.assemble());
|
||||
object.assembly = assembly.assemblyString();
|
||||
return object;
|
||||
@@ -132,5 +132,5 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
|
||||
string AssemblyStack::print() const
|
||||
{
|
||||
solAssert(m_parserResult, "");
|
||||
return assembly::AsmPrinter(m_language == Language::Yul)(*m_parserResult);
|
||||
return yul::AsmPrinter(m_language == Language::Yul)(*m_parserResult);
|
||||
}
|
||||
|
||||
@@ -34,16 +34,17 @@ namespace langutil
|
||||
class Scanner;
|
||||
}
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
{
|
||||
namespace assembly
|
||||
namespace yul
|
||||
{
|
||||
struct AsmAnalysisInfo;
|
||||
struct Block;
|
||||
}
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
{
|
||||
|
||||
struct MachineAssemblyObject
|
||||
{
|
||||
std::shared_ptr<eth::LinkerObject> bytecode;
|
||||
@@ -73,7 +74,7 @@ public:
|
||||
|
||||
/// 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, langutil::Scanner const* _scanner = nullptr);
|
||||
bool analyze(yul::Block const& _block, langutil::Scanner const* _scanner = nullptr);
|
||||
|
||||
/// Run the assembly step (should only be called after parseAndAnalyze).
|
||||
MachineAssemblyObject assemble(Machine _machine) const;
|
||||
@@ -93,8 +94,8 @@ private:
|
||||
std::shared_ptr<langutil::Scanner> m_scanner;
|
||||
|
||||
bool m_analysisSuccessful = false;
|
||||
std::shared_ptr<assembly::Block> m_parserResult;
|
||||
std::shared_ptr<assembly::AsmAnalysisInfo> m_analysisInfo;
|
||||
std::shared_ptr<yul::Block> m_parserResult;
|
||||
std::shared_ptr<yul::AsmAnalysisInfo> m_analysisInfo;
|
||||
langutil::ErrorList m_errors;
|
||||
langutil::ErrorReporter m_errorReporter;
|
||||
};
|
||||
|
||||
@@ -1012,8 +1012,8 @@ ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> con
|
||||
m_scanner->next();
|
||||
}
|
||||
|
||||
assembly::Parser asmParser(m_errorReporter);
|
||||
shared_ptr<assembly::Block> block = asmParser.parse(m_scanner, true);
|
||||
yul::Parser asmParser(m_errorReporter);
|
||||
shared_ptr<yul::Block> block = asmParser.parse(m_scanner, true);
|
||||
nodeFactory.markEndPosition();
|
||||
return nodeFactory.createNode<InlineAssembly>(_docString, block);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user