Animate the comparator
With this change, the comparison operator as well as the comparison result is displayed in the comparator graphics item.
MODIFY
src/graphics/descriptions.h
src/graphics/descriptions.h
@@ -30,7 +30,8 @@ static QMap<QString, QString> init() {
map.insert("main ALU", "Main functional unit for arithmetic instructions");
map.insert("immgen", "Immediate value generator");
- map.insert("comp", "Comparator used for branch instructions");
+ map.insert("comp", "Comparator used for branch instructions.\nWhen the ID stage contains a branch instruction,\nthe "
+ "color of the comparator will indicate the comparison result.");
return map;
}

MODIFY
src/graphics/pipelinewidget.cpp
src/graphics/pipelinewidget.cpp
@@ -50,7 +50,7 @@ PipelineWidget::PipelineWidget(QWidget* parent) : QGraphicsView(parent) {
data_mem->addBotPoint("Read");
data_mem->setName("Data\nmemory");
data_mem->setSignal(Graphics::SignalPos::Top, m_pipelinePtr->r_MemWrite_EXMEM.getOutput());
- data_mem->setSignal(Graphics::SignalPos::Bot, m_pipelinePtr->r_MemRead_EXMEM.getOutput());
+ data_mem->setSignal(Graphics::SignalPos::Bottom, m_pipelinePtr->r_MemRead_EXMEM.getOutput());
m_animatedItems.push_back(data_mem);
data_mem->setToolTip(Descriptions::m["Data memory"]);
@@ -66,7 +66,7 @@ PipelineWidget::PipelineWidget(QWidget* parent) : QGraphicsView(parent) {
pc->addInput();
pc->addOutput();
pc->addBotPoint("");
- pc->setSignal(Graphics::SignalPos::Bot, &m_pipelinePtr->s_PCWrite);
+ pc->setSignal(Graphics::SignalPos::Bottom, &m_pipelinePtr->s_PCWrite);
pc->setName("PC");
m_animatedItems.push_back(pc);
pc->setToolTip(Descriptions::m["PC"]);
@@ -236,13 +236,16 @@ PipelineWidget::PipelineWidget(QWidget* parent) : QGraphicsView(parent) {
immgen->addOutput();
immgen->setToolTip(Descriptions::m["immgen"]);
- auto* comp = new Graphics::Shape(Graphics::ShapeType::Static, Graphics::Stage::EX, 0, 20);
- comp->setName("=");
+ auto* comp = new Graphics::Shape(Graphics::ShapeType::Comparator, Graphics::Stage::EX, 0, 20);
comp->addOutput();
comp->setHiddenOutputs(std::set<int>{0});
comp->addTopPoint("");
comp->addBotPoint("");
comp->setToolTip(Descriptions::m["comp"]);
+ comp->setSignal(Graphics::SignalPos::Bottom, &m_pipelinePtr->s_branchTaken);
+ comp->setSignal(Graphics::SignalPos::Top, &m_pipelinePtr->s_CompOp);
+ comp->setSignal(Graphics::SignalPos::Left, &m_pipelinePtr->s_Branch);
+ m_animatedItems.push_back(comp);
// ----------- Create connections ----------------------
Graphics::Connection* connPtr;

MODIFY
src/graphics/shape.h
src/graphics/shape.h
namespace Graphics {
class Connection;
-enum class ShapeType { Block, ALU, MUX, Static };
+enum class ShapeType { Block, ALU, MUX, Comparator, Static };
enum class Stage { IF = 1, ID = 2, EX = 3, MEM = 4, WB = 5 };
-enum class SignalPos { Left, Top, Bot };
+enum class SignalPos { Left, Top, Bottom };
class Shape : public QGraphicsItem {
public:
@@ -69,6 +69,7 @@ private:
// when new descriptors have been added)
QPainterPath drawALUPath(QRectF boundingRect) const;
+ QString getName() const;
const ShapeType m_type;
Stage m_stage; // Used for correctly positioning the shape
@@ -117,7 +118,7 @@ private:
// Interfacing signals to pipeline
SignalBase* m_leftSignal = nullptr;
SignalBase* m_topSignal = nullptr;
- SignalBase* m_botsignal = nullptr;
+ SignalBase* m_botSignal = nullptr;
bool m_singleIOBlink = false; // registers can be set to have individually controlled IO coloring
std::map<int, SignalBase*> m_IOSignalPairs;

MODIFY
src/pipeline.h
src/pipeline.h
@@ -11,6 +11,10 @@ class Pipeline {
friend class RWJumpModel;
public:
+ // Control signal enums
+ enum CompOp { BEQ = 1, BNE = 2, BLT = 3, BLTU = 4, BGE = 5, BGEU = 6 };
+ enum MemRead { LB = 1, LH = 2, LW = 3, LBU = 4, LHU = 5 };
+ enum MemWrite { SB = 1, SH = 2, SW = 3 };
enum class ECALL { none, exit, print_string, print_int };
Pipeline();
// Utility functions
@@ -141,11 +145,6 @@ private:
Signal<1> s_jal, s_jalr;
Signal<1> s_auipc; // used for controlling input 1 to main alu (registers or PC)
Signal<1> s_alures_PC4_MEM; // Control signal for forwarding MUX in MEM stage
-
- // Control signal enums
- enum CompOp { BEQ = 1, BNE = 2, BLT = 3, BLTU = 4, BGE = 5, BGEU = 6 };
- enum MemRead { LB = 1, LH = 2, LW = 3, LBU = 4, LHU = 5 };
- enum MemWrite { SB = 1, SH = 2, SW = 3 };
};
namespace Forwarding {

Animate the comparator

With this change, the comparison operator as well as the comparison result is displayed in the comparator graphics item.