aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui
diff options
context:
space:
mode:
Diffstat (limited to 'qtmips_gui')
-rw-r--r--qtmips_gui/coreview/memory.cpp30
-rw-r--r--qtmips_gui/coreview/memory.h7
2 files changed, 30 insertions, 7 deletions
diff --git a/qtmips_gui/coreview/memory.cpp b/qtmips_gui/coreview/memory.cpp
index f4ba058..41e7ee9 100644
--- a/qtmips_gui/coreview/memory.cpp
+++ b/qtmips_gui/coreview/memory.cpp
@@ -6,20 +6,30 @@ using namespace coreview;
//////////////////////
#define WIDTH 60
#define HEIGHT 80
-#define CACHE_HEIGHT 50
+#define CACHE_HEIGHT 47
#define PENW 1
//////////////////////
-Memory::Memory(machine::QtMipsMachine *machine) : QGraphicsObject(nullptr), name("Memory", this), type(this) {
+Memory::Memory(const machine::Cache *cch) : QGraphicsObject(nullptr), name("Memory", this), type(this), cache_t("Cache", this), cache_hit_t("Hit: 0", this), cache_miss_t("Miss: 0", this) {
cache = false;
QFont font;
font.setPointSize(7);
name.setFont(font);
type.setFont(font);
+ cache_t.setFont(font);
+ cache_hit_t.setFont(font);
+ cache_miss_t.setFont(font);
- const QRectF &name_box = name.boundingRect();
- name.setPos(WIDTH/2 - name_box.width()/2, HEIGHT - (HEIGHT - CACHE_HEIGHT)/2);
+ name.setPos(WIDTH/2 - name.boundingRect().width()/2, HEIGHT - (HEIGHT - CACHE_HEIGHT)/2);
+ const QRectF &cache_t_b = cache_t.boundingRect();
+ cache_t.setPos(WIDTH/2 - cache_t_b.width()/2, 1);
+ const QRectF &cache_hit_b = cache_hit_t.boundingRect();
+ cache_hit_t.setPos(WIDTH/2 - cache_hit_b.width()/2, cache_t_b.height() + 2);
+ cache_miss_t.setPos(WIDTH/2 - cache_miss_t.boundingRect().width()/2, cache_t_b.height() + cache_hit_b.height() + 3);
+
+ connect(cch, SIGNAL(hit_update(uint)), this, SLOT(cache_hit_update(uint)));
+ connect(cch, SIGNAL(miss_update(uint)), this, SLOT(cache_miss_update(uint)));
setPos(x(), y()); // set connector's position
}
@@ -34,6 +44,14 @@ void Memory::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __a
painter->drawLine(0, CACHE_HEIGHT, WIDTH, CACHE_HEIGHT);
}
+void Memory::cache_hit_update(unsigned val) {
+ cache_hit_t.setText("Hit: " + QString::number(val));
+}
+
+void Memory::cache_miss_update(unsigned val) {
+ cache_miss_t.setText("Miss: " + QString::number(val));
+}
+
void Memory::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
QGraphicsObject::mouseDoubleClickEvent(event);
@@ -49,7 +67,7 @@ void Memory::set_type(const QString &text) {
type.setPos(WIDTH/2 - box.width()/2, HEIGHT - (HEIGHT - CACHE_HEIGHT)/2 - box.height());
}
-ProgramMemory::ProgramMemory(machine::QtMipsMachine *machine) : Memory(machine) {
+ProgramMemory::ProgramMemory(machine::QtMipsMachine *machine) : Memory(machine->cache_program()) {
cache = machine->config().cache_program().enabled();
set_type("Program");
@@ -77,7 +95,7 @@ const Connector *ProgramMemory::connector_instruction() const {
return con_inst;
}
-DataMemory::DataMemory(machine::QtMipsMachine *machine) : Memory(machine) {
+DataMemory::DataMemory(machine::QtMipsMachine *machine) : Memory(machine->cache_data()) {
cache = machine->config().cache_data().enabled();
set_type("Data");
diff --git a/qtmips_gui/coreview/memory.h b/qtmips_gui/coreview/memory.h
index 177dc6d..57158a6 100644
--- a/qtmips_gui/coreview/memory.h
+++ b/qtmips_gui/coreview/memory.h
@@ -13,7 +13,7 @@ namespace coreview {
class Memory : public QGraphicsObject {
Q_OBJECT
public:
- Memory(machine::QtMipsMachine *machine);
+ Memory(const machine::Cache *cache);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@@ -22,6 +22,10 @@ signals:
void open_mem();
void open_cache();
+private slots:
+ void cache_hit_update(unsigned);
+ void cache_miss_update(unsigned);
+
protected:
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
@@ -31,6 +35,7 @@ protected:
private:
QGraphicsSimpleTextItem name, type;
+ QGraphicsSimpleTextItem cache_t, cache_hit_t, cache_miss_t;
};
class ProgramMemory : public Memory {