summaryrefslogtreecommitdiff
path: root/qwadb.h
blob: 87335cfc7edee40f959572d3765aced2e30d46e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef QWADB_H
#define QWADB_H

#include <QByteArray>
#include <QList>
#include <QMainWindow>
#include <QTcpSocket>
#include <QQueue>
#include "ui_qwadb.h"
#include "wasm.h"

QT_BEGIN_NAMESPACE
namespace Ui {
class QWadb;
}
QT_END_NAMESPACE

struct QWadbLinear
{
    WasmType type;
};

Q_DECLARE_METATYPE(QWadbLinear);

class QWadb : public QMainWindow
{
    Q_OBJECT

public:
    QWadb(const QCoreApplication &app, QWidget *parent = nullptr);

private:

    struct request
    {
        enum class type {global, local, param, bkpt, linear} type;
        varuint32 index, rindex;
        QVariant v;
    };

    void open(const QString &path);

    int trap(const QList<QByteArray> &frame);
    int ok(const QList<QByteArray> &frame);
    int parse(const QByteArray &frame);
    int process(const QByteArray &frame);
    QVariant parse_value(const QByteArray &v, WasmType type) const;
    int parse_global(const QList<QByteArray> &params) const;
    int parse_param(const QList<QByteArray> &params) const;
    int parse_local(const QList<QByteArray> &params) const;
    int parse_linear(const QList<QByteArray> &params) const;

    int push(const request &r);
    int pop(request &r);

    typedef int (QWadb::*stepfn)(char);
    int getlf(char b);
    int getsync(char b);

    int write(const QByteArray &ba);

    const char *to_fmt(WasmType type) const;
    const char *to_string(WasmType type) const;
    int from_string(const QString &s, WasmType &type) const;

    request lastreq;
    bool connected;
    QTcpSocket socket;
    QByteArray frame;
    QQueue<request> reqs;
    stepfn step;
    Ui::QWadb ui;
    Wasm w;

signals:
    void sendreq(void);

private slots:
    void disconnected(void);
};

#endif