Browse Source

- Instruction.h: add functions "getInstructionNumber"

- AssemblyDebuggerCtrl add members AppContext, QQMLApplicationEngine
cl-refactor
yann300 10 years ago
committed by yann300
parent
commit
c9bf5fcd7c
  1. 18
      libevmcore/Instruction.h
  2. 12
      mix/AssemblyDebuggerCtrl.cpp
  3. 3
      mix/AssemblyDebuggerCtrl.h
  4. 3
      mix/DebuggingStateWrapper.cpp

18
libevmcore/Instruction.h

@ -173,6 +173,24 @@ enum class Instruction: uint8_t
SUICIDE = 0xff ///< halt execution and register account for later deletion
};
/// @returns the number of PUSH Instruction _inst
inline unsigned getPushNumber(Instruction _inst)
{
return (byte)_inst - unsigned(Instruction::PUSH1) + 1;
}
/// @returns the number of DUP Instruction _inst
inline unsigned getDupNumber(Instruction _inst)
{
return (byte)_inst - unsigned(Instruction::DUP1) + 1;
}
/// @returns the number of SWAP Instruction _inst
inline unsigned getSwapNumber(Instruction _inst)
{
return (byte)_inst - unsigned(Instruction::SWAP1) + 1;
}
/// @returns the PUSH<_number> instruction
inline Instruction pushInstruction(unsigned _number)
{

12
mix/AssemblyDebuggerCtrl.cpp

@ -32,6 +32,8 @@ using namespace dev::mix;
AssemblyDebuggerCtrl::AssemblyDebuggerCtrl(QTextDocument* _doc): Extension(ExtensionDisplayBehavior::ModalDialog)
{
m_ctx = AppContext::getInstance();
m_appEngine = m_ctx->appEngine();
qRegisterMetaType<AssemblyDebuggerData>();
qRegisterMetaType<DebuggingStatusResult>();
connect(this, SIGNAL(dataAvailable(bool, DebuggingStatusResult, QList<QObject*>, AssemblyDebuggerData)),
@ -53,7 +55,7 @@ QString AssemblyDebuggerCtrl::title() const
void AssemblyDebuggerCtrl::start() const
{
//start to listen on F5
AppContext::getInstance()->getKeyEventManager()->registerEvent(this, SLOT(keyPressed(int)));
m_ctx->getKeyEventManager()->registerEvent(this, SLOT(keyPressed(int)));
}
void AssemblyDebuggerCtrl::keyPressed(int _key)
@ -95,11 +97,11 @@ void AssemblyDebuggerCtrl::updateGUI(bool success, DebuggingStatusResult reason,
Q_UNUSED(reason);
if (success)
{
AppContext::getInstance()->appEngine()->rootContext()->setContextProperty("debugStates", QVariant::fromValue(_wStates));
AppContext::getInstance()->appEngine()->rootContext()->setContextProperty("humanReadableExecutionCode", QVariant::fromValue(std::get<0>(_code)));
AppContext::getInstance()->appEngine()->rootContext()->setContextProperty("bytesCodeMapping", QVariant::fromValue(std::get<1>(_code)));
m_appEngine->rootContext()->setContextProperty("debugStates", QVariant::fromValue(_wStates));
m_appEngine->rootContext()->setContextProperty("humanReadableExecutionCode", QVariant::fromValue(std::get<0>(_code)));
m_appEngine->rootContext()->setContextProperty("bytesCodeMapping", QVariant::fromValue(std::get<1>(_code)));
this->addContentOn(this);
}
else
AppContext::getInstance()->displayMessageDialog("debugger","compilation failed");
m_ctx->displayMessageDialog("debugger","compilation failed");
}

3
mix/AssemblyDebuggerCtrl.h

@ -24,6 +24,7 @@
#include "Extension.h"
#include "ConstantCompilationModel.h"
#include "AssemblyDebuggerModel.h"
#include "AppContext.h"
using AssemblyDebuggerData = std::tuple<QList<QObject*>, dev::mix::QQMLMap*>;
enum DebuggingStatusResult
@ -54,6 +55,8 @@ public:
private:
std::unique_ptr<AssemblyDebuggerModel> m_modelDebugger;
QTextDocument* m_doc;
AppContext* m_ctx;
QQmlApplicationEngine* m_appEngine;
public slots:
void keyPressed(int);

3
mix/DebuggingStateWrapper.cpp

@ -23,6 +23,7 @@
#include <QDebug>
#include <QString>
#include <QTextStream>
#include "libevmcore/Instruction.h"
#include "libdevcore/CommonJS.h"
#include "libdevcrypto/Common.h"
#include "libevmcore/Instruction.h"
@ -48,7 +49,7 @@ std::tuple<QList<QObject*>, QQMLMap*> DebuggingStateWrapper::getHumanReadableCod
int line = i;
if (b >= (byte)Instruction::PUSH1 && b <= (byte)Instruction::PUSH32)
{
unsigned bc = b - (byte)Instruction::PUSH1 + 1;
unsigned bc = getPushNumber((Instruction)b);
s = "PUSH 0x" + QString::fromStdString(toHex(bytesConstRef(&_code[i + 1], bc)));
i += bc;
}

Loading…
Cancel
Save