Added Python support for AllianceLibrary in CRL Core.

* New: In CRL Core, added support for AllianceLibrary.
This commit is contained in:
Jean-Paul Chaput 2016-04-13 18:26:08 +02:00
parent 2a40fa7d92
commit b46c06042b
7 changed files with 364 additions and 15 deletions

View File

@ -575,6 +575,17 @@ namespace CRL {
}
Library* AllianceFramework::getLibrary ( const Name &libName )
{
for ( size_t ilib=0 ; ilib<_libraries.size() ; ++ilib ) {
if ( _libraries[ilib]->getLibrary()->getName() == libName )
return _libraries[ilib]->getLibrary();
}
return NULL;
}
unsigned int AllianceFramework::loadLibraryCells ( Library *library )
{
cmess2 << " " << tab++ << "+ Library: " << getString(library->getName()) << endl;

View File

@ -86,6 +86,7 @@ namespace CRL {
inline const Name& getParentLibraryName () const;
inline Library* getParentLibrary ();
Library* getLibrary ( unsigned int index );
Library* getLibrary ( const Name& libName );
AllianceLibrary* getAllianceLibrary ( unsigned int index );
AllianceLibrary* getAllianceLibrary ( const Name& libName, unsigned int flags );
AllianceLibrary* getAllianceLibrary ( Library* );

View File

@ -31,6 +31,7 @@
PyCatalog.cpp
PyCatalogState.cpp
PyEnvironment.cpp
PyAllianceLibrary.cpp
PyCellGauge.cpp
PyRoutingGauge.cpp
PyRoutingLayerGauge.cpp
@ -47,6 +48,7 @@
crlcore/PyCatalog.h
crlcore/PyCatalogState.h
crlcore/PyEnvironment.h
crlcore/PyAllianceLibrary.h
crlcore/PyCellGauge.h
crlcore/PyRoutingGauge.h
crlcore/PyRoutingLayerGauge.h

View File

@ -20,6 +20,7 @@
#include "crlcore/PyEnvironment.h"
#include "crlcore/PyCellGauge.h"
#include "crlcore/PyRoutingGauge.h"
#include "crlcore/PyAllianceLibrary.h"
#include "crlcore/PyAllianceFramework.h"
#include "crlcore/GraphicsParser.h"
#include "crlcore/SymbolicTechnologyParser.h"
@ -39,6 +40,8 @@ namespace CRL {
using Hurricane::Error;
using Hurricane::Warning;
using Hurricane::DataBase;
using Isobar::__cs;
using Isobar::Converter;
using Isobar::ProxyProperty;
using Isobar::ProxyError;
using Isobar::ConstructorError;
@ -112,7 +115,7 @@ extern "C" {
}
extern PyObject* PyAllianceFramework_getEnvironment ( PyAllianceFramework* self )
static PyObject* PyAllianceFramework_getEnvironment ( PyAllianceFramework* self )
{
trace << "PyAllianceFramework_getEnvironment ()" << endl;
@ -130,9 +133,9 @@ extern "C" {
}
extern PyObject* PyAllianceFramework_getLibrary ( PyAllianceFramework* self, PyObject* args )
static PyObject* PyAllianceFramework_getLibrary ( PyAllianceFramework* self, PyObject* args )
{
trace << "PyAllianceFramework_getLibrary ()" << endl;
trace << "PyAllianceFramework_getLibrary()" << endl;
Library* lib = NULL;
@ -140,18 +143,62 @@ extern "C" {
METHOD_HEAD("AllianceFramework.getLibrary()")
PyObject* arg0;
if ( not ParseOneArg ( "AllianceFramework.getLibrary()", args, INT_ARG, &arg0 ) ) return NULL;
__cs.init ("AllianceFramework.getLibrary");
if (not PyArg_ParseTuple( args, "O&:AllianceFramework.getLibrary", Converter, &arg0)) {
PyErr_SetString( ConstructorError, "Invalid number of parameters for AllianceFramework.getLibrary()." );
return NULL;
}
lib = af->getLibrary ( PyAny_AsLong(arg0) );
if ( lib == NULL ) Py_RETURN_NONE;
if (__cs.getObjectIds() == STRING_ARG) lib = af->getLibrary( Name(PyString_AsString(arg0)) );
else if (__cs.getObjectIds() == INT_ARG ) lib = af->getLibrary( PyAny_AsLong(arg0) );
else {
PyErr_SetString( ConstructorError, "Bad parameter type for AllianceFramework.getLibrary()." );
return NULL;
}
if (lib == NULL) Py_RETURN_NONE;
HCATCH
return PyLibrary_Link(lib);
}
extern PyObject* PyAllianceFramework_getCell ( PyAllianceFramework* self, PyObject* args )
static PyObject* PyAllianceFramework_getAllianceLibrary ( PyAllianceFramework* self, PyObject* args )
{
trace << "PyAllianceFramework_getAllianceLibrary()" << endl;
AllianceLibrary* alib = NULL;
HTRY
METHOD_HEAD("AllianceFramework.getAllianceLibrary()")
PyObject* arg0;
PyObject* arg1;
__cs.init ("AllianceFramework.getAllianceLibrary");
if (not PyArg_ParseTuple( args
, "O&|O&:AllianceFramework.getAllianceLibrary"
, Converter, &arg0
, Converter, &arg1)) {
PyErr_SetString( ConstructorError, "Invalid number of parameters for AllianceFramework.getLibrary()." );
return NULL;
}
if (__cs.getObjectIds() == INT_ARG ) alib = af->getAllianceLibrary( PyAny_AsLong(arg0) );
else if (__cs.getObjectIds() == ":string:int") alib = af->getAllianceLibrary( Name(PyString_AsString(arg0)), PyAny_AsLong(arg1) );
else if (__cs.getObjectIds() == ":library" ) alib = af->getAllianceLibrary( PYLIBRARY_O(arg0) );
else {
PyErr_SetString( ConstructorError, "Bad parameter type for AllianceFramework.getAllianceLibrary()." );
return NULL;
}
if (alib == NULL) Py_RETURN_NONE;
HCATCH
return PyAllianceLibrary_Link(alib);
}
static PyObject* PyAllianceFramework_getCell ( PyAllianceFramework* self, PyObject* args )
{
trace << "PyAllianceFramework_getCell ()" << endl;
@ -174,7 +221,7 @@ extern "C" {
}
extern PyObject* PyAllianceFramework_saveCell ( PyAllianceFramework* self, PyObject* args )
static PyObject* PyAllianceFramework_saveCell ( PyAllianceFramework* self, PyObject* args )
{
trace << "PyAllianceFramework_saveCell ()" << endl;
@ -195,7 +242,7 @@ extern "C" {
}
extern PyObject* PyAllianceFramework_createCell ( PyAllianceFramework* self, PyObject* args )
static PyObject* PyAllianceFramework_createCell ( PyAllianceFramework* self, PyObject* args )
{
trace << "PyAllianceFramework_createCell ()" << endl;
@ -217,6 +264,45 @@ extern "C" {
}
static PyObject* PyAllianceFramework_createLibrary ( PyAllianceFramework* self, PyObject* args )
{
trace << "PyAllianceFramework_createLibrary()" << endl;
AllianceLibrary* alib = NULL;
string libName = "";
HTRY
METHOD_HEAD("AllianceFramework.createLibrary()")
PyObject* arg0;
PyObject* arg1;
PyObject* arg2;
__cs.init ("AllianceFramework.createLibrary");
if (not PyArg_ParseTuple( args
, "O&O&|O&:AllianceFramework.createLibrary"
, Converter, &arg0
, Converter, &arg1
, Converter, &arg2
)) {
PyErr_SetString( ConstructorError, "Invalid number of parameters for AllianceFramework.createLibrary()." );
return NULL;
}
if (__cs.getObjectIds() == ":string:int" ) { }
else if (__cs.getObjectIds() == ":strint:int:string") libName = PyString_AsString(arg2);
else {
PyErr_SetString( ConstructorError, "Bad parameter type for AllianceFramework.createLibrary()." );
return NULL;
}
alib = af->createLibrary( PyString_AsString(arg0), PyAny_AsLong(arg1), libName );
if (alib == NULL) Py_RETURN_NONE;
HCATCH
return PyAllianceLibrary_Link(alib);
}
static PyObject* PyAllianceFramework_isPad ( PyAllianceFramework* self, PyObject* args )
{
trace << "PyAllianceFramework_isPad ()" << endl;
@ -238,7 +324,7 @@ extern "C" {
}
extern PyObject* PyAllianceFramework_addRoutingGauge ( PyAllianceFramework* self, PyObject* args )
static PyObject* PyAllianceFramework_addRoutingGauge ( PyAllianceFramework* self, PyObject* args )
{
trace << "PyAllianceFramework_addRoutingGauge ()" << endl;
@ -254,7 +340,7 @@ extern "C" {
}
extern PyObject* PyAllianceFramework_getRoutingGauge ( PyAllianceFramework* self, PyObject* args )
static PyObject* PyAllianceFramework_getRoutingGauge ( PyAllianceFramework* self, PyObject* args )
{
trace << "PyAllianceFramework_getRoutingGauge ()" << endl;
@ -278,7 +364,7 @@ extern "C" {
}
extern PyObject* PyAllianceFramework_addCellGauge ( PyAllianceFramework* self, PyObject* args )
static PyObject* PyAllianceFramework_addCellGauge ( PyAllianceFramework* self, PyObject* args )
{
trace << "PyAllianceFramework_addCellGauge ()" << endl;
@ -294,7 +380,7 @@ extern "C" {
}
extern PyObject* PyAllianceFramework_getCellGauge ( PyAllianceFramework* self, PyObject* args )
static PyObject* PyAllianceFramework_getCellGauge ( PyAllianceFramework* self, PyObject* args )
{
trace << "PyAllianceFramework_getCellGauge ()" << endl;
@ -317,6 +403,35 @@ extern "C" {
return PyCellGauge_Link(rg);
}
static PyObject* PyAllianceFramework_loadLibraryCells ( PyAllianceFramework* self, PyObject* args )
{
trace << "PyAllianceFramework_loadLibraryCells()" << endl;
unsigned int count = 0;
HTRY
METHOD_HEAD("AllianceFramework.loadLibraryCells()")
PyObject* arg0;
__cs.init ("AllianceFramework.loadLibraryCells");
if (not PyArg_ParseTuple( args, "O&:AllianceFramework.loadLibraryCells", Converter, &arg0)) {
PyErr_SetString( ConstructorError, "Invalid number of parameters for AllianceFramework.loadLibraryCells()." );
return NULL;
}
if (__cs.getObjectIds() == STRING_ARG) count = af->loadLibraryCells( Name(PyString_AsString(arg0)) );
else if (__cs.getObjectIds() == ":library") count = af->loadLibraryCells( PYLIBRARY_O(arg0) );
else {
PyErr_SetString( ConstructorError, "Bad parameter type for AllianceFramework.loadLibraryCells()." );
return NULL;
}
HCATCH
return Py_BuildValue( "I", count );
}
// Standart Accessors (Attributes).
@ -334,12 +449,18 @@ extern "C" {
, "Gets the Alliance Environment." }
, { "getLibrary" , (PyCFunction)PyAllianceFramework_getLibrary , METH_VARARGS
, "Gets a Library, by index." }
, { "getAllianceLibrary" , (PyCFunction)PyAllianceFramework_getAllianceLibrary , METH_VARARGS
, "Gets an AllianceLibrary, by index, name or Hurricane Library." }
, { "getCell" , (PyCFunction)PyAllianceFramework_getCell , METH_VARARGS
, "Gets an Alliance Cell." }
, { "saveCell" , (PyCFunction)PyAllianceFramework_saveCell , METH_VARARGS
, "Saves an Alliance Cell." }
, { "createCell" , (PyCFunction)PyAllianceFramework_createCell , METH_VARARGS
, "Create a Cell in the Alliance framework." }
, { "createLibrary" , (PyCFunction)PyAllianceFramework_createLibrary , METH_VARARGS
, "Create a Library in the Alliance framework." }
, { "loadLibraryCells" , (PyCFunction)PyAllianceFramework_loadLibraryCells , METH_VARARGS
, "Load in memory all Cells from an Alliance Library." }
, { "isPad" , (PyCFunction)PyAllianceFramework_isPad , METH_VARARGS
, "Tells if a cell name is a Pad." }
, { "addCellGauge" , (PyCFunction)PyAllianceFramework_addCellGauge , METH_VARARGS
@ -376,7 +497,10 @@ extern "C" {
{
PyObject* constant;
LoadObjectConstant(PyTypeAllianceFramework.tp_dict,AllianceFramework::NoPythonInit,"NoPythonInit");
LoadObjectConstant(PyTypeAllianceFramework.tp_dict,AllianceFramework::NoPythonInit ,"NoPythonInit" );
LoadObjectConstant(PyTypeAllianceFramework.tp_dict,AllianceFramework::CreateLibrary,"CreateLibrary");
LoadObjectConstant(PyTypeAllianceFramework.tp_dict,AllianceFramework::AppendLibrary,"AppendLibrary");
LoadObjectConstant(PyTypeAllianceFramework.tp_dict,AllianceFramework::HasCatalog ,"HasCatalog" );
}

View File

@ -0,0 +1,146 @@
// -*- C++ -*-
//
// This file is part of the Coriolis Software.
// Copyright (c) UPMC 2016-2016, 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 : "./PyAllianceLibrary.cpp" |
// +-----------------------------------------------------------------+
#include "hurricane/isobar/PyLibrary.h"
#include "crlcore/PyAllianceLibrary.h"
#include <string>
#include <sstream>
namespace CRL {
using std::cerr;
using std::endl;
using std::hex;
using std::string;
using std::ostringstream;
using Hurricane::tab;
using Hurricane::in_trace;
using Hurricane::Exception;
using Hurricane::Bug;
using Hurricane::Error;
using Hurricane::Warning;
using Hurricane::Library;
using Isobar::ProxyProperty;
using Isobar::ProxyError;
using Isobar::ConstructorError;
using Isobar::HurricaneError;
using Isobar::HurricaneWarning;
using Isobar::ParseOneArg;
using Isobar::ParseTwoArg;
using Isobar::__cs;
using Isobar::PyLibrary_Link;
extern "C" {
#define METHOD_HEAD(function) GENERIC_METHOD_HEAD(AllianceLibrary,alib,function)
#if defined(__PYTHON_MODULE__)
// +=================================================================+
// | "PyAllianceLibrary" Python Module Code Part |
// +=================================================================+
static PyObject* PyAllianceLibrary_getLibrary ( PyAllianceLibrary* self, PyObject* args )
{
trace << "PyAllianceLibrary_getLibrary()" << endl;
Library* lib = NULL;
HTRY
METHOD_HEAD("AllianceLibrary.getLibrary()")
lib = alib->getLibrary();
HCATCH
return PyLibrary_Link(lib);
}
static PyObject* PyAllianceLibrary_getPath ( PyAllianceLibrary* self, PyObject* args )
{
trace << "PyAllianceLibrary_getPath()" << endl;
HTRY
METHOD_HEAD("AllianceLibrary.getPath()")
return PyString_FromString( getString(alib->getPath()).c_str() );
HCATCH
return NULL;
}
static PyObject* PyAllianceLibrary_Repr ( PyAllianceLibrary* self )
{
if ( self->ACCESS_OBJECT == NULL )
return PyString_FromString("<PyObject unbound>");
string s = getString( self->ACCESS_OBJECT );
return PyString_FromString( s.c_str() );
}
// Standart Destroy (Attribute).
// DBoDestroyAttribute(PyAllianceLibrary_destroy,PyAllianceLibrary)
PyMethodDef PyAllianceLibrary_Methods[] =
{ { "getPath" , (PyCFunction)PyAllianceLibrary_getPath , METH_NOARGS
, "Return the complete path of the library." }
, { "getLibrary" , (PyCFunction)PyAllianceLibrary_getLibrary , METH_NOARGS
, "Returns the associated Hurricane library." }
//, { "destroy" , (PyCFunction)PyAllianceLibrary_destroy , METH_VARARGS
// , "Destroy the associated hurricane object. The python object remains." }
, {NULL, NULL, 0, NULL} /* sentinel */
};
PythonOnlyDeleteMethod(AllianceLibrary)
DirectHashMethod(PyAllianceLibrary_Hash, PyAllianceLibrary)
extern void PyAllianceLibrary_LinkPyType() {
trace << "PyAllianceLibrary_LinkType()" << endl;
PyTypeAllianceLibrary.tp_dealloc = (destructor) PyAllianceLibrary_DeAlloc;
PyTypeAllianceLibrary.tp_repr = (reprfunc) PyAllianceLibrary_Repr;
PyTypeAllianceLibrary.tp_str = (reprfunc) PyAllianceLibrary_Repr;
PyTypeAllianceLibrary.tp_hash = (hashfunc) PyAllianceLibrary_Hash;
PyTypeAllianceLibrary.tp_methods = PyAllianceLibrary_Methods;
}
#else // End of Python Module Code Part.
// +=================================================================+
// | "PyAllianceLibrary" Shared Library Code Part |
// +=================================================================+
// Type Definition.
PyTypeObjectDefinitionsOfModule(CRL,AllianceLibrary)
// Link/Creation Method.
LinkCreateMethod(AllianceLibrary)
#endif // End of Shared Library Code Part.
} // extern "C".
} // CRL namespace.

View File

@ -22,6 +22,7 @@
#include "crlcore/PyCatalogState.h"
#include "crlcore/PyAllianceFramework.h"
#include "crlcore/PyEnvironment.h"
#include "crlcore/PyAllianceLibrary.h"
#include "crlcore/PyCellGauge.h"
#include "crlcore/PyRoutingGauge.h"
#include "crlcore/PyRoutingLayerGauge.h"
@ -109,6 +110,7 @@ extern "C" {
PyCatalogState_LinkPyType ();
PyCatalog_LinkPyType ();
PyEnvironment_LinkPyType ();
PyAllianceLibrary_LinkPyType ();
PyCellGauge_LinkPyType ();
PyRoutingGauge_LinkPyType ();
PyRoutingLayerGauge_LinkPyType ();
@ -124,6 +126,7 @@ extern "C" {
PYTYPE_READY ( CatalogState );
PYTYPE_READY ( Catalog );
PYTYPE_READY ( Environment );
PYTYPE_READY ( AllianceLibrary );
PYTYPE_READY ( CellGauge );
PYTYPE_READY ( RoutingGauge );
PYTYPE_READY ( RoutingLayerGaugeVector );
@ -138,6 +141,7 @@ extern "C" {
PYTYPE_READY ( Blif );
// Identifier string can take up to 10 characters.
__cs.addType ( "alcLib" , &PyTypeAllianceLibrary , "<AllianceLibrary>" , false );
__cs.addType ( "alcEnv" , &PyTypeEnvironment , "<Environment>" , false );
__cs.addType ( "cellGauge" , &PyTypeCellGauge , "<CellGauge>" , false );
__cs.addType ( "routGauge" , &PyTypeRoutingGauge , "<RoutingGauge>" , false );
@ -157,6 +161,8 @@ extern "C" {
PyModule_AddObject ( module, "Banner", (PyObject*)&PyTypeBanner );
Py_INCREF ( &PyTypeCatalog );
PyModule_AddObject ( module, "Catalog", (PyObject*)&PyTypeCatalog );
Py_INCREF ( &PyTypeAllianceLibrary );
PyModule_AddObject ( module, "AllianceLibrary", (PyObject*)&PyTypeAllianceLibrary );
Py_INCREF ( &PyTypeEnvironment );
PyModule_AddObject ( module, "Environment", (PyObject*)&PyTypeEnvironment );
Py_INCREF ( &PyTypeCellGauge );

View File

@ -0,0 +1,59 @@
// -*- C++ -*-
//
// This file is part of the Coriolis Software.
// Copyright (c) UPMC 2016-2016, 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/PyAllianceLibrary.h" |
// +-----------------------------------------------------------------+
#ifndef CRL_PY_ALLIANCE_LIBRARY_H
#define CRL_PY_ALLIANCE_LIBRARY_H
#include "hurricane/isobar/PyHurricane.h"
#include "crlcore/AllianceLibrary.h"
namespace CRL {
extern "C" {
// -------------------------------------------------------------------
// Python Object : "PyAllianceLibrary".
typedef struct {
PyObject_HEAD
AllianceLibrary* _object;
} PyAllianceLibrary;
// -------------------------------------------------------------------
// Functions & Types exported to "PyCRL.ccp".
extern PyTypeObject PyTypeAllianceLibrary;
extern PyMethodDef PyAllianceLibrary_Methods[];
extern PyObject* PyAllianceLibrary_Link ( AllianceLibrary* );
extern void PyAllianceLibrary_LinkPyType ();
#define IsPyAllianceLibrary(v) ( (v)->ob_type == &PyTypeAllianceLibrary )
#define PYALLIANCE_LIBRARY(v) ( (PyAllianceLibrary*)(v) )
#define PYALLIANCE_LIBRARY_O(v) ( PYALLIANCE_LIBRARY(v)->_object )
} // extern "C".
} // Hurricane namespace.
#endif // __CRL_PY_ALLIANCE_LIBRARY__