mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Interface for new ABI encoder.
This commit is contained in:
parent
42fe8a2cb1
commit
4630b3315a
@ -25,6 +25,7 @@
|
|||||||
#include <libevmasm/Instruction.h>
|
#include <libevmasm/Instruction.h>
|
||||||
#include <libsolidity/codegen/ArrayUtils.h>
|
#include <libsolidity/codegen/ArrayUtils.h>
|
||||||
#include <libsolidity/codegen/LValue.h>
|
#include <libsolidity/codegen/LValue.h>
|
||||||
|
#include <libsolidity/codegen/ABIFunctions.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -180,8 +181,17 @@ void CompilerUtils::encodeToMemory(
|
|||||||
t = t->mobileType()->interfaceType(_encodeAsLibraryTypes)->encodingType();
|
t = t->mobileType()->interfaceType(_encodeAsLibraryTypes)->encodingType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool activateNewEncoder = false;
|
||||||
if (_givenTypes.empty())
|
if (_givenTypes.empty())
|
||||||
return;
|
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:
|
// Stack during operation:
|
||||||
// <v1> <v2> ... <vn> <mem_start> <dyn_head_1> ... <dyn_head_r> <end_of_mem>
|
// <v1> <v2> ... <vn> <mem_start> <dyn_head_1> ... <dyn_head_r> <end_of_mem>
|
||||||
@ -289,6 +299,28 @@ void CompilerUtils::encodeToMemory(
|
|||||||
popStackSlots(argSize + dynPointers + 1);
|
popStackSlots(argSize + dynPointers + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CompilerUtils::abiEncode(
|
||||||
|
TypePointers const& _givenTypes,
|
||||||
|
TypePointers const& _targetTypes,
|
||||||
|
bool _encodeAsLibraryTypes
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// stack: <$value0> <$value1> ... <$value(n-1)> <$headStart>
|
||||||
|
|
||||||
|
vector<string> 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)
|
void CompilerUtils::zeroInitialiseMemoryArray(ArrayType const& _type)
|
||||||
{
|
{
|
||||||
auto repeat = m_context.newTag();
|
auto repeat = m_context.newTag();
|
||||||
|
@ -103,6 +103,14 @@ public:
|
|||||||
bool _encodeAsLibraryTypes = false
|
bool _encodeAsLibraryTypes = false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// Special case of @a encodeToMemory which assumes that everything is padded to words
|
||||||
|
/// and dynamic data is not copied in place (i.e. a proper ABI encoding).
|
||||||
|
void abiEncode(
|
||||||
|
TypePointers const& _givenTypes,
|
||||||
|
TypePointers const& _targetTypes,
|
||||||
|
bool _encodeAsLibraryTypes = false
|
||||||
|
);
|
||||||
|
|
||||||
/// Zero-initialises (the data part of) an already allocated memory array.
|
/// Zero-initialises (the data part of) an already allocated memory array.
|
||||||
/// Length has to be nonzero!
|
/// Length has to be nonzero!
|
||||||
/// Stack pre: <length> <memptr>
|
/// Stack pre: <length> <memptr>
|
||||||
|
Loading…
Reference in New Issue
Block a user