Skip to content

Commit

Permalink
Merge pull request #587 from emsec/feature/logic_evaluator
Browse files Browse the repository at this point in the history
Logic Evaluator for combinatoric logic
  • Loading branch information
joern274 committed Aug 6, 2024
2 parents ac2454c + d650001 commit 5a59c30
Show file tree
Hide file tree
Showing 20 changed files with 2,231 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ All notable changes to this project will be documented in this file.
* added `json.hpp` from nlohmann to deps to offer a light weight json api
* adapted cmake to consider the correct flags when finding and linking against the new version of Bitwuzla
* miscellaneous
* added logic evaluator plugin
* added backward compatibility for view management
* slightly improved symbolic execution engine
* added a version of `netlist_factory::load_netlist` that takes a path to a netlist file as well as a pointer to a gate library
Expand Down
2 changes: 1 addition & 1 deletion include/hal_core/plugin_system/plugin_parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace hal
class PluginParameter
{
public:
enum ParameterType { Absent, Boolean, Color, ComboBox, Dictionary, ExistingDir, ExistingFile, Float, Gate, Integer, Module, NewFile, PushButton, String, TabName };
enum ParameterType { Absent, Boolean, Color, ComboBox, Dictionary, ExistingDir, ExistingFile, Float, Gate, Integer, Label, Module, NewFile, PushButton, String, TabName };
private:
ParameterType m_type;
std::string m_tagname;
Expand Down
2 changes: 2 additions & 0 deletions plugins/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
!hgl_writer/**/*
!liberty_parser*
!liberty_parser/**/*
!logic_evaluator*
!logic_evaluator/**/*
!module_identification*
!module_identification/**/*
!netlist_preprocessing*
Expand Down
10 changes: 10 additions & 0 deletions plugins/gui/include/gui/module_model/module_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <QVariant>
#include <set>
#include <array>
#include <vector>
#include <QTextStream>

namespace hal
Expand Down Expand Up @@ -153,6 +154,15 @@ namespace hal
*/
void populateTree(const QVector<u32>& modIds = {}, const QVector<u32>& gatIds = {}, const QVector<u32>& netIds = {});

/**
* Clears current tree item model and repopulates it by a list of gates. This function will
* automatically load all parent modules to gates listed. Thus gates will be shown at their
* place within the module hierarchy.
*
* @param gates std::vector of gates to be added to the item model.
*/
void populateFromGatelist(const std::vector<Gate*>& gates);

/**
* Add a module to the item model. For the specified module new ModuleItems are created and stored.
*
Expand Down
137 changes: 137 additions & 0 deletions plugins/gui/resources/stylesheet/dark.qss
Original file line number Diff line number Diff line change
Expand Up @@ -1511,3 +1511,140 @@ hal--Overlay
background : rgba(0, 0, 0, 150);
}

hal--LogicEvaluatorDialog
{
font-size : 14px;
color : #A9B7C6;
background : #515253;
}

hal--LogicEvaluatorPingroup
{
background : #717273;
border : 2px solid gray;
padding-top : 4px;
padding-bottom : 4px;
padding-left : 0px;
padding-right : 0px;
}


hal--LogicEvaluatorPingroup[output="true"]
{
border-color : #A0A5A8 #414243 #414243 black;
border-width : 2 2 2 0;
}

hal--LogicEvaluatorPingroup[output="false"]
{
border-color : #A0A5A8 black #414243 #A0A5A8;
border-width : 2 0 2 2;
}

hal--LogicEvaluatorValue
{
min-width : 48;
max-width : 48;
min-height : 28;
max-height : 28;
}

hal--LogicEvaluatorValue QSpinBox
{
color : #CBD2D0;
font-family : "Iosevka";
font-style : normal;
background-color : rgb(28, 28, 29);
border : none;
}

hal--LogicEvaluatorValue QSpinBox::up-button
{
color : #CBD2D0;
background-color : #505152;
border-style : solid;
border-color : #808182 #313233 #313233 #808182;
border-width : 1;
}

hal--LogicEvaluatorValue QSpinBox::down-button
{
color : #CBD2D0;
background-color : #505152;
border-style : solid;
border-color : #808182 #313233 #313233 #808182;
border-width : 1;
}

/*
hal--LogicEvaluatorValue QSpinBox::up-arrow
{
color : #CBD2D0;
background-color : rgb(128, 28, 29);
}

hal--LogicEvaluatorValue QSpinBox::down-arrow
{
color : #CBD2D0;
background-color : rgb(28, 28, 128);
}
*/

hal--LogicEvaluatorValue QLabel
{
color : #CBD2D0;
font-family : "Iosevka";
font-style : normal;
background-color : rgb(28, 28, 29);
border : none;
}

hal--LogicEvaluatorPingroup > QLabel
{
color : white;
font-family : "Iosevka";
font-style : bold;
border : none;
background-color : none;
max-height : 28;
}

hal--LogicEvaluatorPingroup QCheckBox
{
font : bold "Iosevka";
color : white;
background : black;
padding-top : 4px;
padding-bottom : 4px;
padding-left : 8px;
padding-right : 8px;
min-width : 250px;
}

hal--LogicEvaluatorPingroup QCheckBox::indicator:checked
{
background : rgb(255,0,0);
border : 1px solid black;
}

hal--LogicEvaluatorPingroup QCheckBox::indicator:unchecked
{
background : rgb(0,170,255);
border : 1px solid black;
}

hal--LogicEvaluatorDialog > QTreeView
{
border-style : solid;
border-color : #A0A5A8 black #414243 black;
border-width : 2 2 2 2;
background : black;
min-width : 400px;
}

hal--LogicEvaluatorSelectGates
{
qproperty-selForeground : #FFE8A0;
qproperty-selBackground : #102030;
min-width : 400px;
}
12 changes: 12 additions & 0 deletions plugins/gui/src/main_window/plugin_parameter_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ namespace hal {
mWidgetMap[parTagname] = floatBox;
break;
}
case PluginParameter::Label:
{
QLabel* label = new QLabel(this);
label->setText(parDefault);
mWidgetMap[parTagname] = label;
break;
}
case PluginParameter::String:
{
QLineEdit* ledit = new QLineEdit(this);
Expand Down Expand Up @@ -247,6 +254,11 @@ namespace hal {
par.set_value(QString::number(floatBox->value()).toStdString());
break;
}
case PluginParameter::Label:
{
par.set_value(std::string());
break;
}
case PluginParameter::String:
{
const QLineEdit* ledit = static_cast<const QLineEdit*>(w);
Expand Down
41 changes: 41 additions & 0 deletions plugins/gui/src/module_model/module_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,47 @@ namespace hal
endResetModel();
}

void ModuleModel::populateFromGatelist(const std::vector<Gate *> &gates)
{
setIsModifying(true);
beginResetModel();
clear();

QMap<Module*,ModuleItem*> parentMap;
for (const Gate* g : gates)
{
Module* parentModule = g->get_module();
ModuleItem* parentItem;
bool insertToRoot = true;
ModuleItem* childItem = new ModuleItem(g->get_id(), ModuleItem::TreeItemType::Gate);

while (parentModule && insertToRoot)
{
parentItem = parentMap.value(parentModule);
if (!parentItem)
{
parentItem = new ModuleItem(parentModule->get_id(), ModuleItem::TreeItemType::Module);
parentMap.insert(parentModule, parentItem);
}
else
{
insertToRoot = false;
}
parentItem->appendChild(childItem);
parentModule = parentModule->get_parent_module();
childItem = parentItem;
}

if (insertToRoot)
{
mRootItem->appendChild(parentItem);
}
}

setIsModifying(false);
endResetModel();
}

void ModuleModel::populateTree(const QVector<u32>& modIds, const QVector<u32>& gateIds, const QVector<u32>& netIds)
{
setIsModifying(true);
Expand Down
2 changes: 2 additions & 0 deletions plugins/gui_extension_demo/python/python_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ namespace hal
.value("ComboBox", PluginParameter::ComboBox, R"(Combo box to select string from semicolon separated input list.)")
.value("Dictionary", PluginParameter::Dictionary, R"(Key value pairs (string).)")
.value("ExistingDir", PluginParameter::ExistingDir, R"(Existing directory.)")
.value("ExistingFile",PluginParameter::ExistingFile,R"(Existing file.)")
.value("Float", PluginParameter::Float, R"(Floating point number.)")
.value("Gate", PluginParameter::Gate, R"(Gate ID.)")
.value("Integer", PluginParameter::Integer, R"(Integer number.)")
.value("Module", PluginParameter::Gate, R"(Module ID.)")
.value("NewFile", PluginParameter::NewFile, R"(New file name.)")
.value("PushButton", PluginParameter::PushButton, R"(Push Button.)")
.value("Label", PluginParameter::Label, R"(Text Label.)")
.value("String", PluginParameter::String, R"(String value.)")
.value("TabName", PluginParameter::TabName, R"(Tab name for structuring other elements.)")
.export_values();
Expand Down
24 changes: 24 additions & 0 deletions plugins/logic_evaluator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
option(PL_LOGIC_EVALUATOR "PL_LOGIC_EVALUATOR" ON)
if(PL_LOGIC_EVALUATOR OR BUILD_ALL_PLUGINS)

find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)

if(Qt5Core_FOUND)
message(VERBOSE "Qt5Core_INCLUDE_DIRS: ${Qt5Core_INCLUDE_DIRS}")
elseif(NOT Qt5Core_FOUND)
message(STATUS "Qt5Core not found for logic_evaluator")
endif(Qt5Core_FOUND)


file(GLOB_RECURSE LOGIC_EVALUATOR_INC ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
file(GLOB_RECURSE LOGIC_EVALUATOR_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE LOGIC_EVALUATOR_PYTHON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/python/*.cpp)
qt5_wrap_cpp(MOC_HDR ${LOGIC_EVALUATOR_INC})

hal_add_plugin(logic_evaluator
SHARED
HEADER ${LOGIC_EVALUATOR_INC}
SOURCES ${LOGIC_EVALUATOR_SRC} ${LOGIC_EVALUATOR_PYTHON_SRC} ${MOC_HDR}
LINK_LIBRARIES PUBLIC gui netlist_simulator_controller Qt5::Core Qt5::Gui Qt5::Widgets)

endif()
Loading

0 comments on commit 5a59c30

Please sign in to comment.