HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
plugin_logic_evaluator.cpp
Go to the documentation of this file.
2 
4 #include "gui/gui_api/gui_api.h"
5 #include "gui/gui_globals.h"
10 
11 #include <QDebug>
12 
13 namespace hal
14 {
16  {
18  }
19 
20  extern std::unique_ptr<BasePluginInterface> create_plugin_instance()
21  {
22  return std::make_unique<LogicEvaluatorPlugin>();
23  }
24 
25  std::string LogicEvaluatorPlugin::get_name() const
26  {
27  return std::string("waveform_viewer");
28  }
29 
31  {
32  return std::string("0.7");
33  }
34 
36  {
37  return std::string("GUI to control simulation and view resulting waveforms");
38  }
39 
40  std::set<std::string> LogicEvaluatorPlugin::get_dependencies() const
41  {
42  std::set<std::string> retval;
43  retval.insert("netlist_simulator_controller");
44  retval.insert("hal_gui");
45  return retval;
46  }
47 
49  {
50  qRegisterMetaType<std::string>();
52  }
53 
55  {
56  }
57 
58  //---------------------------------------
59 
60  std::vector<PluginParameter> GuiExtensionLogicEvaluator::get_parameter() const
61  {
62  std::vector<PluginParameter> retval;
63  retval.push_back(PluginParameter(PluginParameter::Label,
64  "help",
65  "",
66  "Press 'Launch' to launch logic evaluator\n"
67  "with the gates that are currently selected.\n\n"
68  "Per default boolean logic gets compiled and\n"
69  "evaluated by compiled binary code. If 'skip' is\n"
70  "checked the compile step gets omitted and the\n"
71  "build-in BooleanFunction class does the evaluation."));
72  retval.push_back(PluginParameter(PluginParameter::Boolean, "skip", "Skip compilation", "false"));
73  retval.push_back(PluginParameter(PluginParameter::PushButton, "exec", "Launch"));
74  return retval;
75  }
76 
77  void GuiExtensionLogicEvaluator::set_parameter(const std::vector<PluginParameter>& params)
78  {
79  for (const PluginParameter& pp : params)
80  {
81  // will launch by execute_function after parameter are set
82  // if (pp.get_tagname() == "exec" && pp.get_value() == "clicked")
83  if (pp.get_tagname() == "skip")
84  {
85  mSkipCompile = (pp.get_value() == "true");
86  }
87  }
88  }
89 
91  {
92  const GateType* gt = g->get_type();
94  {
95  return false;
96  }
98  {
99  return false;
100  }
102  {
103  return false;
104  }
105  return true;
106  }
107 
108  std::vector<ContextMenuContribution>
109  GuiExtensionLogicEvaluator::get_context_contribution(const Netlist* nl, const std::vector<u32>& mods, const std::vector<u32>& gats, const std::vector<u32>& nets)
110  {
111  std::vector<ContextMenuContribution> retval;
112  if (nl && (!mods.empty() || !gats.empty()))
113  {
114  retval.push_back({this, "Logic Evaluator", "Launch logic evaluator..."});
115  }
116  return retval;
117  }
118 
119  void GuiExtensionLogicEvaluator::execute_function(std::string tag, Netlist* nl, const std::vector<u32>& mods, const std::vector<u32>& gats, const std::vector<u32>& nets)
120  {
121  if (nl && (!mods.empty() || !gats.empty()))
122  {
123  std::unordered_set<Gate*> gates;
124  for (u32 gatId : gats)
125  {
126  Gate* g = nl->get_gate_by_id(gatId);
127  if (g && acceptGate(g))
128  {
129  gates.insert(g);
130  }
131  }
132  for (u32 modId : mods)
133  {
134  Module* m = nl->get_module_by_id(modId);
135  if (m)
136  {
137  for (Gate* g : m->get_gates(nullptr, true))
138  {
139  if (acceptGate(g))
140  {
141  gates.insert(g);
142  }
143  }
144  }
145  }
146 
147  if (gates.empty())
148  {
149  std::vector<Gate*> emptyList;
150  LogicEvaluatorSelectGates lesg(emptyList);
151  lesg.exec();
152  return;
153  }
154 
155  std::vector<Gate*> vgates(gates.begin(), gates.end());
156  LogicEvaluatorDialog* led = new LogicEvaluatorDialog(vgates, false);
157  led->show();
158  led->raise();
159  }
160  }
161 
162 } // namespace hal
std::vector< AbstractExtensionInterface * > m_extensions
Definition: gate.h:58
GateType * get_type() const
Definition: gate.cpp:125
bool has_property(GateTypeProperty property) const
Definition: gate_type.cpp:101
virtual void execute_function(std::string tag, Netlist *nl, const std::vector< u32 > &mods, const std::vector< u32 > &gats, const std::vector< u32 > &nets) override
virtual std::vector< ContextMenuContribution > get_context_contribution(const Netlist *nl, const std::vector< u32 > &mods, const std::vector< u32 > &gats, const std::vector< u32 > &nets) override
std::vector< PluginParameter > get_parameter() const override
Get a vector of configurable parameters.
static bool acceptGate(const Gate *g)
void set_parameter(const std::vector< PluginParameter > &params) override
Set values for a vector of configurable parameters.
std::shared_ptr< spdlog::logger > add_channel(const std::string &channel_name, const std::vector< std::shared_ptr< log_sink >> &sinks, const std::string &level="info")
Definition: log.cpp:100
static std::shared_ptr< log_sink > create_gui_sink()
Definition: log.cpp:274
static std::shared_ptr< log_sink > create_file_sink(const std::filesystem::path &file_name="", const bool truncate=false)
Definition: log.cpp:247
static std::shared_ptr< log_sink > create_stdout_sink(const bool colored=true)
Definition: log.cpp:216
static LogManager * get_instance(const std::filesystem::path &file_name="")
Definition: log.cpp:61
std::set< std::string > get_dependencies() const override
std::string get_version() const override
std::string get_description() const override
std::string get_name() const override
const std::vector< Gate * > & get_gates() const
Definition: module.cpp:393
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
Module * get_module_by_id(u32 module_id) const
Definition: netlist.cpp:613
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45
std::unique_ptr< BasePluginInterface > create_plugin_instance()
virtual int exec()
void raise()
void show()