From 083e58d9531c08a8b4d1a54fe6deeb04b6af34a9 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Fri, 21 Aug 2020 16:00:50 +0200 Subject: [PATCH] Add CRL::Catalog and Net::getRoutingPads() to the Python interface. * New: In CRL::PyAllianceFramework, export getCatalog(), in PyCatalog, export the getState(name) method and add a PyCatalog_Link(). In PyCatalogState, add PyCatalogState_Link(), cannot use the macro because of the C++ name resolution operator (Catalog::State). * New: In Isobar, export the RoutingPads collection to the Python interface. * New: In Hurricane::Net, export the getRoutingPads() method to the Python interface (hence the need of the previous export). --- crlcore/src/pyCRL/PyAllianceFramework.cpp | 16 ++++++ crlcore/src/pyCRL/PyCatalog.cpp | 30 ++++++++-- crlcore/src/pyCRL/PyCatalogState.cpp | 16 ++++++ hurricane/src/isobar/CMakeLists.txt | 2 + hurricane/src/isobar/PyContact.cpp | 55 +++++++++++------- hurricane/src/isobar/PyHurricane.cpp | 8 ++- hurricane/src/isobar/PyNet.cpp | 40 +++++++++---- .../src/isobar/PyRoutingPadCollection.cpp | 56 +++++++++++++++++++ .../hurricane/isobar/PyRoutingPadCollection.h | 50 +++++++++++++++++ 9 files changed, 234 insertions(+), 39 deletions(-) create mode 100644 hurricane/src/isobar/PyRoutingPadCollection.cpp create mode 100644 hurricane/src/isobar/hurricane/isobar/PyRoutingPadCollection.h diff --git a/crlcore/src/pyCRL/PyAllianceFramework.cpp b/crlcore/src/pyCRL/PyAllianceFramework.cpp index 32927667..99002d2a 100644 --- a/crlcore/src/pyCRL/PyAllianceFramework.cpp +++ b/crlcore/src/pyCRL/PyAllianceFramework.cpp @@ -18,6 +18,7 @@ #include "hurricane/isobar/PyLibrary.h" #include "hurricane/DataBase.h" #include "crlcore/PyEnvironment.h" +#include "crlcore/PyCatalog.h" #include "crlcore/PyCellGauge.h" #include "crlcore/PyRoutingGauge.h" #include "crlcore/PyAllianceLibrary.h" @@ -336,6 +337,19 @@ extern "C" { } + static PyObject* PyAllianceFramework_getCatalog ( PyAllianceFramework* self ) + { + cdebug_log(30,0) << "PyAllianceFramework_getCatalog ()" << endl; + + Catalog* catalog = NULL; + HTRY + METHOD_HEAD("AllianceFramework.getCatalog()") + catalog = af->getCatalog(); + HCATCH + return PyCatalog_Link(catalog); + } + + static PyObject* PyAllianceFramework_isInCatalog ( PyAllianceFramework* self, PyObject* args ) { cdebug_log(30,0) << "PyAllianceFramework_isInCatalog ()" << endl; @@ -555,6 +569,8 @@ extern "C" { , "Gets the Alliance Framework." } , { "getEnvironment" , (PyCFunction)PyAllianceFramework_getEnvironment , METH_NOARGS , "Gets the Alliance Environment." } + , { "getCatalog" , (PyCFunction)PyAllianceFramework_getCatalog , METH_NOARGS + , "Gets the libraries composite catalog." } , { "bindLibraries" , (PyCFunction)PyAllianceFramework_bindLibraries , METH_NOARGS , "Bind Alliance libraries to Hurricane one. This is a one-time only methods." } , { "getLibrary" , (PyCFunction)PyAllianceFramework_getLibrary , METH_VARARGS diff --git a/crlcore/src/pyCRL/PyCatalog.cpp b/crlcore/src/pyCRL/PyCatalog.cpp index e0c73384..e511e9c0 100644 --- a/crlcore/src/pyCRL/PyCatalog.cpp +++ b/crlcore/src/pyCRL/PyCatalog.cpp @@ -29,6 +29,8 @@ namespace CRL { using std::hex; using std::ostringstream; using Hurricane::tab; + using Hurricane::Exception; + using Hurricane::Bug; using Hurricane::Error; using Hurricane::Warning; using Isobar::ProxyProperty; @@ -56,17 +58,34 @@ extern "C" { // x=================================================================x #if defined(__PYTHON_MODULE__) - - // Standart Accessors (Attributes). - - // Standart Destroy (Attribute). // DBoDestroyAttribute(PyCatalog_destroy,PyCatalog) + static PyObject* PyCatalog_getState ( PyCatalog* self, PyObject* args ) + { + cdebug_log(30,0) << "PyCatalog_getState ()" << endl; + + char* name = NULL; + Catalog::State* state = NULL; + HTRY + METHOD_HEAD("Catalog.getState()") + if ( not PyArg_ParseTuple(args,"s",&name) ) { + PyErr_SetString( ConstructorError, "Catalog.getState(): Invalid number or bad type of parameters."); + return NULL; + } + state = catalog->getState( Name(name) ); + HCATCH + if (not state) Py_RETURN_FALSE; + return PyCatalogState_Link(state); + } + + PyMethodDef PyCatalog_Methods[] = - { {NULL, NULL, 0, NULL} /* sentinel */ + { { "getState" , (PyCFunction)PyCatalog_getState, METH_VARARGS + , "Gets the catalog state of a cell." } + , {NULL, NULL, 0, NULL} /* sentinel */ }; @@ -83,6 +102,7 @@ extern "C" { // Link/Creation Method. PyTypeObjectDefinitions(Catalog) + LinkCreateMethod(Catalog) extern void PyCatalog_postModuleInit () diff --git a/crlcore/src/pyCRL/PyCatalogState.cpp b/crlcore/src/pyCRL/PyCatalogState.cpp index ad482513..10c2f2dc 100644 --- a/crlcore/src/pyCRL/PyCatalogState.cpp +++ b/crlcore/src/pyCRL/PyCatalogState.cpp @@ -156,6 +156,22 @@ extern "C" { // Link/Creation Method. PyTypeObjectDefinitions(CatalogState) + + PyObject* PyCatalogState_Link ( Catalog::State* object ) + { + if (not object) Py_RETURN_NONE; + PyCatalogState* pyObject = NULL; + HTRY + pyObject = PyObject_NEW( PyCatalogState, &PyTypeCatalogState ); + if (not pyObject) return NULL; + + pyObject->_object = object; + cdebug_log(20,0) << "PyCatalogState_Link(" << (void*)pyObject << ") " + << (void*)object << ":" << object << endl; + HCATCH + return (PyObject*)pyObject; + } + #endif // End of Shared Library Code Part. diff --git a/hurricane/src/isobar/CMakeLists.txt b/hurricane/src/isobar/CMakeLists.txt index abb7f16e..2f5e2015 100644 --- a/hurricane/src/isobar/CMakeLists.txt +++ b/hurricane/src/isobar/CMakeLists.txt @@ -64,6 +64,7 @@ PyReference.cpp PyReferenceCollection.cpp PyRoutingPad.cpp + PyRoutingPadCollection.cpp PySegment.cpp PySegmentCollection.cpp PyTechnology.cpp @@ -140,6 +141,7 @@ hurricane/isobar/PyReference.h hurricane/isobar/PyReferenceCollection.h hurricane/isobar/PyRoutingPad.h + hurricane/isobar/PyRoutingPadCollection.h hurricane/isobar/PySegment.h hurricane/isobar/PySegmentCollection.h hurricane/isobar/PyTechnology.h diff --git a/hurricane/src/isobar/PyContact.cpp b/hurricane/src/isobar/PyContact.cpp index 220bec0b..1c039188 100644 --- a/hurricane/src/isobar/PyContact.cpp +++ b/hurricane/src/isobar/PyContact.cpp @@ -96,6 +96,22 @@ extern "C" { return PyContact_Link(contact); } + + + static PyObject* PyContact_getAnchor ( PyContact *self ) + { + cdebug_log(20,0) << "PyContact_getAnchor ()" << endl; + METHOD_HEAD ( "Contact.getAnchor()" ) + Component* anchor = NULL; + PyObject* pyAnchor = NULL; + HTRY + anchor = contact->getAnchor(); + if (anchor) pyAnchor = PyEntity_NEW( anchor ); + else + Py_RETURN_NONE; + HCATCH + return pyAnchor; + } static PyObject* PyContact_translate ( PyContact *self, PyObject* args ) { @@ -123,25 +139,26 @@ extern "C" { PyMethodDef PyContact_Methods[] = - { { "create" , (PyCFunction)PyContact_create , METH_VARARGS|METH_STATIC - , "Create a new Contact." } - , { "destroy" , (PyCFunction)PyContact_destroy , METH_NOARGS - , "Destroy associated hurricane object, the python object remains." } - , { "getAnchorHook" , (PyCFunction)PyContact_getAnchorHook , METH_NOARGS , "Return the contact anchor hook." } - , { "getWidth" , (PyCFunction)PyContact_getWidth , METH_NOARGS , "Return the contact width." } - , { "getHalfWidth" , (PyCFunction)PyContact_getHalfWidth , METH_NOARGS , "Return the contact half width." } - , { "getHeight" , (PyCFunction)PyContact_getHeight , METH_NOARGS , "Return the contact height." } - , { "getHalfHeight" , (PyCFunction)PyContact_getHalfHeight , METH_NOARGS , "Return the contact half height." } - , { "getDx" , (PyCFunction)PyContact_getDx , METH_NOARGS , "Return the contact dx value." } - , { "getDy" , (PyCFunction)PyContact_getDy , METH_NOARGS , "Return the contact dy value." } - , { "translate" , (PyCFunction)PyContact_translate , METH_VARARGS, "Translates the Contact of dx and dy." } - , { "setX" , (PyCFunction)PyContact_setX , METH_VARARGS, "Sets the contact X value." } - , { "setY" , (PyCFunction)PyContact_setY , METH_VARARGS, "Sets the contact Y value." } - , { "setDx" , (PyCFunction)PyContact_setDx , METH_VARARGS, "Sets the contact dx value." } - , { "setDy" , (PyCFunction)PyContact_setDy , METH_VARARGS, "Sets the contact dy value." } - , { "setWidth" , (PyCFunction)PyContact_setWidth , METH_VARARGS, "Sets the contact width." } - , { "setHeight" , (PyCFunction)PyContact_setHeight , METH_VARARGS, "Sets the contact height." } - , {NULL, NULL, 0, NULL} /* sentinel */ + { { "create" , (PyCFunction)PyContact_create , METH_VARARGS|METH_STATIC + , "Create a new Contact." } + , { "destroy" , (PyCFunction)PyContact_destroy , METH_NOARGS + , "Destroy associated hurricane object, the python object remains." } + , { "getAnchorHook" , (PyCFunction)PyContact_getAnchorHook , METH_NOARGS , "Return the contact anchor hook." } + , { "getAnchor" , (PyCFunction)PyContact_getAnchor , METH_NOARGS , "Return the contact anchor (component)." } + , { "getWidth" , (PyCFunction)PyContact_getWidth , METH_NOARGS , "Return the contact width." } + , { "getHalfWidth" , (PyCFunction)PyContact_getHalfWidth , METH_NOARGS , "Return the contact half width." } + , { "getHeight" , (PyCFunction)PyContact_getHeight , METH_NOARGS , "Return the contact height." } + , { "getHalfHeight" , (PyCFunction)PyContact_getHalfHeight , METH_NOARGS , "Return the contact half height." } + , { "getDx" , (PyCFunction)PyContact_getDx , METH_NOARGS , "Return the contact dx value." } + , { "getDy" , (PyCFunction)PyContact_getDy , METH_NOARGS , "Return the contact dy value." } + , { "translate" , (PyCFunction)PyContact_translate , METH_VARARGS, "Translates the Contact of dx and dy." } + , { "setX" , (PyCFunction)PyContact_setX , METH_VARARGS, "Sets the contact X value." } + , { "setY" , (PyCFunction)PyContact_setY , METH_VARARGS, "Sets the contact Y value." } + , { "setDx" , (PyCFunction)PyContact_setDx , METH_VARARGS, "Sets the contact dx value." } + , { "setDy" , (PyCFunction)PyContact_setDy , METH_VARARGS, "Sets the contact dy value." } + , { "setWidth" , (PyCFunction)PyContact_setWidth , METH_VARARGS, "Sets the contact width." } + , { "setHeight" , (PyCFunction)PyContact_setHeight , METH_VARARGS, "Sets the contact height." } + , {NULL, NULL, 0, NULL} /* sentinel */ }; diff --git a/hurricane/src/isobar/PyHurricane.cpp b/hurricane/src/isobar/PyHurricane.cpp index 3c13f294..4f0d5d1c 100644 --- a/hurricane/src/isobar/PyHurricane.cpp +++ b/hurricane/src/isobar/PyHurricane.cpp @@ -47,6 +47,7 @@ #include "hurricane/isobar/PyPinPlacementStatus.h" #include "hurricane/isobar/PyPinDirection.h" #include "hurricane/isobar/PyPinCollection.h" +#include "hurricane/isobar/PyRoutingPadCollection.h" #include "hurricane/isobar/PyPlacementStatus.h" #include "hurricane/isobar/PyInstance.h" #include "hurricane/isobar/PyInstanceCollection.h" @@ -555,6 +556,7 @@ extern "C" { PyPinPlacementStatus_LinkPyType (); PyPinDirection_LinkPyType (); PyPinCollection_LinkPyType (); + PyRoutingPadCollection_LinkPyType (); PySegmentCollection_LinkPyType (); PyOccurrenceCollection_LinkPyType (); PyComponentCollection_LinkPyType (); @@ -635,6 +637,8 @@ extern "C" { PYTYPE_READY( PinDirection ) PYTYPE_READY( PinCollection ) PYTYPE_READY( PinCollectionLocator ) + PYTYPE_READY( RoutingPadCollection ) + PYTYPE_READY( RoutingPadCollectionLocator ) PYTYPE_READY( SegmentCollection ) PYTYPE_READY( SegmentCollectionLocator ) PYTYPE_READY( ComponentCollection ) @@ -723,6 +727,7 @@ extern "C" { __cs.addType( "hyperNet" , &PyTypeHyperNet , "" , false ); __cs.addType( "pin" , &PyTypePin , "" , false, "contact" ); __cs.addType( "pinCol" , &PyTypePinCollection , "" , false ); + __cs.addType( "rpCol" , &PyTypeRoutingPadCollection , "" , false ); __cs.addType( "plug" , &PyTypePlug , "" , false, "comp" ); __cs.addType( "plugCol" , &PyTypePlugCollection , "" , false ); __cs.addType( "point" , &PyTypePoint , "" , false ); @@ -772,7 +777,6 @@ extern "C" { PyModule_AddObject ( module, "Path" , (PyObject*)&PyTypePath ); Py_INCREF ( &PyTypeOccurrence ); PyModule_AddObject ( module, "Occurrence" , (PyObject*)&PyTypeOccurrence ); - Py_INCREF ( &PyTypeDataBase ); PyModule_AddObject ( module, "DataBase" , (PyObject*)&PyTypeDataBase ); Py_INCREF ( &PyTypeLibrary ); @@ -817,7 +821,6 @@ extern "C" { PyModule_AddObject ( module, "Query" , (PyObject*)&PyTypeQuery ); Py_INCREF ( &PyTypeReference ); PyModule_AddObject ( module, "Reference" , (PyObject*)&PyTypeReference ); - Py_INCREF ( &PyTypeHook ); PyModule_AddObject ( module, "Hook" , (PyObject*)&PyTypeHook ); Py_INCREF ( &PyTypeHookCollection ); @@ -844,7 +847,6 @@ extern "C" { PyModule_AddObject ( module, "Rectilinear" , (PyObject*)&PyTypeRectilinear ); Py_INCREF ( &PyTypePolygon ); PyModule_AddObject ( module, "Polygon" , (PyObject*)&PyTypePolygon ); - Py_INCREF( &PyTypeDeviceDescriptor ); PyModule_AddObject( module, "DeviceDescriptor" , (PyObject*)&PyTypeDeviceDescriptor ); diff --git a/hurricane/src/isobar/PyNet.cpp b/hurricane/src/isobar/PyNet.cpp index a0e84d12..4f20bc04 100644 --- a/hurricane/src/isobar/PyNet.cpp +++ b/hurricane/src/isobar/PyNet.cpp @@ -23,6 +23,7 @@ #include "hurricane/isobar/PySegmentCollection.h" #include "hurricane/isobar/PyComponentCollection.h" #include "hurricane/isobar/PyPinCollection.h" +#include "hurricane/isobar/PyRoutingPadCollection.h" #include "hurricane/Cell.h" #include "hurricane/NetExternalComponents.h" using namespace Hurricane; @@ -197,26 +198,40 @@ extern "C" { } - static PyObject* PyNet_getPins(PyNet *self) { + static PyObject* PyNet_getPins ( PyNet *self ) + { cdebug_log(20,0) << "PyNet_getPins()" << endl; METHOD_HEAD ("Net.getPins()") - PyPinCollection* pyPinCollection = NULL; - HTRY - Pins* pins = new Pins(net->getPins()); - - pyPinCollection = PyObject_NEW(PyPinCollection, &PyTypePinCollection); - if (pyPinCollection == NULL) { - return NULL; - } - - pyPinCollection->_object = pins; + Pins* pins = new Pins( net->getPins() ); + pyPinCollection = PyObject_NEW(PyPinCollection, &PyTypePinCollection); + if (pyPinCollection == NULL) { + return NULL; + } + pyPinCollection->_object = pins; HCATCH - return (PyObject*)pyPinCollection; } + + + static PyObject* PyNet_getRoutingPads ( PyNet *self ) + { + cdebug_log(20,0) << "PyNet_getRoutingPads()" << endl; + + METHOD_HEAD ("Net.getRoutingPads()") + PyRoutingPadCollection* pyRoutingPadCollection = NULL; + HTRY + RoutingPads* routingPads = new RoutingPads( net->getRoutingPads() ); + pyRoutingPadCollection = PyObject_NEW(PyRoutingPadCollection, &PyTypeRoutingPadCollection); + if (pyRoutingPadCollection == NULL) { + return NULL; + } + pyRoutingPadCollection->_object = routingPads; + HCATCH + return (PyObject*)pyRoutingPadCollection; + } static PyObject* PyNet_getComponents(PyNet *self) { @@ -451,6 +466,7 @@ extern "C" { , { "getExternalComponents", (PyCFunction)PyNet_getExternalComponents , METH_NOARGS , "Returns the collection of net's external components. (only for an external net)" } , { "getPlugs" , (PyCFunction)PyNet_getPlugs , METH_NOARGS , "Returns the collection of net's plugs." } , { "getPins" , (PyCFunction)PyNet_getPins , METH_NOARGS , "Returns the collection of net's pins." } + , { "getRoutingPads" , (PyCFunction)PyNet_getRoutingPads , METH_NOARGS , "Returns the collection of net's RoutingPads." } , { "getSegments" , (PyCFunction)PyNet_getSegments , METH_NOARGS , "Returns the collection of net's segments." } , { "isGlobal" , (PyCFunction)PyNet_isGlobal , METH_NOARGS , "return true if the net is global" } , { "isExternal" , (PyCFunction)PyNet_isExternal , METH_NOARGS , "return true if the the net is external." } diff --git a/hurricane/src/isobar/PyRoutingPadCollection.cpp b/hurricane/src/isobar/PyRoutingPadCollection.cpp new file mode 100644 index 00000000..e8f75dfe --- /dev/null +++ b/hurricane/src/isobar/PyRoutingPadCollection.cpp @@ -0,0 +1,56 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) SU/LIP6 2020-2020, All Rights Reserved +// +// +-----------------------------------------------------------------+ +// | C O R I O L I S | +// | I s o b a r - Hurricane / Python Interface | +// | | +// | Author : Jean-Paul Chaput | +// | E-mail : Jean-Paul.Chaput@lip6.fr | +// | =============================================================== | +// | C++ Module : "./PyRoutingPadCollection.h" | +// +-----------------------------------------------------------------+ + + +#include "hurricane/isobar/PyRoutingPadCollection.h" +#include "hurricane/isobar/PyRoutingPad.h" + +namespace Isobar { + + using namespace Hurricane; + + + extern "C" { + + + +#if defined(__PYTHON_MODULE__) + +// +=================================================================+ +// | "PyRoutingPadCollection" Python Module Code Part | +// +=================================================================+ + + DirectDeleteMethod(PyRoutingPadCollection_DeAlloc, PyRoutingPadCollection) + LocatorNextMethod(RoutingPad) + CollectionMethods(RoutingPad) + + +#else // End of Python Module Code Part. + +// +=================================================================+ +// | "PyRoutingPadCollection" Shared Library Code Part | +// +=================================================================+ + + PyTypeCollectionObjectDefinitions(RoutingPadCollection) + PyTypeCollectionObjectDefinitions(RoutingPadCollectionLocator) + + +#endif // End of Shared Library Code Part. + + + } // End of extern "C". + +} // Isobar namespace. diff --git a/hurricane/src/isobar/hurricane/isobar/PyRoutingPadCollection.h b/hurricane/src/isobar/hurricane/isobar/PyRoutingPadCollection.h new file mode 100644 index 00000000..79f3a7b4 --- /dev/null +++ b/hurricane/src/isobar/hurricane/isobar/PyRoutingPadCollection.h @@ -0,0 +1,50 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) SU/LIP6 2020-2020, All Rights Reserved +// +// +-----------------------------------------------------------------+ +// | C O R I O L I S | +// | I s o b a r - Hurricane / Python Interface | +// | | +// | Author : Jean-Paul Chaput | +// | E-mail : Jean-Paul.Chaput@lip6.fr | +// | =============================================================== | +// | C++ Header : "./isobar/PyRoutingPadCollection.h" | +// +-----------------------------------------------------------------+ + + +#pragma once +#include "hurricane/isobar/PyHurricane.h" +#include "hurricane/RoutingPad.h" +#include "hurricane/RoutingPads.h" + + +namespace Isobar { + + extern "C" { + + + typedef struct { + PyObject_HEAD + Hurricane::RoutingPads* _object; + } PyRoutingPadCollection; + + typedef struct { + PyObject_HEAD + Hurricane::Locator* _object; + PyRoutingPadCollection* _collection; + } PyRoutingPadCollectionLocator; + + + extern PyTypeObject PyTypeRoutingPadCollection; + extern PyTypeObject PyTypeRoutingPadCollectionLocator; + + extern void PyRoutingPadCollection_LinkPyType(); + extern void PyRoutingPadCollectionLocator_LinkPyType(); + + + } // End of extern "C". + +} // Isobar namespace.