HAL  v4.5.0-83-g30c8f0afc
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 
36 class QGraphicsLineItem;
37 
38 QPointF scenePoint(const QPoint& p);
39 
41 // Note: hidden from doxygen because it collides with hal::u32 from "hal_core/defines.h".
42 // Doxygen has no real name lookup and would resolve every `u32` in the project to
43 // whichever of the two typedefs it saw last, breaking overload matching across the
44 // whole netlist API.
45 typedef quint32 u32;
47 
48 namespace hal {
49 
56  {
57  public:
58  enum DirectionType {Undefined = -1, Left = 0, Right = 1, Up = 2, Down = 3, MaxDir = 4};
60  NetLayoutDirection(int idir);
61  bool isHorizontal() const { return mDir == Left || mDir == Right; }
62  int iHorizontal() const { return index()/2; }
63  bool isVertical() const { return mDir == Up || mDir == Down; }
64  bool isNull() const { return mDir == Undefined; }
65  QPoint step(bool omitEndpoint=false) const;
66  DirectionType direction() const { return mDir; }
67  u32 toPattern() const { return 1 << mDir; }
70  int index() const { return static_cast<int>(mDir); }
71  bool isLeft() const { return mDir==Left; }
72  bool isUp() const { return mDir==Up; }
73  bool isMax() const { return mDir==MaxDir; }
74  bool operator==(const NetLayoutDirection& other) const { return mDir == other.mDir; }
75  private:
76  static DirectionType numberToDirection(int idir);
77  DirectionType mDir;
78  };
79 
85  class NetLayoutPoint : public QPoint
86  {
87  public:
88  NetLayoutPoint(int x_=INT_MIN, int y_=INT_MIN);
89  NetLayoutPoint(const QPoint& p);
90  QGraphicsEllipseItem* graphicsFactory(float r) const;
91  int distanceTo(const NetLayoutPoint& other) const;
92  int yGrid() const;
93  QPoint gridPoint() const { return QPoint(x(),yGrid()); }
94  bool isEndpoint() const;
95  bool isUndefined() const { return x()==INT_MIN || y()==INT_MIN; }
96  NetLayoutPoint nextPoint(const NetLayoutDirection& dir, bool omitEndpoint=false) const;
97  static NetLayoutPoint fromBox(const QPoint& boxPosition, bool isInput);
99  };
100 
107  {
108  public:
110  NetLayoutWire(const NetLayoutPoint& p, const NetLayoutDirection& dir, bool isEnd);
112 
114  bool isEndpoint() const { return mIsEndpoint; }
115  bool isHorizontal() const { return mDir.isHorizontal(); }
116  bool operator==(const NetLayoutWire& other) const;
117  QString toString() const;
118  private:
119  NetLayoutPoint mPoint;
120  NetLayoutDirection mDir;
121  bool mIsEndpoint;
122  };
123 
129  class NetLayoutConnection : public QList<NetLayoutWire>
130  {
131  public:
133  NetLayoutConnection(const NetLayoutPoint& pa, const NetLayoutPoint& pb);
134  QList<NetLayoutPoint> wayPoints() const { return mWaypointLinks.keys(); }
135  NetLayoutPoint closestPoint(const NetLayoutPoint& pnt) const;
136  void add(const NetLayoutConnection& other, bool atomicNet);
137  private:
138  QHash<NetLayoutPoint,QList<int>> mWaypointLinks;
139 
140  NetLayoutPoint addWire(const NetLayoutPoint& pnt, const NetLayoutDirection& dir, bool omitEndpoint);
141  };
142 
149  {
150  public:
151  NetLayoutMetric(u32 id, const NetLayoutConnection* con);
152  u32 getId() const { return mId; }
153  int firstMoment() const {return mFirst; }
154  int secondMoment() const {return mSecond; }
155  bool operator< (const NetLayoutMetric& other) const;
156  private:
157  void evaluate(const QMap<int,QMap<int,int>>& map);
158  u32 mId;
159  int mFirst;
160  int mSecond;
161  };
162 
169  {
170  public:
171  NetLayoutConnectionFactory(const QList<NetLayoutPoint>& sources, const QList<NetLayoutPoint>& destinations);
172  QList<NetLayoutPoint> points() const { return mPoints; }
174  void dump(const QString& stub) const;
175  private:
176  QList<NetLayoutPoint> mSources;
177  QList<NetLayoutPoint> mDestinations;
178  QList<NetLayoutPoint> mPoints;
179  };
180 
186  class NetLayoutConnectionMetric : public QMap<NetLayoutMetric,NetLayoutConnection*>
187  {
188  public:
191  void clearAll();
192  };
193 
194  uint qHash(const hal::NetLayoutWire& w);
195  uint qHash(const hal::NetLayoutPoint& p);
196 }
197 
198 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