aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-08-25 23:04:31 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-09-16 03:44:49 +0800
commit73771f5bb2d8aee1b71dfcc909a60aa47c591dec (patch)
tree25e580641cc09f52c11447e2045dea747f3980b3 /libsolidity
parent7dd372ce5c9ea1cacf2c70a16f0285bb74314db8 (diff)
downloaddexon-solidity-73771f5bb2d8aee1b71dfcc909a60aa47c591dec.tar.gz
dexon-solidity-73771f5bb2d8aee1b71dfcc909a60aa47c591dec.tar.zst
dexon-solidity-73771f5bb2d8aee1b71dfcc909a60aa47c591dec.zip
Named assembly labels.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/codegen/CompilerContext.cpp16
-rw-r--r--libsolidity/codegen/CompilerContext.h5
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp2
-rw-r--r--libsolidity/inlineasm/AsmCodeGen.cpp16
-rw-r--r--libsolidity/inlineasm/AsmCodeGen.h3
5 files changed, 24 insertions, 18 deletions
diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp
index ed780d0b..5a77162e 100644
--- a/libsolidity/codegen/CompilerContext.cpp
+++ b/libsolidity/codegen/CompilerContext.cpp
@@ -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(
diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h
index 5116585e..dd36bba0 100644
--- a/libsolidity/codegen/CompilerContext.h
+++ b/libsolidity/codegen/CompilerContext.h
@@ -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.
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index 146472f9..3662478d 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -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);
}
diff --git a/libsolidity/inlineasm/AsmCodeGen.cpp b/libsolidity/inlineasm/AsmCodeGen.cpp
index 6d0c0255..dded9f76 100644
--- a/libsolidity/inlineasm/AsmCodeGen.cpp
+++ b/libsolidity/inlineasm/AsmCodeGen.cpp
@@ -83,6 +83,10 @@ public:
{
return assemblyTagToIdentifier(m_assembly.newTag());
}
+ virtual size_t namedLabel(std::string const& _name) override
+ {
+ return assemblyTagToIdentifier(m_assembly.namedTag(_name));
+ }
virtual void appendLinkerSymbol(std::string const& _linkerSymbol) override
{
m_assembly.appendLibraryAddress(_linkerSymbol);
@@ -141,9 +145,17 @@ void assembly::CodeGenerator::assemble(
Block const& _parsedData,
AsmAnalysisInfo& _analysisInfo,
eth::Assembly& _assembly,
- julia::ExternalIdentifierAccess const& _identifierAccess
+ julia::ExternalIdentifierAccess const& _identifierAccess,
+ bool _useNamedLabelsForFunctions
)
{
EthAssemblyAdapter assemblyAdapter(_assembly);
- julia::CodeTransform(assemblyAdapter, _analysisInfo, false, false, _identifierAccess)(_parsedData);
+ julia::CodeTransform(
+ assemblyAdapter,
+ _analysisInfo,
+ false,
+ false,
+ _identifierAccess,
+ _useNamedLabelsForFunctions
+ )(_parsedData);
}
diff --git a/libsolidity/inlineasm/AsmCodeGen.h b/libsolidity/inlineasm/AsmCodeGen.h
index 2a36a590..a7d7ead1 100644
--- a/libsolidity/inlineasm/AsmCodeGen.h
+++ b/libsolidity/inlineasm/AsmCodeGen.h
@@ -46,7 +46,8 @@ public:
Block const& _parsedData,
AsmAnalysisInfo& _analysisInfo,
eth::Assembly& _assembly,
- julia::ExternalIdentifierAccess const& _identifierAccess = julia::ExternalIdentifierAccess()
+ julia::ExternalIdentifierAccess const& _identifierAccess = julia::ExternalIdentifierAccess(),
+ bool _useNamedLabelsForFunctions = false
);
};