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::eth;
void Assembly::append(Assembly const& _a)
{
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
{
for (unsigned br = 1;; ++br)
@ -172,7 +181,7 @@ Json::Value Assembly::createJsonValue(string _name, int _locationX, int _locatio
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;
@ -183,25 +192,32 @@ ostream& Assembly::streamAsmJson(ostream& _out, string const& _prefix, StringMap
switch (i.type())
{
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;
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;
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;
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;
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;
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;
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;
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);
for (auto it: currentCollection)
collection.append(it);
root[currentArrayName] = collection;
Json::Value rootData;
if (!m_data.empty() || !m_subs.empty())
{
Json::Value dataCollection(Json::arrayValue);
@ -249,29 +263,32 @@ ostream& Assembly::streamAsmJson(ostream& _out, string const& _prefix, StringMap
data["value"] = hexStr.str();
dataCollection.append(data);
}
rootData[_prefix + ".data"] = collection;
_out << root << rootData;
for (size_t i = 0; i < m_subs.size(); ++i)
{
std::stringstream hexStr;
hexStr << _prefix << hex << i << ": ";
//_out << _prefix << " " << hex << i << ": " << endl;
//todo check recursion check order.
m_subs[i].stream(_out, _prefix + " ", _sourceCodes, _inJsonFormat);
hexStr << _prefix << hex << i;
Json::Value num;
num["sub assembly"] = hexStr.str();
dataCollection.append(num);
dataCollection.append(m_subs[i].stream(_out, _prefix + " ", _sourceCodes, _inJsonFormat));
}
} else
root[_prefix + ".data"] = dataCollection;
_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)
return streamAsmJson(_out, _prefix, _sourceCodes, _inJsonFormat);
else
return streamAsm(_out, _prefix, _sourceCodes);
{
streamAsm(_out, _prefix, _sourceCodes);
return Json::Value();
}
}
AssemblyItem const& Assembly::append(AssemblyItem const& _i)

8
libevmcore/Assembly.h

@ -29,6 +29,7 @@
#include <libevmcore/Instruction.h>
#include <libevmcore/AssemblyItem.h>
#include "Exceptions.h"
#include <json/json.h>
namespace Json
{
@ -80,7 +81,7 @@ public:
void popTo(int _deposit) { while (m_deposit > _deposit) append(Instruction::POP); }
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; }
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()); }
@ -90,7 +91,7 @@ public:
bytes assemble() const;
Assembly& optimise(bool _enable);
std::ostream& stream(
Json::Value stream(
std::ostream& _out,
std::string const& _prefix = "",
const StringMap &_sourceCodes = StringMap(),
@ -102,7 +103,7 @@ protected:
unsigned bytesRequired() const;
private:
std::ostream& streamAsmJson(
Json::Value streamAsmJson(
std::ostream& _out,
const std::string &_prefix,
const StringMap &_sourceCodes,
@ -132,5 +133,6 @@ inline std::ostream& operator<<(std::ostream& _out, Assembly const& _a)
return _out;
}
}
}

1
liblll/CMakeLists.txt

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

Loading…
Cancel
Save