diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-06-15 17:22:47 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-09-11 22:48:52 +0800 |
commit | a535a8b06ed1b9c0c5fd41805a4fe39939755f05 (patch) | |
tree | 94484019deeef72cc1bab99de51b844647ec6881 /libevmasm | |
parent | 55d2a459a9193024930101c79bbf48af2eb39e2d (diff) | |
download | dexon-solidity-a535a8b06ed1b9c0c5fd41805a4fe39939755f05.tar.gz dexon-solidity-a535a8b06ed1b9c0c5fd41805a4fe39939755f05.tar.zst dexon-solidity-a535a8b06ed1b9c0c5fd41805a4fe39939755f05.zip |
Split out the JSON functionality from assembly.stream()
Diffstat (limited to 'libevmasm')
-rw-r--r-- | libevmasm/Assembly.cpp | 21 | ||||
-rw-r--r-- | libevmasm/Assembly.h | 15 |
2 files changed, 13 insertions, 23 deletions
diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index 696ab0b3..a07226ca 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -181,7 +181,7 @@ private: } -ostream& Assembly::streamAsm(ostream& _out, string const& _prefix, StringMap const& _sourceCodes) const +ostream& Assembly::assemblyStream(ostream& _out, string const& _prefix, StringMap const& _sourceCodes) const { Functionalizer f(_out, _prefix, _sourceCodes); @@ -199,7 +199,7 @@ ostream& Assembly::streamAsm(ostream& _out, string const& _prefix, StringMap con for (size_t i = 0; i < m_subs.size(); ++i) { _out << endl << _prefix << "sub_" << i << ": assembly {\n"; - m_subs[i]->streamAsm(_out, _prefix + " ", _sourceCodes); + m_subs[i]->assemblyStream(_out, _prefix + " ", _sourceCodes); _out << _prefix << "}" << endl; } } @@ -230,7 +230,7 @@ string Assembly::toStringInHex(u256 _value) return hexStr.str(); } -Json::Value Assembly::streamAsmJson(ostream& _out, StringMap const& _sourceCodes) const +Json::Value Assembly::assemblyJSON(StringMap const& _sourceCodes) const { Json::Value root; @@ -301,29 +301,16 @@ Json::Value Assembly::streamAsmJson(ostream& _out, StringMap const& _sourceCodes { std::stringstream hexStr; hexStr << hex << i; - data[hexStr.str()] = m_subs[i]->stream(_out, "", _sourceCodes, true); + data[hexStr.str()] = m_subs[i]->assemblyJSON(_sourceCodes); } } if (m_auxiliaryData.size() > 0) root[".auxdata"] = toHex(m_auxiliaryData); - _out << root; - return root; } -Json::Value Assembly::stream(ostream& _out, string const& _prefix, StringMap const& _sourceCodes, bool _inJsonFormat) const -{ - if (_inJsonFormat) - return streamAsmJson(_out, _sourceCodes); - else - { - streamAsm(_out, _prefix, _sourceCodes); - return Json::Value(); - } -} - AssemblyItem const& Assembly::append(AssemblyItem const& _i) { assertThrow(m_deposit >= 0, AssemblyException, ""); diff --git a/libevmasm/Assembly.h b/libevmasm/Assembly.h index 8116c2ce..ab8f174d 100644 --- a/libevmasm/Assembly.h +++ b/libevmasm/Assembly.h @@ -120,11 +120,16 @@ public: /// If @a _enable is not set, will perform some simple peephole optimizations. Assembly& optimise(bool _enable, bool _isCreation = true, size_t _runs = 200); - Json::Value stream( + /// Create a text representation of the assembly. + std::ostream& assemblyStream( std::ostream& _out, std::string const& _prefix = "", - const StringMap &_sourceCodes = StringMap(), - bool _inJsonFormat = false + StringMap const& _sourceCodes = StringMap() + ) const; + + /// Create a JSON representation of the assembly. + Json::Value assemblyJSON( + StringMap const& _sourceCodes = StringMap() ) const; protected: @@ -136,8 +141,6 @@ protected: unsigned bytesRequired(unsigned subTagSize) const; private: - Json::Value streamAsmJson(std::ostream& _out, StringMap const& _sourceCodes) const; - std::ostream& streamAsm(std::ostream& _out, std::string const& _prefix, StringMap const& _sourceCodes) const; static Json::Value createJsonValue(std::string _name, int _begin, int _end, std::string _value = std::string(), std::string _jumpType = std::string()); static std::string toStringInHex(u256 _value); @@ -162,7 +165,7 @@ protected: inline std::ostream& operator<<(std::ostream& _out, Assembly const& _a) { - _a.stream(_out); + _a.assemblyStream(_out); return _out; } |