MCPcopy Create free account
hub / github.com/chipsalliance/Surelog / evalScript

Method evalScript

src/API/PythonAPI.cpp:283–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281}
282
283void PythonAPI::evalScript(const std::string& function,
284 SV3_1aPythonListener* listener,
285 parser_rule_context* ctx1) {
286#ifdef SURELOG_WITH_PYTHON
287 antlr4::ParserRuleContext* ctx = (antlr4::ParserRuleContext*)ctx1;
288 PyEval_AcquireThread(listener->getPyThreadState());
289 PyObject *pModuleName, *pModule, *pFunc;
290 PyObject *pArgs, *pValue;
291 pModuleName = PyString_FromString("__main__");
292 pModule = PyImport_Import(pModuleName);
293 Py_DECREF(pModuleName);
294 pFunc = PyObject_GetAttrString(pModule, function.c_str());
295 if (!pFunc || !PyCallable_Check(pFunc)) {
296 if (m_strictMode)
297 std::cout << "PYTHON API ERROR: Function \"" << function
298 << "\" does not exist.\n";
299 PyEval_ReleaseThread(listener->getPyThreadState());
300 return;
301 }
302 pArgs = PyTuple_New(2);
303 pValue = SWIG_NewPointerObj(SWIG_as_voidptr(listener),
304 SWIGTYPE_p_SURELOG__SV3_1aPythonListener, 0 | 0);
305 PyTuple_SetItem(pArgs, 0, pValue);
306 pValue = SWIG_NewPointerObj(SWIG_as_voidptr(ctx),
307 SWIGTYPE_p_antlr4__ParserRuleContext, 0 | 0);
308 PyTuple_SetItem(pArgs, 1, pValue);
309 PyObject_CallObject(pFunc, pArgs);
310 PyErr_Print();
311 Py_DECREF(pArgs);
312 Py_XDECREF(pFunc);
313 Py_DECREF(pModule);
314 PyEval_ReleaseThread(listener->getPyThreadState());
315#endif
316}
317
318std::string PythonAPI::evalScript(const std::string& module,
319 const std::string& function,

Callers

nothing calls this directly

Calls 1

getErrorContainerMethod · 0.45

Tested by

no test coverage detected