diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-09-21 21:19:14 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2018-09-26 19:46:03 +0800 |
commit | 913ddf158f46b66b58bd8e60105edfe6aad89188 (patch) | |
tree | 20b2966da9ef1cb9eb8fe2d2a73027a0b36fb6e7 | |
parent | 535026b492bd57eff6a96a4252e5ab32f5711b54 (diff) | |
download | dexon-solidity-913ddf158f46b66b58bd8e60105edfe6aad89188.tar.gz dexon-solidity-913ddf158f46b66b58bd8e60105edfe6aad89188.tar.zst dexon-solidity-913ddf158f46b66b58bd8e60105edfe6aad89188.zip |
Group LLL only assembly features in libevmasm
-rw-r--r-- | libevmasm/Assembly.h | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/libevmasm/Assembly.h b/libevmasm/Assembly.h index 9278c929..2a29874e 100644 --- a/libevmasm/Assembly.h +++ b/libevmasm/Assembly.h @@ -52,20 +52,19 @@ public: /// Returns a tag identified by the given name. Creates it if it does not yet exist. AssemblyItem namedTag(std::string const& _name); AssemblyItem newData(bytes const& _data) { h256 h(dev::keccak256(asString(_data))); m_data[h] = _data; return AssemblyItem(PushData, h); } + bytes const& data(h256 const& _i) const { return m_data.at(_i); } AssemblyItem newSub(AssemblyPointer const& _sub) { m_subs.push_back(_sub); return AssemblyItem(PushSub, m_subs.size() - 1); } Assembly const& sub(size_t _sub) const { return *m_subs.at(_sub); } Assembly& sub(size_t _sub) { return *m_subs.at(_sub); } - AssemblyItem newPushString(std::string const& _data) { h256 h(dev::keccak256(_data)); m_strings[h] = _data; return AssemblyItem(PushString, h); } AssemblyItem newPushSubSize(u256 const& _subId) { return AssemblyItem(PushSubSize, _subId); } AssemblyItem newPushLibraryAddress(std::string const& _identifier); - // These two are only used by liblll - void append(Assembly const& _a); - void append(Assembly const& _a, int _deposit); - AssemblyItem const& append(AssemblyItem const& _i); AssemblyItem const& append(std::string const& _data) { return append(newPushString(_data)); } AssemblyItem const& append(bytes const& _data) { return append(newData(_data)); } + + template <class T> Assembly& operator<<(T const& _d) { append(_d); return *this; } + /// Pushes the final size of the current assembly itself. Use this when the code is modified /// after compilation and CODESIZE is not an option. void appendProgramSize() { append(AssemblyItem(PushProgramSize)); } @@ -86,12 +85,9 @@ public: /// Appends @a _data literally to the very end of the bytecode. void appendAuxiliaryDataToEnd(bytes const& _data) { m_auxiliaryData += _data; } - template <class T> Assembly& operator<<(T const& _d) { append(_d); return *this; } + /// Returns the assembly items. AssemblyItems const& items() const { return m_items; } - AssemblyItem const& back() const { return m_items.back(); } - std::string backString() const { return m_items.size() && m_items.back().type() == PushString ? m_strings.at((h256)m_items.back().data()) : std::string(); } - void injectStart(AssemblyItem const& _i); int deposit() const { return m_deposit; } void adjustDeposit(int _adjustment) { m_deposit += _adjustment; assertThrow(m_deposit >= 0, InvalidDeposit, ""); } void setDeposit(int _deposit) { m_deposit = _deposit; assertThrow(m_deposit >= 0, InvalidDeposit, ""); } @@ -99,9 +95,8 @@ public: /// Changes the source location used for each appended item. void setSourceLocation(SourceLocation const& _location) { m_currentSourceLocation = _location; } - /// Assembles the assembly into bytecode. The assembly should not be modified after this call. + /// Assembles the assembly into bytecode. The assembly should not be modified after this call, since the assembled version is cached. LinkerObject const& assemble() const; - bytes const& data(h256 const& _i) const { return m_data.at(_i); } struct OptimiserSettings { @@ -142,6 +137,18 @@ public: StringMap const& _sourceCodes = StringMap() ) const; +public: + // These features are only used by LLL + AssemblyItem newPushString(std::string const& _data) { h256 h(dev::keccak256(_data)); m_strings[h] = _data; return AssemblyItem(PushString, h); } + + void append(Assembly const& _a); + void append(Assembly const& _a, int _deposit); + + void injectStart(AssemblyItem const& _i); + + AssemblyItem const& back() const { return m_items.back(); } + std::string backString() const { return m_items.size() && m_items.back().type() == PushString ? m_strings.at((h256)m_items.back().data()) : std::string(); } + protected: /// Does the same operations as @a optimise, but should only be applied to a sub and /// returns the replaced tags. Also takes an argument containing the tags of this assembly |