From 5c6f103f823968d6a5fbf86eb0c28a5039e84c58 Mon Sep 17 00:00:00 2001 From: joern274 Date: Sat, 9 Mar 2024 11:27:09 +0100 Subject: [PATCH] Added frames for lut and state --- .../gatelibrary_frames/gatelibrary_frame_ff.h | 5 -- .../gatelibrary_frame_init.h | 4 -- .../gatelibrary_frame_lut.h | 50 ++++++++++++++++++ .../gatelibrary_frame_state.h | 51 +++++++++++++++++++ .../gatelibrary_tab_general.h | 8 ++- .../gatelibrary_frame_ff.cpp | 18 ------- .../gatelibrary_frame_lut.cpp | 31 +++++++++++ .../gatelibrary_frame_state.cpp | 35 +++++++++++++ .../gatelibrary_tab_general.cpp | 19 +++++-- 9 files changed, 189 insertions(+), 32 deletions(-) create mode 100644 plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_lut.h create mode 100644 plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_state.h create mode 100644 plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_lut.cpp create mode 100644 plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_state.cpp diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.h index e4239a08e8d..07d5de5fa27 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.h @@ -49,15 +49,10 @@ namespace hal void update(GateType* gt) override; private: - - QFormLayout* mFormLayout; - GateLibraryLabel* mClockProperty; GateLibraryLabel* mNextStateProperty; GateLibraryLabel* mAsynchronousResetProperty; GateLibraryLabel* mAsynchronousSetProperty; - GateLibraryLabel* mInternalStateProperty; - GateLibraryLabel* mNegatedInternalStateProperty; GateLibraryLabel* mInternalStateOnReset; GateLibraryLabel* mNegatedInternalStateOnReset; diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_init.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_init.h index 1a00e37586d..870327349cb 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_init.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_init.h @@ -42,10 +42,6 @@ namespace hal void update(GateType* gt) override; private: - QFormLayout* mFormLayout; - QString mCategory; - QStringList mIdentifiers; - QLabel* mCategoryLabel; QLabel* mIdentifiersLabel; }; diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_lut.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_lut.h new file mode 100644 index 00000000000..a967a0acf6e --- /dev/null +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_lut.h @@ -0,0 +1,50 @@ +// 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 "gui/gatelibrary_management/gatelibrary_frames/gatelibrary_component_frame.h" + +#include +#include + +namespace hal +{ + class GatelibraryFrameLut : public GatelibraryComponentFrame + { + Q_OBJECT + + public: + GatelibraryFrameLut(QWidget* parent = nullptr); + + void update(GateType* gt) override; + + private: + QLabel* mAscending; + }; + +} + + diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_state.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_state.h new file mode 100644 index 00000000000..bb3dc925fe7 --- /dev/null +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_state.h @@ -0,0 +1,51 @@ +// 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 "gui/gatelibrary_management/gatelibrary_frames/gatelibrary_component_frame.h" + +#include +#include + +namespace hal +{ + class GatelibraryFrameState : public GatelibraryComponentFrame + { + Q_OBJECT + + public: + GatelibraryFrameState(QWidget* parent = nullptr); + + void update(GateType* gt) override; + + private: + QLabel* mStateIdentifier; + QLabel* mNegStateIdentifier; + }; + +} + + diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h index a6ec83b1f06..53609f5253e 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h @@ -38,6 +38,8 @@ namespace hal class GateLibraryLabel; class GatelibraryFrameFF; class GatelibraryFrameInit; + class GatelibraryFrameState; + class GatelibraryFrameLut; class GatelibraryFrameGeneral : public GatelibraryComponentFrame { @@ -76,9 +78,11 @@ namespace hal private: GatelibraryFrameGeneral* mGeneralFrame; + GatelibraryFrameFF* mFlipflopFrame; + GatelibraryFrameState* mStateFrame; + GatelibraryFrameLut* mLutFrame; + GatelibraryFrameInit* mInitFrame; GatelibraryFrameBoolean* mBooleanFrame; - GatelibraryFrameFF* mFlipflopFrame; - GatelibraryFrameInit* mInitFrame; }; } diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.cpp index 64ab0bf66ff..13a26a5beb9 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.cpp @@ -13,8 +13,6 @@ namespace hal mNextStateProperty = new GateLibraryLabel(true, " - ", this); mAsynchronousResetProperty = new GateLibraryLabel(true, " - ", this); mAsynchronousSetProperty = new GateLibraryLabel(true, " - ", this); - mInternalStateProperty = new GateLibraryLabel(true, " - ", this); - mNegatedInternalStateProperty = new GateLibraryLabel(true, " - ", this); mInternalStateOnReset = new GateLibraryLabel(true, " - ", this); mNegatedInternalStateOnReset = new GateLibraryLabel(true, " - ", this); @@ -22,8 +20,6 @@ namespace hal mLayout->addRow(new GateLibraryLabel(false, "Next state:", parent), mNextStateProperty); mLayout->addRow(new GateLibraryLabel(false, "Asynchronous reset:", parent), mAsynchronousResetProperty); mLayout->addRow(new GateLibraryLabel(false, "Asynchronous set:", parent), mAsynchronousSetProperty); - mLayout->addRow(new GateLibraryLabel(false, "Internal state:", parent), mInternalStateProperty); - mLayout->addRow(new GateLibraryLabel(false, "Negated internal state:", parent), mNegatedInternalStateProperty); mLayout->addRow(new GateLibraryLabel(false, "Set+Reset -> internal state:", parent), mInternalStateOnReset); mLayout->addRow(new GateLibraryLabel(false, "Set+Reset -> neg. int. state:", parent), mNegatedInternalStateOnReset); } @@ -61,20 +57,6 @@ namespace hal mAsynchronousSetProperty->setValue(true); } - mInternalStateProperty->setText(QString::fromStdString(gt->get_boolean_function().to_string())); - - Result result = BooleanFunction::Not(gt->get_boolean_function(), gt->get_boolean_function().size()); - if(result.is_ok()) - { - mNegatedInternalStateProperty->setText(QString::fromStdString(result.get().to_string())); - mNegatedInternalStateProperty->setValue(true); - } - else - { - mNegatedInternalStateProperty->setText("ERROR"); - mNegatedInternalStateProperty->setValue(false); - } - auto [stateBeh,negStateBeh] = ff->get_async_set_reset_behavior(); if (stateBeh == AsyncSetResetBehavior::undef) { diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_lut.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_lut.cpp new file mode 100644 index 00000000000..b62d71fc1d4 --- /dev/null +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_lut.cpp @@ -0,0 +1,31 @@ +#include "gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_lut.h" +#include "gui/gatelibrary_management/gatelibrary_label.h" +#include "hal_core/netlist/gate_library/gate_type_component/lut_component.h" + +namespace hal +{ + GatelibraryFrameLut::GatelibraryFrameLut(QWidget* parent) + : GatelibraryComponentFrame("LUT Init", parent) + { + mAscending = new GateLibraryLabel(true, " - ", this); + + mLayout->addRow(new GateLibraryLabel(false, "Bit Order:", parent), mAscending); + } + + void GatelibraryFrameLut::update(GateType* gt) + { + if(gt->has_component_of_type(GateTypeComponent::ComponentType::init)) + { + auto lutc = gt->get_component_as([](const GateTypeComponent* c) { return LUTComponent::is_class_of(c); }); + + if(lutc != nullptr) + { + mAscending->setText(QString::fromStdString(lutc->is_init_ascending() ? "Ascending" : "Descending")); + show(); + } + else hide(); + } + else hide(); + } +} + diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_state.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_state.cpp new file mode 100644 index 00000000000..e343cd58c18 --- /dev/null +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_state.cpp @@ -0,0 +1,35 @@ +#include "gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_state.h" +#include "gui/gatelibrary_management/gatelibrary_label.h" +#include "hal_core/netlist/gate_library/gate_type_component/state_component.h" + +namespace hal +{ + GatelibraryFrameState::GatelibraryFrameState(QWidget* parent) + : GatelibraryComponentFrame("Internal States", parent) + { + mStateIdentifier = new GateLibraryLabel(true, " - ", this); + mNegStateIdentifier = new GateLibraryLabel(true, " - ", this); + + mLayout->addRow(new GateLibraryLabel(false, "State identifier:", parent), mStateIdentifier); + mLayout->addRow(new GateLibraryLabel(false, "Neg. state identifier:", parent), mNegStateIdentifier); + + } + + void GatelibraryFrameState::update(GateType* gt) + { + if(gt->has_component_of_type(GateTypeComponent::ComponentType::state)) + { + auto stat = gt->get_component_as([](const GateTypeComponent* c) { return StateComponent::is_class_of(c); }); + + if(stat != nullptr) + { + mStateIdentifier->setText(QString::fromStdString(stat->get_state_identifier())); + mNegStateIdentifier->setText(QString::fromStdString(stat->get_neg_state_identifier())); + show(); + } + else hide(); + } + else hide(); + } +} + diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.cpp index 42088d68d57..e9a51d9a170 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.cpp @@ -1,7 +1,8 @@ #include "gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h" #include "gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.h" - +#include "gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_state.h" +#include "gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_lut.h" #include "gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_init.h" #include "gui/gatelibrary_management/gatelibrary_label.h" @@ -101,6 +102,14 @@ namespace hal layout->addWidget(mFlipflopFrame); mFlipflopFrame->hide(); + mStateFrame = new GatelibraryFrameState(this); + layout->addWidget(mStateFrame); + mStateFrame->hide(); + + mLutFrame = new GatelibraryFrameLut(this); + layout->addWidget(mLutFrame); + mLutFrame->hide(); + mInitFrame = new GatelibraryFrameInit(this); layout->addWidget(mInitFrame); mInitFrame->hide(); @@ -118,13 +127,17 @@ namespace hal if(!gt){ //TODO make default look mFlipflopFrame->hide(); - mBooleanFrame->hide(); + mStateFrame->hide(); + mLutFrame->hide(); mInitFrame->hide(); + mBooleanFrame->hide(); return; } mFlipflopFrame->update(gt); - mBooleanFrame->update(gt); + mStateFrame->update(gt); + mLutFrame->update(gt); mInitFrame->update(gt); + mBooleanFrame->update(gt); } }