Skip to content

Commit

Permalink
somewhat working version
Browse files Browse the repository at this point in the history
  • Loading branch information
oleeng committed Apr 26, 2024
1 parent a28819c commit e704fa8
Show file tree
Hide file tree
Showing 13 changed files with 343 additions and 17 deletions.
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, Float, Gate, Integer, Module, NewFile, PushButton, String, TabName };
enum ParameterType { Absent, Boolean, Color, ComboBox, Dictionary, ExistingDir, ExistingFile, Float, Gate, Integer, 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 @@ -40,5 +40,7 @@
!z3_utils/**/*
!netlist_modifier*
!netlist_modifier/**/*
!netlist_simulator_study*
!netlist_simulator_study/**/*
!CMakeLists.txt
!.gitignore
25 changes: 19 additions & 6 deletions plugins/gui/src/main_window/plugin_parameter_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ namespace hal {
break;
}
case PluginParameter::ExistingDir:
case PluginParameter::ExistingFile:
case PluginParameter::NewFile:
mWidgetMap[parTagname] = new PluginParameterFileDialog(par,this);
break;
Expand Down Expand Up @@ -253,6 +254,7 @@ namespace hal {
break;
}
case PluginParameter::ExistingDir:
case PluginParameter::ExistingFile:
case PluginParameter::NewFile:
{
const PluginParameterFileDialog* fileDlg = static_cast<const PluginParameterFileDialog*>(w);
Expand Down Expand Up @@ -314,9 +316,9 @@ namespace hal {
mEditor->setText(parDefault);
layout->addWidget(mEditor,0,0);

QString iconPath = (mParameter.get_type() == PluginParameter::ExistingDir)
? ":/icons/folder"
: ":/icons/folder-down";
QString iconPath = (mParameter.get_type() == PluginParameter::NewFile)
? ":/icons/folder-down"
: ":/icons/folder";
mButton = new QPushButton(gui_utility::getStyledSvgIcon("all->#3192C5",iconPath),"",this);
mButton->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Preferred);
connect(mButton,&QPushButton::clicked,this,&PluginParameterFileDialog::handleActivateFileDialog);
Expand All @@ -328,9 +330,20 @@ namespace hal {
QString parLabel = QString::fromStdString(mParameter.get_label());
QString parDefault = QString::fromStdString(mParameter.get_value());
QString dir = QFileInfo(parDefault).isDir() ? parDefault : QFileInfo(parDefault).path();
QString filename = (mParameter.get_type() == PluginParameter::ExistingDir)
? QFileDialog::getExistingDirectory(this,parLabel,dir)
: QFileDialog::getSaveFileName(this,parLabel,dir);
QString filename;
switch (mParameter.get_type()) {
case PluginParameter::ExistingDir:
filename = QFileDialog::getExistingDirectory(this,parLabel,dir);
break;
case PluginParameter::ExistingFile:
filename = QFileDialog::getOpenFileName(this,parLabel,dir);
break;
case PluginParameter::NewFile:
filename = QFileDialog::getSaveFileName(this,parLabel,dir);
break;
default:
Q_ASSERT (1==0); // should never happen
}
if (!filename.isEmpty())
mEditor->setText(filename);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
#pragma once
#include "hal_core/defines.h"
#include "hal_core/plugin_system/plugin_interface_base.h"
#include "hal_core/plugin_system/gui_extension_interface.h"
#include "hal_core/utilities/result.h"
#include "hal_core/netlist/netlist.h"

namespace hal
{
class GuiExtensionNetlistModifier;

class PLUGIN_API NetlistModifierPlugin : public BasePluginInterface
{
GuiExtensionNetlistModifier* m_gui_extension;

public:
std::string get_name() const override;
std::string get_version() const override;
void initialize() override;

NetlistModifierPlugin(){};
void on_load() override;
void on_unload() override;

std::set<std::string> get_dependencies() const override;

NetlistModifierPlugin();

bool create_modified_netlist();

Netlist* modified_netlist_pointer = nullptr;
static Netlist* modified_netlist_pointer;
private:

bool replace_gates();
};



class GuiExtensionNetlistModifier : public GuiExtensionInterface
{
std::vector<PluginParameter> m_parameter;

public:
NetlistModifierPlugin* m_parent;

GuiExtensionNetlistModifier();

std::vector<PluginParameter> get_parameter() const override;

void set_parameter(const std::vector<PluginParameter>& params) override;

};
} // namespace hal
83 changes: 76 additions & 7 deletions plugins/netlist_modifier/src/netlist_modifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ namespace hal

extern Netlist* gNetlist;

Netlist* NetlistModifierPlugin::modified_netlist_pointer = nullptr;

extern std::unique_ptr<BasePluginInterface> create_plugin_instance()
{
return std::make_unique<NetlistModifierPlugin>();
}

NetlistModifierPlugin::NetlistModifierPlugin(){
m_gui_extension = nullptr;
}

std::string NetlistModifierPlugin::get_name() const
{
return std::string("netlist-modifier");
Expand All @@ -29,18 +35,38 @@ namespace hal
return std::string("0.1");
}

void NetlistModifierPlugin::on_load()
{
m_gui_extension = new GuiExtensionNetlistModifier;
m_gui_extension->m_parent = this;
m_extensions.push_back(m_gui_extension);
}

void NetlistModifierPlugin::on_unload()
{
delete_extension(m_gui_extension);
}

std::set<std::string> NetlistModifierPlugin::get_dependencies() const
{
std::set<std::string> retval;
retval.insert("hal_gui");
retval.insert("verilog_writer");
return retval;
}

void NetlistModifierPlugin::initialize()
{
}

bool NetlistModifierPlugin::replace_gates(){
auto gates = modified_netlist_pointer->get_gates();
auto gates = NetlistModifierPlugin::modified_netlist_pointer->get_gates();

for(Gate* gate: gates){
// std::cout << gate->get_type()->to_string() << std::endl;

if(gate->get_type()->to_string() == "AND"){
GateType* new_gate_type = modified_netlist_pointer->get_gate_library()->get_gate_type_by_name("OR");
GateType* new_gate_type = NetlistModifierPlugin::modified_netlist_pointer->get_gate_library()->get_gate_type_by_name("UNKNOWN_2IN");
std::string gate_name = gate->get_name();
u32 gate_id = gate->get_id();

Expand All @@ -56,9 +82,9 @@ namespace hal
successors[endpoint->get_pin()->get_name()] = endpoint->get_net();
}

modified_netlist_pointer->delete_gate(gate);
NetlistModifierPlugin::modified_netlist_pointer->delete_gate(gate);

Gate* new_gate = modified_netlist_pointer->create_gate(gate_id, new_gate_type, gate_name);
Gate* new_gate = NetlistModifierPlugin::modified_netlist_pointer->create_gate(gate_id, new_gate_type, gate_name);

for(auto entry: predecessors){
entry.second->add_destination(new_gate, entry.first);
Expand All @@ -74,20 +100,63 @@ namespace hal
}

bool NetlistModifierPlugin::create_modified_netlist(){
std::cout << gNetlist->get_gates().size() << std::endl;

auto tmp = gNetlist->copy();
modified_netlist_pointer = tmp.get().get();
NetlistModifierPlugin::modified_netlist_pointer = std::move(tmp.get().get());


replace_gates();

replace_gates();

// no writer for .v ????
// netlist_writer_manager::write(modified_netlist_pointer, "~/Documents/MPI/hal_project_for_testing/modified_netlist_pointer.v");
netlist_writer_manager::write(modified_netlist_pointer, "/home/ole/Documents/MPI/hal_project_for_testing/modified_netlist_pointer.v");

// gNetlist = modified_netlist_pointer;
// crashes when executed
// gNetlist = (NetlistModifierPlugin::modified_netlist_pointer->copy()).get().get();

// std::cout << gNetlist->get_gates().size() << std::endl;

return true;
}













GuiExtensionNetlistModifier::GuiExtensionNetlistModifier()
{
m_parameter.push_back(PluginParameter(PluginParameter::PushButton,"modify","Modify and save"));
}

std::vector<PluginParameter> GuiExtensionNetlistModifier::get_parameter() const
{
return m_parameter;
}

void GuiExtensionNetlistModifier::set_parameter(const std::vector<PluginParameter>& params)
{
m_parameter = params;
bool modify_save = false;
for (PluginParameter par : m_parameter)
{
if(par.get_tagname()=="modify" && par.get_value() == "clicked")
modify_save = true;
}
if (modify_save && m_parent )
{
m_parent->create_modified_netlist();
}
}


} // namespace hal
15 changes: 15 additions & 0 deletions plugins/netlist_simulator_study/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
option(PL_NETLIST_SIMULATOR_STUDY "PL_NETLIST_SIMULATOR_STUDY" OFF)

if(PL_NETLIST_SIMULATOR_STUDY OR BUILD_ALL_PLUGINS)
file(GLOB_RECURSE NETLIST_SIMULATOR_STUDY_INC ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
file(GLOB_RECURSE NETLIST_SIMULATOR_STUDY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE NETLIST_SIMULATOR_STUDY_PYTHON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/python/*.cpp)

hal_add_plugin(netlist_simulator_study
SHARED
HEADER ${NETLIST_SIMULATOR_STUDY_INC}
SOURCES ${NETLIST_SIMULATOR_STUDY_SRC} ${NETLIST_SIMULATOR_STUDY_PYTHON_SRC}
LINK_LIBRARIES PUBLIC gui netlist_simulator_controller
PYDOC SPHINX_DOC_INDEX_FILE ${CMAKE_CURRENT_SOURCE_DIR}/documentation/netlist_simulator_study.rst
)
endif()
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#include "hal_core/plugin_system/plugin_interface_base.h"
#include "hal_core/plugin_system/gui_extension_interface.h"


namespace hal
{
class NetlistSimulatorController;
class GuiExtensionNetlistSimulatorStudy;

class PLUGIN_API NetlistSimulatorStudyPlugin : public BasePluginInterface
{
GuiExtensionNetlistSimulatorStudy* m_gui_extension;
std::unique_ptr<NetlistSimulatorController> m_simul_controller;
public:
std::unique_ptr<Netlist> m_original_netlist;
NetlistSimulatorStudyPlugin();

std::string get_name() const override;
std::string get_version() const override;

void on_load() override;
void on_unload() override;

/**
* Returns plugin dependencies (GUI, simulation controller, verilator, waveform viewer)
*/
std::set<std::string> get_dependencies() const override;

bool simulate(std::filesystem::path sim_input);

};

class GuiExtensionNetlistSimulatorStudy : public GuiExtensionInterface
{
std::vector<PluginParameter> m_parameter;

public:
NetlistSimulatorStudyPlugin* m_parent;

GuiExtensionNetlistSimulatorStudy();

std::vector<PluginParameter> get_parameter() const override;

void set_parameter(const std::vector<PluginParameter>& params) override;

};
} // namespace hal
Loading

0 comments on commit e704fa8

Please sign in to comment.