Skip to content

Commit

Permalink
Merge branch 'master' of github.com:emsec/hal
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonKlx committed Oct 24, 2024
2 parents 0a45d72 + a8ea52b commit c7a3c68
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 13 deletions.
4 changes: 4 additions & 0 deletions plugins/gui/include/gui/graph_widget/graph_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ namespace hal

void focusRect(QRectF targetRect, bool applyCenterFix);

bool hasFocusedItem(SelectionRelay::Subfocus navigateDirection) const;

bool hasGate(const Gate* g) const;

GraphGraphicsView* mView;
GraphContext* mContext;

Expand Down
70 changes: 70 additions & 0 deletions plugins/gui/src/graph_widget/graph_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ namespace hal
// ADD SOUND OR ERROR MESSAGE TO FAILED NAVIGATION ATTEMPTS
void GraphWidget::handleNavigationLeftRequest()
{
if (!hasFocusedItem(SelectionRelay::Subfocus::Left)) return;
const SelectionRelay::Subfocus navigateLeft = SelectionRelay::Subfocus::Left;
mOverlay->setWidget(mNavigationWidgetV3);
switch (gSelectionRelay->focusType())
Expand Down Expand Up @@ -658,6 +659,7 @@ namespace hal

void GraphWidget::handleNavigationRightRequest()
{
if (!hasFocusedItem(SelectionRelay::Subfocus::Right)) return;
const SelectionRelay::Subfocus navigateRight = SelectionRelay::Subfocus::Right;
mOverlay->setWidget(mNavigationWidgetV3);
switch (gSelectionRelay->focusType())
Expand Down Expand Up @@ -768,8 +770,75 @@ namespace hal
}
}

bool GraphWidget::hasFocusedItem(SelectionRelay::Subfocus navigateDirection) const
{
if (gSelectionRelay->focusType() == SelectionRelay::ItemType::None && gSelectionRelay->numberSelectedItems() == 1)
{
// focus item has not been set but since only one item is selected it is obvious what the user wants
if (gSelectionRelay->numberSelectedModules())
gSelectionRelay->setFocusDirect(SelectionRelay::ItemType::Module, gSelectionRelay->selectedModulesVector().at(0));
else if (gSelectionRelay->numberSelectedGates())
gSelectionRelay->setFocusDirect(SelectionRelay::ItemType::Gate, gSelectionRelay->selectedGatesVector().at(0));
else if (gSelectionRelay->numberSelectedNets())
gSelectionRelay->setFocusDirect(SelectionRelay::ItemType::Net, gSelectionRelay->selectedNetsVector().at(0));
}

u32 id = gSelectionRelay->focusId();
switch (gSelectionRelay->focusType())
{
case SelectionRelay::ItemType::Module:
if (!mContext->modules().contains(id))
{
log_warning("gui", "Cannot navigate from selected origin module ID={}, folded module not found on current view.", id);
return false;
}
break;
case SelectionRelay::ItemType::Gate:
if (!mContext->gates().contains(id))
{
log_warning("gui", "Cannot navigate from selected origin gate ID={}, gate not found on current view.", id);
return false;
}
break;
case SelectionRelay::ItemType::Net:
switch (navigateDirection) {
case SelectionRelay::Subfocus::Left:
for (const Endpoint* ep : gNetlist->get_net_by_id(id)->get_destinations())
if (hasGate(ep->get_gate())) return true;
break;
case SelectionRelay::Subfocus::Right:
for (const Endpoint* ep : gNetlist->get_net_by_id(id)->get_sources())
if (hasGate(ep->get_gate())) return true;
break;
default:
return true;
}
log_warning("gui", "Cannot navigate from selected origin net ID={}, net not found on current view.", id);
return false;
default:
log_warning("gui", "Cannot navigate, no origin selected");
return false;
}
return true;
}

bool GraphWidget::hasGate(const Gate* g) const
{
if (!g) return false;
if (mContext->gates().contains(g->get_id())) return true;
const Module* parentModule = g->get_module();
while (parentModule)
{
if (mContext->modules().contains(parentModule->get_id()))
return true;
parentModule = parentModule->get_parent_module();
}
return false;
}

void GraphWidget::handleNavigationUpRequest()
{
if (!hasFocusedItem(SelectionRelay::Subfocus::None)) return;
// FIXME this is ugly
if ((gSelectionRelay->focusType() == SelectionRelay::ItemType::Gate && mContext->gates().contains(gSelectionRelay->focusId()))
|| (gSelectionRelay->focusType() == SelectionRelay::ItemType::Module && mContext->modules().contains(gSelectionRelay->focusId())))
Expand All @@ -778,6 +847,7 @@ namespace hal

void GraphWidget::handleNavigationDownRequest()
{
if (!hasFocusedItem(SelectionRelay::Subfocus::None)) return;
// FIXME this is ugly
if ((gSelectionRelay->focusType() == SelectionRelay::ItemType::Gate && mContext->gates().contains(gSelectionRelay->focusId()))
|| (gSelectionRelay->focusType() == SelectionRelay::ItemType::Module && mContext->modules().contains(gSelectionRelay->focusId())))
Expand Down
1 change: 1 addition & 0 deletions plugins/gui/src/graph_widget/progress_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace hal {

void ProgressBar::setValue(int percent)
{
if (percent >= 6) mButAbort->setDisabled(true);
mProgressBar->setValue(percent);
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/gui/src/module_model/module_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,8 @@ namespace hal
void ModuleModel::updateNetName(u32 id)
{
Q_ASSERT(gNetlist->get_net_by_id(id));
Q_ASSERT(mNetMap.contains(id));

// if net elment not in model loop will reject
for (auto it = mNetMap.lowerBound(id); it != mNetMap.upperBound(id); ++it)
{
ModuleItem* item = it.value();
Expand Down
34 changes: 24 additions & 10 deletions plugins/gui/src/netlist_relay/netlist_relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,27 @@ namespace hal
Node firstNode = node;
QSet<u32> gatIds;
QSet<u32> modIds;

GraphContext* context = gContentManager->getContextManagerWidget()->getCurrentContext();
Q_ASSERT(context);

// exclusive module view will update automatically if module elements get moved
bool specialUpdateRequired = !context->getExclusiveModuleId();

if (node.isNull())
{
for (u32 id : gSelectionRelay->selectedGatesList())
{
if (specialUpdateRequired && ! context->gates().contains(id))
specialUpdateRequired = false;
if (firstNode.isNull()) firstNode = Node(id,Node::Gate);
gatIds.insert(id);
}

for (u32 id : gSelectionRelay->selectedModulesList())
{
if (specialUpdateRequired && ! context->modules().contains(id))
specialUpdateRequired = false;
if (firstNode.isNull()) firstNode = Node(id,Node::Module);
modIds.insert(id);
}
Expand Down Expand Up @@ -234,22 +245,25 @@ namespace hal
}
else
{
u32 targetModuleId = md.selectedId();
ActionAddItemsToObject* actAddItems = new ActionAddItemsToObject(modIds,gatIds);
actAddItems->setObject(UserActionObject(md.selectedId(),UserActionObjectType::Module));
actAddItems->setObject(UserActionObject(targetModuleId,UserActionObjectType::Module));
compound->addAction(actAddItems);
specialUpdateRequired = false;
}

// move module to position of first content node
GraphContext* context = gContentManager->getContextManagerWidget()->getCurrentContext();
if (context)
const NodeBox* box = context->getLayouter()->boxes().boxForNode(firstNode);
if (box && (specialUpdateRequired || context->getExclusiveModuleId()))
{
const NodeBox* box = context->getLayouter()->boxes().boxForNode(firstNode);
if (box)
{
ActionMoveNode* actMoveNode = new ActionMoveNode(context->id(),
QPoint(box->x(),box->y()));
compound->addAction(actMoveNode);
}
ActionMoveNode* actMoveNode = new ActionMoveNode(context->id(), QPoint(box->x(),box->y()));
compound->addAction(actMoveNode);
}

if (specialUpdateRequired)
{
context->setSpecialUpdate(true);
context->setScheduleRemove(modIds,gatIds);
}

compound->exec();
Expand Down
1 change: 1 addition & 0 deletions plugins/resynthesis/src/plugin_resynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace hal
{
std::set<std::string> retval;
retval.insert("genlib_writer");
retval.insert("verilog_parser");
return retval;
}
} // namespace hal
2 changes: 1 addition & 1 deletion plugins/verilog_parser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
option(PL_VERILOG_PARSER "PL_VERILOG_PARSER" ON)
if(PL_VERILOG_PARSER OR BUILD_ALL_PLUGINS)
if(PL_VERILOG_PARSER OR PL_RESYNTHESIS OR BUILD_ALL_PLUGINS)
file(GLOB_RECURSE VERILOG_PARSER_INC ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
file(GLOB_RECURSE VERILOG_PARSER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)

Expand Down
2 changes: 1 addition & 1 deletion src/python_bindings/bindings/gate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace hal
:type: list[hal_py.Module]
)");

py_gate.def("get_modules", &Gate::get_modules, R"(
py_gate.def("get_modules", &Gate::get_modules, py::arg("filter") = nullptr, py::arg("recursive") = true, R"(
Get all modules that contain this gate, either directly or as parent of another module.
If recursive is set to True, indirect parent modules are also included. Otherwise, only the module containing the gate directly is returned.
The optional filter is evaluated on every candidate such that the result only contains those matching the specified condition.
Expand Down
9 changes: 9 additions & 0 deletions src/utilities/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "hal_core/utilities/log.h"

#include <algorithm>
#include <dirent.h>
#include <fstream>
#include <random>
Expand Down Expand Up @@ -37,11 +38,17 @@ namespace hal
#ifdef _WIN32
DWORD ftyp = GetFileAttributesA(folder.c_str());
if (ftyp == INVALID_FILE_ATTRIBUTES)
{
return false; //something is wrong with your path!
}

if (ftyp & FILE_ATTRIBUTE_DIRECTORY)
{
if (0 == access(folder.c_str(), R_OK))
{
return true;
}
}

return false; // this is not a directory!
#else
Expand All @@ -65,7 +72,9 @@ namespace hal
#ifdef _WIN32
DWORD ret = GetModuleFileNameA(NULL, buf, sizeof(buf));
if (ret == 0 || ret == sizeof(buf))
{
return std::string();
}
return std::filesystem::path(buf);
#elif __APPLE__ && __MACH__
uint32_t size = sizeof(buf);
Expand Down

0 comments on commit c7a3c68

Please sign in to comment.