From 4884a5d6dcbd14513bfcc21b43e14b18fcbc2b87 Mon Sep 17 00:00:00 2001 From: gatecat Date: Tue, 23 Nov 2021 10:23:41 +0000 Subject: [PATCH] crlcore: Add Python bindings for DEF export Signed-off-by: gatecat --- crlcore/src/pyCRL/CMakeLists.txt | 2 + crlcore/src/pyCRL/PyCRL.cpp | 5 ++ crlcore/src/pyCRL/PyDefExport.cpp | 108 ++++++++++++++++++++++++ crlcore/src/pyCRL/crlcore/PyDefExport.h | 55 ++++++++++++ 4 files changed, 170 insertions(+) create mode 100644 crlcore/src/pyCRL/PyDefExport.cpp create mode 100644 crlcore/src/pyCRL/crlcore/PyDefExport.h diff --git a/crlcore/src/pyCRL/CMakeLists.txt b/crlcore/src/pyCRL/CMakeLists.txt index 36358b17..1ca6e829 100644 --- a/crlcore/src/pyCRL/CMakeLists.txt +++ b/crlcore/src/pyCRL/CMakeLists.txt @@ -51,6 +51,7 @@ PyLefImport.cpp PyDefImport.cpp PyLefExport.cpp + PyDefExport.cpp ) set( pyIncludes crlcore/PySystem.h crlcore/PyBanner.h @@ -74,6 +75,7 @@ crlcore/PyLefImport.h crlcore/PyDefImport.h crlcore/PyLefExport.h + crlcore/PyDefExport.h ) # target_link_libraries ( crlcore ${HURRICANE_PYTHON_NEW_LIBRARIES} # ${HURRICANE_PYTHON_LIBRARIES} diff --git a/crlcore/src/pyCRL/PyCRL.cpp b/crlcore/src/pyCRL/PyCRL.cpp index a4979fdf..22de2ee2 100644 --- a/crlcore/src/pyCRL/PyCRL.cpp +++ b/crlcore/src/pyCRL/PyCRL.cpp @@ -38,6 +38,7 @@ #include "crlcore/PyLefImport.h" #include "crlcore/PyLefExport.h" #include "crlcore/PyDefImport.h" +#include "crlcore/PyDefExport.h" #include "crlcore/VhdlEntity.h" @@ -148,6 +149,7 @@ extern "C" { PyLefImport_LinkPyType (); PyDefImport_LinkPyType (); PyLefExport_LinkPyType (); + PyDefExport_LinkPyType (); PYTYPE_READY ( System ); PYTYPE_READY ( Banner ); @@ -172,6 +174,7 @@ extern "C" { PYTYPE_READY ( LefImport ); PYTYPE_READY ( DefImport ); PYTYPE_READY ( LefExport ); + PYTYPE_READY ( DefExport ); // Identifier string can take up to 10 characters. __cs.addType ( "alcLib" , &PyTypeAllianceLibrary , "" , false ); @@ -234,6 +237,8 @@ extern "C" { PyModule_AddObject ( module, "DefImport", (PyObject*)&PyTypeDefImport ); Py_INCREF ( &PyTypeLefExport ); PyModule_AddObject ( module, "LefExport", (PyObject*)&PyTypeLefExport ); + Py_INCREF ( &PyTypeDefExport ); + PyModule_AddObject ( module, "DefExport", (PyObject*)&PyTypeDefExport ); PyCatalog_postModuleInit (); PyEnvironment_postModuleInit (); diff --git a/crlcore/src/pyCRL/PyDefExport.cpp b/crlcore/src/pyCRL/PyDefExport.cpp new file mode 100644 index 00000000..5c8ee79f --- /dev/null +++ b/crlcore/src/pyCRL/PyDefExport.cpp @@ -0,0 +1,108 @@ +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC 2017-2018, All Rights Reserved +// +// +-----------------------------------------------------------------+ +// | C O R I O L I S | +// | Alliance / Hurricane Interface | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@lip6.fr | +// | =============================================================== | +// | C++ Module : "./PyDefExport.cpp" | +// +-----------------------------------------------------------------+ + + +#include "crlcore/PyDefExport.h" +#include "hurricane/isobar/PyCell.h" +#include +#include + + +namespace CRL { + + using std::cerr; + using std::endl; + using std::hex; + using std::string; + using std::ostringstream; + using Hurricane::tab; + using Hurricane::Exception; + using Hurricane::Bug; + using Hurricane::Error; + using Hurricane::Warning; + using Hurricane::Cell; + using Isobar::ProxyProperty; + using Isobar::ProxyError; + using Isobar::ConstructorError; + using Isobar::HurricaneError; + using Isobar::HurricaneWarning; + using Isobar::getPyHash; + using Isobar::ParseOneArg; + using Isobar::ParseTwoArg; + using Isobar::__cs; + using Isobar::PyTypeCell; + using Isobar::PyCell; + + +extern "C" { + + +#if defined(__PYTHON_MODULE__) + +// +=================================================================+ +// | "PyDefExport" Python Module Code Part | +// +=================================================================+ + + + static PyObject* PyDefExport_drive ( PyObject*, PyObject* args ) + { + cdebug_log(30,0) << "PyDefExport_drive()" << endl; + + PyCell* pyCell = NULL; + + HTRY + unsigned int flags = 0; + + if (PyArg_ParseTuple( args, "O!I:DefExport.drive", &PyTypeCell, &pyCell, &flags)) { + DefExport::drive( PYCELL_O(pyCell) , flags ); + } else { + PyErr_SetString ( ConstructorError, "DefExport.drive(): Bad type or bad number of parameters." ); + return NULL; + } + HCATCH + + Py_RETURN_NONE; + } + + // Standart Destroy (Attribute). + + + PyMethodDef PyDefExport_Methods[] = + { { "drive" , (PyCFunction)PyDefExport_drive , METH_VARARGS|METH_STATIC + , "Save a complete Cadence DEF design." } + , {NULL, NULL, 0, NULL} /* sentinel */ + }; + + + NoObjectDeleteMethod(DefExport) + PyTypeObjectLinkPyTypeWithoutObject(DefExport,DefExport) + + +#else // End of Python Module Code Part. + + +// +=================================================================+ +// | "PyDefExport" Shared Library Code Part | +// +=================================================================+ + + // Type Definition. + PyTypeObjectDefinitionsOfModule(CRL,DefExport) + + +#endif // End of Shared Library Code Part. + +} // extern "C". + +} // CRL namespace. diff --git a/crlcore/src/pyCRL/crlcore/PyDefExport.h b/crlcore/src/pyCRL/crlcore/PyDefExport.h new file mode 100644 index 00000000..cb804493 --- /dev/null +++ b/crlcore/src/pyCRL/crlcore/PyDefExport.h @@ -0,0 +1,55 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC 2017-2018, All Rights Reserved +// +// +-----------------------------------------------------------------+ +// | C O R I O L I S | +// | Alliance / Hurricane Interface | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@lip6.fr | +// | =============================================================== | +// | C++ Header : "./crlcore/PyDefExport.h" | +// +-----------------------------------------------------------------+ + + +#ifndef CRL_PY_DEF_EXPORT_H +#define CRL_PY_DEF_EXPORT_H + +#include "hurricane/isobar/PyHurricane.h" +#include "crlcore/DefExport.h" + + +namespace CRL { + +extern "C" { + + +// ------------------------------------------------------------------- +// Python Object : "PyDefExport". + + typedef struct { + PyObject_HEAD + } PyDefExport; + + +// ------------------------------------------------------------------- +// Functions & Types exported to "PyCRL.ccp". + + extern PyTypeObject PyTypeDefExport; + extern PyMethodDef PyDefExport_Methods[]; + + extern void PyDefExport_LinkPyType(); + + +#define IsPyDefExport(v) ( (v)->ob_type == &PyTypeDefExport ) +#define PY_DEFEXPORT(v) ( (PyDefExport*)(v) ) + + +} // extern "C". + +} // CRL namespace. + +#endif // CRL_PY_DEF_EXPORT_H