From: Christoph Egger Date: Thu, 4 Dec 2014 18:56:15 +0000 (+0100) Subject: Add support for backward edges X-Git-Tag: v0.1~159 X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=9230b2cf1a95c50e2bf0b4ca8e214bddd45cf65f;p=frida%2Ffrida.git Add support for backward edges --- diff --git a/src/gui/widgets/BasicBlockWidget.hxx b/src/gui/widgets/BasicBlockWidget.hxx index dd2fa30..5fda53e 100644 --- a/src/gui/widgets/BasicBlockWidget.hxx +++ b/src/gui/widgets/BasicBlockWidget.hxx @@ -30,10 +30,10 @@ public: return mapToScene(QPointF(width/2, 0)); } - std::tuple getExits() const { - return std::make_tuple(mapToScene(QPointF( width/3, height)), - mapToScene(QPointF( width/2, height)), - mapToScene(QPointF(2*width/3, height))); + std::array getExits() const { + return { { mapToScene(QPointF( width/3, height)), + mapToScene(QPointF( width/2, height)), + mapToScene(QPointF(2*width/3, height)) } }; } void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, diff --git a/src/gui/widgets/CFGScene.cxx b/src/gui/widgets/CFGScene.cxx index 81c9735..75a39f0 100644 --- a/src/gui/widgets/CFGScene.cxx +++ b/src/gui/widgets/CFGScene.cxx @@ -6,7 +6,7 @@ void CFGScene::drawBackground(QPainter* painter, const QRectF & rect) { spaceWidgets(); for (BasicBlockWidget * widget : widgets) { - QPointF kopf = widget->getEntry(); + QPointF kopf = widget->getEntry(); painter->setPen(QColor(0x00, 0xff, 0x00, 0xff)); painter->drawLine(kopf, kopf - QPointF(0, 20)); @@ -16,25 +16,52 @@ void CFGScene::drawBackground(QPainter* painter, const QRectF & rect) { if (NULL != next[1]) { painter->setPen(QColor(0xff, 0x00, 0x00, 0xff)); painter->drawLine(std::get<0>(tails), std::get<0>(tails) + QPointF(0, 20)); - drawLine(painter, std::get<0>(tails) + QPointF(0, 20), next[1]->getEntry() - QPointF(0, 20)); + drawLine(painter, widget, next[1], -1); + painter->setPen(QColor(0x00, 0xff, 0x00, 0xff)); painter->drawLine(std::get<2>(tails), std::get<2>(tails) + QPointF(0, 20)); - drawLine(painter, std::get<2>(tails) + QPointF(0, 20), next[0]->getEntry() - QPointF(0, 20)); + drawLine(painter, widget, next[0], 1); } else { painter->setPen(QColor(0x00, 0x00, 0x00, 0xff)); painter->drawLine(std::get<1>(tails), std::get<1>(tails) + QPointF(0, 20)); - drawLine(painter, std::get<1>(tails) + QPointF(0, 20), next[0]->getEntry() - QPointF(0, 20)); + drawLine(painter, widget, next[0], 0); } } } } -void CFGScene::drawLine(QPainter* painter, QPointF from, QPointF to, bool left) { - if ((to - from).y() > 0) { - QPointF angle1(from + QPointF(0, (to - from).y())), angle2(to - QPointF(0, (to - from).y() / 2)); - painter->drawLine(from, angle1); - painter->drawLine(angle1, to); - } +void CFGScene::drawLine(QPainter* painter, BasicBlockWidget * from, BasicBlockWidget * to, int8_t side) { + QPointF from_p = from->getExits()[side+1] + QPointF(0, 20); + QPointF to_p = to->getEntry() - QPointF(0, 20); + if ((to_p - from_p).y() > 0) { + /* Forward Edge */ + QPointF angle1(from_p + QPointF(0, (to_p - from_p).y())); + painter->drawLine(from_p, angle1); + painter->drawLine(angle1, to_p); + } else { + /* Backward Edge */ + QRectF from_r(from->boundingRect()), to_r(to->boundingRect()); + from_r.moveTo(from->scenePos()); + to_r.moveTo(to->scenePos()); + QRectF bound = from_r | to_r; + if (std::abs(bound.right() - from_p.x()) > std::abs(bound.left() - to_p.x())) { + /* we go left */ + QPointF middle1 = from_p + QPointF(bound.left() - from_p.x() - 20, 0); + QPointF middle2 = to_p + QPointF(bound.left() - to_p.x() - 20, 0); + + painter->drawLine(from_p, middle1); + painter->drawLine(middle1, middle2); + painter->drawLine(middle2, to_p); + } else { + /* we go right */ + QPointF middle1 = from_p - QPointF(from_p.x() - bound.right() - 20, 0); + QPointF middle2 = to_p - QPointF(to_p.x() - bound.right() - 20, 0); + + painter->drawLine(from_p, middle1); + painter->drawLine(middle1, middle2); + painter->drawLine(middle2, to_p); + } + } } void CFGScene::spaceWidgets() { diff --git a/src/gui/widgets/CFGScene.hxx b/src/gui/widgets/CFGScene.hxx index 6baa618..fb395f7 100644 --- a/src/gui/widgets/CFGScene.hxx +++ b/src/gui/widgets/CFGScene.hxx @@ -22,7 +22,7 @@ public: private: std::vector widgets; - void drawLine(QPainter* painter, QPointF from, QPointF to, bool left = true); + void drawLine(QPainter* painter, BasicBlockWidget * from, BasicBlockWidget * to, int8_t side = 0); void spaceWidgets(); };