HAL  v4.5.0-133-g64838ea8d
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
net_layout_point.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 #include <QPoint>
29 #include <QPointF>
30 
31 #include <QList>
32 #include <QMap>
33 #include <QHash>
34 #include <limits.h>
35 
37 class QGraphicsLineItem;
38 
39 QPointF scenePoint(const QPoint& p);
40 
42 // Note: hidden from doxygen because it collides with hal::u32 from "hal_core/defines.h".
43 // Doxygen has no real name lookup and would resolve every `u32` in the project to
44 // whichever of the two typedefs it saw last, breaking overload matching across the
45 // whole netlist API.
46 typedef quint32 u32;
48 
49 namespace hal {
50 
57  {
58  public:
59  enum DirectionType {Undefined = -1, Left = 0, Right = 1, Up = 2, Down = 3, MaxDir = 4};
61  NetLayoutDirection(int idir);
62  bool isHorizontal() const { return mDir == Left || mDir == Right; }
63  int iHorizontal() const { return index()/2; }
64  bool isVertical() const { return mDir == Up || mDir == Down; }
65  bool isNull() const { return mDir == Undefined; }
66  QPoint step(bool omitEndpoint=false) const;
67  DirectionType direction() const { return mDir; }
68  u32 toPattern() const { return 1 << mDir; }
71  int index() const { return static_cast<int>(mDir); }
72  bool isLeft() const { return mDir==Left; }
73  bool isUp() const { return mDir==Up; }
74  bool isMax() const { return mDir==MaxDir; }
75  bool operator==(const NetLayoutDirection& other) const { return mDir == other.mDir; }
76  private:
77  static DirectionType numberToDirection(int idir);
78  DirectionType mDir;
79  };
80 
86  class NetLayoutPoint : public QPoint
87  {
88  public:
89  NetLayoutPoint(int x_=INT_MIN, int y_=INT_MIN);
90  NetLayoutPoint(const QPoint& p);
91  QGraphicsEllipseItem* graphicsFactory(float r) const;
92  int distanceTo(const NetLayoutPoint& other) const;
93  int yGrid() const;
94  QPoint gridPoint() const { return QPoint(x(),yGrid()); }
95  bool isEndpoint() const;
96  bool isUndefined() const { return x()==INT_MIN || y()==INT_MIN; }
97  NetLayoutPoint nextPoint(const NetLayoutDirection& dir, bool omitEndpoint=false) const;
98  static NetLayoutPoint fromBox(const QPoint& boxPosition, bool isInput);
100  };
101 
108  {
109  public:
111  NetLayoutWire(const NetLayoutPoint& p, const NetLayoutDirection& dir, bool isEnd);
113 
115  bool isEndpoint() const { return mIsEndpoint; }
116  bool isHorizontal() const { return mDir.isHorizontal(); }
117  bool operator==(const NetLayoutWire& other) const;
118  QString toString() const;
119  private:
120  NetLayoutPoint mPoint;
121  NetLayoutDirection mDir;
122  bool mIsEndpoint;
123  };
124 
130  class NetLayoutConnection : public QList<NetLayoutWire>
131  {
132  public:
134  NetLayoutConnection(const NetLayoutPoint& pa, const NetLayoutPoint& pb);
135  QList<NetLayoutPoint> wayPoints() const { return mWaypointLinks.keys(); }
136  NetLayoutPoint closestPoint(const NetLayoutPoint& pnt) const;
137  void add(const NetLayoutConnection& other, bool atomicNet);
138  private:
139  QHash<NetLayoutPoint,QList<int>> mWaypointLinks;
140 
141  NetLayoutPoint addWire(const NetLayoutPoint& pnt, const NetLayoutDirection& dir, bool omitEndpoint);
142  };
143 
150  {
151  public:
152  NetLayoutMetric(u32 id, const NetLayoutConnection* con);
153  u32 getId() const { return mId; }
154  int firstMoment() const {return mFirst; }
155  int secondMoment() const {return mSecond; }
156  bool operator< (const NetLayoutMetric& other) const;
157  private:
158  void evaluate(const QMap<int,QMap<int,int>>& map);
159  u32 mId;
160  int mFirst;
161  int mSecond;
162  };
163 
170  {
171  public:
172  NetLayoutConnectionFactory(const QList<NetLayoutPoint>& sources, const QList<NetLayoutPoint>& destinations);
173  QList<NetLayoutPoint> points() const { return mPoints; }
175  void dump(const QString& stub) const;
176  private:
177  QList<NetLayoutPoint> mSources;
178  QList<NetLayoutPoint> mDestinations;
179  QList<NetLayoutPoint> mPoints;
180  };
181 
187  class NetLayoutConnectionMetric : public QMap<NetLayoutMetric,NetLayoutConnection*>
188  {
189  public:
192  void clearAll();
193  };
194 
195  uint qHash(const hal::NetLayoutWire& w);
196  uint qHash(const hal::NetLayoutPoint& p);
197 }
198 
199 uint qHash(const QPoint& p);
NetLayoutConnectionFactory(const QList< NetLayoutPoint > &sources, const QList< NetLayoutPoint > &destinations)
void dump(const QString &stub) const
NetLayoutConnection * connection
QList< NetLayoutPoint > points() const
QList< NetLayoutPoint > wayPoints() const
NetLayoutPoint closestPoint(const NetLayoutPoint &pnt) const
void add(const NetLayoutConnection &other, bool atomicNet)
NetLayoutDirection operator++()
NetLayoutDirection(DirectionType dir=Undefined)
bool operator==(const NetLayoutDirection &other) const
QPoint step(bool omitEndpoint=false) const
DirectionType direction() const
NetLayoutMetric(u32 id, const NetLayoutConnection *con)
bool operator<(const NetLayoutMetric &other) const
static QList< NetLayoutPoint > orderByDistance(const QList< NetLayoutPoint > &points)
bool isUndefined() const
QPoint gridPoint() const
NetLayoutPoint nextPoint(const NetLayoutDirection &dir, bool omitEndpoint=false) const
int distanceTo(const NetLayoutPoint &other) const
QGraphicsEllipseItem * graphicsFactory(float r) const
NetLayoutPoint(int x_=INT_MIN, int y_=INT_MIN)
static NetLayoutPoint fromBox(const QPoint &boxPosition, bool isInput)
NetLayoutWire(const NetLayoutPoint &p, const NetLayoutDirection &dir, bool isEnd)
QString toString() const
bool isEndpoint() const
bool isHorizontal() const
NetLayoutPoint endPoint(WirePointType pnt) const
QGraphicsLineItem * graphicsFactory() const
bool operator==(const NetLayoutWire &other) const
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45
uint qHash(const LaneIndex &ri)
QPointF scenePoint(const QPoint &p)
uint qHash(const QPoint &p)
Definition: node_box.cpp:6
int x() const const
int y() const const