Browse Source

reordered output

Conflicts:
	libevmcore/Assembly.cpp
cl-refactor
Liana Husikyan 10 years ago
parent
commit
c6652616ae
  1. 57
      libevmcore/Assembly.cpp
  2. 8
      libevmcore/Assembly.h
  3. 1
      liblll/CMakeLists.txt

57
libevmcore/Assembly.cpp

@ -30,6 +30,8 @@ using namespace std;
using namespace dev; using namespace dev;
using namespace dev::eth; using namespace dev::eth;
void Assembly::append(Assembly const& _a) void Assembly::append(Assembly const& _a)
{ {
auto newDeposit = m_deposit + _a.deposit(); auto newDeposit = m_deposit + _a.deposit();
@ -66,6 +68,13 @@ void Assembly::append(Assembly const& _a, int _deposit)
} }
} }
string Assembly::out() const
{
stringstream ret;
stream(ret);
return ret.str();
}
unsigned Assembly::bytesRequired() const unsigned Assembly::bytesRequired() const
{ {
for (unsigned br = 1;; ++br) for (unsigned br = 1;; ++br)
@ -172,7 +181,7 @@ Json::Value Assembly::createJsonValue(string _name, int _locationX, int _locatio
return move(value); return move(value);
} }
ostream& Assembly::streamAsmJson(ostream& _out, string const& _prefix, StringMap const& _sourceCodes, bool _inJsonFormat) const Json::Value Assembly::streamAsmJson(ostream& _out, string const& _prefix, StringMap const& _sourceCodes, bool _inJsonFormat) const
{ {
Json::Value root; Json::Value root;
@ -183,25 +192,32 @@ ostream& Assembly::streamAsmJson(ostream& _out, string const& _prefix, StringMap
switch (i.type()) switch (i.type())
{ {
case Operation: case Operation:
currentCollection.push_back(createJsonValue(instructionInfo(i.instruction()).name, i.getLocation().start, i.getLocation().end, i.getJumpTypeAsString())); currentCollection.push_back(
createJsonValue(instructionInfo(i.instruction()).name, i.getLocation().start, i.getLocation().end, i.getJumpTypeAsString()));
break; break;
case Push: case Push:
currentCollection.push_back(createJsonValue(string("PUSH"), i.getLocation().start, i.getLocation().end, string(i.data()), i.getJumpTypeAsString())); currentCollection.push_back(
createJsonValue(string("PUSH"), i.getLocation().start, i.getLocation().end, string(i.data()), i.getJumpTypeAsString()));
break; break;
case PushString: case PushString:
currentCollection.push_back(createJsonValue(string("PUSH tag"), i.getLocation().start, i.getLocation().end, m_strings.at((h256)i.data()))); currentCollection.push_back(
createJsonValue(string("PUSH tag"), i.getLocation().start, i.getLocation().end, m_strings.at((h256)i.data())));
break; break;
case PushTag: case PushTag:
currentCollection.push_back(createJsonValue(string("PUSH [tag]"), i.getLocation().start, i.getLocation().end, string(i.data()))); currentCollection.push_back(
createJsonValue(string("PUSH [tag]"), i.getLocation().start, i.getLocation().end, string(i.data())));
break; break;
case PushSub: case PushSub:
currentCollection.push_back(createJsonValue(string("PUSH"), i.getLocation().start, i.getLocation().end, string("[$]" + string(h256(i.data()).abridged())))); currentCollection.push_back(
createJsonValue(string("PUSH"), i.getLocation().start, i.getLocation().end, string("[$]" + string(h256(i.data()).abridged()))));
break; break;
case PushSubSize: case PushSubSize:
currentCollection.push_back(createJsonValue(string("PUSH"), i.getLocation().start, i.getLocation().end, string("#[$]" + string(h256(i.data()).abridged())))); currentCollection.push_back(
createJsonValue(string("PUSH"), i.getLocation().start, i.getLocation().end, string("#[$]" + string(h256(i.data()).abridged()))));
break; break;
case PushProgramSize: case PushProgramSize:
currentCollection.push_back(createJsonValue(string("PUSHSIZE"), i.getLocation().start, i.getLocation().end)); currentCollection.push_back(
createJsonValue(string("PUSHSIZE"), i.getLocation().start, i.getLocation().end));
break; break;
case Tag: case Tag:
{ {
@ -230,13 +246,11 @@ ostream& Assembly::streamAsmJson(ostream& _out, string const& _prefix, StringMap
} }
} }
//todo check if the last was tag
Json::Value collection(Json::arrayValue); Json::Value collection(Json::arrayValue);
for (auto it: currentCollection) for (auto it: currentCollection)
collection.append(it); collection.append(it);
root[currentArrayName] = collection; root[currentArrayName] = collection;
Json::Value rootData;
if (!m_data.empty() || !m_subs.empty()) if (!m_data.empty() || !m_subs.empty())
{ {
Json::Value dataCollection(Json::arrayValue); Json::Value dataCollection(Json::arrayValue);
@ -249,29 +263,32 @@ ostream& Assembly::streamAsmJson(ostream& _out, string const& _prefix, StringMap
data["value"] = hexStr.str(); data["value"] = hexStr.str();
dataCollection.append(data); dataCollection.append(data);
} }
rootData[_prefix + ".data"] = collection;
_out << root << rootData;
for (size_t i = 0; i < m_subs.size(); ++i) for (size_t i = 0; i < m_subs.size(); ++i)
{ {
std::stringstream hexStr; std::stringstream hexStr;
hexStr << _prefix << hex << i << ": "; hexStr << _prefix << hex << i;
//_out << _prefix << " " << hex << i << ": " << endl; Json::Value num;
//todo check recursion check order. num["sub assembly"] = hexStr.str();
m_subs[i].stream(_out, _prefix + " ", _sourceCodes, _inJsonFormat); dataCollection.append(num);
dataCollection.append(m_subs[i].stream(_out, _prefix + " ", _sourceCodes, _inJsonFormat));
} }
} else root[_prefix + ".data"] = dataCollection;
_out << root; _out << root;
}
return _out; return move(root);
} }
ostream& Assembly::stream(ostream& _out, string const& _prefix, StringMap const& _sourceCodes, bool _inJsonFormat) const Json::Value Assembly::stream(ostream& _out, string const& _prefix, StringMap const& _sourceCodes, bool _inJsonFormat) const
{ {
if (_inJsonFormat) if (_inJsonFormat)
return streamAsmJson(_out, _prefix, _sourceCodes, _inJsonFormat); return streamAsmJson(_out, _prefix, _sourceCodes, _inJsonFormat);
else else
return streamAsm(_out, _prefix, _sourceCodes); {
streamAsm(_out, _prefix, _sourceCodes);
return Json::Value();
}
} }
AssemblyItem const& Assembly::append(AssemblyItem const& _i) AssemblyItem const& Assembly::append(AssemblyItem const& _i)

8
libevmcore/Assembly.h

@ -29,6 +29,7 @@
#include <libevmcore/Instruction.h> #include <libevmcore/Instruction.h>
#include <libevmcore/AssemblyItem.h> #include <libevmcore/AssemblyItem.h>
#include "Exceptions.h" #include "Exceptions.h"
#include <json/json.h>
namespace Json namespace Json
{ {
@ -80,7 +81,7 @@ public:
void popTo(int _deposit) { while (m_deposit > _deposit) append(Instruction::POP); } void popTo(int _deposit) { while (m_deposit > _deposit) append(Instruction::POP); }
void injectStart(AssemblyItem const& _i); void injectStart(AssemblyItem const& _i);
std::string out() const { std::stringstream ret; stream(ret); return ret.str(); } std::string out() const;
int deposit() const { return m_deposit; } int deposit() const { return m_deposit; }
void adjustDeposit(int _adjustment) { m_deposit += _adjustment; if (asserts(m_deposit >= 0)) BOOST_THROW_EXCEPTION(InvalidDeposit()); } void adjustDeposit(int _adjustment) { m_deposit += _adjustment; if (asserts(m_deposit >= 0)) BOOST_THROW_EXCEPTION(InvalidDeposit()); }
void setDeposit(int _deposit) { m_deposit = _deposit; if (asserts(m_deposit >= 0)) BOOST_THROW_EXCEPTION(InvalidDeposit()); } void setDeposit(int _deposit) { m_deposit = _deposit; if (asserts(m_deposit >= 0)) BOOST_THROW_EXCEPTION(InvalidDeposit()); }
@ -90,7 +91,7 @@ public:
bytes assemble() const; bytes assemble() const;
Assembly& optimise(bool _enable); Assembly& optimise(bool _enable);
std::ostream& stream( Json::Value stream(
std::ostream& _out, std::ostream& _out,
std::string const& _prefix = "", std::string const& _prefix = "",
const StringMap &_sourceCodes = StringMap(), const StringMap &_sourceCodes = StringMap(),
@ -102,7 +103,7 @@ protected:
unsigned bytesRequired() const; unsigned bytesRequired() const;
private: private:
std::ostream& streamAsmJson( Json::Value streamAsmJson(
std::ostream& _out, std::ostream& _out,
const std::string &_prefix, const std::string &_prefix,
const StringMap &_sourceCodes, const StringMap &_sourceCodes,
@ -132,5 +133,6 @@ inline std::ostream& operator<<(std::ostream& _out, Assembly const& _a)
return _out; return _out;
} }
} }
} }

1
liblll/CMakeLists.txt

@ -11,6 +11,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB")
aux_source_directory(. SRC_LIST) aux_source_directory(. SRC_LIST)
include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS})
include_directories(BEFORE ..) include_directories(BEFORE ..)
include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS})

Loading…
Cancel
Save