Named assembly labels.

This commit is contained in:
chriseth
2017-09-15 20:44:49 +01:00
committed by Alex Beregszaszi
parent 7dd372ce5c
commit 73771f5bb2
13 changed files with 108 additions and 28 deletions
+3 -13
View File
@@ -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(
+4 -1
View File
@@ -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.
+1 -1
View File
@@ -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);
}