diff options
Diffstat (limited to 'qtmips_gui/coreview')
-rw-r--r-- | qtmips_gui/coreview/logicblock.cpp | 4 | ||||
-rw-r--r-- | qtmips_gui/coreview/memory.cpp | 151 | ||||
-rw-r--r-- | qtmips_gui/coreview/memory.h | 53 | ||||
-rw-r--r-- | qtmips_gui/coreview/programcounter.cpp | 8 | ||||
-rw-r--r-- | qtmips_gui/coreview/registers.cpp | 15 | ||||
-rw-r--r-- | qtmips_gui/coreview/registers.h | 2 |
6 files changed, 133 insertions, 100 deletions
diff --git a/qtmips_gui/coreview/logicblock.cpp b/qtmips_gui/coreview/logicblock.cpp index 6b5769a..1ee9a18 100644 --- a/qtmips_gui/coreview/logicblock.cpp +++ b/qtmips_gui/coreview/logicblock.cpp @@ -10,9 +10,7 @@ using namespace coreview; #define PENW 1 ////////////////////// -LogicBlock::LogicBlock(QString name) { - LogicBlock({name}); -} +LogicBlock::LogicBlock(QString name) : LogicBlock(QVector<QString>({name})) { } LogicBlock::LogicBlock(QVector<QString> name) : QGraphicsItem(nullptr) { QFont font; diff --git a/qtmips_gui/coreview/memory.cpp b/qtmips_gui/coreview/memory.cpp index cde1c72..8f1669d 100644 --- a/qtmips_gui/coreview/memory.cpp +++ b/qtmips_gui/coreview/memory.cpp @@ -4,114 +4,127 @@ using namespace coreview; ////////////////////// -#define WIDTH 680 -#define HEIGHT 30 +#define WIDTH 60 +#define HEIGHT 80 +#define CACHE_HEIGHT 50 #define PENW 1 ////////////////////// -Memory::Memory(machine::QtMipsMachine *machine) : QGraphicsObject(nullptr) { - con_pc = new Connector(M_PI_2); - con_inst = new Connector(M_PI_2); - con_address = new Connector(M_PI_2); - con_data_in = new Connector(M_PI_2); - con_data_out = new Connector(M_PI_2); - con_req_write = new Connector(M_PI_2); - con_req_read = new Connector(M_PI_2); - - // TODO cache? - - name = new QGraphicsSimpleTextItem("Memory", this); - QRectF name_box = name->boundingRect(); - name->setPos(WIDTH/2 - name_box.width()/2, HEIGHT/2 - name_box.height()/2); - - // TODO add labels for connections +Memory::Memory(machine::QtMipsMachine *machine) : QGraphicsObject(nullptr), name("Memory", this), type(this) { + cache = false; QFont font; font.setPointSize(7); + name.setFont(font); + type.setFont(font); - // TODO better placement - name_program = new QGraphicsSimpleTextItem("Program", this); - name_box = name_program->boundingRect(); - name_program->setPos(1, HEIGHT - 1 - name_box.height()); - name_program->setFont(font); - - name_data = new QGraphicsSimpleTextItem("Data", this); - name_box = name_data->boundingRect(); - name_data->setPos(WIDTH - 1 - name_box.width(), HEIGHT - 1 - name_box.height()); - name_data->setFont(font); + const QRectF &name_box = name.boundingRect(); + name.setPos(WIDTH/2 - name_box.width()/2, HEIGHT - (HEIGHT - CACHE_HEIGHT)/2); setPos(x(), y()); // set connector's position } -Memory::~Memory() { - delete con_pc; - delete con_inst; - delete con_address; - delete con_data_out; - delete con_data_in; - delete con_req_write; - delete con_req_read; - - delete name; - delete name_program; - delete name_data; -} - QRectF Memory::boundingRect() const { return QRectF(-PENW / 2, -PENW / 2, WIDTH + PENW, HEIGHT + PENW); } void Memory::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) { painter->drawRect(0, 0, WIDTH, HEIGHT); - // TODO cache + if (cache) + painter->drawLine(0, CACHE_HEIGHT, WIDTH, CACHE_HEIGHT); } -void Memory::setPos(qreal x, qreal y) { - QGraphicsObject::setPos(x, y); +void Memory::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { + QGraphicsObject::mouseDoubleClickEvent(event); + + if (cache && event->pos().y() < HEIGHT/2) + emit open_cache(); + else + emit open_mem(); +} - con_pc->setPos(x + 30, y); - con_inst->setPos(x + 40, y); +void Memory::set_type(const QString &text) { + type.setText(text); + const QRectF &box = type.boundingRect(); + type.setPos(WIDTH/2 - box.width()/2, HEIGHT - (HEIGHT - CACHE_HEIGHT)/2 - box.height()); +} + +ProgramMemory::ProgramMemory(machine::QtMipsMachine *machine) : Memory(machine) { + cache = machine->config().cache_program().enabled(); + set_type("Program"); - con_address->setPos(x + WIDTH - 70, y); - con_data_in->setPos(x + WIDTH - 60, y); - con_req_write->setPos(x + WIDTH- 50, y); - con_req_read->setPos(x + WIDTH - 40, y); - con_data_out->setPos(x + WIDTH - 30, y); + con_address = new Connector(0); + con_inst = new Connector(M_PI); } -const Connector *Memory::connector_pc() const { - return con_pc; +ProgramMemory::~ProgramMemory() { + delete con_address; + delete con_inst; } -const Connector *Memory::connector_inst() const { +void ProgramMemory::setPos(qreal x, qreal y) { + QGraphicsObject::setPos(x, y); + + con_address->setPos(x, y + 20); + con_inst->setPos(x + WIDTH, y + 20); +} + +const Connector *ProgramMemory::connector_address() const { + return con_address; +} + +const Connector *ProgramMemory::connector_instruction() const { return con_inst; } -const Connector *Memory::connector_address() const { +DataMemory::DataMemory(machine::QtMipsMachine *machine) : Memory(machine) { + cache = machine->config().cache_data().enabled(); + set_type("Data"); + + con_address = new Connector(0); + con_data_out = new Connector(M_PI); + con_data_in = new Connector(0); + con_req_write = new Connector(M_PI_2); + con_req_read = new Connector(M_PI_2); +} + +DataMemory::~DataMemory() { + delete con_address; + delete con_data_out; + delete con_data_in; + delete con_req_write; + delete con_req_read; +} + +void DataMemory::setPos(qreal x, qreal y) { + QGraphicsObject::setPos(x, y); + + con_address->setPos(x, y + 20); + con_data_out->setPos(x + WIDTH, y + 20); + if (cache) + con_data_in->setPos(x, y + 40); + else + con_data_in->setPos(x, y + 60); + con_req_write->setPos(x + 40, y); + con_req_read->setPos(x + 50, y); +} + +const Connector *DataMemory::connector_address() const { return con_address; } -const Connector *Memory::connector_data_out() const { +const Connector *DataMemory::connector_data_out() const { return con_data_out; } -const Connector *Memory::connector_data_in() const { +const Connector *DataMemory::connector_data_in() const { return con_data_in; } -const Connector *Memory::connector_req_write() const { +const Connector *DataMemory::connector_req_write() const { return con_req_write; } -const Connector *Memory::connector_req_read() const { +const Connector *DataMemory::connector_req_read() const { return con_req_read; } - -void Memory::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { - QGraphicsObject::mouseDoubleClickEvent(event); - - if (event->pos().x() < WIDTH/2) - emit open_program_mem(); - else - emit open_data_mem(); -} diff --git a/qtmips_gui/coreview/memory.h b/qtmips_gui/coreview/memory.h index 067d62f..177dc6d 100644 --- a/qtmips_gui/coreview/memory.h +++ b/qtmips_gui/coreview/memory.h @@ -14,35 +14,56 @@ class Memory : public QGraphicsObject { Q_OBJECT public: Memory(machine::QtMipsMachine *machine); - ~Memory(); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); +signals: + void open_mem(); + void open_cache(); + +protected: + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + + void set_type(const QString&); + + bool cache; + +private: + QGraphicsSimpleTextItem name, type; +}; + +class ProgramMemory : public Memory { + Q_OBJECT +public: + ProgramMemory(machine::QtMipsMachine *machine); + ~ProgramMemory(); + + void setPos(qreal x, qreal y); + + const Connector *connector_address() const; + const Connector *connector_instruction() const; + +private: + Connector *con_address, *con_inst; +}; + +class DataMemory : public Memory { + Q_OBJECT +public: + DataMemory(machine::QtMipsMachine *machine); + ~DataMemory(); + void setPos(qreal x, qreal y); - const Connector *connector_pc() const; - const Connector *connector_inst() const; + const Connector *connector_address() const; const Connector *connector_data_out() const; const Connector *connector_data_in() const; const Connector *connector_req_write() const; const Connector *connector_req_read() const; - // TODO integrate cache - -signals: - void open_data_mem(); - void open_program_mem(); - -protected: - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); private: - // Connectors for instruction memory - Connector *con_pc, *con_inst; - // Connectors for data memory Connector *con_address, *con_data_out, *con_data_in, *con_req_write, *con_req_read; - - QGraphicsSimpleTextItem *name, *name_program, *name_data; }; } diff --git a/qtmips_gui/coreview/programcounter.cpp b/qtmips_gui/coreview/programcounter.cpp index b66d7ac..c43ff6d 100644 --- a/qtmips_gui/coreview/programcounter.cpp +++ b/qtmips_gui/coreview/programcounter.cpp @@ -22,8 +22,8 @@ ProgramCounter::ProgramCounter(machine::QtMipsMachine *machine) : QGraphicsObjec connect(machine->registers(), SIGNAL(pc_update(std::uint32_t)), this, SLOT(pc_update(std::uint32_t))); - con_in = new Connector(M_PI_2); - con_out = new Connector(-M_PI_2); + con_in = new Connector(-M_PI_2); + con_out = new Connector(M_PI_2); setPos(x(), y()); // To set initial connectors positions } @@ -37,8 +37,8 @@ void ProgramCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem *op void ProgramCounter::setPos(qreal x, qreal y) { QGraphicsObject::setPos(x, y); - con_in->setPos(x + WIDTH/2, y); - con_out->setPos(x + WIDTH/2, y + HEIGHT); + con_in->setPos(x + WIDTH/2, y + HEIGHT); + con_out->setPos(x + WIDTH/2, y); } const Connector *ProgramCounter::connector_in() const { diff --git a/qtmips_gui/coreview/registers.cpp b/qtmips_gui/coreview/registers.cpp index 12684e8..87db32e 100644 --- a/qtmips_gui/coreview/registers.cpp +++ b/qtmips_gui/coreview/registers.cpp @@ -4,12 +4,12 @@ using namespace coreview; ////////////////////// -#define WIDTH 680 -#define HEIGHT 30 +#define WIDTH 60 +#define HEIGHT 80 #define PENW 1 ////////////////////// -Registers::Registers() : QGraphicsObject(nullptr) { +Registers::Registers() : QGraphicsObject(nullptr), name("Registers", this) { con_read1 = new Connector(-M_PI_2); con_read1_reg = new Connector(-M_PI_2); con_read2 = new Connector(-M_PI_2); @@ -20,11 +20,12 @@ Registers::Registers() : QGraphicsObject(nullptr) { // TODO do we want to have any hooks on real registers? - // TODO add labels for connections + QFont font; + font.setPointSize(7); + name.setFont(font); - name = new QGraphicsSimpleTextItem("Registers", this); - QRectF name_box = name->boundingRect(); - name->setPos(WIDTH/2 - name_box.width()/2, HEIGHT/2 - name_box.height()/2); + QRectF name_box = name.boundingRect(); + name.setPos(WIDTH/2 - name_box.width()/2, HEIGHT/2 - name_box.height()/2); setPos(x(), y()); // set connector's position } diff --git a/qtmips_gui/coreview/registers.h b/qtmips_gui/coreview/registers.h index ece710d..67f09c5 100644 --- a/qtmips_gui/coreview/registers.h +++ b/qtmips_gui/coreview/registers.h @@ -36,7 +36,7 @@ private: Connector *con_read1, *con_read1_reg, *con_read2, *con_read2_reg; Connector *con_write, *con_write_reg, *con_ctl_write; - QGraphicsSimpleTextItem *name; + QGraphicsSimpleTextItem name; }; } |