aboutsummaryrefslogtreecommitdiffstats
path: root/libjulia/backends/evm
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-06-23 08:00:14 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-06-23 08:00:14 +0800
commit58fca7215c2735a7697278ca7f0dd52393b2b301 (patch)
treeab945c3044fc12d54c54839455319f3bd6d97c24 /libjulia/backends/evm
parent5cf2332d6d273e6c9ac4c2b2bdb41c18b9cbf535 (diff)
downloaddexon-solidity-58fca7215c2735a7697278ca7f0dd52393b2b301.tar
dexon-solidity-58fca7215c2735a7697278ca7f0dd52393b2b301.tar.gz
dexon-solidity-58fca7215c2735a7697278ca7f0dd52393b2b301.tar.bz2
dexon-solidity-58fca7215c2735a7697278ca7f0dd52393b2b301.tar.lz
dexon-solidity-58fca7215c2735a7697278ca7f0dd52393b2b301.tar.xz
dexon-solidity-58fca7215c2735a7697278ca7f0dd52393b2b301.tar.zst
dexon-solidity-58fca7215c2735a7697278ca7f0dd52393b2b301.zip
Refactor updateReference
Diffstat (limited to 'libjulia/backends/evm')
-rw-r--r--libjulia/backends/evm/EVMAssembly.cpp17
-rw-r--r--libjulia/backends/evm/EVMAssembly.h1
2 files changed, 11 insertions, 7 deletions
diff --git a/libjulia/backends/evm/EVMAssembly.cpp b/libjulia/backends/evm/EVMAssembly.cpp
index 8ebebda1..173d5e93 100644
--- a/libjulia/backends/evm/EVMAssembly.cpp
+++ b/libjulia/backends/evm/EVMAssembly.cpp
@@ -148,10 +148,8 @@ 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);
+ updateReference(ref, assemblySizeReferenceSize, u256(bytecodeSize));
for (auto const& ref: m_labelReferences)
{
@@ -159,10 +157,7 @@ eth::LinkerObject EVMAssembly::finalize()
solAssert(m_labelPositions.count(ref.second), "");
size_t labelPos = m_labelPositions.at(ref.second);
solAssert(labelPos != size_t(-1), "Undefined but allocated label used.");
- solAssert(m_bytecode.size() >= 4 && referencePos <= m_bytecode.size() - 4, "");
- solAssert(uint64_t(labelPos) < (uint64_t(1) << (8 * labelReferenceSize)), "");
- for (size_t i = 0; i < labelReferenceSize; i++)
- m_bytecode[referencePos + i] = byte((labelPos >> (8 * (labelReferenceSize - i - 1))) & 0xff);
+ updateReference(referencePos, labelReferenceSize, u256(labelPos));
}
eth::LinkerObject obj;
@@ -189,3 +184,11 @@ void EVMAssembly::appendAssemblySize()
m_assemblySizePositions.push_back(m_bytecode.size());
m_bytecode += bytes(assemblySizeReferenceSize);
}
+
+void EVMAssembly::updateReference(size_t pos, size_t size, u256 value)
+{
+ solAssert(m_bytecode.size() >= size && pos <= m_bytecode.size() - size, "");
+ solAssert(value < (u256(1) << (8 * size)), "");
+ for (size_t i = 0; i < size; i++)
+ m_bytecode[pos + i] = byte((value >> (8 * (size - i - 1))) & 0xff);
+}
diff --git a/libjulia/backends/evm/EVMAssembly.h b/libjulia/backends/evm/EVMAssembly.h
index d6d667b0..69585822 100644
--- a/libjulia/backends/evm/EVMAssembly.h
+++ b/libjulia/backends/evm/EVMAssembly.h
@@ -79,6 +79,7 @@ public:
private:
void setLabelToCurrentPosition(AbstractAssembly::LabelID _labelId);
void appendLabelReferenceInternal(AbstractAssembly::LabelID _labelId);
+ void updateReference(size_t pos, size_t size, u256 value);
bool m_evm15 = false; ///< if true, switch to evm1.5 mode
LabelID m_nextLabelId = 0;