HAL
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  return netCodePrefix.arg(netId);
215  }
216 
218  {
219  const QString suffix = "get_id()";
220 
221  return buildPyCode(netCodePrefix, suffix, netId);
222  }
223 
225  {
226  const QString suffix = "get_name()";
227 
228  return buildPyCode(netCodePrefix, suffix, netId);
229  }
230 
232  {
233  const QString prefix = QString(netCodePrefix).arg(netId);
234 
235  const QString check1 = prefix + ".is_global_input_net()";
236  const QString check2 = prefix + ".is_global_output_net()";
237  const QString check3 = prefix + ".is_unrouted()";
238 
239  const QString result1 = "\"Global Input\"";
240  const QString result2 = "\"Global Output\"";
241  const QString result3 = "\"Unrouted\"";
242  const QString result4 = "\"Internal\"";
243 
244  const QString pyCode = result1 + " if " + check1 + " else " + result2 + " if " + check2 + " else " + result3 + " if " + check3 + " else " + result4;
245 
246  return pyCode;
247  }
248 
250  {
251  const QString suffix = "get_sources()";
252 
253  return buildPyCode(netCodePrefix, suffix, netId);
254  }
255 
257  {
258  const QString suffix = "get_destinations()";
259 
260  return buildPyCode(netCodePrefix, suffix, netId);
261  }
262 
264  {
265  const QString suffix = QString("data[(\"%1\", \"%2\")]").arg(category, key);
266 
267  return buildPyCode(netCodePrefix, suffix, netId);
268  }
269 
271  {
272  const QString suffix = QString("get_data_map()");
273  return buildPyCode(netCodePrefix, suffix, netId);
274  }
275 
277  {
278  return moduleCodePrefix.arg(moduleId);
279  }
280 
282  {
283  const QString suffix = "get_id()";
284 
285  return buildPyCode(moduleCodePrefix, suffix, moduleId);
286  }
287 
289  {
290  const QString suffix = "get_name()";
291 
292  return buildPyCode(moduleCodePrefix, suffix, moduleId);
293  }
294 
296  {
297  const QString suffix = "get_type()";
298 
299  return buildPyCode(moduleCodePrefix, suffix, moduleId);
300 
301  }
302 
304  {
305  const QString suffix = "get_parent_module()";
306 
307  return buildPyCode(moduleCodePrefix, suffix, moduleId);
308  }
309 
311  {
312  const QString suffix = "get_submodules()";
313 
314  return buildPyCode(moduleCodePrefix, suffix, moduleId);
315  }
316 
317  QString PyCodeProvider::pyCodeModuleGates(u32 moduleId, bool recursively)
318  {
319  QString rec = recursively ? QString("None, True") : QString("");
320  const QString suffix = "get_gates(%2)";
321  return QString(moduleCodePrefix + "." + suffix).arg(QString::number(moduleId), rec);
322  }
323 
325  {
326  const QString suffix = "get_nets()";
327 
328  return buildPyCode(moduleCodePrefix, suffix, moduleId);
329  }
330 
332  {
333  const QString suffix = "get_input_nets()";
334 
335  return buildPyCode(moduleCodePrefix, suffix, moduleId);
336  }
337 
339  {
340  const QString suffix = "get_output_nets()";
341 
342  return buildPyCode(moduleCodePrefix, suffix, moduleId);
343  }
344 
346  {
347  const QString suffix = "get_pins(lambda pin: pin.get_direction() == hal_py.PinDirection.input)";
348 
349  return buildPyCode(moduleCodePrefix, suffix, moduleId);
350  }
351 
353  {
354  const QString suffix = "get_pins(lambda pin: pin.get_direction() == hal_py.PinDirection.output)";
355 
356  return buildPyCode(moduleCodePrefix, suffix, moduleId);
357  }
358 
360  {
361  const QString suffix = "get_internal_nets()";
362 
363  return buildPyCode(moduleCodePrefix, suffix, moduleId);
364  }
365 
367  {
368  const QString suffix = "is_top_module()";
369 
370  return buildPyCode(moduleCodePrefix, suffix, moduleId);
371  }
372 
374  {
375  const QString suffix = QString("data[(\"%1\", \"%2\")]").arg(category, key);
376 
377  return buildPyCode(moduleCodePrefix, suffix, moduleId);
378  }
379 
381  {
382  const QString suffix = QString("get_data_map()");
383  return buildPyCode(moduleCodePrefix, suffix, moduleId);
384  }
385 
387  {
388  const QString suffix = QString("get_pin_group_by_id(%1)").arg(groupId);
389 
390  return buildPyCode(moduleCodePrefix, suffix, moduleId);
391  }
392 
394  {
395  const QString suffix = "get_pin_groups()";
396 
397  return buildPyCode(moduleCodePrefix, suffix, moduleId);
398  }
399 
401  {
402  return pyCodeModulePinGroup(moduleId, groupId) + ".get_name()";
403  }
404 
406  {
407  const QString suffix = QString("get_pin_by_id(%1)").arg(pinId);
408 
409  return buildPyCode(moduleCodePrefix, suffix, moduleId);
410  }
411 
413  {
414  return pyCodeModulePinById(moduleId, pinId) + ".get_name()";
415  }
416 
418  {
419  return pyCodeModulePinById(moduleId, pinId) + ".get_direction()";
420  }
421 
423  {
424  return pyCodeModulePinById(moduleId, pinId) + ".get_type()";
425  }
426 
428  {
429  static QString suffix = "get_pins()";
430 
431  return buildPyCode(moduleCodePrefix, suffix, moduleId);
432  }
433 
435  {
436  return groupingCodePrefix.arg(groupingId);
437  }
438 
440  {
441  const QString suffix = QString("get_name()");
442 
443  return buildPyCode(groupingCodePrefix, suffix, groupingId);
444  }
445 
447  {
448  const QString suffix = QString("get_id()");
449 
450  return buildPyCode(groupingCodePrefix, suffix, groupingId);
451  }
452 
453 } // namespace hal
GateType * get_type() const
Definition: gate.cpp:125
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:193
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 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)
Netlist * gNetlist
Definition: plugin_gui.cpp:80
quint32 u32
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString number(int n, int base)