mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Named assembly labels.
This commit is contained in:
committed by
Alex Beregszaszi
parent
7dd372ce5c
commit
73771f5bb2
@@ -266,19 +266,9 @@ void CompilerContext::resetVisitedNodes(ASTNode const* _node)
|
||||
void CompilerContext::appendInlineAssembly(
|
||||
string const& _assembly,
|
||||
vector<string> const& _localVariables,
|
||||
map<string, string> const& _replacements
|
||||
bool _system
|
||||
)
|
||||
{
|
||||
string replacedAssembly;
|
||||
string const* assembly = &_assembly;
|
||||
if (!_replacements.empty())
|
||||
{
|
||||
replacedAssembly = _assembly;
|
||||
for (auto const& replacement: _replacements)
|
||||
replacedAssembly = boost::algorithm::replace_all_copy(replacedAssembly, replacement.first, replacement.second);
|
||||
assembly = &replacedAssembly;
|
||||
}
|
||||
|
||||
int startStackHeight = stackHeight();
|
||||
|
||||
julia::ExternalIdentifierAccess identifierAccess;
|
||||
@@ -320,7 +310,7 @@ void CompilerContext::appendInlineAssembly(
|
||||
|
||||
ErrorList errors;
|
||||
ErrorReporter errorReporter(errors);
|
||||
auto scanner = make_shared<Scanner>(CharStream(*assembly), "--CODEGEN--");
|
||||
auto scanner = make_shared<Scanner>(CharStream(_assembly), "--CODEGEN--");
|
||||
auto parserResult = assembly::Parser(errorReporter).parse(scanner);
|
||||
solAssert(parserResult, "Failed to parse inline assembly block.");
|
||||
solAssert(errorReporter.errors().empty(), "Failed to parse inline assembly block.");
|
||||
@@ -329,7 +319,7 @@ void CompilerContext::appendInlineAssembly(
|
||||
assembly::AsmAnalyzer analyzer(analysisInfo, errorReporter, false, identifierAccess.resolve);
|
||||
solAssert(analyzer.analyze(*parserResult), "Failed to analyze inline assembly block.");
|
||||
solAssert(errorReporter.errors().empty(), "Failed to analyze inline assembly block.");
|
||||
assembly::CodeGenerator::assemble(*parserResult, analysisInfo, *m_asm, identifierAccess);
|
||||
assembly::CodeGenerator::assemble(*parserResult, analysisInfo, *m_asm, identifierAccess, _system);
|
||||
}
|
||||
|
||||
FunctionDefinition const& CompilerContext::resolveVirtualFunction(
|
||||
|
||||
@@ -156,6 +156,8 @@ public:
|
||||
eth::AssemblyItem pushNewTag() { return m_asm->append(m_asm->newPushTag()).tag(); }
|
||||
/// @returns a new tag without pushing any opcodes or data
|
||||
eth::AssemblyItem newTag() { return m_asm->newTag(); }
|
||||
/// @returns a new tag identified by name.
|
||||
eth::AssemblyItem namedTag(std::string const& _name) { return m_asm->namedTag(_name); }
|
||||
/// Adds a subroutine to the code (in the data section) and pushes its size (via a tag)
|
||||
/// on the stack. @returns the pushsub assembly item.
|
||||
eth::AssemblyItem addSubroutine(eth::AssemblyPointer const& _assembly) { return m_asm->appendSubroutine(_assembly); }
|
||||
@@ -185,10 +187,11 @@ public:
|
||||
/// Appends inline assembly. @a _replacements are string-matching replacements that are performed
|
||||
/// prior to parsing the inline assembly.
|
||||
/// @param _localVariables assigns stack positions to variables with the last one being the stack top
|
||||
/// @param _system if true, this is a "system-level" assembly where all functions use named labels.
|
||||
void appendInlineAssembly(
|
||||
std::string const& _assembly,
|
||||
std::vector<std::string> const& _localVariables = std::vector<std::string>(),
|
||||
std::map<std::string, std::string> const& _replacements = std::map<std::string, std::string>{}
|
||||
bool _system = false
|
||||
);
|
||||
|
||||
/// Appends arbitrary data to the end of the bytecode.
|
||||
|
||||
@@ -319,7 +319,7 @@ void CompilerUtils::abiEncode(
|
||||
ABIFunctions funs;
|
||||
string routine = funs.tupleEncoder(_givenTypes, _targetTypes, _encodeAsLibraryTypes);
|
||||
routine += funs.requestedFunctions();
|
||||
m_context.appendInlineAssembly("{" + routine + "}", variables);
|
||||
m_context.appendInlineAssembly("{" + routine + "}", variables, true);
|
||||
// Remove everyhing except for "value0" / the final memory pointer.
|
||||
popStackSlots(numValues);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user