Skip to content

Commit

Permalink
Merge branch 'feature/word_level_structures' of github.com:emsec/hal …
Browse files Browse the repository at this point in the history
…into feature/word_level_structures
  • Loading branch information
SimonKlx committed Mar 15, 2024
2 parents 0c3af9b + 063ef8d commit c7d8df2
Show file tree
Hide file tree
Showing 33 changed files with 857 additions and 208 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file.
* removed layouter code used prior to version 3.1.0 - thus removing the setting option to use that code
* added setting option to dump junction layout input data for experts to debug in case of layout errors
* miscellaneous
* added drag'n drop feature allowing to move several nodes in graph view at same time
* added functions to Python GUI API to create, modifiy and delete views
* added GUI PluginParameter type `ComboBox` for parameters that can be requested from plugin
* added GUI PluginParameter types `Module` and `Gated` for parameters that can be requested from plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ namespace hal
*/
Result<Net*> connect_nets(Net* master_net, Net* slave_net);

/**
* Searches for a GND net in the netlist.
* If there are no existing ones then the function will try to search for a GND gate type in the gate library and create a GND net with corresponding gate source.
*
* @returns A vector containing the either newly created or all already existing GND nets.
*/
Result<std::vector<Net*>> create_gnd_net();

/**
* Searches for a VCC net in the netlist.
* If there are no existing ones then the function will try to search for a VCC gate type in the gate library and create a VCC net with corresponding gate source.
*
* @returns A vector containing the either newly created or all already existing VCC nets.
*/
Result<std::vector<Net*>> create_vcc_net();

private:
Netlist& m_netlist;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,43 @@ namespace hal
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

// TODO implement: get_subgraph_gates()
/**
* Starting from the given net, traverse the netlist and return only the successor/predecessor gates for which the `target_gate_filter` evaluates to `true`.
* Stop traversal if (1) the `exit_endpoint_filter` evaluates to `false` on a fan-in/out endpoint (i.e., when exiting the current gate during traversal), or (2) the `entry_endpoint_filter` evaluates to `false` on a successor/predecessor endpoint (i.e., when entering the next gate during traversal).
* The target_gate_filter may be ommitted in which case all traversed gates will be returned.
* Both `entry_endpoint_filter` and the `exit_endpoint_filter` may be omitted as well.
*
* @param[in] net - Start net.
* @param[in] successors - Set `true` to get successors, set `false` to get predecessors.
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
* @param[in] exit_endpoint_filter - Filter condition that determines whether to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition that determines whether to stop traversal on a successor/predecessor endpoint.
* @returns The next gates fulfilling the target gate filter condition.
*/
Result<std::set<Gate*>> get_subgraph_gates(const Net* net,
bool successors,
const std::function<bool(const Gate*)>& target_gate_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* Starting from the given gate, traverse the netlist and return only the successor/predecessor gates for which the `target_gate_filter` evaluates to `true`.
* Stop traversal if (1) the `exit_endpoint_filter` evaluates to `false` on a fan-in/out endpoint (i.e., when exiting the current gate during traversal), or (2) the `entry_endpoint_filter` evaluates to `false` on a successor/predecessor endpoint (i.e., when entering the next gate during traversal).
* The target_gate_filter may be ommitted in which case all traversed gates will be returned.
* Both `entry_endpoint_filter` and the `exit_endpoint_filter` may be omitted as well.
*
* @param[in] gate - Start gate.
* @param[in] successors - Set `true` to get successors, set `false` to get predecessors.
* @param[in] target_gate_filter - Filter condition that must be met for the target gates.
* @param[in] exit_endpoint_filter - Filter condition that determines whether to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition that determines whether to stop traversal on a successor/predecessor endpoint.
* @returns The next gates fulfilling the target gate filter condition.
*/
Result<std::set<Gate*>> get_subgraph_gates(const Gate* gate,
bool successors,
const std::function<bool(const Gate*)>& target_gate_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* TODO document
Expand Down
14 changes: 14 additions & 0 deletions include/hal_core/netlist/netlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,20 @@ namespace hal
*/
void enable_automatic_net_checks(bool enable_checks = true);

/**
* Get all GND nets in the netlist.
*
* @returns A vector nets.
*/
std::vector<Net*> get_gnd_nets() const;

/**
* Get all VCC nets in the netlist.
*
* @returns A vector of nets.
*/
std::vector<Net*> get_vcc_nets() const;

/*
* ################################################################
* module functions
Expand Down
9 changes: 9 additions & 0 deletions plugins/bitwuzla_utils/src/bitwuzla_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ namespace hal
}
return OK(BooleanFunction::Var(name.value(), size));
}
else if (t.is_variable())
{
const auto name = t.symbol();
if (!name.has_value())
{
return ERR("cannot translate term to hal Boolean function: failed to extract symbol");
}
return OK(BooleanFunction::Var(name.value(), size));
}
}
// else
// {
Expand Down
6 changes: 4 additions & 2 deletions plugins/gate_libraries/definitions/XILINX_UNISIM.hgl
Original file line number Diff line number Diff line change
Expand Up @@ -666586,7 +666586,8 @@
{
"name": "URAM288",
"types": [
"combinational"
"sequential",
"ram"
],
"pin_groups": [
{
Expand Down Expand Up @@ -673473,7 +673474,8 @@
{
"name": "URAM288_BASE",
"types": [
"combinational"
"sequential",
"ram"
],
"pin_groups": [
{
Expand Down
90 changes: 90 additions & 0 deletions plugins/gui/include/gui/graph_widget/drag_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// MIT License
//
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once
#include <QObject>
#include <QSet>
#include <QPoint>
#include <QHash>
#include "gui/gui_def.h"
#include "gui/graph_widget/items/utility_items/node_drag_shadow.h"

namespace hal {

class GraphWidget;
class GraphicsNode;
class NodeBox;
class NodeDragShadow;
class GraphicsScene;

class DragController : public QObject
{
Q_OBJECT
GraphWidget* mGraphWidget;
bool mDropAllowed;
bool mWantSwap;
QPoint mMousedownPosition;
NodeBox* mDragNodeBox;
QPoint mCurrentGridpos;
QSet<NodeBox*> mAdditionalBoxes;
QHash<const NodeBox*,NodeDragShadow*> mShadows;
GraphicsScene* mShadowScene;

void setSwapIntent(bool wantSwap);
void addShadow(const NodeBox* nb);
public:
DragController(GraphWidget* gw, QObject* parent = nullptr);

void clear();

void set(GraphicsNode* drgItem, const QPoint& eventPos);

/**
* Starts the dragging of a gate or module to show its shadow meanwhile.
*
* @param wantSwap - True if keyboard swap modifier has been pressed, false otherwise
*/
void enterDrag(bool wantSwap);

/**
* Moves the shadow that appears while dragging a gate or module.
*
* @param eventPos - The mouse position in scene coordinates while dragging
* @param wantSwap - True if keyboard swap modifier has been pressed, false otherwise
* @param gridPos - The new grid position of the primary node
*/
void move(const QPoint& eventPos, bool wantSwap, const QPoint& gridPos);

/**
* Remove all painted shadows from graphics scene
*/
void clearShadows(GraphicsScene* sc);

bool hasDragged(const QPoint& eventPos);
bool isDropAllowed() const;
GridPlacement* finalGridPlacement() const;
NodeDragShadow::DragCue dragCue() const;
};
}
11 changes: 4 additions & 7 deletions plugins/gui/include/gui/graph_widget/graph_graphics_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace hal
{
class GraphicsItem;
class GraphWidget;
class DragController;

namespace graph_widget_constants
{
Expand Down Expand Up @@ -202,6 +203,8 @@ namespace hal
void addSuccessorToView(int maxLevel, bool succ);
void addCommonSuccessorToView(int maxLevel, bool succ);

void dragPan(float dpx, float dpy);

GraphWidget* mGraphWidget;

QSet<u32> getSelectableGates();
Expand Down Expand Up @@ -233,13 +236,7 @@ namespace hal
bool mGridClustersEnabled;
GraphicsScene::GridType mGridType;

QPoint mDragMousedownPosition;
QPoint mDragStartGridpos;
GraphicsGate* mDragItem;
QPoint mDragCurrentGridpos;
bool mDragCurrentModifier;
bool mDropAllowed;

DragController* mDragController;
Qt::KeyboardModifier mDragModifier;

QPoint mMovePosition;
Expand Down
32 changes: 8 additions & 24 deletions plugins/gui/include/gui/graph_widget/graphics_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace hal
class GraphicsItem;
class GraphicsModule;
class GraphicsNet;
class DragController;

/**
* @ingroup graph
Expand Down Expand Up @@ -119,28 +120,6 @@ namespace hal
*/
~GraphicsScene();

/**
* Starts the dragging of a gate or module to show its shadow meanwhile.
*
* @param posF - The position of the shadow
* @param sizeF - The size of the shadow (i.e. the size of the dragged gate)
* @param cue - The cue of the current position
*/
void startDragShadow(const QPointF& posF, const QSizeF& sizeF, const NodeDragShadow::DragCue cue);

/**
* Moves the shadow that appears while dragging a gate or module.
*
* @param posF - The new position of the shadow
* @param cue - The cue of the current position
*/
void moveDragShadow(const QPointF& posF, const NodeDragShadow::DragCue cue);

/**
* Removes the shadow that appears while dragging a gate or module (at the end of the drag action).
*/
void stopDragShadow();

/**
* Gets the position of the drag shadow.
*
Expand Down Expand Up @@ -297,6 +276,12 @@ namespace hal
*/
void updateAllItems();

/**
* Set reference pointer to drag controller on start drag, nullptr when drag ended
* @param dc - Reference to drag controller
*/
void setDragController(DragController* dc);

protected:
/**
* Handles the mouse event. Used to intercept and ignore right-clicks.
Expand All @@ -321,8 +306,6 @@ namespace hal

void drawBackground(QPainter* painter, const QRectF& rect) override;

NodeDragShadow* mDragShadowGate;

QVector<GraphicsModule*> mModuleItems;
QVector<GraphicsGate*> mGateItems;
QVector<GraphicsNet*> mNetItems;
Expand All @@ -334,6 +317,7 @@ namespace hal
qreal mDebugDefaultWidth;
qreal mDebugDefaultHeight;
bool mDebugGridEnable;
DragController* mDragController;
enum RubberBandSelectionStatus
{
NotPressed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@

#pragma once

#include <QGraphicsObject>
#include <QGraphicsItem>
#include <QRectF>
#include <QList>

namespace hal
{
/**
* @ingroup graph-visuals
* @brief An item that is drawn when a node is dragged through the scene.
*/
class NodeDragShadow : public QGraphicsObject
class NodeDragShadow : public QGraphicsItem
{
Q_OBJECT

public:
enum class DragCue
Expand All @@ -50,14 +51,17 @@ namespace hal
void start(const QPointF& posF, const QSizeF& sizeF);
void stop();

/*
qreal width() const;
qreal height() const;
QSizeF size() const;
void setWidth(const qreal width);
void setHeight(const qreal height);
*/

void setVisualCue(const DragCue cue);
QList<QPoint> multiMoveGridPositions() const;

static void setLod(const qreal lod);
static void loadSettings();
Expand All @@ -75,8 +79,6 @@ namespace hal
static QColor sColorTranslucent[];

DragCue mCue;

qreal mWidth;
qreal mHeight;
QRectF mRect;
};
} // namespace hal
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,15 @@ namespace hal

const QMap<Node, QPoint> nodeToPositionMap() const;
const QMap<QPoint, Node> positionToNodeMap() const;

/**
* Creates a new GridPlacement instance (node to position hash) and returns the pointer
* The caller has the ownership and responsibility to delete that instance
*/
GridPlacement* gridPlacementFactory() const;

NetLayoutPoint positonForNode(const Node& nd) const;
Node nodeAtPosition(const QPoint& p) const;

QPoint gridPointByItem(GraphicsNode* item) const;

Expand Down
2 changes: 2 additions & 0 deletions plugins/gui/include/gui/python/python_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -848,5 +848,7 @@ namespace hal
SettingsItemKeybind* mSettingSaveFileAs;
SettingsItemKeybind* mSettingRunFile;
SettingsItemKeybind* mSettingCreateFile;

QList<u32> mBlockedContextIds;
};
} // namespace hal
Loading

0 comments on commit c7d8df2

Please sign in to comment.