HAL  v4.5.0-254-g8f9f6a423
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
py_code_provider.cpp
Go to the documentation of this file.
2 
3 //------
9 #include "gui/gui_globals.h"
10 
11 namespace hal
12 {
13  const QString PyCodeProvider::gateCodePrefix = "netlist.get_gate_by_id(%1)";
14  const QString PyCodeProvider::netCodePrefix = "netlist.get_net_by_id(%1)";
15  const QString PyCodeProvider::moduleCodePrefix = "netlist.get_module_by_id(%1)";
16  const QString PyCodeProvider::groupingCodePrefix = "netlist.get_grouping_by_id(%1)";
17 
18  QString PyCodeProvider::buildPyCode(const QString& prefix, const QString& suffix, u32 id)
19  {
20  return QString(prefix + "." + suffix).arg(id);
21  }
22 
24  {
25  return gateCodePrefix.arg(gateId);
26  }
27 
29  {
30  const QString suffix = "get_id()";
31 
32  return buildPyCode(gateCodePrefix, suffix, gateId);
33  }
34 
36  {
37  const QString suffix = "get_name()";
38 
39  return buildPyCode(gateCodePrefix, suffix, gateId);
40  }
41 
43  {
44  const QString suffix = "get_type()";
45 
46  return buildPyCode(gateCodePrefix, suffix, gateId);
47  }
48 
50  {
51  return pyCodeGateType(gateId) + QString(".get_pin_by_name(\"%1\")").arg(pin);
52  }
53 
55  {
56  return pyCodeGateTypePinByName(gateId, pin) + QString(".get_direction()");
57  }
58 
60  {
61  return pyCodeGateTypePinByName(gateId, pin) + QString(".get_type()");
62  }
63 
65  {
66  const QString suffix = ".get_input_pins()";
67 
68  return pyCodeGateType(gateId) + suffix;
69  }
70 
72  {
73  const QString suffix = ".get_output_pins()";
74 
75  return pyCodeGateType(gateId) + suffix;
76  }
77 
79  {
80  const QString suffix = QString("get_boolean_function(\"%1\")").arg(booleanFunctionName);
81 
82  return buildPyCode(gateCodePrefix, suffix, gateId);
83  }
84 
86  {
87  //logic (ff/latch check) can also be done beforehand to remove any logic from
88  //this class, but could "blow up" the code if many other places need to call this function
89 
90  GateType* gt = gNetlist->get_gate_by_id(gateId)->get_type();
91  QString pyString = pyCodeGateType(gateId) + ".get_component(filter = lambda f: hal_py.%1.is_class_of(f)).get_async_set_reset_behavior()";
92 
93  if(FFComponent* ff_component = gt->get_component_as<FFComponent>([](const GateTypeComponent* c) { return FFComponent::is_class_of(c); }); ff_component != nullptr)
94  pyString = pyString.arg("FFComponent");
95  else if(LatchComponent* latch_component = gt->get_component_as<LatchComponent>([](const GateTypeComponent* c) { return LatchComponent::is_class_of(c); }); latch_component != nullptr)
96  pyString = pyString.arg("LatchComponent");
97  else
98  pyString = "";
99 
100  return pyString;
101  }
102 
104  {
105  const QString suffix = QString("get_data_map()");
106  return buildPyCode(gateCodePrefix, suffix, gateId);
107  }
108 
110  {
111  return pyCodeGateType(gateId) + ".get_component(filter = hal_py.StateComponent.is_class_of)";
112  }
113 
115  {
116  return pyCodeStateComp(gateId) + ".get_state_identifier()";
117  }
118 
120  {
121  return pyCodeStateComp(gateId) + ".get_neg_state_identifier()";
122  }
123 
125  {
126  return pyCodeGateType(gateId) + ".get_component(filter = hal_py.FFComponent.is_class_of)";
127  }
128 
130  {
131  return pyCodeFFComp(gateId) + ".get_clock_function()";
132  }
133 
135  {
136  return pyCodeFFComp(gateId) + ".get_next_state_function()";
137  }
138 
140  {
141  return pyCodeFFComp(gateId) + ".get_async_set_function()";
142  }
143 
145  {
146  return pyCodeFFComp(gateId) + ".get_async_reset_function()";
147  }
148 
150  {
151  return pyCodeFFComp(gateId) + ".get_async_set_reset_behavior()";
152  }
153 
155  {
156  return pyCodeGateType(gateId) + ".get_component(filter = hal_py.LatchComponent.is_class_of)";
157  }
158 
160  {
161  return pyCodeLatchComp(gateId) + ".get_enable_function()";
162  }
163 
165  {
166  return pyCodeLatchComp(gateId) + ".get_data_in_function()";
167  }
168 
170  {
171  return pyCodeLatchComp(gateId) + ".get_async_set_function()";
172  }
173 
175  {
176  return pyCodeLatchComp(gateId) + ".get_async_reset_function()";
177  }
178 
180  {
181  return pyCodeLatchComp(gateId) + ".get_async_set_reset_behavior()";
182  }
183 
185  {
186  const QString suffix = "get_type().get_properties()";
187 
188  return buildPyCode(gateCodePrefix, suffix, gateId);
189  }
190 
192  {
193  const QString suffix = "get_location()";
194 
195  return buildPyCode(gateCodePrefix, suffix, gateId);
196  }
197 
199  {
200  const QString suffix = "get_module()";
201 
202  return buildPyCode(gateCodePrefix, suffix, gateId);
203  }
204 
206  {
207  const QString suffix = QString("data[(\"%1\", \"%2\")]").arg(category, key);
208 
209  return buildPyCode(gateCodePrefix, suffix, gateId);
210  }
211 
213  {
214  const QString suffix = QString("get_parameter_value(\"%1\")").arg(name);
215 
216  return buildPyCode(gateCodePrefix, suffix, gateId);
217  }
218 
220  {
221  return netCodePrefix.arg(netId);
222  }
223 
225  {
226  const QString suffix = "get_id()";
227 
228  return buildPyCode(netCodePrefix, suffix, netId);
229  }
230 
232  {
233  const QString suffix = "get_name()";
234 
235  return buildPyCode(netCodePrefix, suffix, netId);
236  }
237 
239  {
240  const QString prefix = QString(netCodePrefix).arg(netId);
241 
242  const QString check1 = prefix + ".is_global_input_net()";
243  const QString check2 = prefix + ".is_global_output_net()";
244  const QString check3 = prefix + ".is_unrouted()";
245 
246  const QString result1 = "\"Global Input\"";
247  const QString result2 = "\"Global Output\"";
248  const QString result3 = "\"Unrouted\"";
249  const QString result4 = "\"Internal\"";
250 
251  const QString pyCode = result1 + " if " + check1 + " else " + result2 + " if " + check2 + " else " + result3 + " if " + check3 + " else " + result4;
252 
253  return pyCode;
254  }
255 
257  {
258  const QString suffix = "get_sources()";
259 
260  return buildPyCode(netCodePrefix, suffix, netId);
261  }
262 
264  {
265  const QString suffix = "get_destinations()";
266 
267  return buildPyCode(netCodePrefix, suffix, netId);
268  }
269 
271  {
272  const QString suffix = QString("data[(\"%1\", \"%2\")]").arg(category, key);
273 
274  return buildPyCode(netCodePrefix, suffix, netId);
275  }
276 
278  {
279  const QString suffix = QString("get_data_map()");
280  return buildPyCode(netCodePrefix, suffix, netId);
281  }
282 
284  {
285  return moduleCodePrefix.arg(moduleId);
286  }
287 
289  {
290  const QString suffix = "get_id()";
291 
292  return buildPyCode(moduleCodePrefix, suffix, moduleId);
293  }
294 
296  {
297  const QString suffix = "get_name()";
298 
299  return buildPyCode(moduleCodePrefix, suffix, moduleId);
300  }
301 
303  {
304  const QString suffix = "get_type()";
305 
306  return buildPyCode(moduleCodePrefix, suffix, moduleId);
307 
308  }
309 
311  {
312  const QString suffix = "get_parent_module()";
313 
314  return buildPyCode(moduleCodePrefix, suffix, moduleId);
315  }
316 
318  {
319  const QString suffix = "get_submodules()";
320 
321  return buildPyCode(moduleCodePrefix, suffix, moduleId);
322  }
323 
324  QString PyCodeProvider::pyCodeModuleGates(u32 moduleId, bool recursively)
325  {
326  QString rec = recursively ? QString("None, True") : QString("");
327  const QString suffix = "get_gates(%2)";
328  return QString(moduleCodePrefix + "." + suffix).arg(QString::number(moduleId), rec);
329  }
330 
332  {
333  const QString suffix = "get_nets()";
334 
335  return buildPyCode(moduleCodePrefix, suffix, moduleId);
336  }
337 
339  {
340  const QString suffix = "get_input_nets()";
341 
342  return buildPyCode(moduleCodePrefix, suffix, moduleId);
343  }
344 
346  {
347  const QString suffix = "get_output_nets()";
348 
349  return buildPyCode(moduleCodePrefix, suffix, moduleId);
350  }
351 
353  {
354  const QString suffix = "get_pins(lambda pin: pin.get_direction() == hal_py.PinDirection.input)";
355 
356  return buildPyCode(moduleCodePrefix, suffix, moduleId);
357  }
358 
360  {
361  const QString suffix = "get_pins(lambda pin: pin.get_direction() == hal_py.PinDirection.output)";
362 
363  return buildPyCode(moduleCodePrefix, suffix, moduleId);
364  }
365 
367  {
368  const QString suffix = "get_internal_nets()";
369 
370  return buildPyCode(moduleCodePrefix, suffix, moduleId);
371  }
372 
374  {
375  const QString suffix = "is_top_module()";
376 
377  return buildPyCode(moduleCodePrefix, suffix, moduleId);
378  }
379 
381  {
382  const QString suffix = QString("data[(\"%1\", \"%2\")]").arg(category, key);
383 
384  return buildPyCode(moduleCodePrefix, suffix, moduleId);
385  }
386 
388  {
389  const QString suffix = QString("get_data_map()");
390  return buildPyCode(moduleCodePrefix, suffix, moduleId);
391  }
392 
394  {
395  const QString suffix = QString("get_pin_group_by_id(%1)").arg(groupId);
396 
397  return buildPyCode(moduleCodePrefix, suffix, moduleId);
398  }
399 
401  {
402  const QString suffix = "get_pin_groups()";
403 
404  return buildPyCode(moduleCodePrefix, suffix, moduleId);
405  }
406 
408  {
409  return pyCodeModulePinGroup(moduleId, groupId) + ".get_name()";
410  }
411 
413  {
414  const QString suffix = QString("get_pin_by_id(%1)").arg(pinId);
415 
416  return buildPyCode(moduleCodePrefix, suffix, moduleId);
417  }
418 
420  {
421  return pyCodeModulePinById(moduleId, pinId) + ".get_name()";
422  }
423 
425  {
426  return pyCodeModulePinById(moduleId, pinId) + ".get_direction()";
427  }
428 
430  {
431  return pyCodeModulePinById(moduleId, pinId) + ".get_type()";
432  }
433 
435  {
436  static QString suffix = "get_pins()";
437 
438  return buildPyCode(moduleCodePrefix, suffix, moduleId);
439  }
440 
442  {
443  return groupingCodePrefix.arg(groupingId);
444  }
445 
447  {
448  const QString suffix = QString("get_name()");
449 
450  return buildPyCode(groupingCodePrefix, suffix, groupingId);
451  }
452 
454  {
455  const QString suffix = QString("get_id()");
456 
457  return buildPyCode(groupingCodePrefix, suffix, groupingId);
458  }
459 
460 } // namespace hal
GateType * get_type() const
Definition: gate.cpp:162
T * get_component_as(const std::function< bool(const GateTypeComponent *)> &filter=nullptr) const
Definition: gate_type.h:89
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:195
static QString pyCodeModulePinDirection(u32 moduleId, u32 pinId)
static QString pyCodeModuleIsTopModule(u32 moduleId)
static QString pyCodeFFComp(u32 gateId)
static QString pyCodeGateLocation(u32 gateId)
static QString pyCodeGateTypePinDirection(u32 gateId, QString pin)
static QString pyCodeNetSources(u32 netId)
static QString pyCodeGrouping(u32 groupingId)
static QString pyCodeStateCompNegState(u32 gateId)
static QString pyCodeModulePinType(u32 moduleId, u32 pinId)
static QString pyCodeModuleType(u32 moduleId)
static QString pyCodeLatchCompAsyncSetFunc(u32 gateId)
static QString pyCodeStateCompPosState(u32 gateId)
static QString pyCodeLatchCompAsyncResetFunc(u32 gateId)
static QString pyCodeGateTypePinByName(u32 gateId, QString pin)
static QString pyCodeGateTypePinType(u32 gateId, QString pin)
static QString pyCodeModuleOutputNets(u32 moduleId)
static QString pyCodeLatchComp(u32 gateId)
static QString pyCodeGateInputPins(u32 gateId)
static QString pyCodeLatchCompEnableFunc(u32 gateId)
static QString pyCodeModule(u32 moduleId)
static QString pyCodeModuleInternalNets(u32 moduleId)
static QString pyCodeGateType(u32 gateId)
static QString pyCodeLatchCompDataInFunc(u32 gateId)
static QString pyCodeGateData(u32 gateId, QString category, QString key)
static QString pyCodeProperties(u32 gateId)
static QString pyCodeNet(u32 netId)
static QString pyCodeGateBooleanFunction(u32 gateId, QString booleanFunctionName)
static QString pyCodeGroupingName(u32 groupingId)
static QString pyCodeModuleInputNets(u32 moduleId)
static QString pyCodeModuleDataMap(u32 moduleId)
static QString pyCodeGate(u32 gateId)
static QString pyCodeModulePinGroup(u32 moduleId, u32 groupId)
static QString pyCodeGateModule(u32 gateId)
static QString pyCodeNetType(u32 netId)
static QString pyCodeModuleNets(u32 moduleId)
static QString pyCodeModulePins(u32 moduleId)
static QString pyCodeModulePinById(u32 moduleId, u32 pinId)
static QString pyCodeModulePinName(u32 moduleId, u32 pinId)
static QString pyCodeNetDataMap(u32 netId)
static QString pyCodeModuleInputPins(u32 moduleId)
static QString pyCodeStateComp(u32 gateId)
static QString pyCodeGroupingId(u32 groupingId)
static QString pyCodeNetId(u32 netId)
static QString pyCodeModuleModule(u32 moduleId)
static QString pyCodeFFCompSetResetBehav(u32 gateId)
static QString pyCodeFFCompAsyncSetFunc(u32 gateId)
static QString pyCodeModulePinGroupName(u32 moduleId, u32 groupId)
static QString pyCodeNetDestinations(u32 netId)
static QString pyCodeModuleOutputPins(u32 moduleId)
static QString pyCodeFFCompAsyncResetFunc(u32 gateId)
static QString pyCodeModuleId(u32 moduleId)
static QString pyCodeNetData(u32 netId, QString category, QString key)
static QString pyCodeModuleSubmodules(u32 moduleId)
static QString pyCodeModuleData(u32 moduleId, QString category, QString key)
static QString pyCodeModuleGates(u32 moduleId, bool recursively=false)
static QString pyCodeGateOutputPins(u32 gateId)
static QString pyCodeGateParameterValue(u32 gateId, QString name)
static QString pyCodeGateName(u32 gateId)
static QString pyCodeGateAsyncSetResetBehavior(u32 gateId)
static QString pyCodeGateId(u32 gateId)
static QString pyCodeFFCompNextStateFunc(u32 gateId)
static QString pyCodeModulePinGroups(u32 moduleId)
static QString pyCodeModuleName(u32 moduleId)
static QString pyCodeFFCompClockFunc(u32 gateId)
static QString pyCodeLatchCompSetResetBehav(u32 gateId)
static QString pyCodeGateDataMap(u32 gateId)
static QString pyCodeNetName(u32 netId)
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45
Netlist * gNetlist
Definition: gui_globals.h:69
std::string name
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString number(int n, int base)