aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-01-21 11:36:34 +0100
committerKarel Kočí <cynerd@email.cz>2018-01-21 11:36:34 +0100
commit16b1544fff7e9ca11deb3ae1b891c79eac7ec50e (patch)
treee9f04ca11d330e1e47469bb7471d6abcb25c8d49
parent507e81b60af88721780a1eb5591d884d1667c4b4 (diff)
downloadqtmips-16b1544fff7e9ca11deb3ae1b891c79eac7ec50e.tar.gz
qtmips-16b1544fff7e9ca11deb3ae1b891c79eac7ec50e.tar.bz2
qtmips-16b1544fff7e9ca11deb3ae1b891c79eac7ec50e.zip
Implement little bit more of scheme and fix connection angle
This commit adds few more bits to scheme but mainly it chnages how connectors specify angles. Originally it was in radians but we was mapping that trough mathematical operations directly to sizes. But that was problematic because of floating point inacuracy and we sometimes founded intersection where there should be one. So this commit gets rid of this at all and instead allows just some fixes axes to be used instead of arbitrary angles.
-rw-r--r--qtmips_gui/coreview.cpp87
-rw-r--r--qtmips_gui/coreview.h10
-rw-r--r--qtmips_gui/coreview/adder.cpp6
-rw-r--r--qtmips_gui/coreview/alu.cpp8
-rw-r--r--qtmips_gui/coreview/alu.h1
-rw-r--r--qtmips_gui/coreview/and.cpp53
-rw-r--r--qtmips_gui/coreview/and.h29
-rw-r--r--qtmips_gui/coreview/connection.cpp95
-rw-r--r--qtmips_gui/coreview/connection.h54
-rw-r--r--qtmips_gui/coreview/constant.cpp4
-rw-r--r--qtmips_gui/coreview/junction.cpp16
-rw-r--r--qtmips_gui/coreview/junction.h5
-rw-r--r--qtmips_gui/coreview/latch.cpp4
-rw-r--r--qtmips_gui/coreview/logicblock.cpp2
-rw-r--r--qtmips_gui/coreview/memory.cpp14
-rw-r--r--qtmips_gui/coreview/multiplexer.cpp14
-rw-r--r--qtmips_gui/coreview/multiplexer.h3
-rw-r--r--qtmips_gui/coreview/programcounter.cpp4
-rw-r--r--qtmips_gui/coreview/registers.cpp14
-rw-r--r--qtmips_gui/qtmips_gui.pro6
20 files changed, 319 insertions, 110 deletions
diff --git a/qtmips_gui/coreview.cpp b/qtmips_gui/coreview.cpp
index ad1572b..6b85cfe 100644
--- a/qtmips_gui/coreview.cpp
+++ b/qtmips_gui/coreview.cpp
@@ -77,8 +77,9 @@ CoreViewScene::CoreViewScene(CoreView *view, machine::QtMipsMachine *machine) :
NEW(Adder, ft.adder, 100, 330);
struct coreview::Latch::ConnectorPair pc_latch_pair = ft.latch->new_connector(10);
NEW_B(Constant, ft.adder_4, ft.adder->connector_in_b(), "4");
- NEW(Junction, ft.junction, 80, mem_program->connector_address()->y());
- NEW(Multiplexer, ft.multiplex, 20, 390, 4);
+ NEW(Junction, ft.junc_pc, 80, mem_program->connector_address()->y());
+ NEW(Junction, ft.junc_pc_4, 130, 380);
+ NEW(Multiplexer, ft.multiplex, 20, 390, 2);
// Decode stage
NEW(LogicBlock, dc.ctl_block, 230, 90, {"Control", "unit"});
dc.ctl_block->setSize(35, 70);
@@ -87,6 +88,11 @@ CoreViewScene::CoreViewScene(CoreView *view, machine::QtMipsMachine *machine) :
NEW(Adder, dc.add, 320, 390);
const coreview::Connector *dc_con_sign_ext = dc.sign_ext->new_connector(1, 0);
NEW(Junction, dc.j_sign_ext, 270, dc_con_sign_ext->y());
+ NEW(LogicBlock, dc.cmp, 320, 200, "=");
+ NEW(And, dc.and_branch, 350, 190);
+ dc.cmp->setSize(24, 12);
+ NEW(Junction, dc.j_inst_up, 180, 126);
+ NEW(Junction, dc.j_inst_down, 180, dc_con_sign_ext->y());
// Execute stage
NEW(Alu, alu, 470, 230);
// Memory stage
@@ -95,17 +101,30 @@ CoreViewScene::CoreViewScene(CoreView *view, machine::QtMipsMachine *machine) :
// Connections //
coreview::Connection *con;
// Fetch stage
- new_connection(ft.pc->connector_out(), pc_latch_pair.in);
- new_connection(pc_latch_pair.out, ft.junction->new_connector(0));
- new_connection(ft.junction->new_connector(M_PI_2), ft.adder->connector_in_a());
- new_connection(ft.junction->new_connector(M_PI), mem_program->connector_address());
- new_connection(ft.multiplex->connector_out(), ft.pc->connector_in());
- con = new_connection(ft.adder->connector_out(), ft.multiplex->connector_in(0));
- con->setAxes({CON_AXIS_Y(130), CON_AXIS_X(380), CON_AXIS_Y(10)});
+ new_bus(ft.pc->connector_out(), pc_latch_pair.in);
+ new_bus(pc_latch_pair.out, ft.junc_pc->new_connector(coreview::Connector::AX_X));
+ new_bus(ft.junc_pc->new_connector(coreview::Connector::AX_Y), ft.adder->connector_in_a());
+ new_bus(ft.junc_pc->new_connector(coreview::Connector::AX_X), mem_program->connector_address());
+ new_bus(ft.multiplex->connector_out(), ft.pc->connector_in());
+ new_bus(ft.adder->connector_out(), ft.junc_pc_4->new_connector(coreview::Connector::AX_Y));
+ con = new_bus(ft.junc_pc_4->new_connector(coreview::Connector::AX_X), ft.multiplex->connector_in(0));
+ con->setAxes({CON_AXIS_Y(10)});
// Decode stage
- new_connection(dc_con_sign_ext, dc.j_sign_ext->new_connector(0));
- new_connection(dc.j_sign_ext->new_connector(-M_PI_2), dc.shift2->new_connector(-1, 0));
- new_connection(dc.shift2->new_connector(1, 0), dc.add->connector_in_a());
+ new_bus(dc_con_sign_ext, dc.j_sign_ext->new_connector(coreview::Connector::AX_X));
+ new_bus(dc.j_sign_ext->new_connector(coreview::Connector::AX_Y), dc.shift2->new_connector(-1, 0));
+ new_bus(dc.shift2->new_connector(1, 0), dc.add->connector_in_a());
+ con = new_signal(dc.cmp->new_connector(1, 0), dc.and_branch->connector_in(1));
+ con->setAxes({CON_AXIS_Y(343)});
+ con = new_signal(dc.ctl_block->new_connector(1, 0.9), dc.and_branch->connector_in(0));
+ con->setAxes({CON_AXIS_Y(343)});
+ dc.instr_bus = new_bus(dc.j_inst_up->new_connector(coreview::Connector::AX_Y), dc.j_inst_down->new_connector(coreview::Connector::AX_Y));
+ new_bus(dc.j_inst_up->new_connector(coreview::Connector::AX_X), dc.ctl_block->new_connector(-1, 0), 2);
+ new_bus(dc.j_inst_down->new_connector(coreview::Connector::AX_X), dc.sign_ext->new_connector(-1, 0), 2);
+ // From decode stage to fetch stage
+ con = new_signal(dc.and_branch->connector_out(), ft.multiplex->connector_ctl());
+ con->setAxes({CON_AXIS_Y(365), CON_AXIS_X(490)});
+ con = new_bus(dc.add->connector_out(), ft.multiplex->connector_in(1));
+ con->setAxes({CON_AXIS_Y(340), CON_AXIS_X(480), CON_AXIS_Y(10)});
connect(regs, SIGNAL(open_registers()), this, SIGNAL(request_registers()));
connect(mem_program, SIGNAL(open_mem()), this, SIGNAL(request_program_memory()));
@@ -120,9 +139,16 @@ CoreViewScene::~CoreViewScene() {
delete ft.latch;
delete ft.adder;
delete ft.adder_4;
- delete ft.junction;
+ delete ft.junc_pc;
+ delete ft.junc_pc_4;
delete ft.multiplex;
delete dc.ctl_block;
+ delete dc.sign_ext;
+ delete dc.shift2;
+ delete dc.cmp;
+ delete dc.add;
+ delete dc.j_sign_ext;
+ delete dc.and_branch;
delete alu;
delete mem_program;
delete mem_data;
@@ -137,6 +163,21 @@ coreview::Connection *CoreViewScene::new_connection(const coreview::Connector *a
return c;
}
+coreview::Bus *CoreViewScene::new_bus(const coreview::Connector *a, const coreview::Connector *b, unsigned width) {
+ coreview::Bus *c = new coreview::Bus(a, b, width);
+ connections.append(c);
+ addItem(c);
+ return c;
+}
+
+coreview::Signal *CoreViewScene::new_signal(const coreview::Connector *a, const coreview::Connector *b) {
+ coreview::Signal *c = new coreview::Signal(a, b);
+ connections.append(c);
+ addItem(c);
+ c->setZValue(-1); // hide connections under neath the items
+ return c;
+}
+
CoreViewSceneSimple::CoreViewSceneSimple(CoreView *view, machine::QtMipsMachine *machine) : CoreViewScene(view, machine) {
NEW(Latch, delay_slot_latch, 160, 50, machine, 150);
}
@@ -146,13 +187,13 @@ CoreViewSceneSimple::~CoreViewSceneSimple() {
}
CoreViewScenePipelined::CoreViewScenePipelined(CoreView *view, machine::QtMipsMachine *machine) : CoreViewScene(view, machine) {
- NEW(Latch, latch_if_id, 158, 90, machine, 400);
+ NEW(Latch, latch_if_id, 158, 90, machine, 380);
latch_if_id->setTitle("IF/ID");
- NEW(Latch, latch_id_ex, 392, 90, machine, 400);
+ NEW(Latch, latch_id_ex, 392, 90, machine, 380);
latch_id_ex->setTitle("ID/EX");
- NEW(Latch, latch_ex_mem, 536, 90, machine, 400);
+ NEW(Latch, latch_ex_mem, 536, 90, machine, 380);
latch_ex_mem->setTitle("EX/MEM");
- NEW(Latch, latch_mem_wb, 680, 90, machine, 400);
+ NEW(Latch, latch_mem_wb, 680, 90, machine, 380);
latch_mem_wb->setTitle("MEM/WB");
NEW_I(inst_fetch, 100, 2, instruction_fetched(const machine::Instruction&));
@@ -166,8 +207,16 @@ CoreViewScenePipelined::CoreViewScenePipelined(CoreView *view, machine::QtMipsMa
hazard_unit->setSize(SC_WIDTH - 100, 12);
}
- struct coreview::Latch::ConnectorPair program_latch_pair = latch_if_id->new_connector(mem_program->connector_instruction()->y() - latch_if_id->y());
- new_connection(mem_program->connector_instruction(), program_latch_pair.in);
+ coreview::Connection *con;
+ // Fetch stage
+ struct coreview::Latch::ConnectorPair lp_ft_inst = latch_if_id->new_connector(mem_program->connector_instruction()->y() - latch_if_id->y());
+ new_bus(mem_program->connector_instruction(), lp_ft_inst.in);
+ struct coreview::Latch::ConnectorPair lp_ft_pc = latch_if_id->new_connector(370);
+ new_bus(ft.junc_pc_4->new_connector(coreview::Connector::AX_Y), lp_ft_pc.in);
+ // Decode stage
+ //new_bus(lp_ft_inst.out, dc.instr_bus->new_connector(lp_ft_inst.out->point()));
+ con = new_bus(lp_ft_pc.out, dc.add->connector_in_b());
+ con->setAxes({CON_AXIS_Y(270)});
}
CoreViewScenePipelined::~CoreViewScenePipelined() {
diff --git a/qtmips_gui/coreview.h b/qtmips_gui/coreview.h
index ff2cbe2..edc970c 100644
--- a/qtmips_gui/coreview.h
+++ b/qtmips_gui/coreview.h
@@ -16,6 +16,7 @@
#include "coreview/junction.h"
#include "coreview/constant.h"
#include "coreview/logicblock.h"
+#include "coreview/and.h"
class CoreView : public QGraphicsView {
public:
@@ -49,19 +50,24 @@ protected:
coreview::Latch *latch;
coreview::Adder *adder;
coreview::Constant *adder_4;
- coreview::Junction *junction;
+ coreview::Junction *junc_pc, *junc_pc_4;
coreview::Multiplexer *multiplex;
} ft;
struct {
- coreview::LogicBlock *ctl_block, *sign_ext, *shift2;
+ coreview::LogicBlock *ctl_block, *sign_ext, *shift2, *cmp;
coreview::Adder *add;
coreview::Junction *j_sign_ext;
+ coreview::And *and_branch;
+ coreview::Junction *j_inst_up, *j_inst_down;
+ coreview::Bus *instr_bus;
} dc;
coreview::Alu *alu;
coreview::Multiplexer *mem_or_reg;
QVector<coreview::Connection*> connections;
coreview::Connection *new_connection(const coreview::Connector*, const coreview::Connector*);
+ coreview::Bus *new_bus(const coreview::Connector*, const coreview::Connector*, unsigned width = 4);
+ coreview::Signal *new_signal(const coreview::Connector*, const coreview::Connector*);
coreview::Connection *pc2pc_latch;
coreview::Connection *pc_latch2pc_joint, *pc_joint2pc_adder, *pc_joint2mem;
coreview::Connection *pc_multiplexer2pc;
diff --git a/qtmips_gui/coreview/adder.cpp b/qtmips_gui/coreview/adder.cpp
index cd227ab..4363f97 100644
--- a/qtmips_gui/coreview/adder.cpp
+++ b/qtmips_gui/coreview/adder.cpp
@@ -17,9 +17,9 @@ Adder::Adder() : QGraphicsItem(nullptr), plus("+", this) {
QRectF plus_box = plus.boundingRect();
plus.setPos(DENT + (WIDTH-DENT)/2 - plus_box.width()/2, HEIGHT/2 - plus_box.height()/2);
- con_in_a = new Connector(0);
- con_in_b = new Connector(0);
- con_out = new Connector(M_PI);
+ con_in_a = new Connector(Connector::AX_X);
+ con_in_b = new Connector(Connector::AX_X);
+ con_out = new Connector(Connector::AX_X);
setPos(x(), y()); // set connector's position
}
diff --git a/qtmips_gui/coreview/alu.cpp b/qtmips_gui/coreview/alu.cpp
index d49cab2..2f24210 100644
--- a/qtmips_gui/coreview/alu.cpp
+++ b/qtmips_gui/coreview/alu.cpp
@@ -14,10 +14,10 @@ coreview::Alu::Alu() : QGraphicsItem(nullptr), name("ALU", this) {
font.setPointSize(7);
name.setFont(font);
- con_in_a = new Connector(0);
- con_in_b = new Connector(0);
- con_out = new Connector(M_PI);
- con_ctl = new Connector(-M_PI_2);
+ con_in_a = new Connector(Connector::AX_X);
+ con_in_b = new Connector(Connector::AX_X);
+ con_out = new Connector(Connector::AX_X);
+ con_ctl = new Connector(Connector::AX_Y);
setPos(x(), y()); // set connector's position
}
diff --git a/qtmips_gui/coreview/alu.h b/qtmips_gui/coreview/alu.h
index 25d7351..288de87 100644
--- a/qtmips_gui/coreview/alu.h
+++ b/qtmips_gui/coreview/alu.h
@@ -2,7 +2,6 @@
#define COREVIEW_ALU_H
#include <QGraphicsItem>
-#include <qtmipsmachine.h>
#include "connection.h"
namespace coreview {
diff --git a/qtmips_gui/coreview/and.cpp b/qtmips_gui/coreview/and.cpp
new file mode 100644
index 0000000..f60dfcd
--- /dev/null
+++ b/qtmips_gui/coreview/and.cpp
@@ -0,0 +1,53 @@
+#include "and.h"
+#include <cmath>
+
+using namespace coreview;
+
+//////////////////////
+#define GAP 5
+#define PENW 1
+//////////////////////
+
+And::And(unsigned size) : QGraphicsItem(nullptr) {
+ for (unsigned i = 0; i < size; i++)
+ connectors.append(new Connector(Connector::AX_X));
+ con_out = new Connector(Connector::AX_X);
+
+ setPos(x(), y()); // update connectors positions
+}
+
+And::~And() {
+ delete con_out;
+ for (int i = 0; i < connectors.size(); i++)
+ delete connectors[i];
+}
+
+QRectF And::boundingRect() const {
+ qreal side = GAP * connectors.size();
+ return QRectF(-PENW, -PENW, side + PENW, side + PENW);
+}
+
+void And::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) {
+ qreal size = GAP * connectors.size();
+ painter->drawLine(0, 0, 0, size);
+ painter->drawLine(0, 0, size/2, 0);
+ painter->drawLine(0, size, size/2, size);
+ painter->drawArc(0, 0, size, size, 270 * 16, 180 * 16);
+}
+
+void And::setPos(qreal x, qreal y) {
+ QGraphicsItem::setPos(x, y);
+
+ qreal size = GAP * connectors.size();
+ con_out->setPos(x + size, y + size/2);
+ for (int i = 0; i < connectors.size(); i++)
+ connectors[i]->setPos(x, y + GAP/2 + GAP*i);
+}
+
+const Connector *And::connector_in(unsigned i) const {
+ return connectors[i];
+}
+
+const Connector *And::connector_out() const {
+ return con_out;
+}
diff --git a/qtmips_gui/coreview/and.h b/qtmips_gui/coreview/and.h
new file mode 100644
index 0000000..ca0af30
--- /dev/null
+++ b/qtmips_gui/coreview/and.h
@@ -0,0 +1,29 @@
+#ifndef COREVIEW_AND_H
+#define COREVIEW_AND_H
+
+#include <QGraphicsItem>
+#include <QVector>
+#include "connection.h"
+
+namespace coreview {
+
+class And : public QGraphicsItem {
+public:
+ And(unsigned size = 2);
+ ~And();
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+ void setPos(qreal x, qreal y);
+ const Connector *connector_in(unsigned) const;
+ const Connector *connector_out() const;
+
+private:
+ QVector<Connector*> connectors;
+ Connector* con_out;
+};
+
+}
+
+#endif // COREVIEW_AND_H
diff --git a/qtmips_gui/coreview/connection.cpp b/qtmips_gui/coreview/connection.cpp
index 71647e2..3355eed 100644
--- a/qtmips_gui/coreview/connection.cpp
+++ b/qtmips_gui/coreview/connection.cpp
@@ -3,14 +3,19 @@
using namespace coreview;
-Connector::Connector(qreal angle) {
- ang = angle;
+Connector::Connector(enum Axis ax) {
+ this->ax = ax;
}
void Connector::setPos(qreal x, qreal y) {
qx = x;
qy = y;
- emit updated(QPointF(qx, qy));
+ emit updated(point());
+ emit updated(vector());
+}
+
+enum Connector::Axis Connector::axis() const {
+ return ax;
}
qreal Connector::x() const {
@@ -21,28 +26,34 @@ qreal Connector::y() const {
return qy;
}
-QLineF Connector::vector() const {
- return QLineF(point(), QPointF(x() + cos(ang), y() + sin(ang)));
-}
-
QPointF Connector::point() const {
return QPointF(qx, qy);
}
-qreal Connector::angle() const {
- return ang;
+QLineF Connector::vector() const {
+ QPointF p = point();
+ switch (ax) {
+ case AX_X:
+ return QLineF(p, p + QPointF(1, 0));
+ case AX_Y:
+ return QLineF(p, p + QPointF(0, 1));
+ case AX_XY:
+ return QLineF(p, p + QPointF(1, 1));
+ case AX_MXY:
+ return QLineF(p, p + QPoint(1, -1));
+ }
}
Connection::Connection(const Connector *a, const Connector *b) : QGraphicsObject(nullptr) {
pen_width = 1;
- ang_start = a->angle();
- ang_end = b->angle();
+ ax_start = a->vector();
+ ax_end = a->vector();
- connect(a, SIGNAL(updated(QPointF)), this, SLOT(moved_start(QPointF)));
- connect(b, SIGNAL(updated(QPointF)), this, SLOT(moved_end(QPointF)));
- moved_start(a->point());
- moved_end(b->point());
+ connect(a, SIGNAL(updated(QLineF)), this, SLOT(moved_start(QLineF)));
+ connect(b, SIGNAL(updated(QLineF)), this, SLOT(moved_end(QLineF)));
+ moved_start(a->vector());
+ moved_end(b->vector());
}
void Connection::setHasText(bool has) {
@@ -65,13 +76,13 @@ void Connection::setAxes(QVector<QLineF> axes) {
recalc_line();
}
-void Connection::moved_start(QPointF p) {
- p_start = p;
+void Connection::moved_start(QLineF p) {
+ ax_start = p;
recalc_line();
}
-void Connection::moved_end(QPointF p) {
- p_end = p;
+void Connection::moved_end(QLineF p) {
+ ax_end = p;
recalc_line();
}
@@ -88,7 +99,9 @@ QRectF Connection::boundingRect() const {
void Connection::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) {
QPen pen;
pen.setWidth(pen_width);
- // TODO color?
+ pen.setColor(color);
+ pen.setCapStyle(Qt::FlatCap);
+ pen.setJoinStyle(Qt::BevelJoin);
painter->setPen(pen);
painter->drawPolyline(QPolygonF(points));
@@ -97,20 +110,44 @@ void Connection::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
void Connection::recalc_line() {
points.clear();
- points.append(p_start);
+ points.append(ax_start.p1());
- QLineF cur_l(p_start, QPointF(p_start.x() + cos(ang_start), p_start.y() + sin(ang_start)));
+ QLineF cur_l = ax_start;
for (int i = 0; i < break_axes.size(); i++) {
- recalc_line_add_point(cur_l, break_axes[i]);
- cur_l = break_axes[i];
+ if (recalc_line_add_point(cur_l, break_axes[i]))
+ cur_l = break_axes[i];
}
- recalc_line_add_point(cur_l, QLineF(QPoint(p_end.x() + cos(ang_end), p_end.y() + sin(ang_end)), p_end));
+ recalc_line_add_point(cur_l, ax_end);
- points.append(p_end);
+ points.append(ax_end.p1());
}
-void Connection::recalc_line_add_point(const QLineF &l1, const QLineF &l2) {
+bool Connection::recalc_line_add_point(const QLineF &l1, const QLineF &l2) {
QPointF intersec;
- if (l1.intersect(l2, &intersec) != QLineF::NoIntersection)
- points.append(intersec);
+ if (l1.intersect(l2, &intersec) == QLineF::NoIntersection)
+ return false;
+ points.append(intersec);
+ return true;
+}
+
+Bus::Bus(const Connector *start, const Connector *end, unsigned width) : Connection(start, end) {
+ pen_width = width;
+}
+
+const Connector *Bus::new_connector(qreal x, qreal y, enum Connector::Axis axis) {
+ Connector *c = new Connector(axis);
+ conns.append({
+ .c = c,
+ .p = QPoint(x, y)
+ });
+ // TODO update positions
+ return c;
+}
+
+const Connector *Bus::new_connector(const QPointF &p, enum Connector::Axis axis) {
+ return new_connector(p.x(), p.y(), axis);
+}
+
+Signal::Signal(const Connector *start, const Connector *end) : Connection(start, end) {
+ color = QColor(0, 0, 255);
}
diff --git a/qtmips_gui/coreview/connection.h b/qtmips_gui/coreview/connection.h
index 0ee981e..88ad1da 100644
--- a/qtmips_gui/coreview/connection.h
+++ b/qtmips_gui/coreview/connection.h
@@ -10,21 +10,30 @@ namespace coreview {
class Connector : public QObject {
Q_OBJECT
public:
- Connector(qreal angle);
+ enum Axis {
+ AX_X, // X axis
+ AX_Y, // Y axis
+ AX_XY, // X=Y axis (45°)
+ AX_MXY // X=-Y axis (-45°)
+ };
+
+ Connector(enum Axis axis = AX_X);
void setPos(qreal x, qreal y);
+
+ enum Axis axis() const;
qreal x() const;
qreal y() const;
+
QPointF point() const;
QLineF vector() const;
- qreal angle() const;
-
signals:
- void updated(QPointF);
+ void updated(QPointF point);
+ void updated(QLineF vector);
private:
- qreal ang;
+ enum Axis ax;
qreal qx, qy;
};
@@ -42,22 +51,43 @@ public:
void setAxes(QVector<QLineF>);
private slots:
- void moved_start(QPointF);
- void moved_end(QPointF);
+ void moved_start(QLineF);
+ void moved_end(QLineF);
-private:
+protected:
QGraphicsSimpleTextItem *value;
QVector<QPointF> points;
- QPointF p_start, p_end;
- qreal ang_start, ang_end;
+ QLineF ax_start, ax_end;
QVector<QLineF> break_axes;
QString text;
int pen_width;
+ QColor color;
- // TODO line width and possibly bus width
void recalc_line();
- void recalc_line_add_point(const QLineF &l1, const QLineF &l2);
+ bool recalc_line_add_point(const QLineF &l1, const QLineF &l2);
+};
+
+class Bus : public Connection {
+public:
+ Bus(const Connector *start, const Connector *end, unsigned width = 4);
+
+ // This creates connector snapped to closes point to x,y that is on bus
+ const Connector *new_connector(qreal x, qreal y, enum Connector::Axis = Connector::AX_X);
+ const Connector *new_connector(const QPointF&, enum Connector::Axis = Connector::AX_X);
+
+protected:
+ struct con_pos {
+ Connector *c;
+ QPointF p;
+ };
+ QVector<struct con_pos> conns;
+ // TODO because of this we have to overload setAxis function and update that in there
+};
+
+class Signal : public Connection {
+public:
+ Signal(const Connector *start, const Connector *end);
};
#define CON_AXIS_X(Y) QLineF(QPointF(0, Y), QPointF(1, Y))
diff --git a/qtmips_gui/coreview/constant.cpp b/qtmips_gui/coreview/constant.cpp
index 2f39fce..433d842 100644
--- a/qtmips_gui/coreview/constant.cpp
+++ b/qtmips_gui/coreview/constant.cpp
@@ -12,8 +12,8 @@ Constant::Constant(const Connector *con, const QString &text) : QGraphicsObject(
font.setPointSize(7);
this->text.setFont(font);
- con_our = new Connector(M_PI);
- conn = new Connection(con_our, con);
+ con_our = new Connector(Connector::AX_X);
+ conn = new Bus(con_our, con, 2);
connect(con, SIGNAL(updated(QPointF)), this, SLOT(ref_con_updated(QPointF)));
ref_con_updated(con->point()); // update initial connector position
}
diff --git a/qtmips_gui/coreview/junction.cpp b/qtmips_gui/coreview/junction.cpp
index 271284c..494aca6 100644
--- a/qtmips_gui/coreview/junction.cpp
+++ b/qtmips_gui/coreview/junction.cpp
@@ -6,7 +6,9 @@ using namespace coreview;
#define DOT_SIZE 4
//////////////////////
-Junction::Junction() : QGraphicsItem(nullptr) { }
+Junction::Junction(bool point) : QGraphicsItem(nullptr) {
+ this->point = point;
+}
Junction::~Junction() {
for (int i = 0; i < cons.size(); i++)
@@ -14,11 +16,17 @@ Junction::~Junction() {
}
QRectF Junction::boundingRect() const {
- return QRectF(-DOT_SIZE/2, -DOT_SIZE/2, DOT_SIZE, DOT_SIZE);
+ if (point)
+ return QRectF(-DOT_SIZE/2, -DOT_SIZE/2, DOT_SIZE, DOT_SIZE);
+ else
+ return QRectF();
}
void Junction::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) {
+ if (!point)
+ return;
painter->setBrush(QBrush(QColor(0, 0, 0)));
+ painter->setPen(QPen(Qt::NoPen)); // Disable pen (render only brush)
painter->drawEllipse(-DOT_SIZE/2, -DOT_SIZE/2, DOT_SIZE, DOT_SIZE);
}
@@ -28,8 +36,8 @@ void Junction::setPos(qreal x, qreal y) {
con->setPos(x, y);
}
-Connector *Junction::new_connector(qreal angle) {
- Connector*n = new Connector(angle);
+Connector *Junction::new_connector(enum Connector::Axis axis) {
+ Connector*n = new Connector(axis);
cons.append(n);
setPos(x(), y()); // set connector's position
return n;
diff --git a/qtmips_gui/coreview/junction.h b/qtmips_gui/coreview/junction.h
index 1a8f5d7..2eaa732 100644
--- a/qtmips_gui/coreview/junction.h
+++ b/qtmips_gui/coreview/junction.h
@@ -10,17 +10,18 @@ namespace coreview {
class Junction : public QGraphicsItem {
public:
- Junction();
+ Junction(bool point = true);
~Junction();
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void setPos(qreal x, qreal y);
- Connector *new_connector(qreal angle);
+ Connector *new_connector(enum Connector::Axis axis = Connector::AX_X);
private:
QList<Connector*> cons;
+ bool point;
};
}
diff --git a/qtmips_gui/coreview/latch.cpp b/qtmips_gui/coreview/latch.cpp
index c3bab4f..e3d8ef5 100644
--- a/qtmips_gui/coreview/latch.cpp
+++ b/qtmips_gui/coreview/latch.cpp
@@ -69,8 +69,8 @@ void Latch::setPos(qreal x, qreal y) {
struct Latch::ConnectorPair Latch::new_connector(qreal cy) {
SANITY_ASSERT(cy < height, "Latch: Trying to create connector outside of latch height");
ConnectorPair cp;
- cp.in = new Connector(0);
- cp.out = new Connector(M_PI);
+ cp.in = new Connector(Connector::AX_X);
+ cp.out = new Connector(Connector::AX_X);
connectors.append(cp);
connectors_off.append(cy);
setPos(x(), y()); // Update connectors position
diff --git a/qtmips_gui/coreview/logicblock.cpp b/qtmips_gui/coreview/logicblock.cpp
index 1ee9a18..2e74a77 100644
--- a/qtmips_gui/coreview/logicblock.cpp
+++ b/qtmips_gui/coreview/logicblock.cpp
@@ -78,7 +78,7 @@ const Connector *LogicBlock::new_connector(qreal x, qreal y) {
y = sign(y);
// Note: we are using here that 0 and M_PI is same angle but different orientation (but we ignore orientation for now)
- Connector *c = new Connector(fabs(x) > fabs(y) ? 0 : M_PI_2);
+ Connector *c = new Connector(fabs(x) > fabs(y) ? Connector::AX_X : Connector::AX_Y);
connectors.append({
.con = c,
.x = x,
diff --git a/qtmips_gui/coreview/memory.cpp b/qtmips_gui/coreview/memory.cpp
index 8f1669d..a2e5899 100644
--- a/qtmips_gui/coreview/memory.cpp
+++ b/qtmips_gui/coreview/memory.cpp
@@ -53,8 +53,8 @@ ProgramMemory::ProgramMemory(machine::QtMipsMachine *machine) : Memory(machine)
cache = machine->config().cache_program().enabled();
set_type("Program");
- con_address = new Connector(0);
- con_inst = new Connector(M_PI);
+ con_address = new Connector(Connector::AX_X);
+ con_inst = new Connector(Connector::AX_X);
}
ProgramMemory::~ProgramMemory() {
@@ -81,11 +81,11 @@ 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);
+ con_address = new Connector(Connector::AX_X);
+ con_data_out = new Connector(Connector::AX_X);
+ con_data_in = new Connector(Connector::AX_X);
+ con_req_write = new Connector(Connector::AX_X);
+ con_req_read = new Connector(Connector::AX_X);
}
DataMemory::~DataMemory() {
diff --git a/qtmips_gui/coreview/multiplexer.cpp b/qtmips_gui/coreview/multiplexer.cpp
index 7429fda..b25e6d1 100644
--- a/qtmips_gui/coreview/multiplexer.cpp
+++ b/qtmips_gui/coreview/multiplexer.cpp
@@ -10,15 +10,15 @@ using namespace coreview;
#define PENW 1
//////////////////////
-Multiplexer::Multiplexer(unsigned size) {
+Multiplexer::Multiplexer(unsigned size, bool ctl_up) {
this->size = size;
seton = 0;
- ctlfrom = false;
- con_ctl = new Connector(M_PI_2);
- con_out = new Connector(M_PI);
+ ctlfrom = ctl_up;
+ con_ctl = new Connector(Connector::AX_Y);
+ con_out = new Connector(Connector::AX_X);
con_in = new Connector*[size];
for (unsigned i = 0; i < size; i++)
- con_in[i] = new Connector(0);
+ con_in[i] = new Connector(Connector::AX_X);
setPos(x(), y()); // Set connectors possitions
}
@@ -80,7 +80,3 @@ void Multiplexer::set(unsigned i) {
update();
}
-void Multiplexer::setCtl(bool up) {
- ctlfrom = up;
- setPos(x(), y()); // Update connectors
-}
diff --git a/qtmips_gui/coreview/multiplexer.h b/qtmips_gui/coreview/multiplexer.h
index 2cfc90d..ad4fd0b 100644
--- a/qtmips_gui/coreview/multiplexer.h
+++ b/qtmips_gui/coreview/multiplexer.h
@@ -9,7 +9,7 @@ namespace coreview {
class Multiplexer : public QGraphicsItem {
public:
- Multiplexer(unsigned size);
+ Multiplexer(unsigned size, bool ctl_up = false);
~Multiplexer();
QRectF boundingRect() const;
@@ -21,7 +21,6 @@ public:
const Connector *connector_in(unsigned i) const; // Inputs
void set(unsigned i); // Set what value should be set as connected (indexing from 1 where 0 is no line)
- void setCtl(bool up); // Set if control signal is from up or down (in default down)
private:
bool ctlfrom;
diff --git a/qtmips_gui/coreview/programcounter.cpp b/qtmips_gui/coreview/programcounter.cpp
index c43ff6d..ab7d49b 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(Connector::AX_Y);
+ con_out = new Connector(Connector::AX_Y);
setPos(x(), y()); // To set initial connectors positions
}
diff --git a/qtmips_gui/coreview/registers.cpp b/qtmips_gui/coreview/registers.cpp
index 87db32e..9a4fcff 100644
--- a/qtmips_gui/coreview/registers.cpp
+++ b/qtmips_gui/coreview/registers.cpp
@@ -10,13 +10,13 @@ using namespace coreview;
//////////////////////
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);
- con_read2_reg = new Connector(-M_PI_2);
- con_write = new Connector(-M_PI_2);
- con_write_reg = new Connector(-M_PI_2);
- con_ctl_write = new Connector(-M_PI_2);
+ con_read1 = new Connector(Connector::AX_Y);
+ con_read1_reg = new Connector(Connector::AX_Y);
+ con_read2 = new Connector(Connector::AX_Y);
+ con_read2_reg = new Connector(Connector::AX_Y);
+ con_write = new Connector(Connector::AX_Y);
+ con_write_reg = new Connector(Connector::AX_Y);
+ con_ctl_write = new Connector(Connector::AX_Y);
// TODO do we want to have any hooks on real registers?
diff --git a/qtmips_gui/qtmips_gui.pro b/qtmips_gui/qtmips_gui.pro
index a71509e..4767fe9 100644
--- a/qtmips_gui/qtmips_gui.pro
+++ b/qtmips_gui/qtmips_gui.pro
@@ -32,7 +32,8 @@ SOURCES += \
coreview/adder.cpp \
coreview/constant.cpp \
coreview/junction.cpp \
- coreview/logicblock.cpp
+ coreview/logicblock.cpp \
+ coreview/and.cpp
HEADERS += \
mainwindow.h \
@@ -53,7 +54,8 @@ HEADERS += \
coreview/adder.h \
coreview/constant.h \
coreview/junction.h \
- coreview/logicblock.h
+ coreview/logicblock.h \
+ coreview/and.h
FORMS += \
NewDialog.ui \