From 0f46cfdb7f3476b833afbb2d35963c156febb863 Mon Sep 17 00:00:00 2001 From: Christophe Alexandre Date: Tue, 14 Oct 2008 10:48:53 +0000 Subject: [PATCH] net collections in progress --- hurricane/src/isobar/CMakeLists.txt | 1 + hurricane/src/isobar/PyCell.cpp | 21 +- hurricane/src/isobar/PyHurricane.cpp | 5 + hurricane/src/isobar/PyNetCollection.cpp | 192 ++++++++++++++++++ .../isobar/hurricane/isobar/PyNetCollection.h | 46 +++++ 5 files changed, 255 insertions(+), 10 deletions(-) create mode 100644 hurricane/src/isobar/PyNetCollection.cpp create mode 100644 hurricane/src/isobar/hurricane/isobar/PyNetCollection.h diff --git a/hurricane/src/isobar/CMakeLists.txt b/hurricane/src/isobar/CMakeLists.txt index ca1eae93..f444cf1a 100644 --- a/hurricane/src/isobar/CMakeLists.txt +++ b/hurricane/src/isobar/CMakeLists.txt @@ -22,6 +22,7 @@ PyName.cpp PyNet.cpp PyNetLocator.cpp + PyNetCollection.cpp PyOccurrence.cpp PyOccurrenceLocator.cpp PyPath.cpp diff --git a/hurricane/src/isobar/PyCell.cpp b/hurricane/src/isobar/PyCell.cpp index c6e2245c..b001e0e8 100644 --- a/hurricane/src/isobar/PyCell.cpp +++ b/hurricane/src/isobar/PyCell.cpp @@ -58,6 +58,7 @@ #include "hurricane/isobar/ProxyProperty.h" #include "hurricane/isobar/PyNet.h" #include "hurricane/isobar/PyNetLocator.h" +#include "hurricane/isobar/PyNetCollection.h" #include "hurricane/isobar/PyReferenceLocator.h" #include "hurricane/isobar/PyInstanceLocator.h" #include "hurricane/isobar/PyOccurrenceLocator.h" @@ -377,25 +378,25 @@ extern "C" { // --------------------------------------------------------------- - // Attribute Method : "PyCell_getNetsLocator ()" + // Attribute Method : "PyCell_getNets ()" - static PyObject* PyCell_getNetsLocator ( PyCell *self ) { - trace << "PyCell_getNetsLocator ()" << endl; + static PyObject* PyCell_getNets ( PyCell *self ) { + trace << "PyCell_getNets()" << endl; - METHOD_HEAD ( "Cell.getNetsLocator()" ) + METHOD_HEAD ( "Cell.getNets()" ) - PyNetLocator* pyNetLocator = NULL; + PyNetCollection* pyNetCollection = NULL; HTRY Nets nets = cell->getNets (); - pyNetLocator = PyObject_NEW ( PyNetLocator, &PyTypeNetLocator ); - if (pyNetLocator == NULL) { return NULL; } + pyNetCollection = PyObject_NEW ( PyNetCollection, &PyTypeNetCollection); + if (pyNetCollection == NULL) { return NULL; } - pyNetLocator->_object = nets.getLocator (); + pyNetCollection->_object = nets; HCATCH - return ( (PyObject*)pyNetLocator ); + return ( (PyObject*)pyNetCollection); } @@ -612,7 +613,7 @@ extern "C" { , { "getReferencesLocator" , (PyCFunction)PyCell_getReferencesLocator , METH_VARARGS, "Returns the collection of all references belonging to the cell." } , { "getHyperNetsLocator" , (PyCFunction)PyCell_getHyperNetsLocator , METH_VARARGS, "Returns the collection of all hyperNets belonging to the cell." } , { "getNet" , (PyCFunction)PyCell_getNet , METH_VARARGS, "Returns the net of name if it exists, else NULL." } - , { "getNetsLocator" , (PyCFunction)PyCell_getNetsLocator , METH_NOARGS , "Returns the collection of all nets of the cell." } + , { "getNets" , (PyCFunction)PyCell_getNets , METH_NOARGS , "Returns the collection of all nets of the cell." } , { "getExternalNetsLocator", (PyCFunction)PyCell_getExternalNetsLocator, METH_NOARGS , "Returns the collection of all external nets of the cell." } , { "getClockNetsLocator" , (PyCFunction)PyCell_getClockNetsLocator , METH_NOARGS , "Returns the collection of all clock nets of the cell." } , { "getSupplyNetsLocator", (PyCFunction)PyCell_getSupplyNetsLocator, METH_NOARGS , "Returns the collection of all supply nets of the cell." } diff --git a/hurricane/src/isobar/PyHurricane.cpp b/hurricane/src/isobar/PyHurricane.cpp index 9a2b511e..0c9bb46b 100644 --- a/hurricane/src/isobar/PyHurricane.cpp +++ b/hurricane/src/isobar/PyHurricane.cpp @@ -84,6 +84,7 @@ #include "hurricane/isobar/PyComponentLocator.h" #include "hurricane/isobar/PyOccurrenceLocator.h" #include "hurricane/isobar/PyNetLocator.h" +#include "hurricane/isobar/PyNetCollection.h" #include "hurricane/isobar/PyCellLocator.h" #include "hurricane/isobar/PyReferenceLocator.h" #include "hurricane/isobar/PyTechnology.h" @@ -555,6 +556,7 @@ extern "C" { PyInstanceLocator_LinkPyType (); PyPlugLocator_LinkPyType (); PyNetLocator_LinkPyType (); + PyNetCollection_LinkPyType (); PyCellLocator_LinkPyType (); PyPinLocator_LinkPyType (); PySegmentLocator_LinkPyType (); @@ -607,6 +609,8 @@ extern "C" { PYTYPE_READY ( InstanceLocator ) PYTYPE_READY ( PlugLocator ) PYTYPE_READY ( NetLocator ) + PYTYPE_READY ( NetCollection ) + PYTYPE_READY ( NetCollectionLocator ) PYTYPE_READY ( CellLocator ) PYTYPE_READY ( PinLocator ) PYTYPE_READY ( SegmentLocator ) @@ -656,6 +660,7 @@ extern "C" { __cs.AddType ( "refLoc" , &PyTypeReferenceLocator , "" , false ); __cs.AddType ( "net" , &PyTypeNet , "" , false, "ent" ); __cs.AddType ( "netLoc" , &PyTypeNetLocator , "" , false ); + __cs.AddType ( "netCol" , &PyTypeNetCollection , "" , false ); __cs.AddType ( "hyperNet" , &PyTypeHyperNet , "" , false ); __cs.AddType ( "pin" , &PyTypePin , "" , false, "contact" ); __cs.AddType ( "pinLoc" , &PyTypePinLocator , "" , false ); diff --git a/hurricane/src/isobar/PyNetCollection.cpp b/hurricane/src/isobar/PyNetCollection.cpp new file mode 100644 index 00000000..23411278 --- /dev/null +++ b/hurricane/src/isobar/PyNetCollection.cpp @@ -0,0 +1,192 @@ +#include "hurricane/isobar/PyNetCollection.h" +#include "hurricane/isobar/PyNet.h" + + +namespace Isobar { + +using namespace Hurricane; + + +extern "C" { + + +#define METHOD_HEAD(function) GENERIC_METHOD_HEAD(Collection,collection,function) + + +// x=================================================================x +// | "PyNetCollection" Python Module Code Part | +// x=================================================================x + +#if defined(__PYTHON_MODULE__) + + + // x-------------------------------------------------------------x + // | "PyNetCollection" Attribute Methods | + // x-------------------------------------------------------------x + + +#if 0 + // Standart Predicates (Attributes). + DirectGetBoolAttribute(PyNetLocator_isValid,isValid,PyNetLocator,Locator) + + + // Standart Locator Accessors (Attributes). + LocatorProgressAttribute(Net) + LocatorGetElementAttribute(Net) + LocatorGetCloneAttribute(Net) + + + // Standart destroy (Attribute). + DirectDestroyAttribute(PyNetLocator_destroy, PyNetLocator) + + + + // --------------------------------------------------------------- + // PyNetLocator Attribute Method table. + + PyMethodDef PyNetLocator_Methods[] = + { { "isValid" , (PyCFunction)PyNetLocator_isValid , METH_NOARGS , "Returns true while the walk has not exhausted the set of elements, else false." } + , { "progress" , (PyCFunction)PyNetLocator_progress , METH_NOARGS , "Moves forward the locator to the following element." } + , { "getElement" , (PyCFunction)PyNetLocator_getElement , METH_NOARGS , "Returns the current element (or the value Type() when the locator is not or no longer valid)." } + , { "getClone" , (PyCFunction)PyNetLocator_getClone , METH_NOARGS , "This function allocates and returns a new locator that will have the same visiting course than the remaining one of the locator being cloned." } + , { "destroy" , (PyCFunction)PyNetLocator_destroy , METH_NOARGS + , "Destroy associated hurricane object, the python object remains." } + , {NULL, NULL, 0, NULL} /* sentinel */ + }; + + + // x-------------------------------------------------------------x + // | "PyNetLocator" Object Methods | + // x-------------------------------------------------------------x + + + DirectDeleteMethod(PyNetLocator_DeAlloc,PyNetLocator) + LocatorPyTypeObjectLinkPyType(Net, Net*) + + + +#endif + + static PyObject* GetNetLocator(PyNetCollection *collection) { + PyNetCollectionLocator* nl = PyObject_New(PyNetCollectionLocator, &PyTypeNetCollectionLocator); + if (nl == NULL) { + return NULL; + } + Py_INCREF(nl); + + nl->_object = collection->_object.getLocator(); + return (PyObject *)nl; + } + + static PyObject* NetLocatorNext(PyNetCollectionLocator* pyLocator) { + Locator* locator = pyLocator->_object; + + if (locator->isValid()) { + cerr << "akecoucou" << endl; + Net* net = locator->getElement(); + locator->progress(); + return PyNet_Link(net); + } + cerr << "end" << endl; + + return NULL; + } + + extern void PyNetCollection_LinkPyType () { + trace << "PyNetCollection_LinkType()" << endl; + PyTypeNetCollection.tp_iter = (getiterfunc)GetNetLocator; /* tp_iter */ + PyTypeNetCollectionLocator.tp_iter = PyObject_SelfIter; + PyTypeNetCollectionLocator.tp_iternext = (iternextfunc)NetLocatorNext; + } + + +#else // End of Python Module Code Part. + + +// x=================================================================x +// | "PyNetCollection" Shared Library Code Part | +// x=================================================================x + + + // --------------------------------------------------------------- + // PyNetCollection Object Definitions. + + PyTypeObject PyTypeNetCollection = + { PyObject_HEAD_INIT(NULL) + 0 /* ob_size. */ + , "Hurricane.NetCollection" /* tp_name. */ + , sizeof(PyNetCollection) /* tp_basicsize. */ + , 0 /* tp_itemsize. */ + /* methods. */ + , 0 /* tp_dealloc. */ + , 0 /* tp_print. */ + , 0 /* tp_getattr. */ + , 0 /* tp_setattr. */ + , 0 /* tp_compare. */ + , 0 /* tp_repr. */ + , 0 /* tp_as_number. */ + , 0 /* tp_as_sequence. */ + , 0 /* tp_as_mapping. */ + , 0 /* tp_hash. */ + , 0 /* tp_call. */ + , 0 /* tp_str */ + , 0 /* tp_getattro. */ + , 0 /* tp_setattro. */ + , 0 /* tp_as_buffer. */ + , Py_TPFLAGS_DEFAULT /* tp_flags. */ + , "NetCollection objects" /* tp_doc. */ + , 0 /* tp_traverse */ + , 0 /* tp_clear */ + , 0 /* tp_richcompare */ + , 0 /* tp_weaklistoffset */ + , 0 /* tp_iter */ + , 0 /* tp_iternext */ + , 0 /* tp_methods */ + , 0 + }; + + PyTypeObject PyTypeNetCollectionLocator = + { PyObject_HEAD_INIT(NULL) + 0 /* ob_size. */ + , "Hurricane.NetLocator" /* tp_name. */ + , sizeof(PyNetCollectionLocator) /* tp_basicsize. */ + , 0 /* tp_itemsize. */ + /* methods. */ + , 0 /* tp_dealloc. */ + , 0 /* tp_print. */ + , 0 /* tp_getattr. */ + , 0 /* tp_setattr. */ + , 0 /* tp_compare. */ + , 0 /* tp_repr. */ + , 0 /* tp_as_number. */ + , 0 /* tp_as_sequence. */ + , 0 /* tp_as_mapping. */ + , 0 /* tp_hash. */ + , 0 /* tp_call. */ + , 0 /* tp_str */ + , 0 /* tp_getattro. */ + , 0 /* tp_setattro. */ + , 0 /* tp_as_buffer. */ + , Py_TPFLAGS_DEFAULT /* tp_flags. */ + , "NetLocator objects" /* tp_doc. */ + , 0 /* tp_traverse */ + , 0 /* tp_clear */ + , 0 /* tp_richcompare */ + , 0 /* tp_weaklistoffset */ + , 0 /* tp_iter */ + , 0 /* tp_iternext */ + , 0 /* tp_methods */ + , 0 + }; + + + +#endif // End of Shared Library Code Part. + + +} // End of extern "C". + + + + +} // End of Isobar namespace. diff --git a/hurricane/src/isobar/hurricane/isobar/PyNetCollection.h b/hurricane/src/isobar/hurricane/isobar/PyNetCollection.h new file mode 100644 index 00000000..eab5eab4 --- /dev/null +++ b/hurricane/src/isobar/hurricane/isobar/PyNetCollection.h @@ -0,0 +1,46 @@ +#ifndef __PYNETCOLLECTION__ +#define __PYNETCOLLECTION__ + + +#include "hurricane/isobar/PyHurricane.h" + +#include "hurricane/Net.h" +#include "hurricane/Nets.h" + + +namespace Isobar { + + +extern "C" { + + +// ------------------------------------------------------------------- +// Python Object : "PyNetCollection". + + typedef struct { + PyObject_HEAD + Hurricane::Nets _object; + } PyNetCollection; + + typedef struct { + PyObject_HEAD + Hurricane::Locator* _object; + } PyNetCollectionLocator; + + + + +// ------------------------------------------------------------------- +// Functions & Types exported to "PyHurricane.ccp". + + extern PyTypeObject PyTypeNetCollection; + extern PyTypeObject PyTypeNetCollectionLocator; + + extern void PyNetCollection_LinkPyType(); + extern void PyNetCollectionLocator_LinkPyType(); + +} // End of extern "C". + +} // End of Isobar namespace. + +#endif