From 4630b3315aa249508036998e4ed122b5ba260ba1 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 7 Aug 2017 16:46:09 +0200 Subject: Interface for new ABI encoder. --- libsolidity/codegen/CompilerUtils.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'libsolidity/codegen/CompilerUtils.cpp') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 782aad9d..d2dab7d7 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -25,6 +25,7 @@ #include #include #include +#include using namespace std; @@ -180,8 +181,17 @@ void CompilerUtils::encodeToMemory( t = t->mobileType()->interfaceType(_encodeAsLibraryTypes)->encodingType(); } + bool activateNewEncoder = false; if (_givenTypes.empty()) return; + else if (activateNewEncoder && _padToWordBoundaries && !_copyDynamicDataInPlace) + { + // Use the new JULIA-based encoding function + auto stackHeightBefore = m_context.stackHeight(); + abiEncode(_givenTypes, targetTypes, _encodeAsLibraryTypes); + solAssert(stackHeightBefore - m_context.stackHeight() == sizeOnStack(_givenTypes), ""); + return; + } // Stack during operation: // ... ... @@ -289,6 +299,28 @@ void CompilerUtils::encodeToMemory( popStackSlots(argSize + dynPointers + 1); } +void CompilerUtils::abiEncode( + TypePointers const& _givenTypes, + TypePointers const& _targetTypes, + bool _encodeAsLibraryTypes +) +{ + // stack: <$value0> <$value1> ... <$value(n-1)> <$headStart> + + vector variables; + size_t numValues = sizeOnStack(_givenTypes); + for (size_t i = 0; i < numValues; ++i) + variables.push_back("$value" + to_string(i)); + variables.push_back("$headStart"); + + ABIFunctions funs; + string routine = funs.tupleEncoder(_givenTypes, _targetTypes, _encodeAsLibraryTypes); + routine += funs.requestedFunctions(); + m_context.appendInlineAssembly("{" + routine + "}", variables); + // Remove everyhing except for "value0" / the final memory pointer. + popStackSlots(numValues); +} + void CompilerUtils::zeroInitialiseMemoryArray(ArrayType const& _type) { auto repeat = m_context.newTag(); -- cgit v1.2.3 From d1ad62fccc02dba20129d59a81f260b9ac6b41de Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 10 Aug 2017 17:56:04 +0200 Subject: Experimental feature switch for ABI encoder. --- libsolidity/codegen/CompilerUtils.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'libsolidity/codegen/CompilerUtils.cpp') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index d2dab7d7..a0fc5d55 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -181,10 +181,13 @@ void CompilerUtils::encodeToMemory( t = t->mobileType()->interfaceType(_encodeAsLibraryTypes)->encodingType(); } - bool activateNewEncoder = false; if (_givenTypes.empty()) return; - else if (activateNewEncoder && _padToWordBoundaries && !_copyDynamicDataInPlace) + else if ( + _padToWordBoundaries && + !_copyDynamicDataInPlace && + m_context.experimentalFeatureActive(ExperimentalFeature::ABIEncoderV2) + ) { // Use the new JULIA-based encoding function auto stackHeightBefore = m_context.stackHeight(); -- cgit v1.2.3