aboutsummaryrefslogtreecommitdiffstats
path: root/libjulia
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-06-14 06:55:34 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-06-23 07:09:35 +0800
commit5cf2332d6d273e6c9ac4c2b2bdb41c18b9cbf535 (patch)
tree5178cafa24d2fd0be88deaf30ce7f6e8d5c19b82 /libjulia
parent79ed529b3fc9fb03460ad3c8e6f1cb05434358b4 (diff)
downloaddexon-solidity-5cf2332d6d273e6c9ac4c2b2bdb41c18b9cbf535.tar.gz
dexon-solidity-5cf2332d6d273e6c9ac4c2b2bdb41c18b9cbf535.tar.zst
dexon-solidity-5cf2332d6d273e6c9ac4c2b2bdb41c18b9cbf535.zip
Support appendAssemblySize() in AbstractAssembly
Diffstat (limited to 'libjulia')
-rw-r--r--libjulia/backends/evm/AbstractAssembly.h3
-rw-r--r--libjulia/backends/evm/EVMAssembly.cpp16
-rw-r--r--libjulia/backends/evm/EVMAssembly.h3
3 files changed, 22 insertions, 0 deletions
diff --git a/libjulia/backends/evm/AbstractAssembly.h b/libjulia/backends/evm/AbstractAssembly.h
index f667c1a7..cfc9b8a5 100644
--- a/libjulia/backends/evm/AbstractAssembly.h
+++ b/libjulia/backends/evm/AbstractAssembly.h
@@ -89,6 +89,9 @@ public:
/// Return from a subroutine.
/// @param _stackDiffAfter the stack adjustment after this instruction.
virtual void appendReturnsub(int _returns, int _stackDiffAfter = 0) = 0;
+
+ /// Append the assembled size as a constant.
+ virtual void appendAssemblySize() = 0;
};
enum class IdentifierContext { LValue, RValue };
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);
+}
diff --git a/libjulia/backends/evm/EVMAssembly.h b/libjulia/backends/evm/EVMAssembly.h
index a2df0cdc..d6d667b0 100644
--- a/libjulia/backends/evm/EVMAssembly.h
+++ b/libjulia/backends/evm/EVMAssembly.h
@@ -70,6 +70,8 @@ public:
/// Return from a subroutine.
virtual void appendReturnsub(int _returns, int _stackDiffAfter) override;
+ /// Append the assembled size as a constant.
+ virtual void appendAssemblySize() override;
/// Resolves references inside the bytecode and returns the linker object.
eth::LinkerObject finalize();
@@ -84,6 +86,7 @@ private:
bytes m_bytecode;
std::map<LabelID, size_t> m_labelPositions;
std::map<size_t, LabelID> m_labelReferences;
+ std::vector<size_t> m_assemblySizePositions;
};
}