diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-06-14 06:55:34 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-06-23 07:09:35 +0800 |
commit | 5cf2332d6d273e6c9ac4c2b2bdb41c18b9cbf535 (patch) | |
tree | 5178cafa24d2fd0be88deaf30ce7f6e8d5c19b82 /libjulia/backends/evm/EVMAssembly.cpp | |
parent | 79ed529b3fc9fb03460ad3c8e6f1cb05434358b4 (diff) | |
download | dexon-solidity-5cf2332d6d273e6c9ac4c2b2bdb41c18b9cbf535.tar.gz dexon-solidity-5cf2332d6d273e6c9ac4c2b2bdb41c18b9cbf535.tar.zst dexon-solidity-5cf2332d6d273e6c9ac4c2b2bdb41c18b9cbf535.zip |
Support appendAssemblySize() in AbstractAssembly
Diffstat (limited to 'libjulia/backends/evm/EVMAssembly.cpp')
-rw-r--r-- | libjulia/backends/evm/EVMAssembly.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libjulia/backends/evm/EVMAssembly.cpp b/libjulia/backends/evm/EVMAssembly.cpp index 7ec26957..8ebebda1 100644 --- a/libjulia/backends/evm/EVMAssembly.cpp +++ b/libjulia/backends/evm/EVMAssembly.cpp @@ -32,6 +32,8 @@ namespace { /// Size of labels in bytes. Four-byte labels are required by some EVM1.5 instructions. size_t constexpr labelReferenceSize = 4; + +size_t constexpr assemblySizeReferenceSize = 4; } @@ -145,6 +147,12 @@ void EVMAssembly::appendReturnsub(int _returns, int _stackDiffAfter) eth::LinkerObject EVMAssembly::finalize() { + size_t bytecodeSize = m_bytecode.size(); + solAssert(uint64_t(bytecodeSize) < (uint64_t(1) << (8 * assemblySizeReferenceSize)), "Bytecode too big."); + for (auto const& ref: m_assemblySizePositions) + for (size_t i = 0; i < assemblySizeReferenceSize; i++) + m_bytecode[ref + i] = byte((bytecodeSize >> (8 * (assemblySizeReferenceSize - i - 1))) & 0xff); + for (auto const& ref: m_labelReferences) { size_t referencePos = ref.first; @@ -156,6 +164,7 @@ eth::LinkerObject EVMAssembly::finalize() for (size_t i = 0; i < labelReferenceSize; i++) m_bytecode[referencePos + i] = byte((labelPos >> (8 * (labelReferenceSize - i - 1))) & 0xff); } + eth::LinkerObject obj; obj.bytecode = m_bytecode; return obj; @@ -173,3 +182,10 @@ void EVMAssembly::appendLabelReferenceInternal(LabelID _labelId) m_labelReferences[m_bytecode.size()] = _labelId; m_bytecode += bytes(labelReferenceSize); } + +void EVMAssembly::appendAssemblySize() +{ + appendInstruction(solidity::pushInstruction(assemblySizeReferenceSize)); + m_assemblySizePositions.push_back(m_bytecode.size()); + m_bytecode += bytes(assemblySizeReferenceSize); +} |