Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active path and FSM #59

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions core/vsrtl_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
#include "../interface/vsrtl_binutils.h"
#include "../interface/vsrtl_defines.h"
#include "vsrtl_addressspace.h"
#include "../interface/vsrtl_interface.h"
#include "vsrtl_port.h"
#include "../graphics/vsrtl_gridcomponent.h"
#include "../graphics/vsrtl_graphicsbase.h"

#include "../interface/vsrtl_gfxobjecttypes.h"
#include "../graphics/vsrtl_label.h"

namespace vsrtl {
namespace core {
Expand Down Expand Up @@ -61,6 +65,30 @@ class Component : public SimComponent {
void setSensitiveTo(const PortBase* p) { m_sensitivityList.push_back(p); }
void setSensitiveTo(const PortBase& p) { setSensitiveTo(&p); }


bool isCompActivePath() const { return m_compActivePath; }

void setCompActivePath(bool value) {
m_compActivePath = value;
setComponentActivePath(value);
}

bool isCompActiveFsm() const { return m_compActiveFsm; }

void setCompActiveFsm(bool value) {
m_compActiveFsm = value;
setComponentActiveFsm(value);
}

bool isCompActiveFsmCol() const { return m_compActiveFsmCol; }

void setCompActiveFsmCol(bool value) {
m_compActiveFsmCol = value;
setComponentActiveFsmCol(value);
}



template <unsigned int W, typename E_t = void>
Port<W>& createInputPort(const std::string& name) {
return createPort<W, E_t>(name, m_inputPorts, vsrtl::SimPort::PortType::in);
Expand Down Expand Up @@ -258,6 +286,10 @@ class Component : public SimComponent {
return ports;
}

bool m_compActivePath = false;
bool m_compActiveFsm = false;
bool m_compActiveFsmCol = false;

std::vector<const PortBase*> m_sensitivityList;
PropagationState m_propagationState = PropagationState::unpropagated;
};
Expand Down
42 changes: 40 additions & 2 deletions core/vsrtl_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "../interface/vsrtl_binutils.h"
#include "../interface/vsrtl_interface.h"

#include "../graphics/vsrtl_label.h"

namespace vsrtl {
namespace core {

Expand Down Expand Up @@ -40,6 +42,11 @@ class PortBase : public SimPort {
virtual void propagateConstant() = 0;
virtual void setPortValue() = 0;
virtual bool isConnected() const = 0;
virtual bool isActivePath() const = 0;
virtual void setActivePath(bool value) = 0;
virtual bool isActiveFsm() const = 0;
virtual void setActiveFsm(bool value) = 0;


/**
* @brief stringValue
Expand All @@ -62,6 +69,7 @@ class Port : public PortBase {
Port(const std::string& name, SimComponent* parent, PortType type) : PortBase(name, parent, type) {}
bool isConnected() const override { return m_inputPort != nullptr || m_propagationFunction; }


// Port connections are doubly linked
void operator>>(Port<W>& toThis) {
m_outputPorts.push_back(&toThis);
Expand All @@ -85,19 +93,47 @@ class Port : public PortBase {

explicit operator VSRTL_VT_S() const { return signextend<W>(m_value); }

bool isActivePath() const override { return m_activePath; }

bool isActiveFsm() const override { return m_activeFsm; }

void setActivePath(bool value) {
m_activePath = value;

}

void setActiveFsm(bool value) {
m_activeFsm = value;
}


void setPortValue() override {
auto prePropagateValue = m_value;
if (m_propagationFunction) {
m_value = m_propagationFunction();
} else {
m_value = getInputPort<Port<W>>()->uValue();
}
if (m_value != prePropagateValue) {
// Signal all watcher of this port that the port value changed
QString port =QString::fromStdString(getHierName());

if(port.contains("MIPS")){
if (getDesign()->signalsEnabled()) {
changed.Emit();
}
}
else{
if (m_value != prePropagateValue) {
// Signal all watcher of this port that the port value changed
if (getDesign()->signalsEnabled()) {
changed.Emit();
}
}
}





}

void propagate(std::vector<PortBase*>& propagationStack) override {
Expand Down Expand Up @@ -133,6 +169,8 @@ class Port : public PortBase {
// not be the case - the entire circuit is reset when the registers are reset (to 0), and the circuit state is
// then propagated.
VSRTL_VT_U m_value = 0xdeadbeef;
bool m_activePath = false;
bool m_activeFsm = false;

std::function<VSRTL_VT_U()> m_propagationFunction = {};
};
Expand Down
110 changes: 89 additions & 21 deletions graphics/vsrtl_componentgraphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,33 +521,101 @@ QVariant ComponentGraphic::itemChange(QGraphicsItem::GraphicsItemChange change,
}

void ComponentGraphic::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* w) {
painter->save();
QColor color;
if (static_cast<VSRTLScene*>(scene())->darkmode()) {
color = hasSubcomponents() && isExpanded() ? QColorConstants::DarkGray.darker() : QColor{0x80, 0x84, 0x8a};
} else {
color = hasSubcomponents() && isExpanded() ? QColor{0xec, 0xf0, 0xf1} : QColorConstants::White;
if(QString::fromStdString(m_component->getHierName()).contains("MIPS")){
painter->save();

QColor color;
if (static_cast<VSRTLScene*>(scene())->darkmode() ) {
color = hasSubcomponents() && isExpanded() ? QColorConstants::DarkGray.darker() : QColor{0x80, 0x84, 0x8a};
} else {
color = hasSubcomponents() && isExpanded() ? QColor{0xec, 0xf0, 0xf1} : QColorConstants::White;
}

QColor fillColor = (option->state & QStyle::State_Selected) ? color.darker(150) : color;
if (option->state & QStyle::State_MouseOver)
fillColor = fillColor.lighter(125);
constexpr QColor WIRE_BOOLHIGH_COLOR = {0x6E, 0xEB, 0x83};
if(m_component->isComponentActiveFsmCol()){
fillColor = WIRE_BOOLHIGH_COLOR;
}

// Draw component outline
QPen oldPen = painter->pen();
QPen pen = oldPen;
int width = COMPONENT_BORDER_WIDTH;
if (option->state & QStyle::State_Selected)
width += 1;

if(!m_component->isComponentActivePath() && !m_component->isComponentActiveFsm() ){
fillColor = color.darker(250);
}

if(m_label->getText().contains("Processor")){
fillColor = fillColor.lighter(250);
}

if(m_component->isComponentActiveFsmCol()){
fillColor = WIRE_BOOLHIGH_COLOR.darker(125);
}

pen.setWidth(width);
painter->setBrush(QBrush(fillColor.darker((option->state & QStyle::State_Sunken) ? 120 : 100)));
if(!m_component->isComponentActivePath()){
painter->setPen(pen);
painter->setPen(QColorConstants::LightGray);
}


if(m_component->isComponentActiveFsm()){
painter->setPen(pen);

painter->setPen(WIRE_BOOLHIGH_COLOR);
width += 1;
pen.setWidth(width);
}
else{
width = COMPONENT_BORDER_WIDTH;
pen.setWidth(width);

}


painter->drawPath(m_shape);

painter->setPen(oldPen);
}

QColor fillColor = (option->state & QStyle::State_Selected) ? color.darker(150) : color;
if (option->state & QStyle::State_MouseOver)
fillColor = fillColor.lighter(125);

const qreal lod = option->levelOfDetailFromTransform(painter->worldTransform());
else{
painter->save();
QColor color;
if (static_cast<VSRTLScene*>(scene())->darkmode()) {
color = hasSubcomponents() && isExpanded() ? QColorConstants::DarkGray.darker() : QColor{0x80, 0x84, 0x8a};
} else {
color = hasSubcomponents() && isExpanded() ? QColor{0xec, 0xf0, 0xf1} : QColorConstants::White;
}

// Draw component outline
QPen oldPen = painter->pen();
QPen pen = oldPen;
int width = COMPONENT_BORDER_WIDTH;
if (option->state & QStyle::State_Selected)
width += 1;
QColor fillColor = (option->state & QStyle::State_Selected) ? color.darker(150) : color;
if (option->state & QStyle::State_MouseOver)
fillColor = fillColor.lighter(125);

pen.setWidth(width);
painter->setBrush(QBrush(fillColor.darker((option->state & QStyle::State_Sunken) ? 120 : 100)));
painter->setPen(pen);
painter->drawPath(m_shape);

painter->setPen(oldPen);
// Draw component outline
QPen oldPen = painter->pen();
QPen pen = oldPen;
int width = COMPONENT_BORDER_WIDTH;
if (option->state & QStyle::State_Selected)
width += 1;

pen.setWidth(width);
painter->setBrush(QBrush(fillColor.darker((option->state & QStyle::State_Sunken) ? 120 : 100)));
painter->setPen(pen);
painter->drawPath(m_shape);

painter->setPen(oldPen);

}
const qreal lod = option->levelOfDetailFromTransform(painter->worldTransform());

if (hasSubcomponents()) {
if (lod >= 0.35) {
Expand Down
18 changes: 18 additions & 0 deletions graphics/vsrtl_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "vsrtl_labeleditdialog.h"
#include "vsrtl_scene.h"
#include "../interface/vsrtl_interface.h"
#include "../VSRTL/core/vsrtl_port.h"

namespace vsrtl {

Expand Down Expand Up @@ -40,6 +42,15 @@ void Label::setText(const QString& text) {
applyFormatChanges();
}

QString Label::getText() {
QString text = toPlainText();
return text;
}

void Label::setActive(bool value){
m_active = value;
}

void Label::updateText() {}

void Label::setPointSize(int size) {
Expand Down Expand Up @@ -95,6 +106,13 @@ void Label::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWi
if (!m_defaultColorOverridden) {
setDefaultTextColor(static_cast<VSRTLScene*>(scene())->darkmode() ? Qt::white : Qt::black);
}
if(m_active){
setDefaultTextColor(static_cast<VSRTLScene*>(scene())->darkmode() ? Qt::white : Qt::black);
}
else{
setDefaultTextColor(static_cast<VSRTLScene*>(scene())->darkmode() ? Qt::darkGray : Qt::white);
}


QGraphicsTextItem::paint(painter, option, w);
painter->restore();
Expand Down
8 changes: 8 additions & 0 deletions graphics/vsrtl_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "vsrtl_graphicsbaseitem.h"
#include "vsrtl_qt_serializers.h"
#include "vsrtl_component.h"
#include "vsrtl_port.h"

#include "cereal/cereal.hpp"

Expand All @@ -23,6 +25,7 @@ class Label : public GraphicsBaseItem<QGraphicsTextItem> {

void setHoverable(bool enabled);
void setText(const QString& text);
QString getText();
void setAlignment(Qt::Alignment alignment);
void setPointSize(int size);
void setLocked(bool locked) override;
Expand Down Expand Up @@ -99,10 +102,15 @@ class Label : public GraphicsBaseItem<QGraphicsTextItem> {
applyFormatChanges();
}

void setActive(bool value);

bool isActive();

protected:
void applyFormatChanges();
void editTriggered();

bool m_active = true;
bool m_hoverable = true;
QFont m_font;
bool m_defaultColorOverridden = false;
Expand Down
47 changes: 42 additions & 5 deletions graphics/vsrtl_portgraphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,50 @@ void PortGraphic::updatePenColor() {
} else {
m_pen.setWidth(WIRE_WIDTH);
if (m_port->getWidth() == 1) {
if (static_cast<bool>(m_port->uValue())) {
m_pen.setColor(WIRE_BOOLHIGH_COLOR);
} else {
m_pen.setColor(WIRE_DEFAULT_COLOR);
if(!QString::fromStdString(m_port->getHierName()).contains("MIPS")){
if (static_cast<bool>(m_port->uValue())) {
m_pen.setColor(WIRE_BOOLHIGH_COLOR);
} else {
m_pen.setColor(WIRE_DEFAULT_COLOR);
}
}

else{
if(m_port->isActivePath()){
m_pen.setColor(WIRE_BOOLHIGH_COLOR);
}
else{
if (static_cast<bool>(m_port->uValue())) {
m_pen.setColor(WIRE_BOOLHIGH_COLOR);
} else {
m_pen.setColor(WIRE_DEFAULT_COLOR);
}
}
}
} else {
m_pen.setColor(m_penColor);
if(QString::fromStdString(m_port->getHierName()).contains("MIPS")){
if(m_port->isActivePath()){
if(QString::fromStdString(m_port->getHierName()).contains("control->alu_ctrl") || QString::fromStdString(m_port->getHierName()).contains("alu_control->res")
|| QString::fromStdString(m_port->getHierName()).contains("alu_control_reg->out") || QString::fromStdString(m_port->getHierName()).contains("control")){
m_pen.setColor(WIRE_BOOLHIGH_COLOR);
}else{

m_pen.setColor(WIRE_HIGH_COLOR);
}

}
else if(!m_port->isActivePath()){
m_pen.setColor(WIRE_DEFAULT_COLOR);
}
else{
m_pen.setColor(WIRE_DEFAULT_COLOR);
}
}
else{
m_pen.setColor(m_penColor);
}


}
}
propagateRedraw();
Expand Down
Loading